Java Reference
In-Depth Information
The basic pattern is as follows, where you can have multiple at expressions in a timeline and multiple change
expressions within an at.
timeline {
at(duration) {
[change property to value]
}
}
Similar to binding, there is also a second format for referring to the property that makes up the change expression:
timeline {
at(3.s) { change(e.source, 'radius') to 0 }
}.play()
The syntax also supports an optional tween that lets you provide a curve for the speed at which the animation
proceeds:
timeline {
at(3.s) { change e.source.radiusProperty() to 0 tween ease_both }
}.play()
With the preceding change, the animation would start out slow and speed up to its normal rate, and then slow
down at the end the same way.
Compared to the full Java code, the Groovy animation syntax is a huge savings in characters and makes it much
easier to see what your animation is actually doing.
Tables
Between the extra syntactic sugar for builders or imperative Java, and the need to specify Generic at multiple levels,
building simple data tables in Java code can be quite a lot of code. Groovy simplifies this with a fairly intuitive builder
format for creating tables, along with some conveniences, such as a built-in type converter that lets you specify a
closure to change the output type for a field.
As a result, you can write fairly complex tables with very little code. The following example builds from the Person
class that we created earlier to display a list of people in a tabular format. The full code is shown in Listing 13-8.
Listing 13-8. Code Demonstrating a Table in Groovy with Strings, ints, and Dates
import groovyx.javafx.GroovyFX
import groovyx.javafx.SceneGraphBuilder
import binding.Person
import java.text.SimpleDateFormat
def dateFormat = new SimpleDateFormat("MM/dd/yyyy")
def persons = [
new Person(name: "Ada Lovelace", age: 36, gender: "Female",
dob: dateFormat.parse("10/10/1815")),
new Person(name: "Henrietta Swan Leavitt", age: 53, gender: "Female",
dob: dateFormat.parse("7/4/1868")),
new Person(name: "Grete Hermann", age: 83, gender: "Female",
dob: dateFormat.parse("3/2/1901"))
]
 
Search WWH ::




Custom Search