Java Reference
In-Depth Information
public Time() {
// bind the angle properties to the clock time
hourAngleProperty.bind((hoursProperty * 30.0) + (minutesProperty * 0.5))
minuteAngleProperty.bind(minutesProperty * 6.0)
secondAngleProperty.bind(secondsProperty * 6.0)
...
}
The combination of automatic properties expansion via AST transforms and infix notation binding lets you
express fairly complex logic without much code. The resulting Groovy analog clock graphic UI that you get when
running the example is shown in Figure 13-7 .
Figure 13-7. Groovy analog clock demo
GroovyFX API Enhancements
In addition to the core language benefits of using Groovy instead of JavaFX, GroovyFX has taken many of the JavaFX
APIs and Groovy-ized them to make them easier to use from a dynamic language. We cover three major ones in this
section: the GroovyFX custom DSL for animation, a simplified table construction pattern, and streamlined JavaFX
layouts. All of these provide significant benefits over the core JavaFX APIs, allowing you to write less code and do more.
Animation
GroovyFX supports building animations using a special DSL that has syntax for creating Duration s, KeyFrame s, and
KeyValue s, all with a concise syntax. We showed an example of the Groovy animation syntax earlier in the Vanishing
Circles application, which looked like this:
timeline {
at(3.s) { change e.source.radiusProperty() to 0 }
}.play()
 
Search WWH ::




Custom Search