Java Reference

In-Depth Information

How it works...

The JavaFX Transformation API applies operations that transform the geometric properties of

the target shapes relative to their current spatial attributes. All node instances in the scene

graph are capable of receiving transformations. In the previous example, we are applying two

transformation operations to the rectangle: Translate and Scale. As of version 1.2, the JavaFX

SDK provides the transform operations listed next. You can find an example of their usage at

ch03/source-code/src/transformation/
.

F
Translate
—shifts all
x
and
y
points of the node to new co-ordinate space relative to

its original co-ordinate space.

F
Scale
—stretches (scales) the dimension of a node by a specified factor. The number

specified in the scale operation is a multiplier, not a dimension.

F
Shear
—all points along the specified axis remain constant while the parallel side is

shifted by a given factor.

F
Rotate
—rotates a node for the specified number of degrees about a given

pivot point.

You can instantiate transformation classes using the object literal form (as shown in

the previous example), or you may use class-level functions from
Transform
including

Transform.translate()
,
Transform.scale()
,
Transform.shear()
, and

Transform.rotate()
.

In the code snippet for this recipe, we apply the transformation operations using the

transforms:Transform[]
property. This approach allows you to attach several

transformations to the target shape. In this example, the transforms sequence is applied

when the shape receives a mouse event.

There's more...

Besides the
transforms
sequence property discussed earlier in this recipe, the
Node

class (inherited by all shapes) also exposes individual properties to apply the transformation

operations, shown next:

F
translateX
or
translateY
—these properties allow you to specify a value used to

shift the node's co-ordinate space along the x or y axis

F
scaleX
or
scaleY
—this value is used as a factor to scale the dimension of the

object along the
x
or
y
axis about the center of the object

F
rotate
—this value is the degree used to rotate the object about its center

See also

F
Chapter 2—Drawing simple shapes