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

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

public class DisplayChangeAnimation<P extends NodeProperties>
extends AbstractAnimation

The Animation object that defines the Rotation of a BSTTree. Two constructors exist, one setting the animator and animation color Schemes, one setting those to defaults.

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/01/02
Author:
Corey Sanders

Field Summary
static int DEFAULT_STEP
          The Default step size used in the animation (16).
 
Fields inherited from class edu.princeton.cs.algs4.growingtree.framework.AbstractAnimation
DEFAULT_CONVERSION
 
Fields inherited from interface edu.princeton.cs.algs4.growingtree.framework.Animation
ANIMATION_MESSAGE, BEGIN, FINISH, PAUSE, PLAY, REDRAW, REWIND, STEP, STOP
 
Constructor Summary
DisplayChangeAnimation(GrowingTreeHead<P> head, int displayChange)
          The constructor which initiates the status and sets the color Schemes to default.
DisplayChangeAnimation(GrowingTreeHead<P> head, int displayChange, NodeSettings NodeOriginalScheme, KeySettings KeyOriginalScheme, java.lang.String startingCmd, int stepTime)
          The constructor which initiates the status and prepares the color schemes.
 
Method Summary
 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).
 int getDisplayChange()
          Gets the displayChange for the display change animation.
 KeySettings getKeyOriginalScheme()
          Gets the KeySettings for the original scheme of the key.
 MovingBSTTreeAnimation<P> getMovingTreeNodes()
          Gets the MovingBSTTreeAnimation for the tree whose display is changing.
 NodeSettings getNodeOriginalScheme()
          Gets the NodeSettings for the original node scheme for the rotation.
 void setDisplayChange(int displayChange)
          Sets the displayChange for the animation.
 void setKeyOriginalScheme(KeySettings scheme)
          Sets the KeySettings for the original scheme of the key during rotation.
 void setMovingTreeNodes(MovingBSTTreeAnimation<P> movingTreeNodes)
          Sets the MovingBSTTreeAnimation for the tree whose display is changing.
 void setNodeOriginalScheme(NodeSettings scheme)
          Sets the NodeSettings for the original scheme for the rotation.
 
Methods inherited from class edu.princeton.cs.algs4.growingtree.framework.AbstractAnimation
addAnimationListener, addDescription, 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
 

Field Detail

DEFAULT_STEP

public static final int DEFAULT_STEP
The Default step size used in the animation (16).

See Also:
Constant Field Values
Constructor Detail

DisplayChangeAnimation

public DisplayChangeAnimation(GrowingTreeHead<P> head,
                              int displayChange)
The constructor which initiates the status and sets the color Schemes to default. Also sets starting command to Animation.PLAY, and sets the step time to the default.

Parameters:
head - the BSTTreeHead head of the tree whose display is changing.
displayChange - the new kind of display, according to BSTTreeHead.SECT_DISPLAY or BSTTreeHead.BINARY_DISPLAY

DisplayChangeAnimation

public DisplayChangeAnimation(GrowingTreeHead<P> head,
                              int displayChange,
                              NodeSettings NodeOriginalScheme,
                              KeySettings KeyOriginalScheme,
                              java.lang.String startingCmd,
                              int stepTime)
The constructor which initiates the status and prepares the color schemes.

Parameters:
head - the BSTTreeHead head of the tree whose display is changing.
displayChange - the new kind of display, according to BSTTreeHead.SECT_DISPLAY or BSTTreeHead.BINARY_DISPLAY
NodeOriginalAnimationScheme - original scheme for the root.
KeyOriginalScheme - original scheme for the key.
startingCmd - the Animation command that should start.
stepTime - the time for each step of the Animation. Sets the initial value.
Method Detail

getDisplayChange

public int getDisplayChange()
Gets the displayChange for the display change animation.

Returns:
displayChange integer defined in BSTTreeHead.

getMovingTreeNodes

public MovingBSTTreeAnimation<P> getMovingTreeNodes()
Gets the MovingBSTTreeAnimation for the tree whose display is changing.

Returns:
MovingBSTTreeAnimation for the entire tree display change.

getNodeOriginalScheme

public NodeSettings getNodeOriginalScheme()
Gets the NodeSettings for the original node scheme for the rotation.

Returns:
NodeSettings for the original node scheme.

getKeyOriginalScheme

public KeySettings getKeyOriginalScheme()
Gets the KeySettings for the original scheme of the key.

Returns:
KeySettings for the original key scheme.

setDisplayChange

public void setDisplayChange(int displayChange)
Sets the displayChange for the animation.

Parameters:
displayChange - the int defined within BSTTreeHead (SECT_DISPLAY or BINARY_DISPLAY).

setMovingTreeNodes

public void setMovingTreeNodes(MovingBSTTreeAnimation<P> movingTreeNodes)
Sets the MovingBSTTreeAnimation for the tree whose display is changing.

Parameters:
movingTreeNodes - MovingBSTTreeAnimation for the entire tree display change.

setNodeOriginalScheme

public void setNodeOriginalScheme(NodeSettings scheme)
Sets the NodeSettings for the original scheme for the rotation.

Parameters:
scheme - NodeSettings for the original scheme.

setKeyOriginalScheme

public void setKeyOriginalScheme(KeySettings scheme)
Sets the KeySettings for the original scheme of the key during rotation.

Parameters:
scheme - KeySettings for the original of the key.

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
Overrides:
drawAnimation in class AbstractAnimation
Parameters:
g2 - Graphics2D to which the graphics are drawn.

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 - sent to the animators