edu.princeton.cs.algs4.growingtree.framework
Class TraverseBSTAnimation<P extends NodeProperties>

java.lang.Object
  extended by edu.princeton.cs.algs4.growingtree.framework.AbstractAnimation
      extended by edu.princeton.cs.algs4.growingtree.framework.TraverseBSTAnimation<P>
All Implemented Interfaces:
Animation

public class TraverseBSTAnimation<P extends NodeProperties>
extends AbstractAnimation

The Animation object that defines the Searching in a BSTTree.

The object restores all values changed in the given nodes, however, if the object is never allowed to finish, the restoring of values becomes impossible. On any exception occuring elsewhere, the object may not restore the conditions correctly.

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

Field Summary
 
Fields inherited from class edu.princeton.cs.algs4.growingtree.framework.AbstractAnimation
DEFAULT_CONVERSION, DEFAULT_STEP
 
Fields inherited from interface edu.princeton.cs.algs4.growingtree.framework.Animation
ANIMATION_MESSAGE, BEGIN, FINISH, PAUSE, PLAY, REDRAW, REWIND, STEP, STOP
 
Constructor Summary
TraverseBSTAnimation()
          The constructor which initiates the status and sets the color schemes to null.
TraverseBSTAnimation(NodeSettings AnimatorScheme, KeySettings KeyAnimatorScheme, java.lang.String startingCmd, int stepTime)
          The constructor which initiates the status and prepares the colorSchemes.
 
Method Summary
 void add(GrowingTreeNode<P> node)
          Add a step to the Traversal Animation.
 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).
 NodeSettings getAnimatorScheme()
          Gets the NodeSettings for the animator scheme for the search.
 KeySettings getKeyAnimatorScheme()
          Sets the KeySettings for the animator scheme key for the search.
 void setAnimatorScheme(NodeSettings scheme)
          Sets the NodeSettings for the animator scheme for the insertion.
 void setKeyAnimatorScheme(KeySettings scheme)
          Sets the KeySettings for the animator scheme key for the insertion.
 
Methods inherited from class edu.princeton.cs.algs4.growingtree.framework.AbstractAnimation
addAnimationListener, addDescription, drawAnimation, getDescription, getListeners, getStatus, getStep, getStepTime, removeAnimationListener, setStatus, setStep, setStepTime
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TraverseBSTAnimation

public TraverseBSTAnimation(NodeSettings AnimatorScheme,
                            KeySettings KeyAnimatorScheme,
                            java.lang.String startingCmd,
                            int stepTime)
The constructor which initiates the status and prepares the colorSchemes. The node which is animating must be passed.

Parameters:
AnimatorScheme - the NodeSettings associated with a color scheme for a passed node.
KeyAnimatorScheme - the KeySettings associated with a color scheme according to KeySettings.
startingCmd - the Animation command that this should start.
stepTime - the time for each step of the Animation. Sets the initial value.

TraverseBSTAnimation

public TraverseBSTAnimation()
The constructor which initiates the status and sets the color schemes to null. All colors are set to default for this animation. The key which is being searched for must be passed.

Method Detail

getAnimatorScheme

public NodeSettings getAnimatorScheme()
Gets the NodeSettings for the animator scheme for the search.

Returns:
NodeSettings for the node animating.

getKeyAnimatorScheme

public KeySettings getKeyAnimatorScheme()
Sets the KeySettings for the animator scheme key for the search.

Returns:
KeySettings for the key of the node animating.

setAnimatorScheme

public void setAnimatorScheme(NodeSettings scheme)
Sets the NodeSettings for the animator scheme for the insertion. The settings affect the change the node makes as it is animating during the insertion

Parameters:
scheme - NodeSettings for the node animating.

setKeyAnimatorScheme

public void setKeyAnimatorScheme(KeySettings scheme)
Sets the KeySettings for the animator scheme key for the insertion. The settings affect the change the key of the node makes as it is animating during the insertion

Parameters:
scheme - KeySettings for the key of the node animating.

add

public void add(GrowingTreeNode<P> node)
Add a step to the Traversal Animation. The nodes are automatically added as listeners.

Parameters:
node - the color scheme is changed when the step is completed.

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). After completing the drawing, the Animation sends an AnimationEvent to all its listeners, indicating any information that the listerners may wish to use.

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