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 interfaceInterpolator used by animation to change timing fraction.static interfaceAnimation callbacks. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate final Runnableprivate booleanprivate Animator.Interpolatorprivate intprivate booleanprivate longprivate final ArrayList<Animator.TimingTarget> private Timerprivate 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 TypeMethodDescriptionvoidaddTarget(Animator.TimingTarget target) Adds a target to the animation that receives timing events.private voidbegin()voidcancel()Cancels the animation before it normally ends.private floatclampFraction(float fraction) private voidend()intReturns the duration of the animation in milliseconds.Returns the interpolator for the animation.intReturns the resolution of the animation in milliseconds (default is 10).private floatbooleanReturns whether this animation is running.voidremoveTarget(Animator.TimingTarget target) Removes a target from the animation.voidrestart()Restarts the animation.voidsetDuration(int duration) Sets the duration of the animation in milliseconds.voidsetInterpolator(Animator.Interpolator interpolator) Sets the interpolator for the animation.voidsetResolution(int resolution) Sets the resolution of the animation in milliseconds.voidstart()Starts the animation.voidstop()Stops the animation before it normally ends.private voidstop(boolean cancel) private voidprivate voidtimingEvent(float fraction) static booleanChecks whether animations are enabled (the default) or disabled via system propertyflatlaf.animationset 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.animationset 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
-
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
-
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()
-