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

java.lang.Object
  extended by edu.princeton.cs.algs4.growingtree.framework.AbstractAnimation
      extended by edu.princeton.cs.algs4.growingtree.framework.PartitionBSTAnimation<P>
All Implemented Interfaces:
Animation, AnimationListener, java.util.EventListener

public class PartitionBSTAnimation<P extends NodeProperties>
extends AbstractAnimation
implements AnimationListener

The Animation object that defines the Paritioning of a node in a BSTTree. The animation builds RotationBSTAnimations as it goes, keeping only one currently animating and allowing rewinding only to the beginning of the currrent 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.5 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
PartitionBSTAnimation(GrowingTreeNode<P> node, int keySelect)
          The constructor which initiates the status and sets the color schemes to null.
PartitionBSTAnimation(GrowingTreeNode<P> node, int keySelect, java.lang.String startingCmd, int stepTime)
          The constructor which initiates the status and prepares the color schemes.
 
Method Summary
 void animationEventPerformed(AnimationEvent e)
          Implements AnimationListener which requires the following method.
 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).
 int getKeySelect()
          Gets the keySelect of the partition, the kth element.
 int getLevelCount()
          Gets the count of levels for rotated the replacing node to its proper place.
 GrowingTreeNode<P> getNode()
          Gets the node from which the partitioning takes place.
 GrowingTreeNode<P> getReplacingNode()
          Gets the node currently being rotated up to replace (not set until after selection occurs).
 void setKeySelect(int keySelect)
          Sets the keySelect of the partition, the kth element.
 void setLevelCount(int level)
          Sets the count of levels for rotated the replacing node to its proper place.
 void setNode(GrowingTreeNode<P> node)
          Sets the node from which the partitioning takes place.
 void setReplacingNode(GrowingTreeNode<P> node)
          Sets the node currently being drawn during the Partition.
 
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

PartitionBSTAnimation

public PartitionBSTAnimation(GrowingTreeNode<P> node,
                             int keySelect,
                             java.lang.String startingCmd,
                             int stepTime)
The constructor which initiates the status and prepares the color schemes. The node which is being deleted must be passed.

Parameters:
node - the BSTTree from which the partition takes place.
keySelect - integer finding the kth node
startingCmd - the Animation command that this should start.
stepTime - the time for each step of the Animation. Sets the initial value.

PartitionBSTAnimation

public PartitionBSTAnimation(GrowingTreeNode<P> node,
                             int keySelect)
The constructor which initiates the status and sets the color schemes to null. No colors will be changed using this animation. The node which is animating must be passed.

Parameters:
node - the BSTTree which is deleted during the deletion.
keySelect - integer finding the kth node
Method Detail

getNode

public GrowingTreeNode<P> getNode()
Gets the node from which the partitioning takes place.

Returns:
BSTTree of the node currently being partitioned at the KeySelect.

getKeySelect

public int getKeySelect()
Gets the keySelect of the partition, the kth element.

Returns:
int keySelect of the partition.

getReplacingNode

public GrowingTreeNode<P> getReplacingNode()
Gets the node currently being rotated up to replace (not set until after selection occurs).

Returns:
BSTTree of the ndoe currently being replaced and animated.

getLevelCount

public int getLevelCount()
Gets the count of levels for rotated the replacing node to its proper place.

Returns:
int level count of rotations for the replacing node to its new location.

setNode

public void setNode(GrowingTreeNode<P> node)
Sets the node from which the partitioning takes place.

Parameters:
node - BSTTree of the node currently being partitioned at the KeySelect.

setKeySelect

public void setKeySelect(int keySelect)
Sets the keySelect of the partition, the kth element.

Parameters:
keySelect - kth element of the partition.

setReplacingNode

public void setReplacingNode(GrowingTreeNode<P> node)
Sets the node currently being drawn during the Partition.

Parameters:
GrowingTreeNode - of the node currently being replaced and animated.

setLevelCount

public void setLevelCount(int level)
Sets the count of levels for rotated the replacing node to its proper place. The count must be the amount of RotateUp calls the node needs to become the highest node in its tree. The final move does not count as a rotate.

Parameters:
level - intt level count of rotations for the replacing node to its new location.

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. BSTTreeHead calls: Other Animation Objects used:

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.

animationEventPerformed

public void animationEventPerformed(AnimationEvent e)
Implements AnimationListener which requires the following method. The only status of animation it listens for is Animation.ANIMATION_MESSAGE, to pass the message on.

Specified by:
animationEventPerformed in interface AnimationListener
Parameters:
e - AnimationEvent that represents the information of the Animation.