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

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

public class MovingBSTTreeAnimation<P extends NodeProperties>
extends AbstractAnimation

The Animation object that defines the Moving of a MovingBSTTree. Two constructors exist, one setting the animator and animation color Schemes. This animation is the core of many other animations that involve moving (Rotation).

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.4 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
MovingBSTTreeAnimation()
          The constructor which initiates the status as Animation.PLAY, default step size, the default NodeAnimationScheme and KeyAnimationScheme.
MovingBSTTreeAnimation(NodeSettings NodeAnimationScheme, KeySettings KeyAnimationScheme)
          The constructor which initiates the status as Animation.PLAY, default step size, the given NodeAnimationScheme and KeyAnimationScheme.
MovingBSTTreeAnimation(NodeSettings NodeAnimationScheme, KeySettings KeyAnimationScheme, java.lang.String startingCmd, int stepTime)
          The constructor which initiates the status and prepares the color Schemes.
 
Method Summary
 void add(MovingBSTTree<P> movingNode, GrowingTreeNode<P> node)
          Adds the movingBSTTree along with the BSTTree node as a pair.
 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 getAnimationScheme()
          Gets the NodeSettings for the animation of the moving node.
 MovingBSTTree<P> getFirstMovingNode()
          Gets the first moving node in the list.
 KeySettings getKeyAnimationScheme()
          Gets the KeySettings for the animation key for the moving node.
 MovingBSTTree<P> getMovingNode(GrowingTreeNode<P> node)
          Gets the moving node within the Animation that imitates the passed BSTTree node.
 java.util.LinkedList<MovingBSTTree<P>> getMovingNodes()
          Gets the moving nodes used in the Animation.
 NodeSettings getNodeAnimationScheme()
          Gets the node Animationg scheme for each moving node.
 java.util.LinkedList<GrowingTreeNode<P>> getNodes()
          Gets the BSTTree nodes used in the Animation.
 boolean isEmpty()
          Returns true if the moving node list is empty.
 void makeAnimation(java.awt.Graphics2D g2, java.lang.String startingStatus)
          Makes the animation of the next step, using the status of the animation (Animation.PLAY, Animation.PAUSE and so forth).
 void setAnimationScheme(NodeSettings nodeScheme, KeySettings keyScheme)
          Sets the animation scheme for each moving node.
 void setKeyAnimationScheme(KeySettings scheme)
          Sets the KeySettings for the animation key for the moving node.
 void setNodeAnimationScheme(NodeSettings scheme)
          Sets the NodeSettings for the animation of the moving node.
 
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

MovingBSTTreeAnimation

public MovingBSTTreeAnimation()
The constructor which initiates the status as Animation.PLAY, default step size, the default NodeAnimationScheme and KeyAnimationScheme.


MovingBSTTreeAnimation

public MovingBSTTreeAnimation(NodeSettings NodeAnimationScheme,
                              KeySettings KeyAnimationScheme)
The constructor which initiates the status as Animation.PLAY, default step size, the given NodeAnimationScheme and KeyAnimationScheme.

Parameters:
NodeAnimationScheme - the NodeSettings which the nodes uses during animation.
KeyAnimationScheme - the KeySettings which the key in each moving node is drawn.

MovingBSTTreeAnimation

public MovingBSTTreeAnimation(NodeSettings NodeAnimationScheme,
                              KeySettings KeyAnimationScheme,
                              java.lang.String startingCmd,
                              int stepTime)
The constructor which initiates the status and prepares the color Schemes.

Parameters:
NodeAnimationScheme - the NodeSettings which the nodes uses during animation.
KeyAnimationScheme - the KeySettings which the key in each moving node is drawn.
startingCmd - the Animation command that this should start.
stepTime - the time for each step of the Animation. Sets the initial value.
Method Detail

getMovingNodes

public java.util.LinkedList<MovingBSTTree<P>> getMovingNodes()
Gets the moving nodes used in the Animation. The return is the clone of the LinkedList used within the class. Cloning of a LinkedList is a shallow copy. return LinkedList representing the movingBSTTrees.


getNodeAnimationScheme

public NodeSettings getNodeAnimationScheme()
Gets the node Animationg scheme for each moving node.

Returns:
animation scheme for the moving nodes.

getNodes

public java.util.LinkedList<GrowingTreeNode<P>> getNodes()
Gets the BSTTree nodes used in the Animation. The return is the clone of the LinkedList used within the class. Cloning of a LinkedList is a shallow copy. return LinkedList representing the BSTTrees that the movingBSTTrees imitate.


getMovingNode

public MovingBSTTree<P> getMovingNode(GrowingTreeNode<P> node)
Gets the moving node within the Animation that imitates the passed BSTTree node. If the BSTTree node does not exist in the Animation, null is returned.

Parameters:
node - BSTTree node which the returning MovingBSTTree node imitates.
Returns:
MovingBSTTree which imitates the given node.

getFirstMovingNode

public MovingBSTTree<P> getFirstMovingNode()
Gets the first moving node in the list.

Returns:
the first MovingBSTTree in the animation.

isEmpty

public boolean isEmpty()
Returns true if the moving node list is empty.

Returns:
true if the animation contains no moving nodes.

getAnimationScheme

public NodeSettings getAnimationScheme()
Gets the NodeSettings for the animation of the moving node.

Returns:
NodeSettings for the node animating.

getKeyAnimationScheme

public KeySettings getKeyAnimationScheme()
Gets the KeySettings for the animation key for the moving node.

Returns:
KeySettings for the key of the node animating.

setAnimationScheme

public void setAnimationScheme(NodeSettings nodeScheme,
                               KeySettings keyScheme)
Sets the animation scheme for each moving node.

Parameters:
nodeScheme - the NodeSettings for the animation of the moving node.
keyScheme - the KeySettings for the animationg of the key within the moving node.

add

public void add(MovingBSTTree<P> movingNode,
                GrowingTreeNode<P> node)
Adds the movingBSTTree along with the BSTTree node as a pair. The moving Node imitates the given nod.

Parameters:
movingNode - MovingBSTTree that is added to the animation.
node - BSTTree that is added to the animation.

setNodeAnimationScheme

public void setNodeAnimationScheme(NodeSettings scheme)
Sets the NodeSettings for the animation of the moving node.

Parameters:
scheme - NodeSettings for the node animating.

setKeyAnimationScheme

public void setKeyAnimationScheme(KeySettings scheme)
Sets the KeySettings for the animation key for the moving node.

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

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 starting status used if necessary.

makeAnimation

public void makeAnimation(java.awt.Graphics2D g2,
                          java.lang.String startingStatus)
Makes the animation of the next step, using the status of the animation (Animation.PLAY, Animation.PAUSE and so forth). After completing the making, nodeMade is set to true, so when the animation is actually drawn, it will not skip a step.

Parameters:
g2 - the graphics to which the animation step should be drawn.
startingStatus - the starting status used if necessary.