package edu.princeton.cs.algs4.growingtree.framework; /* * @(#)Animation.java * * Last Modified: 9/15/01 */ import java.awt.*; /** * * The Animation interface that must be used for all Animations. All methods must be * implemented to allow the Animation Object to be used in all animation applications.

* * Status fields are provided for usage in Animation objects involving status and mesages. Others may be added if necessary. * * @author Corey Sanders * @version 1.5 9/15/01 */ public interface Animation { /** * Constant for the BEGIN status. */ public static final String BEGIN = "Begin"; /** * Constant for the STOP status. */ public static final String STOP = "Stop"; /** * Constant for the PLAY status. */ public static final String PLAY = "Play"; /** * Constant for the REVERSE status. */ public static final String REWIND = "Rewind"; /** * Constant for the PAUSE status. */ public static final String PAUSE = "Pause"; /** * Constant for the FINISH status. */ public static final String FINISH = "Finish"; /** * Constant for the REDRAW status. */ public static final String REDRAW = "Redraw"; /** * Constant for the STEP status. */ public static final String STEP = "Step"; /** * Constant for the MESSAGE status. */ public static final String ANIMATION_MESSAGE = "Message"; /** * Sets the step size for the animation. * * @param t the step size */ public void setStepTime(int t); /** * Gets the step size for the animation. * * @return int step size */ public int getStepTime(); /** * Adds an animationListener that recieves meaningful events from the animation, according to * the Animation interface and the AnimationEvent. * * @param l the listener for the AnimationEvents occuring within this Animation. */ public void addAnimationListener(AnimationListener l); /** * Removes an animationListener from the animation, according to * the Animation interface and the AnimationEvent. * * @param l the listener removed from recieving the AnimationEvents occuring within this Animation. */ public void removeAnimationListener(AnimationListener l); /** * Adds a description that may be used to describe to the listener the type of event occuring. * The value of teh description may be retrieved through getDescription. * * @param d the string defining the description. */ public void addDescription(String d); /** * Gets the description added with addDescription and should be accessed through the listener. * * @return the string defining the description. */ public String getDescription(); /** * Sets whether the current animation is in stepping mode or not. Step mode indicates * skipping the intermediary drawings in the animation and going instantly from one step * to the next. Generally useful for fast-forward. * @param b boolean defining whether it is skipping. */ public void setStep(boolean b); /** * Gets whether the current animation is in stepping mode or not. Step mode indicates * skipping the intermediary drawings in the animation and going instantly from one step * to the next. Generally useful for fast-forward. * * @return boolean defining whether it is skipping. */ public boolean getStep(); /** * Sets the status of the Animation using a command within Animation interface. * * @param cmd cmd that the Animation's status is set to. */ public void setStatus(String cmd); /** * Gets the status of the Animation using a command within Animation interface. * * @return the Animation's status. */ public String getStatus(); /** * 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 of the animation is defined as Animation.PLAY * * @param b boolean defining whether it is skipping. */ public void drawAnimation(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. * * @param g2 the graphics to which the animation step should be drawn. * @param status the starting status of the animation (what the animation is set to, if in a starting phase like BEGIN or STEP). */ public void drawAnimation(Graphics2D g2, String status); }