Class InsertRedBlackAnimation

java.lang.Object
  |
  +--AbstractAnimation
        |
        +--InsertBSTAnimation
              |
              +--InsertRedBlackAnimation
All Implemented Interfaces:
Animation, AnimationListener, java.util.EventListener

public class InsertRedBlackAnimation
extends InsertBSTAnimation
implements AnimationListener

The Animation object that defines the Insertion into a Red-Black Tree. Two constructors exist, one setting the animator and animation color Schemes.


Field Summary
protected static int BEGIN_CHECK
          The location for beginning of checking rotations.
protected static int LEFT_CHECK
          The location for the left checking of rotations.
protected static int RIGHT_CHECK
          The location for the right checking of rotations.
 
Fields inherited from class InsertBSTAnimation
comparisonCount, insertionSize, nextNodeIndex, previousNodeIndex
 
Fields inherited from class AbstractAnimation
DEFAULT_CONVERSION, DEFAULT_STEP, listeners
 
Fields inherited from interface Animation
ANIMATION_MESSAGE, BEGIN, FINISH, PAUSE, PLAY, REDRAW, REWIND, STEP, STOP
 
Constructor Summary
InsertRedBlackAnimation(BSTTree node)
          The constructor which initiates the status and sets the colorSchemes to null.
InsertRedBlackAnimation(BSTTree node, NodeSettings AnimationSchemeLeft, NodeSettings AnimationSchemeRight, NodeSettings AnimatorScheme, KeySettings KeyAnimatorScheme, java.lang.String startingCmd, int stepTime)
          The constructor which initiates the status and prepares the colorSchemes.
 
Method Summary
protected  void animationAction(java.lang.String cmd, java.lang.String description)
          Calls all of the listeners of the current Animation and passed information regarding the progress and status of the current Animation.
 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).
protected  void makeCurrentRotation(RedBlackTree newTree, RedBlackTree node)
          Constructs the current Rotation according to the current tree, and the defined rotationCheck.
protected  void restore()
          Restores the settings of all nodes encountered during the animation.
 void setBlackChangeLinks()
          Fixes the blackChangeLinks by settings all the nodes links within the list to black.
 void setRedChangeLinks()
          Fixes the redChangeLinks by settings all the nodes links within the list to red.
 
Methods inherited from class InsertBSTAnimation
add, add, add, getAnimationSchemeLeft, getAnimationSchemeRight, getAnimatorScheme, getCurrentLocation, getInsertNode, getKeyAnimatorScheme, getMovements, getNodeMovements, getPreviousLocation, resetPosition, setAnimationSchemeLeft, setAnimationSchemeRight, setAnimatorScheme, setCurrentLocation, setInsertNode, setKeyAnimatorScheme, setPreviousLocation
 
Methods inherited from class AbstractAnimation
addAnimationListener, addDescription, animationAction, animationAction, drawAnimation, getDescription, getListeners, getStartingCommand, getStatus, getStep, getStepConversion, getStepSize, getStepTime, messageAction, removeAnimationListener, setStartingCommand, setStatus, setStep, setStepConversion, setStepSize, setStepTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BEGIN_CHECK

protected static final int BEGIN_CHECK
The location for beginning of checking rotations.

See Also:
Constant Field Values

LEFT_CHECK

protected static final int LEFT_CHECK
The location for the left checking of rotations.

See Also:
Constant Field Values

RIGHT_CHECK

protected static final int RIGHT_CHECK
The location for the right checking of rotations.

See Also:
Constant Field Values
Constructor Detail

InsertRedBlackAnimation

public InsertRedBlackAnimation(BSTTree node,
                               NodeSettings AnimationSchemeLeft,
                               NodeSettings AnimationSchemeRight,
                               NodeSettings AnimatorScheme,
                               KeySettings KeyAnimatorScheme,
                               java.lang.String startingCmd,
                               int stepTime)
The constructor which initiates the status and prepares the colorSchemes. The node which is animating must be passed. The first step added is the identity step.

Parameters:
node - the BSTTree which is animated during the animation.
AnimationSchemeLeft - the NodeSettings associated with a color scheme according to NodeSettings for the left Animation.
AnimationSchemeRight - the NodeSettings associated with a color scheme according to NodeSettings for the right Animation.
AnimatorScheme - the NodeSettings associated with a color scheme according to NodeSettings.
KeyAnimatorScheme - the KeySettings associated with a color scheme according to KeySettings.
startingCmd - the Animation command that this should start.
stepTime - the time for each step of the Animation. Sets the initial value.

InsertRedBlackAnimation

public InsertRedBlackAnimation(BSTTree node)
The constructor which initiates the status and sets the colorSchemes to null. No colors will be change using this animation. The node which is animating must be passed. The first step added is the identity step.

Parameters:
node - the BSTTree which is animated during the animation.
Method Detail

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 InsertBSTAnimation
Parameters:
g2 - the graphics to which the animation step should be drawn.
startingStatus - the status used as the starting command of animation, if needed.

restore

protected void restore()
Restores the settings of all nodes encountered during the animation. Usually called at the end of the animation (Animation.FINISH) to restore all settings changed throughout the animation.

This also restores the animator node. It also passes the animation action to all nodes of Animation.FINISH.

Overrides:
restore in class InsertBSTAnimation

makeCurrentRotation

protected void makeCurrentRotation(RedBlackTree newTree,
                                   RedBlackTree node)
Constructs the current Rotation according to the current tree, and the defined rotationCheck. This method called out of context results in unforeseen errors.

Parameters:
newTree - RedBlackTree that represents the newly added node.
node - RedBlackTree that represents the current checking node.

setRedChangeLinks

public void setRedChangeLinks()
Fixes the redChangeLinks by settings all the nodes links within the list to red. Then the nodes are removed from the list, always leaving it clear after this call.


setBlackChangeLinks

public void setBlackChangeLinks()
Fixes the blackChangeLinks by settings all the nodes links within the list to black. Then the nodes are removed from the list, always leaving it clear after this call.


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.

animationAction

protected void animationAction(java.lang.String cmd,
                               java.lang.String description)
Calls all of the listeners of the current Animation and passed information regarding the progress and status of the current Animation. Additionally, the id of the type of animation is passed. Within, the animationEventPerformed method is called.

Overrides:
animationAction in class InsertBSTAnimation
Parameters:
cmd - String Animation command passed instead of the current Status.
description - String description for messages.