Class Transition
- Direct Known Subclasses:
FadeTransition, FillTransition, ParallelTransition, PathTransition, PauseTransition, RotateTransition, ScaleTransition, SequentialTransition, StrokeTransition, TranslateTransition
Transition based animations, such as PathTransition and
RotateTransition.
This class offers a simple framework to define animation. It provides all the
basic functionality defined in Animation. Transition requires
the implementation of a method interpolate(double) which is the
called in each frame, while the Transition is running.
In addition, an extending class needs to set the duration of a single cycle
with Animation.setCycleDuration(javafx.util.Duration). This duration
is usually set by the user via a duration property (as in
duration) for example. But it can also be calculated
by the extending class as is done in ParallelTransition and
FadeTransition.
Below is a simple example. It creates a small animation that updates the
text property of a Text node. It starts
with an empty String and adds gradually letter by letter until the
full String was set when the animation finishes.
final String content = "Lorem ipsum";
final Text text = new Text(10, 20, "");
final Animation animation = new Transition() {
{
setCycleDuration(Duration.millis(2000));
}
protected void interpolate(double frac) {
final int length = content.length();
final int n = Math.round(length * (float) frac);
text.setText(content.substring(0, n));
}
};
animation.play();- Since:
- JavaFX 2.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces declared in class Animation
Animation.Status -
Property Summary
PropertiesTypePropertyDescriptionfinal ObjectProperty<Interpolator> Controls the timing for acceleration and deceleration at eachTransitioncycle.Properties declared in class Animation
autoReverse, currentRate, currentTime, cycleCount, cycleDuration, delay, onFinished, rate, status, totalDurationTypePropertyDescriptionfinal BooleanPropertyDefines whether thisAnimationreverses direction on alternating cycles.final ReadOnlyDoublePropertyRead-only variable to indicate current direction/speed at which theAnimationis being played.final ReadOnlyObjectProperty<Duration> Defines theAnimation's play head position.final IntegerPropertyDefines the number of cycles in this animation.final ReadOnlyObjectProperty<Duration> Read-only variable to indicate the duration of one cycle of thisAnimation: the time it takes to play from time 0 to the end of the Animation (at the defaultrateof 1.0).final ObjectProperty<Duration> Delays the start of an animation.final ObjectProperty<EventHandler<ActionEvent>> The action to be executed at the conclusion of thisAnimation.final DoublePropertyDefines the direction/speed at which theAnimationis expected to be played.The status of theAnimation.final ReadOnlyObjectProperty<Duration> Read-only variable to indicate the total duration of thisAnimation, including repeats. -
Field Summary
Fields declared in class Animation
INDEFINITEModifier and TypeFieldDescriptionstatic final intUsed as a value forcycleCountto specify an animation that repeats indefinitely, until thestop()method is called. -
Constructor Summary
ConstructorsConstructorDescriptionThe constructor ofTransition.Transition(double targetFramerate) The constructor ofTransition. -
Method Summary
Modifier and TypeMethodDescriptionprotected InterpolatorReturns theInterpolator, that was set when theTransitionwas started.final InterpolatorGets the value of theinterpolatorproperty.protected NodeReturns the first non-nulltargetNodein the parent hierarchy of thisTransition, ornullif such a node is not found.protected abstract voidinterpolate(double frac) The methodinterpolate()has to be provided by implementations ofTransition.final ObjectProperty<Interpolator> Controls the timing for acceleration and deceleration at eachTransitioncycle.final voidsetInterpolator(Interpolator value) Sets the value of theinterpolatorproperty.Methods declared in class Animation
autoReverseProperty, currentRateProperty, currentTimeProperty, cycleCountProperty, cycleDurationProperty, delayProperty, getCuePoints, getCurrentRate, getCurrentTime, getCycleCount, getCycleDuration, getDelay, getOnFinished, getRate, getStatus, getTargetFramerate, getTotalDuration, isAutoReverse, jumpTo, jumpTo, onFinishedProperty, pause, play, playFrom, playFrom, playFromStart, rateProperty, setAutoReverse, setCycleCount, setCycleDuration, setDelay, setOnFinished, setRate, setStatus, statusProperty, stop, totalDurationPropertyModifier and TypeMethodDescriptionfinal BooleanPropertyDefines whether thisAnimationreverses direction on alternating cycles.final ReadOnlyDoublePropertyRead-only variable to indicate current direction/speed at which theAnimationis being played.final ReadOnlyObjectProperty<Duration> Defines theAnimation's play head position.final IntegerPropertyDefines the number of cycles in this animation.final ReadOnlyObjectProperty<Duration> Read-only variable to indicate the duration of one cycle of thisAnimation: the time it takes to play from time 0 to the end of the Animation (at the defaultrateof 1.0).final ObjectProperty<Duration> Delays the start of an animation.final ObservableMap<String, Duration> The cue points can be used to mark important positions of theAnimation.final doubleGets the value of thecurrentRateproperty.final DurationGets the value of thecurrentTimeproperty.final intGets the value of thecycleCountproperty.final DurationGets the value of thecycleDurationproperty.final DurationgetDelay()Gets the value of thedelayproperty.final EventHandler<ActionEvent> Gets the value of theonFinishedproperty.final doublegetRate()Gets the value of therateproperty.final Animation.StatusGets the value of thestatusproperty.final doubleThe target framerate is the maximum framerate at which thisAnimationwill run, in frames per second.final DurationGets the value of thetotalDurationproperty.final booleanGets the value of theautoReverseproperty.voidJumps to a predefined position in thisAnimation.voidJumps to a given position in thisAnimation.final ObjectProperty<EventHandler<ActionEvent>> The action to be executed at the conclusion of thisAnimation.voidpause()Pauses the animation.voidplay()PlaysAnimationfrom current position in the direction indicated byrate.voidA convenience method to play thisAnimationfrom a predefined position.voidA convenience method to play thisAnimationfrom a specific position.voidPlays anAnimationfrom initial position in forward direction.final DoublePropertyDefines the direction/speed at which theAnimationis expected to be played.final voidsetAutoReverse(boolean value) Sets the value of theautoReverseproperty.final voidsetCycleCount(int value) Sets the value of thecycleCountproperty.protected final voidsetCycleDuration(Duration value) Sets the value of thecycleDurationproperty.final voidSets the value of thedelayproperty.final voidsetOnFinished(EventHandler<ActionEvent> value) Sets the value of theonFinishedproperty.final voidsetRate(double value) Sets the value of therateproperty.protected final voidsetStatus(Animation.Status value) Sets the value of thestatusproperty.The status of theAnimation.voidstop()Stops the animation and resets the play head to its initial position.final ReadOnlyObjectProperty<Duration> Read-only variable to indicate the total duration of thisAnimation, including repeats.
-
Property Details
-
interpolator
Controls the timing for acceleration and deceleration at eachTransitioncycle.This may only be changed prior to starting the transition or after the transition has ended. If the value of
interpolatoris changed for a runningTransition, the animation has to be stopped and started again to pick up the new value.Default interpolator is set to
Interpolator.EASE_BOTH.- Default value:
- EASE_BOTH
- See Also:
-
-
Constructor Details
-
Transition
public Transition(double targetFramerate) The constructor ofTransition. This constructor allows to define atarget framerate.- Parameters:
targetFramerate- The custom target frame rate for thisTransition
-
Transition
public Transition()The constructor ofTransition.
-
-
Method Details
-
setInterpolator
Sets the value of theinterpolatorproperty.- Property description:
- Controls the timing for acceleration and deceleration at each
Transitioncycle.This may only be changed prior to starting the transition or after the transition has ended. If the value of
interpolatoris changed for a runningTransition, the animation has to be stopped and started again to pick up the new value.Default interpolator is set to
Interpolator.EASE_BOTH. - Default value:
- EASE_BOTH
- Parameters:
value- the value for theinterpolatorproperty- See Also:
-
getInterpolator
Gets the value of theinterpolatorproperty.- Property description:
- Controls the timing for acceleration and deceleration at each
Transitioncycle.This may only be changed prior to starting the transition or after the transition has ended. If the value of
interpolatoris changed for a runningTransition, the animation has to be stopped and started again to pick up the new value.Default interpolator is set to
Interpolator.EASE_BOTH. - Default value:
- EASE_BOTH
- Returns:
- the value of the
interpolatorproperty - See Also:
-
interpolatorProperty
Controls the timing for acceleration and deceleration at eachTransitioncycle.This may only be changed prior to starting the transition or after the transition has ended. If the value of
interpolatoris changed for a runningTransition, the animation has to be stopped and started again to pick up the new value.Default interpolator is set to
Interpolator.EASE_BOTH.- Default value:
- EASE_BOTH
- Returns:
- the
interpolatorproperty - See Also:
-
getCachedInterpolator
Returns theInterpolator, that was set when theTransitionwas started. Changing theinterpolatorof a runningTransitionshould have no immediate effect. Instead the runningTransitionshould continue to use the originalInterpolatoruntil it is stopped and started again.- Returns:
- the
Interpolatorthat was set when thisTransitionwas started
-
getParentTargetNode
Returns the first non-nulltargetNodein the parent hierarchy of thisTransition, ornullif such a node is not found.A parent animation is one that can have child animations. Examples are
SequentialTransitionandParallelTransition. A parent animation can also be a child of another parent animation.Note that if this
Transitionhas a target node set and is not a parent animation, it will be ignored during the call as this method only queries parent animations.- Returns:
- the target
Node
-
interpolate
protected abstract void interpolate(double frac) The methodinterpolate()has to be provided by implementations ofTransition. While aTransitionis running, this method is called in every frame. The parameter defines the current position with the animation. At the start, the fraction will be0.0and at the end it will be1.0. How the parameter increases, depends on theinterpolator, e.g. if theinterpolatorisInterpolator.LINEAR, the fraction will increase linear. This method must not be called by the user directly.- Parameters:
frac- The relative position
-