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

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

public class RotationBSTAnimation<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.3 9/15/01
Author:
Corey Sanders

Field Summary
static int DEFAULT_STEP
          The Default step size used in the animation (16).
static int LEFT_ROTATION
          Defines a left rotation.
static int RIGHT_ROTATION
          Defines a right rotation.
 
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
RotationBSTAnimation(GrowingTreeNode<P> head, GrowingTreeNode<P> child, int rotationOrientation)
          The constructor which initiates the status and sets the color Schemes to default.
RotationBSTAnimation(GrowingTreeNode<P> head, GrowingTreeNode<P> child, int rotationOrientation, NodeSettings RootAnimationScheme, NodeSettings ChildAnimationScheme, NodeSettings DescendantAnimationScheme, NodeSettings NodeOriginalScheme, KeySettings KeyAnimationScheme, 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).
 NodeSettings getChildAnimationScheme()
          Gets the NodeSettings for the child animation scheme for the rotation.
 NodeSettings getDescendantAnimationScheme()
          Gets the NodeSettings for the descendant animation scheme for the rotation.
 KeySettings getKeyAnimationScheme()
          Gets the KeySettings for the animation scheme for the key during rotation.
 KeySettings getKeyOriginalScheme()
          Gets the KeySettings for the original scheme of the key.
 NodeSettings getNodeOriginalScheme()
          Gets the NodeSettings for the original node scheme for the rotation.
 NodeSettings getRootAnimationScheme()
          Gets the NodeSettings for the root animation scheme for the rotation.
 void setChildAnimationScheme(NodeSettings scheme)
          Sets the NodeSettings for the child animation scheme for the rotation.
 void setDescendantAnimationScheme(NodeSettings scheme)
          Sets the NodeSettings for the descendant animation scheme for the rotation.
 void setKeyAnimationScheme(KeySettings scheme)
          Sets the KeySettings for the animation scheme for the key during rotation.
 void setKeyOriginalScheme(KeySettings scheme)
          Sets the KeySettings for the original scheme of the key during rotation.
 void setNodeOriginalScheme(NodeSettings scheme)
          Sets the NodeSettings for the original scheme for the rotation.
 void setRootAnimationScheme(NodeSettings scheme)
          Sets the NodeSettings for the root animation 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

RIGHT_ROTATION

public static final int RIGHT_ROTATION
Defines a right rotation.

See Also:
Constant Field Values

LEFT_ROTATION

public static final int LEFT_ROTATION
Defines a left rotation.

See Also:
Constant Field Values
Constructor Detail

RotationBSTAnimation

public RotationBSTAnimation(GrowingTreeNode<P> head,
                            GrowingTreeNode<P> child,
                            int rotationOrientation)
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 BSTTree head of the rotation animation.
child - the BSTTree child of the rotation animation.
rotationOrientation - the rotation orientation defined (LEFT_ROTATION or RIGHT_ROTATION).

RotationBSTAnimation

public RotationBSTAnimation(GrowingTreeNode<P> head,
                            GrowingTreeNode<P> child,
                            int rotationOrientation,
                            NodeSettings RootAnimationScheme,
                            NodeSettings ChildAnimationScheme,
                            NodeSettings DescendantAnimationScheme,
                            NodeSettings NodeOriginalScheme,
                            KeySettings KeyAnimationScheme,
                            KeySettings KeyOriginalScheme,
                            java.lang.String startingCmd,
                            int stepTime)
The constructor which initiates the status and prepares the color schemes.

Parameters:
head - the BSTTree head of the rotation animation.
child - the BSTTree child of the rotation animation.
rotationOrientation - the rotation orientation defined (LEFT_ROTATION or RIGHT_ROTATION).
RootAnimationScheme - animation scheme for the root.
ChildAnimationScheme - animation scheme for the child.
DescendantAnimationScheme - animation scheme for the descendant.
NodeOriginalAnimationScheme - original scheme for the root.
KeyAnimationScheme - animation scheme for the key.
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

getRootAnimationScheme

public NodeSettings getRootAnimationScheme()
Gets the NodeSettings for the root animation scheme for the rotation.

Returns:
NodeSettings for the root node.

getChildAnimationScheme

public NodeSettings getChildAnimationScheme()
Gets the NodeSettings for the child animation scheme for the rotation.

Returns:
NodeSettings for the child node.

getDescendantAnimationScheme

public NodeSettings getDescendantAnimationScheme()
Gets the NodeSettings for the descendant animation scheme for the rotation.

Returns:
NodeSettings for the descendant node.

getNodeOriginalScheme

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

Returns:
NodeSettings for the original node scheme.

getKeyAnimationScheme

public KeySettings getKeyAnimationScheme()
Gets the KeySettings for the animation scheme for the key during rotation.

Returns:
KeySettings for the animation of the key.

getKeyOriginalScheme

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

Returns:
KeySettings for the original key scheme.

setRootAnimationScheme

public void setRootAnimationScheme(NodeSettings scheme)
Sets the NodeSettings for the root animation scheme for the rotation.

Parameters:
scheme - NodeSettings for the root node.

setChildAnimationScheme

public void setChildAnimationScheme(NodeSettings scheme)
Sets the NodeSettings for the child animation scheme for the rotation.

Parameters:
scheme - NodeSettings for the child node.

setDescendantAnimationScheme

public void setDescendantAnimationScheme(NodeSettings scheme)
Sets the NodeSettings for the descendant animation scheme for the rotation.

Parameters:
scheme - NodeSettings for the descendant node.

setNodeOriginalScheme

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

Parameters:
scheme - NodeSettings for the original scheme.

setKeyAnimationScheme

public void setKeyAnimationScheme(KeySettings scheme)
Sets the KeySettings for the animation scheme for the key during rotation.

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

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