Package swingtree.animation
Class Animator
java.lang.Object
swingtree.animation.Animator
An API for creating an
The UI API can be used like so:
Animation
and defining how it should be executed.
Instances of this class are intended to be created and used either by the
UI
API or the user event delegation API (see ComponentDelegate
). The UI API can be used like so:
UI.schedule( 100, TimeUnit.MILLISECONDS ) // returns an Animate instance
.until( it -> it.progress() >= 0.75 && someOtherCondition() )
.go( state -> {
// do something
someComponent.setValue( it.progress() );
// ...
someComponent.repaint();
});
The user event delegation API can be used like this:
panel()
.onMouseClick( it -> {
it.animateFor( 100, TimeUnit.MILLISECONDS )
.goOnce( state -> {
int width = (int) (100 * state.progress());
it.getComponent().setSize( width, 100 );
});
})
-
Method Summary
Modifier and TypeMethodDescriptionstatic Animator
animateFor
(LifeTime lifeTime) Creates anAnimator
instance which allows you to define the stop condition for an animation as well as anAnimation
that will be executed when passed to thego(Animation)
method.static Animator
animateFor
(LifeTime lifeTime, Component component) Creates anAnimator
instance which allows you to define the stop condition for an animation as well as anAnimation
that will be executed when passed to thego(Animation)
method.static Animator
animateFor
(LifeTime lifeTime, Stride stride) Creates anAnimator
instance which allows you to define the stop condition for an animation as well as anAnimation
that will be executed when passed to thego(Animation)
method.static Animator
animateFor
(LifeTime lifeTime, Stride stride, Component component) Creates anAnimator
instance which allows you to define the stop condition for an animation as well as anAnimation
that will be executed when passed to thego(Animation)
method.asLongAs
(Predicate<AnimationState> shouldRun) Use this to define a running condition for the animation.void
Runs the given animation based on the stop condition defined byuntil(Predicate)
orasLongAs(Predicate)
.void
goWithOffset
(long offset, TimeUnit unit, Animation animation) Runs the given animation based on a time offset in the given time unit and the stop condition defined byuntil(Predicate)
orasLongAs(Predicate)
.until
(Predicate<AnimationState> shouldStop) Use this to define a stop condition for the animation.
-
Method Details
-
animateFor
Creates anAnimator
instance which allows you to define the stop condition for an animation as well as anAnimation
that will be executed when passed to thego(Animation)
method.- Parameters:
lifeTime
- The schedule that defines when the animation should be executed and for how long.- Returns:
- An
Animator
instance that can be used to define how the animation should be executed.
-
animateFor
Creates anAnimator
instance which allows you to define the stop condition for an animation as well as anAnimation
that will be executed when passed to thego(Animation)
method.- Parameters:
lifeTime
- The schedule that defines when the animation should be executed and for how long.stride
- The stride of the animation, i.e. whether it should be executed progressively or regressively.- Returns:
- An
Animator
instance that can be used to define how the animation should be executed.
-
animateFor
Creates anAnimator
instance which allows you to define the stop condition for an animation as well as anAnimation
that will be executed when passed to thego(Animation)
method.- Parameters:
lifeTime
- The schedule that defines when the animation should be executed and for how long.component
- The component that should be repainted after each animation step.- Returns:
- An
Animator
instance that can be used to define how the animation should be executed.
-
animateFor
Creates anAnimator
instance which allows you to define the stop condition for an animation as well as anAnimation
that will be executed when passed to thego(Animation)
method.- Parameters:
lifeTime
- The schedule that defines when the animation should be executed and for how long.stride
- The stride of the animation, i.e. whether it should be executed progressively or regressively. SeeStride
for more information.component
- The component that should be repainted after each animation step.- Returns:
- An
Animator
instance that can be used to define how the animation should be executed.
-
until
Use this to define a stop condition for the animation.- Parameters:
shouldStop
- The stop condition for the animation, i.e. the animation will be executed until this condition is true.- Returns:
- A new
Animator
instance that will be executed until the given stop condition is true.
-
asLongAs
Use this to define a running condition for the animation.- Parameters:
shouldRun
- The running condition for the animation, i.e. the animation will be executed as long as this condition is true.- Returns:
- A new
Animator
instance that will be executed as long as the given running condition is true.
-
go
Runs the given animation based on the stop condition defined byuntil(Predicate)
orasLongAs(Predicate)
. If no stop condition was defined, the animation will be executed once. If you want to run an animation forever, simply passstate -> true
to theasLongAs(Predicate)
method, orstate -> false
to theuntil(Predicate)
method.- Parameters:
animation
- The animation that should be executed.
-
goWithOffset
Runs the given animation based on a time offset in the given time unit and the stop condition defined byuntil(Predicate)
orasLongAs(Predicate)
. If no stop condition was defined, the animation will be executed once. If you want to run an animation forever, simply passstate -> true
to theasLongAs(Predicate)
method, orstate -> false
to theuntil(Predicate)
method.This method is useful in cases where you want an animation to start in the future, or somewhere in the middle of their lifespan progress (see
AnimationState.progress()
).- Parameters:
offset
- The offset in the given time unit after which the animation should be executed. This number may also be negative, in which case the animation will be executed immediately, and with aAnimationState.progress()
value that is advanced according to the offset.unit
- The time unit in which the offset is specified.animation
- The animation that should be executed.
-