Class AbstractAnimation

java.lang.Object
  |
  +--AbstractAnimation
All Implemented Interfaces:
Animation
Direct Known Subclasses:
BalanceBSTAnimation, DeleteBSTAnimation, DisplayChangeAnimation, InsertBSTAnimation, MovingBSTTreeAnimation, PartitionBSTAnimation, RotationBSTAnimation, RotationDoubleBSTAnimation, SearchBSTAnimation, SelectionBSTAnimation, 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.


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).
protected  java.util.LinkedList listeners
          The list of listeners to this Animation Object.
 
Fields inherited from interface 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.
protected  void animationAction()
          Calls all of the listeners of the current Animation and passed information regarding the progress and status of the current Animation.
protected  void animationAction(int id, java.lang.String cmd, java.lang.String description, double progress)
          Calls all of the listeners of the current Animation and passes information regarding the progress and status of the current Animation.
protected  void animationAction(java.lang.String cmd, java.lang.String description)
          Calls all of the listeners of the current Animation and passed information regarding the progress and status of the current Animation.
 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.
protected  java.lang.String getStartingCommand()
          Gets the starting command for the current animation.
 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.
protected  int getStepConversion()
          Gets the conversion factor for step size and step time.
protected  double getStepSize()
          Gets the step size for the animation.
 int getStepTime()
          Gets the step time for the animation.
protected  void messageAction(java.lang.String msg)
          Calls animationAction with an ANIMATION_MESSAGE, sending the message to all of its listeners.
 void removeAnimationListener(AnimationListener l)
          Removes an animationListener from the animation, according to the Animation interface and the AnimationEvent.
protected  void setStartingCommand(java.lang.String command)
          Sets the starting command for the current animation.
 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.
protected  void setStepConversion(int conversion)
          Sets the conversion factor for step size and step time.
protected  void setStepSize(double t)
          Sets the step size for the animation.
 void setStepTime(int t)
          Sets the step time for the animation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listeners

protected java.util.LinkedList listeners
The list of listeners to this Animation Object. Used when the command addAnimationListener is used.


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

getStartingCommand

protected java.lang.String getStartingCommand()
Gets the starting command for the current animation. The starting command is used when the command is uncertain (Animation.BEGIN status).

Returns:
String starting command.

getStepConversion

protected int getStepConversion()
Gets the conversion factor for step size and step time. The integer dividend for the step time passed to make the step size.

Returns:
int conversion factor for a step.

getStepSize

protected double getStepSize()
Gets the step size for the animation.

Returns:
double step size

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.

setStartingCommand

protected void setStartingCommand(java.lang.String command)
Sets the starting command for the current animation. The starting command is used when the command is uncertain (Animation.BEGIN status).

Parameters:
command - String starting command.

setStepConversion

protected void setStepConversion(int conversion)
Sets the conversion factor for step size and step time. The integer dividend for the step time passed to make the step size.

Parameters:
conversion - factor of conversion for step time to step size.

setStepSize

protected void setStepSize(double t)
Sets the step size for the animation.

Parameters:
t - the step size

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.

animationAction

protected void animationAction(int id,
                               java.lang.String cmd,
                               java.lang.String description,
                               double progress)
Calls all of the listeners of the current Animation and passes information regarding the progress and status of the current Animation. Additionally, the id of the type of animation is passed. Within, the animationEventPerformed method is called.

Parameters:
id - int id for the animation
cmd - String Animation command passed instead of the current Status.
description - String description for messages.
progress - double progress of the animation

animationAction

protected void animationAction(java.lang.String cmd,
                               java.lang.String description)
Calls all of the listeners of the current Animation and passed information regarding the progress and status of the current Animation. The id ABSTRACT_ANIMATION is passed. Within, the animationEventPerformed method is called.

Parameters:
cmd - String Animation command passed instead of the current Status.
description - String description for messages.

animationAction

protected void animationAction()
Calls all of the listeners of the current Animation and passed information regarding the progress and status of the current Animation. The id ABSTRACT_ANIMATION is passed. The current status and current decription are passed. Within, the animationEventPerformed method is called.


messageAction

protected void messageAction(java.lang.String msg)
Calls animationAction with an ANIMATION_MESSAGE, sending the message to all of its listeners. The message is represented in the description string and the status string is Animation.ANIMATION_MESSAGE.

Parameters:
msg - the message sent to all of the listeners as an Animation.ANIMATION_MESSAGE.

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

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.