Class Animator


  • public class Animator
    extends java.lang.Object
    Simple animator based on ideas and concepts from "Filthy Rich Clients" book and "Timing Framework" library.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  Animator.Interpolator
      Interpolator used by animation to change timing fraction.
      static interface  Animator.TimingTarget
      Animation callbacks.
    • Constructor Summary

      Constructors 
      Constructor Description
      Animator​(int duration)
      Creates an animation that runs duration milliseconds.
      Animator​(int duration, Animator.TimingTarget target)
      Creates an animation that runs duration milliseconds.
      Animator​(int duration, Animator.TimingTarget target, java.lang.Runnable endRunnable)
      Creates an animation that runs duration milliseconds.
    • Constructor Detail

      • Animator

        public Animator​(int duration)
        Creates an animation that runs duration milliseconds. Use addTarget(TimingTarget) to receive timing events and start() to start the animation.
        Parameters:
        duration - the duration of the animation in milliseconds
      • Animator

        public Animator​(int duration,
                        Animator.TimingTarget target)
        Creates an animation that runs duration milliseconds. Use start() to start the animation.
        Parameters:
        duration - the duration of the animation in milliseconds
        target - the target that receives timing events
      • Animator

        public Animator​(int duration,
                        Animator.TimingTarget target,
                        java.lang.Runnable endRunnable)
        Creates an animation that runs duration milliseconds. Use start() to start the animation.
        Parameters:
        duration - the duration of the animation in milliseconds
        target - the target that receives timing events
        endRunnable - a runnable invoked when the animation ends; or null
    • Method Detail

      • getDuration

        public int getDuration()
        Returns the duration of the animation in milliseconds.
      • setDuration

        public void setDuration​(int duration)
        Sets the duration of the animation in milliseconds.
        Throws:
        java.lang.IllegalStateException - if animation is running
        java.lang.IllegalArgumentException - if duration is <= zero
      • getResolution

        public int getResolution()
        Returns the resolution of the animation in milliseconds (default is 10). Resolution is the amount of time between timing events.
      • setResolution

        public void setResolution​(int resolution)
        Sets the resolution of the animation in milliseconds.
        Parameters:
        resolution - the resolution of the animation in milliseconds
        Throws:
        java.lang.IllegalStateException - if animation is running
        java.lang.IllegalArgumentException - if resolution is <= zero
      • getInterpolator

        public Animator.Interpolator getInterpolator()
        Returns the interpolator for the animation. Default is null, which means linear.
      • setInterpolator

        public void setInterpolator​(Animator.Interpolator interpolator)
        Sets the interpolator for the animation.
        Throws:
        java.lang.IllegalStateException - if animation is running
      • addTarget

        public void addTarget​(Animator.TimingTarget target)
        Adds a target to the animation that receives timing events.
        Parameters:
        target - the target that receives timing events
      • removeTarget

        public void removeTarget​(Animator.TimingTarget target)
        Removes a target from the animation.
        Parameters:
        target - the target that should be removed
      • start

        public void start()
        Starts the animation.
        Throws:
        java.lang.IllegalStateException - if animation is running
      • cancel

        public void cancel()
        Cancels the animation before it normally ends. Does not invoke Animator.TimingTarget.end() on timing targets.
      • isRunning

        public boolean isRunning()
        Returns whether this animation is running.