edu.princeton.cs.algs4.growingtree.framework
Class AbstractAnimation

java.lang.Object
  extended by edu.princeton.cs.algs4.growingtree.framework.AbstractAnimation
All Implemented Interfaces:
Animation
Direct Known Subclasses:
BalanceBSTAnimation, DeleteBSTAnimation, DisplayChangeAnimation, FreezeAnimation, InsertBSTAnimation, MovingBSTTreeAnimation, PartitionBSTAnimation, RotationBSTAnimation, RotationDoubleBSTAnimation, SearchBSTAnimation, SelectionBSTAnimation, SwapBSTAnimation, TraverseBSTAnimation

public abstract class AbstractAnimation
extends java.lang.Object
implements Animation

The Abstract Animation object defines numerous methods of an Animation that are independent of the specific type of Animation, resulting in much repeated code. Therefore, that code has been inserted in this abstract class that many Animations extend to take use of these methods.

drawAnimation must be defined to extend this class appropriately.

Version:
2.1 9/15/01
Author:
Corey Sanders

Field Summary
static int DEFAULT_CONVERSION
          The Default step conversion used in animation (400).
static int DEFAULT_STEP
          The Default step size used in the animation (16).
 
Fields inherited from interface edu.princeton.cs.algs4.growingtree.framework.Animation
ANIMATION_MESSAGE, BEGIN, FINISH, PAUSE, PLAY, REDRAW, REWIND, STEP, STOP
 
Constructor Summary
AbstractAnimation()
          The constructor which initiates the abstract animation.
 
Method Summary
 void addAnimationListener(AnimationListener l)
          Adds an animationListener that recieves meaningful events from the animation, according to the Animation interface and the AnimationEvent.
 void addDescription(java.lang.String d)
          Adds a description that may be used to describe to the listener the type of event occuring.
 void drawAnimation(java.awt.Graphics2D g2)
          Draws the animation of the next step, using the status of the animation (Animation.PLAY, Animation.PAUSE and so forth).
 void drawAnimation(java.awt.Graphics2D g2, java.lang.String startingStatus)
          Draws the animation of the next step, using the status of the animation (Animation.PLAY, Animation.PAUSE and so forth).
 java.lang.String getDescription()
          Gets the description added with addDescription and should be accessed through the listener.
 AnimationListener[] getListeners()
          Returns an array of all the listeners that were added to this Animation with addAnimationListener.
 java.lang.String getStatus()
          Gets the status of the Animation using a command within Animation interface.
 boolean getStep()
          Gets whether the current animation is in stepping mode or not.
 int getStepTime()
          Gets the step time for the animation.
 void removeAnimationListener(AnimationListener l)
          Removes an animationListener from the animation, according to the Animation interface and the AnimationEvent.
 void setStatus(java.lang.String cmd)
          Sets the status of the Animation using a command within Animation interface.
 void setStep(boolean b)
          Sets whether the current animation is in stepping mode or not.
 void setStepTime(int t)
          Sets the step time for the animation.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_STEP

public static final int DEFAULT_STEP
The Default step size used in the animation (16).

See Also:
Constant Field Values

DEFAULT_CONVERSION

public static final int DEFAULT_CONVERSION
The Default step conversion used in animation (400).

See Also:
Constant Field Values
Constructor Detail

AbstractAnimation

public AbstractAnimation()
The constructor which initiates the abstract animation.

Method Detail

getStepTime

public int getStepTime()
Gets the step time for the animation.

Specified by:
getStepTime in interface Animation
Returns:
int step time

getDescription

public java.lang.String getDescription()
Gets the description added with addDescription and should be accessed through the listener.

Specified by:
getDescription in interface Animation
Returns:
the string defining the description.

getStep

public boolean getStep()
Gets whether the current animation is in stepping mode or not. Step mode indicates skipping the intermediary drawings in the animation and going instantly from one step to the next. Generally useful for fast-forward.

Specified by:
getStep in interface Animation
Returns:
boolean defining whether it is skipping.

getStatus

public java.lang.String getStatus()
Gets the status of the Animation using a command within Animation interface.

Specified by:
getStatus in interface Animation
Returns:
the Animation's status.

getListeners

public AnimationListener[] getListeners()
Returns an array of all the listeners that were added to this Animation with addAnimationListener.

If no such listener list exists, then an empty array is returned.

Returns:
array of AnimationListeners.

setStepTime

public void setStepTime(int t)
Sets the step time for the animation.

Specified by:
setStepTime in interface Animation
Parameters:
t - the step time

addDescription

public void addDescription(java.lang.String d)
Adds a description that may be used to describe to the listener the type of event occuring. The value of teh description may be retrieved through getDescription.

Specified by:
addDescription in interface Animation
Parameters:
d - the string defining the description.

setStep

public void setStep(boolean b)
Sets whether the current animation is in stepping mode or not. Step mode indicates skipping the intermediary drawings in the animation and going instantly from one step to the next. Generally useful for fast-forward.

Specified by:
setStep in interface Animation
Parameters:
b - boolean defining whether it is skipping.

setStatus

public void setStatus(java.lang.String cmd)
Sets the status of the Animation using a command within Animation interface.

Specified by:
setStatus in interface Animation
Parameters:
cmd - cmd that the Animation's status is set to.

addAnimationListener

public void addAnimationListener(AnimationListener l)
Adds an animationListener that recieves meaningful events from the animation, according to the Animation interface and the AnimationEvent.

Specified by:
addAnimationListener in interface Animation
Parameters:
l - the listener for the AnimationEvents occuring within this Animation.

removeAnimationListener

public void removeAnimationListener(AnimationListener l)
Removes an animationListener from the animation, according to the Animation interface and the AnimationEvent.

Specified by:
removeAnimationListener in interface Animation
Parameters:
l - the listener removed from recieving the AnimationEvents occuring within this Animation.

drawAnimation

public void drawAnimation(java.awt.Graphics2D g2)
Draws the animation of the next step, using the status of the animation (Animation.PLAY, Animation.PAUSE and so forth). After completing the drawing, the Animation sends an AnimationEvent to all its listeners, indicating any information that the listerners may wish to use.

The starting status used for the animation is the one previously defined.

Specified by:
drawAnimation in interface Animation
Parameters:
b - boolean defining whether it is skipping.

drawAnimation

public void drawAnimation(java.awt.Graphics2D g2,
                          java.lang.String startingStatus)
Draws the animation of the next step, using the status of the animation (Animation.PLAY, Animation.PAUSE and so forth). This must be declared to extend this abstract class.

Specified by:
drawAnimation in interface Animation
Parameters:
g2 - the graphics to which the animation step should be drawn.
startingStatus - the status used as the starting command of animation, if needed.