Package nl.colorize.util.swing
Class SwingAnimator
java.lang.Object
nl.colorize.util.swing.SwingAnimator
Schedules animations and drives them by performing frame updates at regular
intervals. All animations are performed on the Swing thread, and use the
Swing timer to schedule frame updates.
Animations receive frame updates through the Animatable
interface.
All animations are played using the same framerate. In practice, the actual
framerate may deviate from the targeted framerate, depending on the amount of
work that is performed during frame updates and the performance of the
underlying platform. For this reason, all animations receive the exact delta
time since the last frame updates, so that animations can look consistent
even when there are small deviations in the time between frame updates.
In addition to the animation mechanism itself, this class also contains several convenience methods for performing commonly used animations in Swing applications.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionCreates aSwingAnimator
that will operate at the default framerate of 30 frames per second.SwingAnimator
(int framerate) Creates aSwingAnimator
that will operate at the specified framerate. -
Method Summary
Modifier and TypeMethodDescriptionvoid
animateBackgroundColor
(JComponent component, Color target, float duration) void
animateForegroundColor
(JComponent component, Color target, float duration) void
animateHeight
(JComponent component, int target, float duration) void
animateWidth
(JComponent component, int target, float duration) void
cancel
(Animatable anim) Cancels an animation that is currently playing.void
Cancels all animations that are currently playing.protected List
<Animatable> protected boolean
isCurrentlyActive
(Animatable anim) Returns true if the animation is currently active and should receive frame updates.protected void
performFrameUpdate
(float deltaTime) Performs a frame update for all animations that are currently playing.void
play
(Animatable anim) Starts playing an animation, that will continue playing until it is cancelled.void
play
(Timeline timeline, Animatable callback) Starts playing an animation based to the specified timeline.void
start()
Starts thisAnimator
.void
stop()
Stops thisAnimator
.
-
Field Details
-
DEFAULT_FRAMERATE
public static final int DEFAULT_FRAMERATE- See Also:
-
-
Constructor Details
-
SwingAnimator
public SwingAnimator(int framerate) Creates aSwingAnimator
that will operate at the specified framerate. Note that playback of animations is not actually started untilstart()
is called. -
SwingAnimator
public SwingAnimator()Creates aSwingAnimator
that will operate at the default framerate of 30 frames per second. Note that playback of animations is not actually started untilstart()
is called.
-
-
Method Details
-
start
public void start()Starts thisAnimator
. Scheduled animations will not receive frame updates until this method is called. -
stop
public void stop()Stops thisAnimator
. Animations that are currently playing will be cancelled. -
performFrameUpdate
protected void performFrameUpdate(float deltaTime) Performs a frame update for all animations that are currently playing. -
isCurrentlyActive
Returns true if the animation is currently active and should receive frame updates. By default all registered animations are considered active, but this can be overridden by subclasses. -
play
Starts playing an animation, that will continue playing until it is cancelled. -
play
Starts playing an animation based to the specified timeline. Every frame, the animator will first update the timeline, and then call the specified callback function. The animation will continue to play until it is cancelled. -
cancel
Cancels an animation that is currently playing. -
cancelAll
public void cancelAll()Cancels all animations that are currently playing. -
animateBackgroundColor
-
animateForegroundColor
-
animateWidth
-
animateHeight
-
getCurrentlyPlaying
-