public abstract class Animation
extends java.lang.Object
Animation
provides the core functionality of all animations
used in the JavaFX runtime.
An animation can run in a loop by setting cycleCount
.
To make an animation run back and forth while looping, set the
autoReverse
-flag.
Call play()
or playFromStart()
to play an Animation
. The Animation
progresses in the direction and speed specified by
rate
, and stops when its duration is elapsed. An Animation
with indefinite duration (a cycleCount
of INDEFINITE
) runs
repeatedly until the stop()
method is explicitly called, which will
stop the running Animation
and reset its play head to the initial
position.
An Animation
can be paused by calling pause()
, and the next
play()
call will resume the Animation
from where it was
paused.
An Animation
's play head can be randomly positioned, whether it is
running or not. If the Animation
is running, the play head jumps to
the specified position immediately and continues playing from new position.
If the Animation
is not running, the next play()
will start
the Animation
from the specified position.
Inverting the value of rate
toggles the play direction.
Timeline
,
Transition
Type | Property and Description |
---|---|
BooleanProperty |
autoReverse
Defines whether this
Animation reverses direction on alternating cycles. |
ReadOnlyDoubleProperty |
currentRate
Read-only variable to indicate current direction/speed at which the
Animation is being played. |
<any> |
currentTime
Defines the
Animation 's play head position. |
IntegerProperty |
cycleCount
Defines the number of cycles in this animation.
|
<any> |
cycleDuration
Read-only variable to indicate the duration of one cycle of this
Animation : the time it takes to play from time 0 to the
end of the Animation (at the default rate of
1.0). |
<any> |
delay
Delays the start of an animation.
|
<any> |
onFinished
The action to be executed at the conclusion of this
Animation . |
DoubleProperty |
rate
Defines the direction/speed at which the
Animation is expected to
be played. |
<any> |
status
The status of the
Animation . |
<any> |
totalDuration
Read-only variable to indicate the total duration of this
Animation , including repeats. |
Modifier and Type | Class and Description |
---|---|
private class |
Animation.AnimationReadOnlyProperty<T> |
private class |
Animation.CurrentRateProperty |
private class |
Animation.CurrentTimeProperty |
static class |
Animation.Status
The possible states for
status . |
Modifier and Type | Field and Description |
---|---|
private java.security.AccessControlContext |
accessCtrlCtx |
private BooleanProperty |
autoReverse
Defines whether this
Animation reverses direction on alternating cycles. |
(package private) ClipEnvelope |
clipEnvelope |
private <any> |
cuePoints |
private ReadOnlyDoubleProperty |
currentRate
Read-only variable to indicate current direction/speed at which the
Animation is being played. |
private long |
currentTicks |
private Animation.CurrentTimeProperty |
currentTime
Defines the
Animation 's play head position. |
private IntegerProperty |
cycleCount
Defines the number of cycles in this animation.
|
private <any> |
cycleDuration
Read-only variable to indicate the duration of one cycle of this
Animation : the time it takes to play from time 0 to the
end of the Animation (at the default rate of
1.0). |
private static boolean |
DEFAULT_AUTO_REVERSE |
private static double |
DEFAULT_CURRENT_RATE |
private static int |
DEFAULT_CYCLE_COUNT |
private static Duration |
DEFAULT_CYCLE_DURATION |
private static Duration |
DEFAULT_DELAY |
private static <any> |
DEFAULT_ON_FINISHED |
private static double |
DEFAULT_RATE |
private static Animation.Status |
DEFAULT_STATUS |
private static Duration |
DEFAULT_TOTAL_DURATION |
private <any> |
delay
Delays the start of an animation.
|
private static double |
EPSILON |
static int |
INDEFINITE
Used to specify an animation that repeats indefinitely, until the
stop() method is called. |
private boolean |
lastPlayedFinished |
private boolean |
lastPlayedForward |
private long |
lastPulse |
private double |
oldRate |
private <any> |
onFinished
The action to be executed at the conclusion of this
Animation . |
(package private) Animation |
parent
The parent of this
Animation . |
private boolean |
paused |
private long |
pauseTime |
(package private) PulseReceiver |
pulseReceiver |
private DoubleProperty |
rate
Defines the direction/speed at which the
Animation is expected to
be played. |
private int |
resolution |
private long |
startTime |
private <any> |
status
The status of the
Animation . |
private double |
targetFramerate |
private AbstractMasterTimer |
timer |
private <any> |
totalDuration
Read-only variable to indicate the total duration of this
Animation , including repeats. |
Modifier | Constructor and Description |
---|---|
protected |
Animation()
The constructor of
Animation . |
(package private) |
Animation(AbstractMasterTimer timer) |
(package private) |
Animation(AbstractMasterTimer timer,
ClipEnvelope clipEnvelope,
int resolution) |
protected |
Animation(double targetFramerate)
The constructor of
Animation . |
Modifier and Type | Method and Description |
---|---|
private void |
addPulseReceiver() |
BooleanProperty |
autoReverseProperty()
Defines whether this
Animation reverses direction on alternating cycles. |
ReadOnlyDoubleProperty |
currentRateProperty()
Read-only variable to indicate current direction/speed at which the
Animation is being played. |
<any> |
currentTimeProperty()
Defines the
Animation 's play head position. |
IntegerProperty |
cycleCountProperty()
Defines the number of cycles in this animation.
|
<any> |
cycleDurationProperty()
Read-only variable to indicate the duration of one cycle of this
Animation : the time it takes to play from time 0 to the
end of the Animation (at the default rate of
1.0). |
<any> |
delayProperty()
Delays the start of an animation.
|
(package private) abstract void |
doJumpTo(long currentTicks,
long cycleTicks,
boolean forceJump) |
(package private) void |
doPause() |
(package private) abstract void |
doPlayTo(long currentTicks,
long cycleTicks) |
(package private) void |
doResume() |
private void |
doSetCurrentRate(double value) |
(package private) void |
doStart(boolean forceSync) |
(package private) void |
doStop() |
(package private) void |
doTimePulse(long elapsedTime) |
(package private) void |
finished() |
<any> |
getCuePoints()
The cue points can be
used to mark important positions of the
Animation . |
double |
getCurrentRate()
Gets the value of the property currentRate.
|
Duration |
getCurrentTime()
Gets the value of the property currentTime.
|
int |
getCycleCount()
Gets the value of the property cycleCount.
|
Duration |
getCycleDuration()
Gets the value of the property cycleDuration.
|
Duration |
getDelay()
Gets the value of the property delay.
|
<any> |
getOnFinished()
Gets the value of the property onFinished.
|
double |
getRate()
Gets the value of the property rate.
|
Animation.Status |
getStatus()
Gets the value of the property status.
|
double |
getTargetFramerate()
The target framerate is the maximum framerate at which this
Animation
will run, in frames per second. |
Duration |
getTotalDuration()
Gets the value of the property totalDuration.
|
boolean |
isAutoReverse()
Gets the value of the property autoReverse.
|
private boolean |
isRunningEmbedded() |
void |
jumpTo(Duration time)
Jumps to a given position in this
Animation . |
private long |
now() |
<any> |
onFinishedProperty()
The action to be executed at the conclusion of this
Animation . |
void |
pause()
Pauses the animation.
|
(package private) void |
pauseReceiver() |
void |
play()
Plays
Animation from current position in the direction indicated
by rate . |
void |
playFrom(Duration time)
A convenience method to play this
Animation from a specific
position. |
void |
playFrom(java.lang.String cuePoint)
A convenience method to play this
Animation from a predefined
position. |
void |
playFromStart()
Plays an
Animation from initial position in forward direction. |
DoubleProperty |
rateProperty()
Defines the direction/speed at which the
Animation is expected to
be played. |
(package private) void |
resumeReceiver() |
void |
setAutoReverse(boolean value)
Sets the value of the property autoReverse.
|
(package private) void |
setCurrentRate(double currentRate) |
(package private) void |
setCurrentTicks(long ticks) |
void |
setCycleCount(int value)
Sets the value of the property cycleCount.
|
protected void |
setCycleDuration(Duration value)
Sets the value of the property cycleDuration.
|
void |
setDelay(Duration value)
Sets the value of the property delay.
|
void |
setOnFinished(<any> value)
Sets the value of the property onFinished.
|
void |
setRate(double value)
Sets the value of the property rate.
|
protected void |
setStatus(Animation.Status value)
Sets the value of the property status.
|
(package private) boolean |
startable(boolean forceSync) |
(package private) void |
startReceiver(long delay) |
<any> |
statusProperty()
The status of the
Animation . |
void |
stop()
Stops the animation and resets the play head to its initial position.
|
(package private) void |
sync(boolean forceSync) |
private void |
syncClipEnvelope() |
<any> |
totalDurationProperty()
Read-only variable to indicate the total duration of this
Animation , including repeats. |
private void |
updateTotalDuration() |
public final DoubleProperty rateProperty
Animation
is expected to
be played.
The absolute value of rate
indicates the speed at which the
Animation
is to be played, while the sign of rate
indicates the direction. A positive value of rate
indicates
forward play, a negative value indicates backward play and 0.0
to
stop a running Animation
.
Rate 1.0
is normal play, 2.0
is 2 time normal,
-1.0
is backwards, etc.
Inverting the rate of a running Animation
will cause the
Animation
to reverse direction in place and play back over the
portion of the Animation
that has already elapsed.
getRate()
,
setRate(double)
public final ReadOnlyDoubleProperty currentRateProperty
Animation
is being played.
currentRate
is not necessary equal to rate
.
currentRate
is set to 0.0
when animation is paused or
stopped. currentRate
may also point to different direction during
reverse cycles when autoReverse
is true
getCurrentRate()
public final <any> cycleDurationProperty
Animation
: the time it takes to play from time 0 to the
end of the Animation (at the default rate
of
1.0).getCycleDuration()
,
setCycleDuration(Duration)
public final <any> totalDurationProperty
Animation
, including repeats. A Animation
with a cycleCount
of Animation.INDEFINITE
will have a totalDuration
of
Duration.INDEFINITE
.
This is set to cycleDuration * cycleCount.
getTotalDuration()
public final <any> currentTimeProperty
Animation
's play head position.getCurrentTime()
public final <any> delayProperty
IllegalArgumentException
.getDelay()
,
setDelay(Duration)
public final IntegerProperty cycleCountProperty
cycleCount
may be INDEFINITE
for animations that repeat indefinitely, but
must otherwise be > 0.
It is not possible to change the cycleCount
of a running
Animation
. If the value of cycleCount
is changed for a
running Animation
, the animation has to be stopped and started again to pick
up the new value.
getCycleCount()
,
setCycleCount(int)
public final BooleanProperty autoReverseProperty
Animation
reverses direction on alternating cycles. If
true
, the
Animation
will proceed forward on the first cycle,
then reverses on the second cycle, and so on. Otherwise, animation will
loop such that each cycle proceeds forward from the start.
It is not possible to change the autoReverse
flag of a running
Animation
. If the value of autoReverse
is changed for a
running Animation
, the animation has to be stopped and started again to pick
up the new value.isAutoReverse()
,
setAutoReverse(boolean)
public final <any> statusProperty
Animation
.
In Animation
can be in one of three states:
Animation.Status.STOPPED
, Animation.Status.PAUSED
or Animation.Status.RUNNING
.getStatus()
,
setStatus(Status)
public final <any> onFinishedProperty
Animation
.getOnFinished()
,
#setOnFinished()
public static final int INDEFINITE
stop()
method is called.private static final double EPSILON
private long startTime
private long pauseTime
private boolean paused
private final AbstractMasterTimer timer
private java.security.AccessControlContext accessCtrlCtx
final PulseReceiver pulseReceiver
Animation parent
Animation
. If this animation has not been
added to another animation, such as ParallelTransition
and
SequentialTransition
, then parent will be null.ClipEnvelope clipEnvelope
private boolean lastPlayedFinished
private boolean lastPlayedForward
private DoubleProperty rate
Animation
is expected to
be played.
The absolute value of rate
indicates the speed at which the
Animation
is to be played, while the sign of rate
indicates the direction. A positive value of rate
indicates
forward play, a negative value indicates backward play and 0.0
to
stop a running Animation
.
Rate 1.0
is normal play, 2.0
is 2 time normal,
-1.0
is backwards, etc.
Inverting the rate of a running Animation
will cause the
Animation
to reverse direction in place and play back over the
portion of the Animation
that has already elapsed.
private static final double DEFAULT_RATE
private double oldRate
private ReadOnlyDoubleProperty currentRate
Animation
is being played.
currentRate
is not necessary equal to rate
.
currentRate
is set to 0.0
when animation is paused or
stopped. currentRate
may also point to different direction during
reverse cycles when autoReverse
is true
private static final double DEFAULT_CURRENT_RATE
private <any> cycleDuration
Animation
: the time it takes to play from time 0 to the
end of the Animation (at the default rate
of
1.0).private static final Duration DEFAULT_CYCLE_DURATION
private <any> totalDuration
Animation
, including repeats. A Animation
with a cycleCount
of Animation.INDEFINITE
will have a totalDuration
of
Duration.INDEFINITE
.
This is set to cycleDuration * cycleCount.
private static final Duration DEFAULT_TOTAL_DURATION
private Animation.CurrentTimeProperty currentTime
Animation
's play head position.private long currentTicks
private <any> delay
IllegalArgumentException
.private static final Duration DEFAULT_DELAY
private IntegerProperty cycleCount
cycleCount
may be INDEFINITE
for animations that repeat indefinitely, but
must otherwise be > 0.
It is not possible to change the cycleCount
of a running
Animation
. If the value of cycleCount
is changed for a
running Animation
, the animation has to be stopped and started again to pick
up the new value.
private static final int DEFAULT_CYCLE_COUNT
private BooleanProperty autoReverse
Animation
reverses direction on alternating cycles. If
true
, the
Animation
will proceed forward on the first cycle,
then reverses on the second cycle, and so on. Otherwise, animation will
loop such that each cycle proceeds forward from the start.
It is not possible to change the autoReverse
flag of a running
Animation
. If the value of autoReverse
is changed for a
running Animation
, the animation has to be stopped and started again to pick
up the new value.private static final boolean DEFAULT_AUTO_REVERSE
private <any> status
Animation
.
In Animation
can be in one of three states:
Animation.Status.STOPPED
, Animation.Status.PAUSED
or Animation.Status.RUNNING
.private static final Animation.Status DEFAULT_STATUS
private final double targetFramerate
private final int resolution
private long lastPulse
private <any> onFinished
Animation
.private static final <any> DEFAULT_ON_FINISHED
private final <any> cuePoints
protected Animation(double targetFramerate)
Animation
.
This constructor allows to define a target framerate.targetFramerate
- The custom target frame rate for this Animation
getTargetFramerate()
protected Animation()
Animation
.Animation(AbstractMasterTimer timer)
Animation(AbstractMasterTimer timer, ClipEnvelope clipEnvelope, int resolution)
private long now()
private void addPulseReceiver()
void startReceiver(long delay)
void pauseReceiver()
void resumeReceiver()
public final void setRate(double value)
public final double getRate()
public final DoubleProperty rateProperty()
Animation
is expected to
be played.
The absolute value of rate
indicates the speed at which the
Animation
is to be played, while the sign of rate
indicates the direction. A positive value of rate
indicates
forward play, a negative value indicates backward play and 0.0
to
stop a running Animation
.
Rate 1.0
is normal play, 2.0
is 2 time normal,
-1.0
is backwards, etc.
Inverting the rate of a running Animation
will cause the
Animation
to reverse direction in place and play back over the
portion of the Animation
that has already elapsed.
getRate()
,
setRate(double)
private boolean isRunningEmbedded()
private void doSetCurrentRate(double value)
public final double getCurrentRate()
public final ReadOnlyDoubleProperty currentRateProperty()
Animation
is being played.
currentRate
is not necessary equal to rate
.
currentRate
is set to 0.0
when animation is paused or
stopped. currentRate
may also point to different direction during
reverse cycles when autoReverse
is true
getCurrentRate()
protected final void setCycleDuration(Duration value)
public final Duration getCycleDuration()
public final <any> cycleDurationProperty()
Animation
: the time it takes to play from time 0 to the
end of the Animation (at the default rate
of
1.0).getCycleDuration()
,
setCycleDuration(Duration)
public final Duration getTotalDuration()
public final <any> totalDurationProperty()
Animation
, including repeats. A Animation
with a cycleCount
of Animation.INDEFINITE
will have a totalDuration
of
Duration.INDEFINITE
.
This is set to cycleDuration * cycleCount.
getTotalDuration()
private void updateTotalDuration()
public final Duration getCurrentTime()
public final <any> currentTimeProperty()
Animation
's play head position.getCurrentTime()
public final void setDelay(Duration value)
public final Duration getDelay()
public final <any> delayProperty()
IllegalArgumentException
.getDelay()
,
setDelay(Duration)
public final void setCycleCount(int value)
public final int getCycleCount()
public final IntegerProperty cycleCountProperty()
cycleCount
may be INDEFINITE
for animations that repeat indefinitely, but
must otherwise be > 0.
It is not possible to change the cycleCount
of a running
Animation
. If the value of cycleCount
is changed for a
running Animation
, the animation has to be stopped and started again to pick
up the new value.
getCycleCount()
,
setCycleCount(int)
public final void setAutoReverse(boolean value)
public final boolean isAutoReverse()
public final BooleanProperty autoReverseProperty()
Animation
reverses direction on alternating cycles. If
true
, the
Animation
will proceed forward on the first cycle,
then reverses on the second cycle, and so on. Otherwise, animation will
loop such that each cycle proceeds forward from the start.
It is not possible to change the autoReverse
flag of a running
Animation
. If the value of autoReverse
is changed for a
running Animation
, the animation has to be stopped and started again to pick
up the new value.isAutoReverse()
,
setAutoReverse(boolean)
protected final void setStatus(Animation.Status value)
public final Animation.Status getStatus()
public final <any> statusProperty()
Animation
.
In Animation
can be in one of three states:
Animation.Status.STOPPED
, Animation.Status.PAUSED
or Animation.Status.RUNNING
.getStatus()
,
setStatus(Status)
public final double getTargetFramerate()
Animation
will run, in frames per second. This can be used, for example, to keep
particularly complex Animations
from over-consuming system resources.
By default, an Animation
's framerate is not explicitly limited, meaning
the Animation
will run at an optimal framerate for the underlying platform.public final void setOnFinished(<any> value)
public final <any> getOnFinished()
public final <any> onFinishedProperty()
Animation
.getOnFinished()
,
#setOnFinished()
public final <any> getCuePoints()
Animation
. Once a cue
point was defined, it can be used as an argument of
jumpTo()
and playFrom()
to move to the associated position quickly.
Every Animation
has two predefined cue points "start"
and
"end"
, which are set at the start respectively the end of the
Animation
. The predefined cuepoints do not appear in the map,
attempts to override them have no effect.
Another option to define a cue point in a Animation
is to set the
name
property of a KeyFrame
.
javafx.collections.ObservableMap
of cue pointspublic void jumpTo(Duration time)
Animation
.
If the given time is less than Duration#ZERO
, this method will
jump to the start of the animation. If the given time is larger than the
duration of this Animation
, this method will jump to the end.time
- the new positionjava.lang.NullPointerException
- if time
is null
java.lang.IllegalArgumentException
- if time
is Duration#UNKNOWN
java.lang.IllegalStateException
- if embedded in another animation,
such as SequentialTransition
or ParallelTransition
public void playFrom(java.lang.String cuePoint)
Animation
from a predefined
position. The position has to be predefined in cue points.
Calling this method is equivalent to
animation.jumpTo(cuePoint);
animation.play();
Note that unlike playFromStart()
calling this method will not
change the playing direction of this Animation
.cuePoint
- name of the cue pointjava.lang.NullPointerException
- if cuePoint
is null
java.lang.IllegalStateException
- if embedded in another animation,
such as SequentialTransition
or ParallelTransition
getCuePoints()
public void playFrom(Duration time)
Animation
from a specific
position. Calling this method is equivalent to
animation.jumpTo(time);
animation.play();
Note that unlike playFromStart()
calling this method will not
change the playing direction of this Animation
.time
- position where to play fromjava.lang.NullPointerException
- if time
is null
java.lang.IllegalArgumentException
- if time
is Duration#UNKNOWN
java.lang.IllegalStateException
- if embedded in another animation,
such as SequentialTransition
or ParallelTransition
public void play()
Animation
from current position in the direction indicated
by rate
. If the Animation
is running, it has no effect.
When rate
> 0 (forward play), if an Animation
is already
positioned at the end, the first cycle will not be played, it is
considered to have already finished. This also applies to a backward (
rate
< 0) cycle if an Animation
is positioned at the beginning.
However, if the Animation
has cycleCount
> 1, following
cycle(s) will be played as usual.
When the Animation
reaches the end, the Animation
is stopped and
the play head remains at the end.
To play an Animation
backwards from the end:
animation.setRate(negative rate);
animation.jumpTo(overall duration of animation);
animation.play();
Note:
play()
is an asynchronous call, the Animation
may not
start immediately. java.lang.IllegalStateException
- if embedded in another animation,
such as SequentialTransition
or ParallelTransition
public void playFromStart()
Animation
from initial position in forward direction.
It is equivalent to
animation.stop();
animation.setRate = setRate(Math.abs(animation.getRate()));
animation.jumpTo(Duration.ZERO);
animation.play();
Note:
playFromStart()
is an asynchronous call, Animation
may
not start immediately. java.lang.IllegalStateException
- if embedded in another animation,
such as SequentialTransition
or ParallelTransition
public void stop()
Note:
stop()
is an asynchronous call, the Animation
may not stop
immediately. java.lang.IllegalStateException
- if embedded in another animation,
such as SequentialTransition
or ParallelTransition
public void pause()
Note:
pause()
is an asynchronous call, the Animation
may not pause
immediately. java.lang.IllegalStateException
- if embedded in another animation,
such as SequentialTransition
or ParallelTransition
boolean startable(boolean forceSync)
void sync(boolean forceSync)
private void syncClipEnvelope()
void doStart(boolean forceSync)
void doPause()
void doResume()
void doStop()
void doTimePulse(long elapsedTime)
abstract void doPlayTo(long currentTicks, long cycleTicks)
abstract void doJumpTo(long currentTicks, long cycleTicks, boolean forceJump)
void setCurrentTicks(long ticks)
void setCurrentRate(double currentRate)
final void finished()