Scala에 적합한 GUI 프레임 워크?
적절하다는 의미는 다음과 같습니다.
- 성숙하고 광범위하게 사용
- 잘 렌더링되는 풍부한 위젯 세트
- 관용적 스칼라
- WYSIWYG 같지만 유연한 GUI 빌더가 있습니다.
- 독립형 API 문서 (래퍼 인 경우 다른 언어로 상위 프로젝트를 참조하게해서는 안 됨)
특별한 순서는 없습니다.
어떤 GUI 툴킷이 어떤 조건을 충족합니까?
Scala에는 자체 Swing 라이브러리가 있습니다. 이것은 내부에서 표준 Swing 라이브러리를 사용하지만 몇 가지 멋진 추가 기능이 있으며 특히 Scala 용으로 제작 되었기 때문에 표준 Swing 라이브러리보다 훨씬 간결한 방식으로 사용할 수 있습니다.
import swing._
object HelloWorld extends SimpleSwingApplication {
def top = new MainFrame {
title = "Hello, World!"
contents = new Button {
text = "Click Me!"
}
}
}
위젯 속성을 설정하는 것이 얼마나 좋고 쉬운 지 보십니까?
더 좋은 구문과 ( SimpleSwingApplication
클래스 와 같은) 작은 추가를 제외하고 는 장점과 단점이 vanilla Swing과 거의 동일하다고 생각합니다.
다음 은 Scala Swing 의 개요입니다 .
ScalaFX는 JavaFX 2를 중심으로 한 성숙한 래퍼입니다. 일부 측면에서 Scala Swing과 겉으로는 유사하지만 눈에 띄는 몇 가지 기능이 있습니다.
네이티브 그래픽 라이브러리에 대한 결합-이것은 하드웨어 가속 및 기타 장점에 대한 액세스를 의미하지만 시스템에 JavaFX 런타임을 설치해야합니다. Java 8의 대부분의 주요 배포판에 포함되어 있습니다. 이것은 또한 호환되는 시스템에서 매우 잘 렌더링된다는 것을 의미합니다.
속성 바인딩-이것은 나를위한 킬러 기능입니다. 세 가지 요소
A
인B
,,C
.A
및B
크기 조정, 그리고C
의 높이의 합 높이가하도록되어A
하고B
항상있다. Swing에서는이 작업을 수행하기 위해 사용자 정의 이벤트 리스너 세트를 작성해야합니다. ScalaFX 바인딩을 사용하면 속성 바인딩 연산자를 사용하여 간단하게이를 표현할 수 있습니다C.height <== A.height + B.height
. 이것은 다른 기능 중에서도 매우 Scala-idiomatic 느낌을줍니다.JavaFX Scene Builder (작성 당시 베타 버전)는 WYSIWYG GUI 편집기입니다 (하지만 시도해 보지 않았습니다).
문서화는 약점입니다. 래퍼이기 때문에 종종 JavaFX 문서를 다시 참조합니다.
Java Swing을 사용합니다. 요구 사항과 비교하여 누적되는 방법은 다음과 같습니다.
성숙하고 광범위하게 사용됨 : 예, 톤.
풍부한 위젯이 잘 설정되고 렌더링됩니다. 이것은 논쟁의 여지가 있습니다. 추가 라이브러리 (예 : SwingX)로 Java Swing을 쉽게 보완 할 수있는 기능을 고려할 때, 적어도이 점에서 Scala Swing보다 낫지 만 다른 Java 툴킷 만큼은 아니지만 (그것에 대해 말할 수는 없지만) .
관용적 스칼라 : 생각만큼 나쁘지는 않습니다. 몇 가지 도우미 기능이 더 좋습니다.
implicit class And[A](a: A) { def and(f: A => Unit): A = { f(a); a } }
할 수 있도록
val button = (new JButton("Press me!") and (_ setForeground Color.red) and (_ setFont new Font(null, Font.PLAIN, 12))) val win = (new JFrame("Hello!") and (_ add button) and (_ pack()) and (_ setDefaultCloseOperation JFrame.EXIT_ON_CLOSE) and (_ setVisible(true)))
이제 이벤트와 상태에 관해서는 여전히 모든 GUI 프레임 워크 에서 거친 가장자리라고 생각합니다. 청취자에게는 문제가 있고 이벤트 스트림에는 문제가 있습니다. 나는 상태를 더 쉽게 구성 할 수 있도록 반응 코어 및 재실행 신호 (내 자신, 문서화되지 않음)로 Swing의 이벤트를 보강하는 데 일반적으로 성공했습니다 .
You can improve the verbosity of defining listeners with a few more helper functions like
def actionListener(f: => Unit) = new ActionListener { def actionPerformed(e: ActionEvent) { f } }
and
def later(thing: => Unit) { SwingUtilities.invokeLater(new Runnable { def run() { thing } }) }
Personally, I wish Scala Swing had taken this route. Writing wrappers for existing Java classes is O(n) programmer time, and doesn't get you anything for the classes that the authors didn't choose to write wrappers for. Creating generic syntactic sugar will take you much farther faster.
Got a WYSIWYG-ish but flexible GUI builder: I use IntelliJ IDEA forms, to make an abstract class, and then subclass it with a Scala class. The organizational cost is only 1 extra file, and I write no Java code.
Standalone API documentation: Yes.
Now that some time has passed, it's worth noting that ScalaJS is also an option to consider.
Against your requirements:
- mature and used extensively -- HTML/CSS/JS are, ScalaJS is not (but it's surprisingly good considering). So, you may run into ScalaJS-specific hangups, but the underlying technology is very robust.
- rich widget set that renders well -- Yes.
- idiomatic Scala -- No: you'll end up using a lot of jquery, which will mostly be dynamically typed. ScalaTags does a lot towards making it better though.
- Got a WYSIWYG-ish but flexible GUI builder -- Yes, many.
- standalone API documentation (if a wrapper, it shouldnt make me refer the parent project in another language) -- Yes.
The downside is that it takes your GUI off the JVM and into the browser, so you can't use all those Java libraries.
I'd say use .Net its mature and used extensively.
But ...
I assume that you require to use Scala. For that I'd stick to Java as it has better tool support like in IDEA or NetBeans. You can of course mix Java and Scala. So your GUI can be done in Java that calls Scala backend. Also take a look at JGoodies they have lot of nice stuff to build UI in Swing. At this moment there is no tool support for Scala GUI applications (and for non GUI it is still behind Java).
참고URL : https://stackoverflow.com/questions/10497118/suitable-gui-framework-for-scala
'Programing' 카테고리의 다른 글
암호화없이 PHP 코드를 보호하는 최상의 솔루션 (0) | 2020.11.09 |
---|---|
Fabrice Bellard의 Javascript에서 Linux 에뮬레이터는 어떻게 작동합니까? (0) | 2020.11.09 |
PL / SQL에서 함수와 프로 시저의 차이점은 무엇입니까? (0) | 2020.11.09 |
HTML에서 소수점 정렬 (0) | 2020.11.09 |
판매 통계는 iTunes Connect에서 얼마나 자주 업데이트됩니까? (0) | 2020.11.09 |