Package docking.util

Class AnimationRunner

java.lang.Object
docking.util.AnimationRunner

public class AnimationRunner extends Object
A class that does basic setup work for creating an Animator. The animator will run a timer in a background thread, calling the client periodically until the animation progress is finished. The actual visual animation is handled by the client's AnimationPainter. This class is provided for convenience. Clients can create their own Animator as needed.

A painter must be supplied before calling start(). A simple example usage:

  GTable table = ...;
  AnimationPainter painter = new AnimationPainter() {
        public void paint(GGlassPane glassPane, Graphics graphics, double value) {
                
                // repaint some contents to the glass pane's graphics using the current value as to 
                // know where we are in the progress of animating
        }
  };
  AnimationRunner animation = new AnimationRunner(table);
  animation.setPainter(painter);
  animation.start();
  
  ...
  
  // code to stop animation, such as when a request for a new animation is received
  if (animation != null) {
        animation.stop();
  }
  
 

Clients who wish to perform more configuration can call createAnimator() to perform the basic setup, calling start() when finished with any follow-up configuration.

See Animator for details on the animation process.

  • Constructor Details

    • AnimationRunner

      public AnimationRunner(JComponent component)
  • Method Details

    • setPainter

      public void setPainter(AnimationPainter animationPainter)
      Sets the painter required for the animator to work.
      Parameters:
      animationPainter - the painter.
    • setValues

      public void setValues(Double... values)
      Sets the values passed to the animator created by this class. These values will be split into a range of values, broken up by the duration of the animator. The default values are 0 and 1.

      See PropertySetter.createAnimator(int, Object, String, Object...).

      Parameters:
      values - the values
    • setRemovePainterWhenFinished

      public void setRemovePainterWhenFinished(boolean b)
      Signals to remove the painter from the glass pane when the animation is finished. Clients can specify false which will allow the painting to continue after the animation has finished.
      Parameters:
      b - true to remove the painter. The default value is true.
    • setDoneCallback

      public void setDoneCallback(Callback c)
      Sets a callback to be called when the animation is finished.
      Parameters:
      c - the callback
    • setDuration

      public void setDuration(Duration duration)
      Sets the animation duration. The default is 1 second.
      Parameters:
      duration - the duration
    • setCurrentValue

      public void setCurrentValue(Double value)
      This is a method used by the animator. Clients should not call this method.
      Parameters:
      value - the current value created by the animator
    • createAnimator

      public org.jdesktop.animation.timing.Animator createAnimator()
      Creates the animator used to perform animation. Clients will call Animator.start() to begin animation. Many attributes of the animator can be configured before starting.
      Returns:
      the animator
      Throws:
      IllegalStateException - if require values have not been set on this class, such as setValues(Double...) or setPainter(AnimationPainter).
    • start

      public void start()
      Starts the animation process, creating the animator as needed. This method can be called repeatedly without calling stop first.
    • stop

      public void stop()
      Stops all animation and removes the painter from the glass pane. start() can be called again after calling this method.