AnimationHandlerSort


This class is used to animate the algorithm by drawing to the off screen image.  This class is essentially the same for all sorting algorithms.  It receives calls from the algorithm object and draws the animations.

 

Method Index


public AnimationHandlerSort(Graphics dg, Dimension dd)

Arguments:

  1. dg is a graphics object from the algorithm

  2. dd is a dimension from the algorithm.  It represents the dimension of the drawing panel.

The constructor sets up several colors and creates y-coordinates for labeling the algorithm with text.


public void setSpeed(int i)

Arguments:

  1. i is an int representing the delay time.

The delay time is set to i.  This is used to control the speed of animating motion using Thread.sleep(delay).


public void baseline()

Draws a line underneath the rectangles representing the numbers to sort.


public void setLabelH(String s, int xCoord, boolean draw)

Arguments:

  1. s is a String used to label a rectangle

  2. xCoord represents the x-coordinate of the string

  3. draw determines whether the string is drawn or erased

Draws or erases a string used to label rectangles.  Calls labelPoint().


public void setLabelM(String s, int xCoord, boolean draw)

Arguments:

  1. s is a String used to label a rectangle

  2. xCoord represents the x-coordinate of the string

  3. draw determines whether the string is drawn or erased

Draws or erases a string used to label rectangles.  Calls labelPoint().


public void setLabelL(String s, int xCoord, boolean draw)

Arguments:

  1. s is a String used to label a rectangle

  2. xCoord represents the x-coordinate of the string

  3. draw determines whether the string is drawn or erased

Draws or erases a string used to label rectangles.  Calls labelPoint().


public void labelTemp()

Labels a temp position where rectangles can be stored or copied


private void labelPoint(int x, int stretch)

Arguments:

  1. x is a check to make sure x-coordinate is valid

  2. stretch relates to the length of the arrow drawn

Draws an arrow from the label to the rectangle


public void createRects(int[] array, int s)

Arguments:

  1. array contains the numbers to sort

  2. s is the size of the array

Draws the rectangles in their starting positions and creates another array pos to store possible x-coordinates of the rectangles.


public void colorRect(int i, Color c)

Arguments:

  1. i is the index of the array of rectangles to color

  2. c determines which color is used

Colors the rectangle this color


public void inHoldRect(int i)

Arguments:

  1. i is the index of the array of rectangles

Move the rectangle to the temp position


public void outHoldRect(int dest)

Arguments:

  1. dest is the index of pos

Move the rectangle in the hold position to the pos specified by dest


public void moveRect(int i, int dest)

Arguments:

  1. i is the index of the array of rectangles

  2. dest is the index of pos

Moves the rectangle to the correct position


public void swapRect(int one, int two)

Arguments:

  1. one is the index of the array of rectangles

  2. two is the index of the array of rectangles

Draw the swap of rectangle one and two.  Move them into each others' original position


private void drawMoveRect(int i, int dest, Color var, boolean swap)

Arguments:

  1. i is the index of the rectangle array and pos array

  2. dest is the index of the rectangle array and pos array

  3. var is the color of the moving rectangle

  4. swap determines whether one or two rectangles are moving

Draws the movement of a rectangle from one position to another.  If swap is true, rectangle i is swapped with rectangle dest.  If swap is false, rectangle i is moved to pos dest.


Ted Jenks