Class Animatable<M>

java.lang.Object
swingtree.animation.Animatable<M>
Type Parameters:
M - The type of the model that is continuously transformed by the AnimationTransformation.

public final class Animatable<M> extends Object
This defines what is needed for animating an immutable value type T through a transformation function AnimationTransformation and a LifeTime determining when the animation should run. It is essentially just an immutable wrapper for T, AnimationTransformation and a LifeTime.

An Animatable is designed to be provided by an immutable view model to animate its properties using the UIFactoryMethods.animate(Var, Animatable) or UIFactoryMethods.animate(Var, Function) methods.
Where the Var property is used as the mutable animation state and the animatable defines how the property item should be transformed repeatedly during the iterations of the entire animation lifetime.

  • Method Details

    • none

      public static <T> Animatable<T> none()
      Returns an Animatable instance that does nothing when run due to a LifeTime of LifeTime.none(). This is equivalent to a no-op and may also be used instead of null in cases where an Animatable is expected.
      Type Parameters:
      T - The type of model that is animated.
      Returns:
      An Animatable instance that does nothing.
    • of

      public static <T> Animatable<T> of(T value)
      Returns an Animatable instance that merely holds the supplied value and does nothing when run due to a no-op transformation function and a LifeTime of LifeTime.none().
      You can think of this as an instantaneous animation to the specified value as the first and final state of the "animation".
      Type Parameters:
      T - The type of model used as new animation/application state.
      Parameters:
      value - The value that should be used for setting the new application/animator state.
      Returns:
      An Animatable instance that only holds a single animation state, which is the supplied value.
      Throws:
      NullPointerException - If the supplied value is null.
    • of

      public static <T> Animatable<T> of(LifeTime lifeTime, T initialValue, AnimationTransformation<T> animation)
      Returns an Animatable instance that animates the supplied value through the provided AnimationTransformation function during the specified LifeTime starting with the supplied initial value as initial application/animation state.
      Type Parameters:
      T - The type of model that is animated.
      Parameters:
      lifeTime - The lifetime of the animation.
      initialValue - The initial value of the animation.
      animation - The transformation function that is called repeatedly during the lifetime of the animation.
      Returns:
      An Animatable instance that animates the supplied value.
      Throws:
      NullPointerException - If any of the arguments is null.
      See Also:
    • of

      public static <T> Animatable<T> of(LifeTime lifeTime, AnimationTransformation<T> animation)
      Returns an Animatable instance that is used to transform T values using the supplied AnimationTransformation function during the specified LifeTime.
      Type Parameters:
      T - The type model that is animated.
      Parameters:
      lifeTime - The lifetime of the animation.
      animation - The transformation function that is called repeatedly during the lifetime of the animation.
      Returns:
      An Animatable instance that animates the supplied value.
      Throws:
      NullPointerException - If any of the arguments is null.
      See Also:
    • lifeTime

      public LifeTime lifeTime()
      Returns the LifeTime of the animation, which is used by UIFactoryMethods.animate(Var, Animatable) to determine for how long the animation should run.
      Returns:
      The LifeTime of the animation.
    • initialState

      public Optional<M> initialState()
      Returns the initial value of the animation or an empty Optional if no initial value is set. This is the value that is used as the initial state of the animation before the first transformation is applied.
      If there is no initial value set, the result of the first transformation is used as the initial state of the animation.
      Returns:
      The initial model instance of the animation state or an empty Optional.
      See Also:
    • animator

      public AnimationTransformation<M> animator()
      Returns the transformation function that is called repeatedly during the lifetime of the animation to transform the item of a Var property when passed to the UIFactoryMethods.animate(Var, Animatable) method.
      Returns:
      The transformation function of the animation.
    • toString

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object