Pathnode that provides facilities required for assembly and management of a geometric path (to create custom shapes). JavaFX also has animation support to gradually change a
Nodeproperty, creating a visual transition between two states. TornadoFX seeks to streamline all these features through builder constructs.
0.0. This means that you only need to provide the parameters you care about. The builders have positional parameters for most of the properties of each shape, and the rest can be set in the functional block that follows. Therefore these are all valid ways to create a rectangle:
HBoxwill not care about the
ycoordinates you specify unless you call
setManaged(false)on the shape. However, a
Groupcontrol will. The screenshots in the following examples will be created by wrapping a
StackPanewith padding around a
Group, and finally the shape was created inside that
Groupas shown below.
Rectangledefines a rectangle with an optional size and location in the parent. Rounded corners can be specified with the
arcHeightproperties (Figure 9.1).
Arcrepresents an arc object defined by a center, start angle, angular extent (length of the arc in degrees), and an arc type (
ROUND) (Figure 9.2)
Circlerepresents a circle with the specified
CubicCurverepresents a cubic Bézier parametric curve segment in (x,y) coordinate space. Drawing a curve that intersects both the specified coordinates (
startY) and (
enfY), using the specified points (
controlY1) and (
controlY2) as Bézier control points.
Ellipserepresents an ellipse with parameters specifying size and location.
Polylineis defined by an array of segment points.
Polylineis similar to
Polygon, except it is not automatically closed.
Quadcurverepresents a quadratic Bézier parametric curve segment in (x,y) coordinate space. Drawing a curve that intersects both the specified coordinates (
startY) and (
endY), using the specified point (
controlY) as Bézier control point.
SVGPathrepresents a shape that is constructed by parsing SVG path data from a String.
Pathrepresents a shape and provides facilities required for basic construction and management of a geometric path. In other words, it helps you create a custom shape. The following helper functions can be used to constuct the path:
quadqurveTo(controlX, controlY, x, y)
arcTo(radiusX, radiusY, xAxisRotation, x, y, largeArcFlag, sweepFlag)
Nodeby gradually changing one or more of its properties. There are three components you work with to create animations in JavaFX.
Timeline- A sequence of
KeyFrameitems executed in a specified order
KeyFrame- A "snapshot" specifying value changes on one or more writable properties (via a
KeyValue) on one or more Nodes
KeyValue- A pairing of a
Nodeproperty to a value that will be "transitioned" to
KeyValueis the basic building block of JavaFX animation. It specifies a property and the "new value" it will gradually be transitioned to. So if you have a
0.0, and you specify a
KeyValuethat changes it to
90.0degrees, it will incrementally move from
90.0degrees. Put that
KeyFramewhich will specify how long the animation between those two values will last. In this case let's make it 5 seconds. Then finally put that
Timeline. If you run the code below, you will see a rectange gradually rotate from `0.0` to `90.0` degrees in 5 seconds (Figure 9.1).
KeyFrame, you can simultaneously manipulate other properties in that 5-second window too. For instance we can transition the
Rectangleis rotating (Figure 9.2)
Interpolatorwhich can add subtle effects to the animation. For instance, you can specify
Interpolator.EASE_BOTHto accelerate and decelerate the value change at the beginning and end of the animation gracefully.
cycleCountwill repeat the animation a specified number of times, and setting the
isAutoReverseto true will cause it to revert back with each cycle.
keyset(). Call the
animate()extension function on that propert and provide the
duration, and optionally the
interoplator. This is much shorter and cleaner if you are animating just one property.
Canvasas this is beyond the scope of the
TornadoFXframework. It could easily take up more than several chapters on its own. But the shapes and animation should allow you to do basic custom graphics for a majority of tasks.