Class AnimationState

java.lang.Object
swingtree.animation.AnimationState
All Implemented Interfaces:
Progress

public final class AnimationState extends Object implements Progress
The state of an animation at a given point in time describing how far the animation has progressed using a number between 0 and 1 (see progress()). Use the numbers exposed by the methods of this value based class to define how your animation should progress over time.
  • Method Details

    • of

      public static AnimationState of(LifeSpan lifeSpan, Stride stride, ActionEvent event, long now)
    • endOf

      public static AnimationState endOf(LifeSpan lifeSpan, Stride stride, ActionEvent event, long iteration)
    • startOf

      public static AnimationState startOf(LifeSpan lifeSpan, Stride stride, ActionEvent event)
    • progress

      public double progress()
      Exposes the progress of the animation state, which is a number between 0 and 1 that represents how far the animation has progressed between its start and end. Note that an animation may also regress, in which case the states will transition from 1 to 0 instead of from 0 to 1. See Stride for more information.
      Specified by:
      progress in interface Progress
      Returns:
      The animation progress in terms of a number between 0 and 1, where 0.5 means the animation is halfway through, and 1 means the animation completed.
    • slice

      public Progress slice(double from, double to)
      Slices the progress value of this animation state into a sub-Progress of the animation which starts with a value of 0.0 when the animation reaches the progress value from and ends with a value of 1.0 when the animation reaches the progress value to. If the from and to values are invalid, this method will correct them.
      Parameters:
      from - The progress value at which the sub-progress should start. This value must be between 0 and 1, otherwise it will be adjusted and a warning will be logged.
      to - The progress value at which the sub-progress should end. This value must be between 0 and 1, otherwise it will be adjusted and a warning will be logged.
      Returns:
      A Progress object that represents the sub-progress of the animation. This sub-progress will start with a value of 0.0 when the animation reaches the progress value from and will end with a value of 1.0 when the animation reaches the progress value to.
    • repeats

      public long repeats()
      A single iteration of an animation consists of its progress going from 0 to 1 in case of it being progressive, or from 1 to 0 in case of it being regressive (see Stride). This method returns the number of times the animation has been repeated.
      Returns:
      The number of times the animation has been repeated. This number is guaranteed to be 0 at the beginning of the animation, and for most animations it will be 0 at the end of the animation as well. An animation may be repeated if it is explicitly scheduled to run for a longer time.
    • lifeSpan

      public LifeSpan lifeSpan()
      Exposes the LifeSpan of the animation, which defines when the animation starts, for how long it should run, how is should progress and the refresh rate of the animation.
      Returns:
      The LifeSpan of the animation, i.e. the time when the animation started and how long it should run.
    • event

      public ActionEvent event()
      Exposes the timer event that triggered the animation. Note that under the hood, all animations with the same refresh rate will be updated by the same timer and thus share the same event.
      Returns:
      The timer event that triggered the animation.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object