Package swingtree.animation
Interface AnimationTransformation<T>
- Type Parameters:
T
- The type of the value that is animated through repeated transformations.
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Defines an animation in terms of functional transformations
taking in an
The value is expected to be immutable and may be everything from a simple
AnimationStatus
together with a value
and returning an updated value. The value is expected to be immutable and may be everything from a simple
Number
to a complex view model
holding your application state and business logic.
Implementations of this are designed to be used as
part of the Animatable
class holding the initial
animation state and the LifeTime
determining
when the animation should run.
So you may use this interface to define an Animatable
like this:
return Animatable.of(
LifeTime.of(0.45, TimeUnit.SECONDS), this,
(status, model) -> model.withFontSize((int) (24 + status.pulse() * 16))
);
An Animatable
may then be passed to
UIFactoryMethods.animate(sprouts.Var, Animatable)
together
with a Var
property to repeatedly transform
the property item during the iterations of the entire animation lifetime.-
Method Summary
Modifier and TypeMethodDescriptiondefault T
finish
(AnimationStatus status, T value) This method is called after the animation has finished.run
(AnimationStatus status, T value) This takes in the currentAnimationStatus
and an immutable value of typeT
and returns a new updated value of typeT
.
-
Method Details
-
run
This takes in the currentAnimationStatus
and an immutable value of typeT
and returns a new updated value of typeT
. This may typically be an immutable view model whose fields are bound to the UI components of your application through property lenses.- Parameters:
status
- The current status of the animation.value
- The current value of the animated item.- Returns:
- The updated value of the animated item based on the current status,
typically the
AnimationStatus.progress()
number. - Throws:
Exception
- If the method call encounters errors in the execution of its implementations. Due to this being a generic interface, the likelihood of exceptions being thrown is high and so it is recommended to handle them at the invocation site.
-
finish
This method is called after the animation has finished. The default implementation does nothing but returns the supplied value.
Implement this to create a cleaned up final version of the item after the animation has finished.
Note that this method deliberately requires the handling of checked exceptions at its invocation sites because there may be any number of implementations hiding behind this interface and so it is unwise to assume that all of them will be able to execute gracefully without throwing exceptions.- Parameters:
status
- The current progress status of the animation, which is used to determine the intermediate values of the animated item. You may typically want to use theAnimationStatus.progress()
number to interpolate fields of your view model.value
- The final value of the animated item, which is expected to be an immutable object.- Returns:
- The final value of the animated item after the animation has finished.
- Throws:
Exception
- If the method call encounters errors in the execution of its implementations. Due to this being a generic interface, the likelihood of exceptions being thrown is high and so it is recommended to handle them at the invocation site.
-