public abstract class Animation
extends java.lang.Object
An animation to control a continuous change on a CElement
: a CShape
, a CTag
or a Canvas
.
Animating a CTag
or a Canvas
means animating every CShape
tagged by this tag or displayed in this canvas.
An animation lasts a given number of "laps". A "lap" lasts durationLap
milliseconds (by default, 1000). During a "lap", the value of a parameter t starts at 0 and ends at 1 for odd laps
(and starts at 1 and ends at 0 for even laps.
Value of parameter t whose value is updated every delay
milliseconds (by default, 40).
t value follows a pacing funcyion (by default, a linear pacing function).
An animation can be started, stopped, suspended and resumed.
You can also override the methods doStart()
, doStop()
, doSuspend()
and doResume()
to define specific treatments applied when calling respectively the methods start()
, stop()
, suspend()
and resume()
.
For example, if you want to change the color of the animated elements when you start and stop an animation that rotate and translate:
class AnimationRotateAndTranslateBy extends Animation { double rotate; double translatex, translatey; public AnimationRotateAndTranslateBy(double r, double tx, double ty) { super(); rotate = r; translatex = tx; translatey = ty; } public void step(double t) { getAnimated().rotateBy(rotate).scaleBy(translatex, translatey); } public void doStart() { getAnimated().setFillPaint(Color.RED); } public void doStop() { getAnimated().setFillPaint(Color.LIGHT_GRAY); } }
Modifier and Type | Field and Description |
---|---|
static short |
FUNCTION_LINEAR
The constant to pass to the method
setFunction(short) to have a linear pacing function. |
static short |
FUNCTION_SIGMOID
The constant to pass to the method
setFunction(short) to have a "sigmoid" pacing function. |
static int |
INFINITE_NUMBER_OF_LAPS
The constant to pass to the method
setNbLaps(int) to make an animation never stop. |
Constructor and Description |
---|
Animation()
Builds an animation and registers it to the animation manager.
|
Modifier and Type | Method and Description |
---|---|
Animation |
addTag(AExtensionalTag t)
Adds a tag to this animation.
|
Animation |
addTag(java.lang.String t)
Adds a
ANamedTag tag to this animation. |
void |
doResume()
Method called when this animation is resumed.
|
void |
doStart()
Method called when this animation is started.
|
void |
doStop()
Method called when this animation is stopped.
|
void |
doSuspend()
Method called when this animation is suspended.
|
CElement |
getAnimated() |
int |
getDelay() |
long |
getLapDuration() |
int |
getNbLaps() |
short |
getPacingFunction() |
boolean |
hasTag(ATag t)
Tests whether this animation has a given tag.
|
boolean |
hasTag(java.lang.String t)
Tests whether this animation has a given
ANamedTag tag. |
boolean |
isStarted() |
boolean |
isSuspended() |
Animation |
removeTag(AExtensionalTag t)
Removes a tag from this animation.
|
Animation |
removeTag(java.lang.String t)
Removes a tag from this animation.
|
static void |
resetAnimationManager()
For internal use.
|
Animation |
resume()
Resumes this animation that has been resumed using the method
resume() . |
Animation |
setAnimatedElement(CElement ce)
Sets the
CElement that must be animated by this animation. |
void |
setCanvas(Canvas canvas) |
Animation |
setDelay(int d)
Sets the delay between to successive values of the parameter t.
|
Animation |
setFunction(short t)
Sets the type of the pacing function, use the static constants
Animation.FUNCTION_LINEAR or Animation.FUNCTION_SIGMOID . |
Animation |
setLapDuration(long d)
Sets the duration of a "lap".
|
Animation |
setNbLaps(int laps)
Sets the number of laps of this animation.
|
Animation |
start()
Starts this animation.
|
abstract void |
step(double t)
Override this abstract to specify the effect of this animation.
|
Animation |
stop()
Stops this animation.
|
Animation |
suspend()
Suspends this animation.
|
public static short FUNCTION_LINEAR
setFunction(short)
to have a linear pacing function.public static short FUNCTION_SIGMOID
setFunction(short)
to have a "sigmoid" pacing function. A sigmoid function corresponds to a slow-in/fast-out effect.public static int INFINITE_NUMBER_OF_LAPS
setNbLaps(int)
to make an animation never stop.public Animation()
public static void resetAnimationManager()
SwingStatesApplet
.SwingStatesApplet.init()
public Animation setDelay(int d)
d
- The delay in milliseconds.public long getLapDuration()
public Animation setLapDuration(long d)
d
- The duration in milliseconds.public Animation setFunction(short t)
Animation.FUNCTION_LINEAR
or Animation.FUNCTION_SIGMOID
.
By default, the type function is linear.t
- The type of the pacing function.public Animation setNbLaps(int laps)
laps
- The number of laps.public Animation setAnimatedElement(CElement ce)
CElement
that must be animated by this animation.
If the canvas that must received animation events has not yet been set,
it is set to the canvas to which belongs this CElement
.ce
- The CElement
to animate.public void doStart()
start()
public final Animation start()
public void doStop()
stop()
public final Animation stop()
public void doSuspend()
suspend()
public final Animation suspend()
resume()
to resume the animation being suspended.resume()
public void doResume()
resume()
public final Animation resume()
resume()
.suspend()
public abstract void step(double t)
t
- The parameter of this animation.public CElement getAnimated()
CElement
animated by this animation.public Animation addTag(AExtensionalTag t)
t
- The tag to be addedpublic Animation addTag(java.lang.String t)
ANamedTag
tag to this animation.t
- The name of the tag to be addedpublic Animation removeTag(AExtensionalTag t)
t
- The tag to removepublic Animation removeTag(java.lang.String t)
t
- The name of the ANamedTag
tag to removepublic boolean hasTag(ATag t)
t
- The tag to be testedpublic boolean hasTag(java.lang.String t)
ANamedTag
tag.t
- The name of the tag to be testedpublic short getPacingFunction()
Animation
: Animation.FUNCTION_LINEAR
or Animation.FUNCTION_SIGMOID
.public int getDelay()
public int getNbLaps()
public boolean isSuspended()
public void setCanvas(Canvas canvas)
canvas
- Sets the canvas on which will be fired animation events.public boolean isStarted()