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

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

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

The Animation object that defines the Balancing of a node in a BSTTree. Two constructors exist, one setting the starting string command and step time (preferred use). The other uses defaults. The animation builds PartitionBSTAnimations from the head node as it goes, keeping only one currently animating and allowing rewinding only to the previous rotation. The color schemes are set by the head call. The call is makePartitionAnimation.

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
BalanceBSTAnimation(GrowingTreeNode<P> node)
          The constructor which initiates the status and sets the starting command and step time
BalanceBSTAnimation(GrowingTreeNode<P> node, java.lang.String startingCmd, int stepTime)
          The constructor which initiates the status.
 
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).
 GrowingTreeNode<P> getNode()
          Gets the node from which the balancing takes place.
 GrowingTreeNode<P> getReplacingNode()
          Gets the node currently being replaced by the node being balanced (not set until after partition occurs).
 void setNode(GrowingTreeNode<P> node)
          Sets the node from which the balancing takes place.
 void setReplacingNode(GrowingTreeNode<P> node)
          Sets the node that will replace the balanced 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

BalanceBSTAnimation

public BalanceBSTAnimation(GrowingTreeNode<P> node,
                           java.lang.String startingCmd,
                           int stepTime)
The constructor which initiates the status. The node which is being balanced must be passed.

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

BalanceBSTAnimation

public BalanceBSTAnimation(GrowingTreeNode<P> node)
The constructor which initiates the status and sets the starting command and step time

Parameters:
node - the BSTTree which is balanced.
Method Detail

getNode

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

Returns:
BSTTree of the node currently being balanced.

getReplacingNode

public GrowingTreeNode<P> getReplacingNode()
Gets the node currently being replaced by the node being balanced (not set until after partition occurs).

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

setNode

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

Parameters:
node - BSTTree of the node currently being balanced.

setReplacingNode

public void setReplacingNode(GrowingTreeNode<P> node)
Sets the node that will replace the balanced node.

Parameters:
GrowingTreeNode - of the node replacing the balancing node.

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.