Package com.formdev.flatlaf.util
Class Animator
- java.lang.Object
-
- com.formdev.flatlaf.util.Animator
-
public class Animator extends java.lang.Object
Simple animator based on ideas and concepts from "Filthy Rich Clients" book and "Timing Framework" library.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Animator.Interpolator
Interpolator used by animation to change timing fraction.static interface
Animator.TimingTarget
Animation callbacks.
-
Field Summary
Fields Modifier and Type Field Description private int
duration
private java.lang.Runnable
endRunnable
private boolean
hasBegun
private Animator.Interpolator
interpolator
private int
resolution
private boolean
running
private long
startTime
private java.util.ArrayList<Animator.TimingTarget>
targets
private javax.swing.Timer
timer
private boolean
timeToStop
-
Constructor Summary
Constructors Constructor Description Animator(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, java.lang.Runnable endRunnable)
Creates an animation that runs duration milliseconds.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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
getDuration()
Returns the duration of the animation in milliseconds.Animator.Interpolator
getInterpolator()
Returns the interpolator for the animation.int
getResolution()
Returns the resolution of the animation in milliseconds (default is 10).private float
getTimingFraction()
boolean
isRunning()
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
throwExceptionIfRunning()
private void
timingEvent(float fraction)
static boolean
useAnimation()
Checks whether animations are enabled (the default) or disabled via system propertyflatlaf.animation
set tofalse
.
-
-
-
Field Detail
-
duration
private int duration
-
resolution
private int resolution
-
interpolator
private Animator.Interpolator interpolator
-
targets
private final java.util.ArrayList<Animator.TimingTarget> targets
-
endRunnable
private final java.lang.Runnable endRunnable
-
running
private boolean running
-
hasBegun
private boolean hasBegun
-
timeToStop
private boolean timeToStop
-
startTime
private long startTime
-
timer
private javax.swing.Timer timer
-
-
Constructor Detail
-
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
public Animator(int duration, Animator.TimingTarget target)
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
public Animator(int duration, Animator.TimingTarget target, java.lang.Runnable endRunnable)
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 Detail
-
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:
java.lang.IllegalStateException
- if animation is runningjava.lang.IllegalArgumentException
- 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:
java.lang.IllegalStateException
- if animation is runningjava.lang.IllegalArgumentException
- if resolution is <= zero
-
getInterpolator
public Animator.Interpolator getInterpolator()
Returns the interpolator for the animation. Default isnull
, which means linear.
-
setInterpolator
public void setInterpolator(Animator.Interpolator interpolator)
Sets the interpolator for the animation.- Throws:
java.lang.IllegalStateException
- if animation is running
-
addTarget
public void addTarget(Animator.TimingTarget target)
Adds a target to the animation that receives timing events.- Parameters:
target
- the target that receives timing events
-
removeTarget
public void removeTarget(Animator.TimingTarget target)
Removes a target from the animation.- Parameters:
target
- the target that should be removed
-
start
public void start()
Starts the animation.- Throws:
java.lang.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()
-
-