Package com.formdev.flatlaf.util
Class Animator
java.lang.Object
com.formdev.flatlaf.util.Animator
Simple animator based on ideas and concepts from "Filthy Rich Clients" book
and "Timing Framework" library.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Interpolator used by animation to change timing fraction.static interface
Animation callbacks. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
private final Runnable
private boolean
private Animator.Interpolator
private int
private boolean
private long
private final ArrayList
<Animator.TimingTarget> private Timer
private boolean
-
Constructor Summary
ConstructorsConstructorDescriptionAnimator
(int duration) Creates an animation that runs duration milliseconds.Animator
(int duration, Animator.TimingTarget target) Creates an animation that runs duration milliseconds.Animator
(int duration, Animator.TimingTarget target, Runnable endRunnable) Creates an animation that runs duration milliseconds. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addTarget
(Animator.TimingTarget target) Adds a target to the animation that receives timing events.private void
begin()
void
cancel()
Cancels the animation before it normally ends.private float
clampFraction
(float fraction) private void
end()
int
Returns the duration of the animation in milliseconds.Returns the interpolator for the animation.int
Returns the resolution of the animation in milliseconds (default is 10).private float
boolean
Returns whether this animation is running.void
removeTarget
(Animator.TimingTarget target) Removes a target from the animation.void
restart()
Restarts the animation.void
setDuration
(int duration) Sets the duration of the animation in milliseconds.void
setInterpolator
(Animator.Interpolator interpolator) Sets the interpolator for the animation.void
setResolution
(int resolution) Sets the resolution of the animation in milliseconds.void
start()
Starts the animation.void
stop()
Stops the animation before it normally ends.private void
stop
(boolean cancel) private void
private void
timingEvent
(float fraction) static boolean
Checks whether animations are enabled (the default) or disabled via system propertyflatlaf.animation
set tofalse
.
-
Field Details
-
duration
private int duration -
resolution
private int resolution -
interpolator
-
targets
-
endRunnable
-
running
private boolean running -
hasBegun
private boolean hasBegun -
timeToStop
private boolean timeToStop -
startTime
private long startTime -
timer
-
-
Constructor Details
-
Animator
public Animator(int duration) Creates an animation that runs duration milliseconds. UseaddTarget(TimingTarget)
to receive timing events andstart()
to start the animation.- Parameters:
duration
- the duration of the animation in milliseconds
-
Animator
Creates an animation that runs duration milliseconds. Usestart()
to start the animation.- Parameters:
duration
- the duration of the animation in millisecondstarget
- the target that receives timing events
-
Animator
Creates an animation that runs duration milliseconds. Usestart()
to start the animation.- Parameters:
duration
- the duration of the animation in millisecondstarget
- the target that receives timing eventsendRunnable
- a runnable invoked when the animation ends; ornull
-
-
Method Details
-
useAnimation
public static boolean useAnimation()Checks whether animations are enabled (the default) or disabled via system propertyflatlaf.animation
set tofalse
. This allows disabling all animations at command line with-Dflatlaf.animation=false
. -
getDuration
public int getDuration()Returns the duration of the animation in milliseconds. -
setDuration
public void setDuration(int duration) Sets the duration of the animation in milliseconds.- Throws:
IllegalStateException
- if animation is runningIllegalArgumentException
- if duration is <= zero
-
getResolution
public int getResolution()Returns the resolution of the animation in milliseconds (default is 10). Resolution is the amount of time between timing events. -
setResolution
public void setResolution(int resolution) Sets the resolution of the animation in milliseconds.- Parameters:
resolution
- the resolution of the animation in milliseconds- Throws:
IllegalStateException
- if animation is runningIllegalArgumentException
- if resolution is <= zero
-
getInterpolator
Returns the interpolator for the animation. Default isnull
, which means linear. -
setInterpolator
Sets the interpolator for the animation.- Throws:
IllegalStateException
- if animation is running
-
addTarget
Adds a target to the animation that receives timing events.- Parameters:
target
- the target that receives timing events
-
removeTarget
Removes a target from the animation.- Parameters:
target
- the target that should be removed
-
start
public void start()Starts the animation.- Throws:
IllegalStateException
- if animation is running
-
stop
public void stop()Stops the animation before it normally ends. InvokesAnimator.TimingTarget.end()
on timing targets. -
cancel
public void cancel()Cancels the animation before it normally ends. Does not invokeAnimator.TimingTarget.end()
on timing targets. -
stop
private void stop(boolean cancel) -
restart
public void restart() -
isRunning
public boolean isRunning()Returns whether this animation is running. -
getTimingFraction
private float getTimingFraction() -
clampFraction
private float clampFraction(float fraction) -
timingEvent
private void timingEvent(float fraction) -
begin
private void begin() -
end
private void end() -
throwExceptionIfRunning
private void throwExceptionIfRunning()
-