Package swingtree.animation
Class LifeTime
java.lang.Object
swingtree.animation.LifeTime
The lifetime is an immutable and thread safe value based object, which
defines for how long an
You can create a new lifetime using the static factory methods
Update an existing lifetime using the methods
This class is typically used to schedule animations. The most straight forward way would be to call
Another use case is to schedule an animation through the component event delegate as part of your event handling code using
This may look like this:
Animation
should run.
It consists of a delay, interval and duration as well as a unique id
which ensures that two instances of this class are never equal.
You can create a new lifetime using the static factory methods
of(long, TimeUnit)
,
of(double, TimeUnit)
, of(long, TimeUnit, long, TimeUnit)
and of(double, TimeUnit, double, TimeUnit)
.
Update an existing lifetime using the methods
startingIn(long, TimeUnit)
and withInterval(long, TimeUnit)
.
Note that the default interval of a newly created lifetime is always 16 ms which corresponds to 60 fps.
This class is typically used to schedule animations. The most straight forward way would be to call
UIFactoryMethods.animateFor(LifeTime)
or UIFactoryMethods.animateFor(LifeTime, Component)
.
But you may also schedule a style animation using UIForAnySwing.withTransitoryStyle(Event, LifeTime, AnimatedStyler)
or UIForAnySwing.withTransitionalStyle(Val, LifeTime, AnimatedStyler)
. Another use case is to schedule an animation through the component event delegate as part of your event handling code using
AbstractDelegate.animateFor(LifeTime)
. This may look like this:
UI.button("I pop when you hover over me")
.onMouseEnter( it -> it.animateFor(1, TimeUnit.SECONDS, state -> {
it.style(state, conf -> conf
.borderWidth( 10 * state.cycle() )
.borderColor(UI.color(1,1,0,1-state.cycle()))
.borderRadius( 100 * state.cycle() )
);
}))
-
Method Summary
Modifier and TypeMethodDescriptionboolean
long
getDelayIn
(TimeUnit unit) Returns the delay after which the animation should start in the given time unit.long
getDurationIn
(TimeUnit unit) Returns the duration of the animation in the given time unit.long
getIntervalIn
(TimeUnit unit) Returns the interval in the given time unit, which is a number that determines the delay between two consecutive animation steps.int
hashCode()
static LifeTime
Creates a new lifetime that will run for the given duration in the given time unit and without any start delay.static LifeTime
Creates a new lifetime that will start after the given delay and run for the given duration.static LifeTime
Creates a new lifetime that will run for the given duration and without any start delay.static LifeTime
Creates a new lifetime that will start after the given delay and run for the given duration.startingIn
(long delay, TimeUnit unit) Creates a new lifetime that will start after the given delay in the given time unit.toString()
withInterval
(long interval, TimeUnit unit) Updates this lifetime with the given interval, which is a property that determines the delay between two consecutive animation steps.
-
Method Details
-
of
Creates a new lifetime that will run for the given duration and without any start delay.- Parameters:
time
- The duration of the animation.unit
- The time unit of the duration.- Returns:
- A new lifetime that will start immediately and run for the given duration.
-
of
Creates a new lifetime that will run for the given duration in the given time unit and without any start delay.
Contrary to theof(long, TimeUnit)
method, this method uses adouble
type to allow for fractional time values.- Parameters:
time
- The duration of the animation.unit
- The time unit of the duration.- Returns:
- A new lifetime that will start immediately and run for the given duration.
-
of
public static LifeTime of(long startDelay, TimeUnit startUnit, long duration, TimeUnit durationUnit) Creates a new lifetime that will start after the given delay and run for the given duration.- Parameters:
startDelay
- The delay after which the animation should start.startUnit
- The time unit of the delay.duration
- The duration of the animation.durationUnit
- The time unit of the duration.- Returns:
- A new lifetime that will start after the given delay and run for the given duration.
-
of
public static LifeTime of(double startDelay, TimeUnit startUnit, double duration, TimeUnit durationUnit) Creates a new lifetime that will start after the given delay and run for the given duration. Contrary to theof(long, TimeUnit, long, TimeUnit)
method, this method uses adouble
type to allow for fractional time values.- Parameters:
startDelay
- The delay after which the animation should start.startUnit
- The time unit of the delay.duration
- The duration of the animation.durationUnit
- The time unit of the duration.- Returns:
- A new lifetime that will start after the given delay and run for the given duration.
-
startingIn
Creates a new lifetime that will start after the given delay in the given time unit.- Parameters:
delay
- The delay after which the animation should start.unit
- The time unit of the delay.- Returns:
- A new lifetime that will start after the given delay.
-
withInterval
Updates this lifetime with the given interval, which is a property that determines the delay between two consecutive animation steps. You can think of it as the time between the heartbeats of the animation. The smaller the interval, the higher the refresh rate and the smoother the animation will look. However, the smaller the interval, the more CPU time will be used. The default interval is 16 ms which corresponds to 60 fps.
If you want a custom interval default, you can configure it during library initialization through theSwingTree.initialiseUsing(SwingTreeConfigurator)
method or change it at any other time using theSwingTree.setDefaultAnimationInterval(long)
method.- Parameters:
interval
- The interval in the given time unit.unit
- The time unit of the interval, typicallyTimeUnit.MILLISECONDS
.- Returns:
- A new lifetime that will start after the given delay and run for the given duration.
-
getDurationIn
Returns the duration of the animation in the given time unit.- Parameters:
unit
- The time unit in which the duration should be returned.- Returns:
- The duration of the animation.
-
getDelayIn
Returns the delay after which the animation should start in the given time unit.- Parameters:
unit
- The time unit in which the delay should be returned.- Returns:
- The delay after which the animation should start.
-
getIntervalIn
Returns the interval in the given time unit, which is a number that determines the delay between two consecutive animation steps. You can think of it as the time between the heartbeats of an animation. The smaller the interval, the higher the refresh rate and the smoother the animation will look. However, the smaller the interval, the more CPU time will be used. The default interval is 16 ms which corresponds to 60 fps.
If you want a custom interval default, you can configure it during library initialization through theSwingTree.initialiseUsing(SwingTreeConfigurator)
method or change it at any other time using theSwingTree.setDefaultAnimationInterval(long)
method.- Parameters:
unit
- The time unit in which the interval should be returned.- Returns:
- The interval in the given time unit.
-
equals
-
hashCode
public int hashCode() -
toString
-