Java Reference
In-Depth Information
Named constructor parameters : When initializing an object with a constructor, you can also
set fields on the class by referring to them by name. This pattern is used quite a bit in our
GroovyFX code later.
Built-in data structure syntax : Many commonly used data structures, such as Lists and Maps,
have a built-in syntax in Groovy, which makes it much more convenient to work with them
and build them dynamically.
Using JavaFX directly from Groovy is possible; however, you are missing out on a lot of the benefits of Groovy
without using a dedicated DSL library, such as GroovyFX. In the next few sections we show you some of the benefits
of writing JavaFX code using the Groovy language and GroovyFX library.
Introduction to GroovyFX
GroovyFX is a library for developing JavaFX applications in Groovy that lets you build your application in a more
Groovy-like fashion. It was started by Jim Clarke and Dean Iverson, one of the coauthors of this title, and is being
developed as an open source Groovy module. Russel Winder, who is a well-known expert on Groovy, has updated it
for Java 8. The main landing page for GroovyFX is on GitHub at http://groovyfx-project.github.com/ .
Some of the benefits of writing code using GroovyFX, rather than simply coding directly against the JavaFX APIs
include the following:
Builder pattern : GroovyFX has Groovy builders for all the major JavaFX classes, making it easy
and convenient to declaratively construct a scene graph.
Property generation : The JavaFX property pattern for writing your own properties is quite
long-winded, but is replaced with a one-line annotation in GroovyFX.
Timeline DSL : GroovyFX has a convenient shorthand syntax for animation.
Convenient bind syntax : GroovyFX makes creating bindings much more terse and readable
than the equivalent Java code.
API improvements : A lot of the JavaFX APIs have been tweaked and enhanced to make them
easier to use.
To get you started using GroovyFX, we walk you through setting up a small GroovyFX project from scratch. These
directions assume that you already have a current Java and JavaFX 8 SDK installed on your system. Also, we have
chosen to tailor the instructions for the IntelliJ Community Edition, which is a free, open source IDE with a long track
record of excellent Groovy support. There is also Groovy support for Eclipse, NetBeans, and many other IDEs, so if you
have a preference for a different IDE, you can easily adapt these instructions to work with your IDE of choice.
To start with, download and install the latest version of IntelliJ IDEA. The community edition comes with
Groovy support, so there is no need to purchase the Ultimate Edition. The IntelliJ web site can be found at
http://www.jetbrains.com/idea .
After installing and launching IntelliJ, you need to create a new Java project with Groovy language support
enabled. On the landing page you can click Create New Project, or if you are on a different screen you can get to the
same wizard by selecting New Project . . . from the File menu. This will present you with the New Project Wizard shown
in Figure 13-2 .
 
Search WWH ::




Custom Search