Class SwingAnimator

java.lang.Object
nl.colorize.util.swing.SwingAnimator

public class SwingAnimator extends Object
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 Details

  • Constructor Details

    • SwingAnimator

      public SwingAnimator(int framerate)
      Creates a SwingAnimator that will operate at the specified framerate. Note that playback of animations is not actually started until start() is called.
    • SwingAnimator

      public SwingAnimator()
      Creates a SwingAnimator that will operate at the default framerate of 30 frames per second. Note that playback of animations is not actually started until start() is called.
  • Method Details

    • start

      public void start()
      Starts this Animator. Scheduled animations will not receive frame updates until this method is called.
    • stop

      public void stop()
      Stops this Animator. 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

      protected boolean isCurrentlyActive(Animatable anim)
      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

      public void play(Animatable anim)
      Starts playing an animation, that will continue playing until it is cancelled.
    • play

      public void play(Timeline timeline, Animatable callback)
      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

      public void cancel(Animatable anim)
      Cancels an animation that is currently playing.
    • cancelAll

      public void cancelAll()
      Cancels all animations that are currently playing.
    • animateBackgroundColor

      public void animateBackgroundColor(JComponent component, Color target, float duration)
    • animateForegroundColor

      public void animateForegroundColor(JComponent component, Color target, float duration)
    • animateWidth

      public void animateWidth(JComponent component, int target, float duration)
    • animateHeight

      public void animateHeight(JComponent component, int target, float duration)
    • getCurrentlyPlaying

      protected List<Animatable> getCurrentlyPlaying()