Top Description Inners Fields Constructors Methods
javafx.animation

public final Class PathTransition

extends Transition
Class Inheritance
Imports
javafx.beans.property.ObjectProperty, .ObjectPropertyBase, .SimpleObjectProperty, javafx.scene.Node, javafx.scene.shape.Shape, javafx.util.Duration, com.sun.javafx.geom.PathIterator, com.sun.javafx.scene.NodeHelper, com.sun.javafx.scene.shape.ShapeHelper, java.util.ArrayList

This Transition creates a path animation that spans its duration. The translation along the path is done by updating the translateX and translateY variables of the node, and the rotate variable will get updated if orientation is set to OrientationType.ORTHOGONAL_TO_TANGENT, at regular intervals.

The animated path is defined by the outline of a shape.

Code Segment Example:


import javafx.scene.shape.*;
import javafx.animation.*;

...

    Rectangle rect = new Rectangle (100, 40, 100, 100);
    rect.setArcHeight(50);
    rect.setArcWidth(50);
    rect.setFill(Color.VIOLET);


    Path path = new Path();
    path.getElements().add (new MoveTo (0f, 50f));
    path.getElements().add (new CubicCurveTo (40f, 10f, 390f, 240f, 1904, 50f));

    pathTransition.setDuration(Duration.millis(10000));
    pathTransition.setNode(rect);
    pathTransition.setPath(path);
    pathTransition.setOrientation(OrientationType.ORTHOGONAL_TO_TANGENT);
    pathTransition.setCycleCount(4f);
    pathTransition.setAutoReverse(true);

    pathTransition.play();

...


Since
JavaFX 2.0
See Also
Transition, Animation

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
PathTransition.OrientationType

Specifies the upright orientation of node along the path.

private static class

Field Summary

Modifier and TypeField and Description
private boolean
private Node
private static final Duration
private static final Node
private static final PathTransition.OrientationType
private static final Shape
private ObjectProperty<Duration>
duration

The duration of this Transition.

private ObjectProperty<Node>
node

The target node of this PathTransition.

private ObjectProperty<PathTransition.OrientationType>
orientation

Specifies the upright orientation of node along the path.

private ObjectProperty<Shape>
path

The shape on which outline the node should be animated.

private final ArrayList<PathTransition.Segment>
private static final int
private double

Constructor Summary

AccessConstructor and Description
public
PathTransition(Duration
The duration of this PathTransition
duration
,
Shape
The path of this PathTransition
path
,
Node
The node of this PathTransition
node
)

The constructor of PathTransition.

public
PathTransition(Duration
The duration of this PathTransition
duration
,
Shape
The path of this PathTransition
path
)

The constructor of PathTransition.

public
PathTransition()

The constructor of PathTransition.

Method Summary

Modifier and TypeMethod and Description
public final ObjectProperty<Duration>
private int
findSegment(int begin, int end, double length)

Returns the index of the first segment having accumulated length from the path beginning, greater than length

public final Duration
public final Node
public final PathTransition.OrientationType
public final Shape
private Node
public void
interpolate(double
The relative position
frac
)

Implements abstract javafx.animation.Transition.interpolate.

The method interpolate() has to be provided by implementations of Transition.

private static double
interpolate(double fromAngle, double toAngle, double ratio)

Interpolates angle according to rate, with correct 0->360 and 360->0 transitions

public final ObjectProperty<Node>
private static double
normalize(double angle)

Converts angle to range 0-360

public final ObjectProperty<PathTransition.OrientationType>
public final ObjectProperty<Shape>
private void
public final void
public final void
setNode(Node value)

public final void
public final void
setPath(Shape value)

pack-priv boolean
startable(boolean forceSync)

Overrides javafx.animation.Transition.startable.

pack-priv void
sync(boolean forceSync)

Overrides javafx.animation.Transition.sync.

Inherited from javafx.animation.Transition:
doJumpTodoPlayTogetCachedInterpolatorgetInterpolatorgetParentTargetNodeinterpolatorPropertysetInterpolator

Field Detail

cachedIsNormalRequiredback to summary
private boolean cachedIsNormalRequired
cachedNodeback to summary
private Node cachedNode
DEFAULT_DURATIONback to summary
private static final Duration DEFAULT_DURATION
DEFAULT_NODEback to summary
private static final Node DEFAULT_NODE
DEFAULT_ORIENTATIONback to summary
private static final PathTransition.OrientationType DEFAULT_ORIENTATION
DEFAULT_PATHback to summary
private static final Shape DEFAULT_PATH
durationback to summary
private ObjectProperty<Duration> duration

The duration of this Transition.

It is not possible to change the duration of a running PathTransition. If the value of duration is changed for a running PathTransition, the animation has to be stopped and started again to pick up the new value.

Note

While the unit of duration is a millisecond, the granularity depends on the underlying operating system and will in general be larger. For example animations on desktop systems usually run with a maximum of 60fps which gives a granularity of ~17 ms. Setting duration to value lower than Duration#ZERO will result in IllegalArgumentException.

Default Value
400ms
nodeback to summary
private ObjectProperty<Node> node

The target node of this PathTransition.

It is not possible to change the target node of a running PathTransition. If the value of node is changed for a running PathTransition, the animation has to be stopped and started again to pick up the new value.

orientationback to summary
private ObjectProperty<PathTransition.OrientationType> orientation

Specifies the upright orientation of node along the path. The default orientation is set to OrientationType#NONE.

It is not possible to change the orientation of a running PathTransition. If the value of orientation is changed for a running PathTransition, the animation has to be stopped and started again to pick up the new value.

Default Value
NONE
pathback to summary
private ObjectProperty<Shape> path

The shape on which outline the node should be animated.

It is not possible to change the path of a running PathTransition. If the value of path is changed for a running PathTransition, the animation has to be stopped and started again to pick up the new value.

Default Value
null
segmentsback to summary
private final ArrayList<PathTransition.Segment> segments
SMOOTH_ZONEback to summary
private static final int SMOOTH_ZONE
totalLengthback to summary
private double totalLength

Constructor Detail

PathTransitionback to summary
public PathTransition(Duration duration, Shape path, Node node)

The constructor of PathTransition.

Parameters
duration:Duration

The duration of this PathTransition

path:Shape

The path of this PathTransition

node:Node

The node of this PathTransition

PathTransitionback to summary
public PathTransition(Duration duration, Shape path)

The constructor of PathTransition.

Parameters
duration:Duration

The duration of this PathTransition

path:Shape

The path of this PathTransition

PathTransitionback to summary
public PathTransition()

The constructor of PathTransition.

Method Detail

durationPropertyback to summary
public final ObjectProperty<Duration> durationProperty()
findSegmentback to summary
private int findSegment(int begin, int end, double length)

Returns the index of the first segment having accumulated length from the path beginning, greater than length

getDurationback to summary
public final Duration getDuration()
getNodeback to summary
public final Node getNode()
getOrientationback to summary
public final PathTransition.OrientationType getOrientation()
getPathback to summary
public final Shape getPath()
getTargetNodeback to summary
private Node getTargetNode()
interpolateback to summary
public void interpolate(double frac)

Implements abstract javafx.animation.Transition.interpolate.

Doc from javafx.animation.Transition.interpolate.

The method interpolate() has to be provided by implementations of Transition. While a Transition is running, this method is called in every frame. The parameter defines the current position with the animation. At the start, the fraction will be 0.0 and at the end it will be 1.0. How the parameter increases, depends on the interpolator, e.g. if the interpolator is Interpolator#LINEAR, the fraction will increase linear. This method must not be called by the user directly.

Parameters
frac:double

The relative position

Annotations
@Override
interpolateback to summary
private static double interpolate(double fromAngle, double toAngle, double ratio)

Interpolates angle according to rate, with correct 0->360 and 360->0 transitions

nodePropertyback to summary
public final ObjectProperty<Node> nodeProperty()
normalizeback to summary
private static double normalize(double angle)

Converts angle to range 0-360

orientationPropertyback to summary
public final ObjectProperty<PathTransition.OrientationType> orientationProperty()
pathPropertyback to summary
public final ObjectProperty<Shape> pathProperty()
recomputeSegmentsback to summary
private void recomputeSegments()
setDurationback to summary
public final void setDuration(Duration value)
setNodeback to summary
public final void setNode(Node value)
setOrientationback to summary
public final void setOrientation(PathTransition.OrientationType value)
setPathback to summary
public final void setPath(Shape value)
startableback to summary
pack-priv boolean startable(boolean forceSync)

Overrides javafx.animation.Transition.startable.

Annotations
@Override
syncback to summary
pack-priv void sync(boolean forceSync)

Overrides javafx.animation.Transition.sync.

Annotations
@Override
javafx.animation back to summary

public final Enum PathTransition.OrientationType

extends Enum<PathTransition.OrientationType>
Class Inheritance

Specifies the upright orientation of node along the path.
Since
JavaFX 2.0

Field Summary

Modifier and TypeField and Description
public static final PathTransition.OrientationType
NONE

The targeted node's rotation matrix stays unchanged along the geometric path.

public static final PathTransition.OrientationType
ORTHOGONAL_TO_TANGENT

The targeted node's rotation matrix is set to keep node perpendicular to the path's tangent along the geometric path.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static PathTransition.OrientationType
public static PathTransition.OrientationType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

NONEback to summary
public static final PathTransition.OrientationType NONE

The targeted node's rotation matrix stays unchanged along the geometric path.

ORTHOGONAL_TO_TANGENTback to summary
public static final PathTransition.OrientationType ORTHOGONAL_TO_TANGENT

The targeted node's rotation matrix is set to keep node perpendicular to the path's tangent along the geometric path.

Constructor Detail

OrientationTypeback to summary
private OrientationType()

Method Detail

valueOfback to summary
public static PathTransition.OrientationType valueOf(String name)
valuesback to summary
public static PathTransition.OrientationType[] values()
javafx.animation back to summary

private Class PathTransition.Segment

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv double
pack-priv boolean
pack-priv double
pack-priv PathTransition.Segment
pack-priv PathTransition.Segment
pack-priv double
pack-priv double
pack-priv double
private static final PathTransition.Segment

Constructor Summary

AccessConstructor and Description
private
Segment(boolean isMoveTo, double toX, double toY, double length, double lengthBefore, double rotateAngle)

Method Summary

Modifier and TypeMethod and Description
public void
public static PathTransition.Segment
public static PathTransition.Segment
public static PathTransition.Segment
newLineTo(PathTransition.Segment fromSeg, double toX, double toY)

public static PathTransition.Segment
newMoveTo(double toX, double toY, double accumLength)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

accumLengthback to summary
pack-priv double accumLength
isMoveToback to summary
pack-priv boolean isMoveTo
lengthback to summary
pack-priv double length
nextSegback to summary
pack-priv PathTransition.Segment nextSeg
prevSegback to summary
pack-priv PathTransition.Segment prevSeg
rotateAngleback to summary
pack-priv double rotateAngle
toXback to summary
pack-priv double toX
toYback to summary
pack-priv double toY
zeroSegmentback to summary
private static final PathTransition.Segment zeroSegment

Constructor Detail

Segmentback to summary
private Segment(boolean isMoveTo, double toX, double toY, double length, double lengthBefore, double rotateAngle)

Method Detail

convertToClosePathback to summary
public void convertToClosePath(PathTransition.Segment moveToSeg)
getZeroSegmentback to summary
public static PathTransition.Segment getZeroSegment()
newClosePathback to summary
public static PathTransition.Segment newClosePath(PathTransition.Segment fromSeg, PathTransition.Segment moveToSeg)
newLineToback to summary
public static PathTransition.Segment newLineTo(PathTransition.Segment fromSeg, double toX, double toY)
newMoveToback to summary
public static PathTransition.Segment newMoveTo(double toX, double toY, double accumLength)