Class DrawingPanel

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----java.awt.Panel
                           |
                           +----DrawingPanel

public class DrawingPanel
extends Panel
DrawingPanel is the graphical panel attached to the animation frame AlgAnimFrame. It contains the methods to draw objects for the animation algorithm or instances of another classes, which contain the drawing methods.

This class is NOT TO BE MODIFIED.

Any object class which implements the interface DrawingObj can be added to this panel by calling the addDrawingObj() method. Similarly, commentary box of type ComBox can be added to the panel by using addCom method. Since the commentary box (ComBox) is also implementing the interface DrawingObj, it can also be added by using the addDrawingObj method. However, ComBox added to the drawing panel by using addCom will always appear on top of any object added to the panel by using the addDrawingObj method.

Note that last object added to the panel will be displayed on top.

See Also:
getDrawingPanel, DrawingObj

Constructor Index

 o DrawingPanel()
Creates a panel with white background and initializes the fonts to be used during the animation.

Method Index

 o addCom(ComBox)
Adds a commentary box to the drawing panel.
 o addDrawingObj(DrawingObj)
Adds a drawing object to the canvas.
 o animate(DrawingObj, Vector)
Animate a single drawing object through a sequence of points specified by the Vector construction.
 o animate(DrawingObj[], Vector[])
Animate a list of drawing objects store in an array.
 o delay()
Invoke a delay for a certain duration specified by setDelay(int).
 o getBigFont()
Returns the font objects initialized during the class initialization, which can be readily used during the animation.
 o getFixFont()
Return font objects initialized during the class initialization, which can be readily used during the animation.
 o getHugeFont()
Return font objects initialized during the class initialization, which can be readily used during the animation.
 o getNoAnim()
Check if the noAnim flag is set.
 o getOffset()
Get the number of pixel towards the edge of the panel which are not going to be drawn.
 o getPanelHeight()
Get the height of the drawing panel.
 o getPanelWidth()
Get the width of the drawing panel.
 o getPreferredSize()
Returns the initial preferred size of the drawing panel.
 o getSkip()
Check if the animationis in the skip mode.
 o getSmallFont()
Return font objects initialized during the class initialization, which can be readily used during the animation.
 o getTinyFont()
Return font objects initialized during the class initialization, which can be readily used during the animation.
 o init()
Initialize the commentary boxes and drawing objects, removing all of them from the drawing panel.
 o isComExist(ComBox)
Check if a commentary box has already been added to the drawing panel.
 o isObjExist(DrawingObj)
Checks if a certain object has already been added to the drawing panel.
 o paint(Graphics)
Method to draw objects on the drawing panel.
 o redraw()
Calls repaint() followed by delay().
 o removeCom(ComBox)
Remove the commentary box.
 o removeObj(DrawingObj)
Remove a drawing object which matches the parameter.
 o setAnimStep(int)
Set the animation step, i.e.
 o setDelay(int)
Set the delay duration between animation update.
 o setNoAnim(boolean)
Set if the animation is disable.
 o setSkip(boolean)
Set if the animation is in the 'SKIP' .
 o shortDelay()
Causing a short delay of 1/3 of the normal delay duration.
 o update(Graphics)
This method is invoked when the repaint() method is called.

Constructors

 o DrawingPanel
 public DrawingPanel()
Creates a panel with white background and initializes the fonts to be used during the animation.

See Also:
getBigFont, getSmallFont, getTinyFont, getHugeFont, getFixFont

Methods

 o init
 public void init()
Initialize the commentary boxes and drawing objects, removing all of them from the drawing panel.

 o shortDelay
 public void shortDelay()
Causing a short delay of 1/3 of the normal delay duration. This method is normally used during debugging to speed up the achievement of certain system state.

 o delay
 public void delay()
Invoke a delay for a certain duration specified by setDelay(int).

See Also:
setDelay
 o setDelay
 public void setDelay(int delay)
Set the delay duration between animation update. This method is normally called from the event handler of the simulation delay menu bar.

Parameters:
delay - Delay duration in milliseconds.
 o redraw
 public void redraw()
Calls repaint() followed by delay(). Since these two methods are being called very frequently in order, the redraw() method is constructed to save typing.

 o update
 public void update(Graphics g)
This method is invoked when the repaint() method is called. The update method is override here to eliminate flashing.

Parameters:
g - Graphical context
Overrides:
update in class Container
 o paint
 public void paint(Graphics g)
Method to draw objects on the drawing panel.

Overrides:
paint in class Container
 o getPreferredSize
 public Dimension getPreferredSize()
Returns the initial preferred size of the drawing panel. This method is called by the layout manager during the creation of the corresponding drawing frame.

Returns:
The dimension of the drawing panel.
Overrides:
getPreferredSize in class Container
 o getBigFont
 public Font getBigFont()
Returns the font objects initialized during the class initialization, which can be readily used during the animation. Initialization fonts on the fly during the animation will slow down the screen update significantly (especially on SGI Irix platform). Therefore, this fonts are only initialized during the creation of the class and used by any other classes that require them to reduce font initialization overhead.

Returns:
Size 12 PLAIN Dialog font.
 o getSmallFont
 public Font getSmallFont()
Return font objects initialized during the class initialization, which can be readily used during the animation.

Returns:
Size 10 PLAIN Dialog font.
See Also:
getBigFont
 o getTinyFont
 public Font getTinyFont()
Return font objects initialized during the class initialization, which can be readily used during the animation.

Returns:
Size 8 PLAIN Dialog font.
See Also:
getBigFont
 o getHugeFont
 public Font getHugeFont()
Return font objects initialized during the class initialization, which can be readily used during the animation.

Returns:
Size 14 PLAIN Dialog font.
See Also:
getBigFont
 o getFixFont
 public Font getFixFont()
Return font objects initialized during the class initialization, which can be readily used during the animation.

Returns:
Size 12 PLAIN Courier font.
See Also:
getBigFont
 o getPanelHeight
 public int getPanelHeight()
Get the height of the drawing panel.

Returns:
Height of the drawing panel set during the initialization of the class or after each invoke of the repaint() method.
 o getPanelWidth
 public int getPanelWidth()
Get the width of the drawing panel.

Returns:
Width of the drawing panel set during the initialization of the class or after each invoke of the repaint() method.
 o getOffset
 public int getOffset()
Get the number of pixel towards the edge of the panel which are not going to be drawn.

Returns:
Inset of the drawing panel, i.e. the edge pads on the four sides of of the panel that are not to be drawn.
 o setSkip
 public void setSkip(boolean skip)
Set if the animation is in the 'SKIP' . . 'UNTIL' mode.

Parameters:
skip - TRUE if the algorithm animation is to be fast forwarded to a specific point of execution. FALSE otherwise.
 o setNoAnim
 public void setNoAnim(boolean noAnim)
Set if the animation is disable.

Parameters:
noAnim - TRUE is animation is disabled; FALSE otherwise.
 o getNoAnim
 public boolean getNoAnim()
Check if the noAnim flag is set.

Returns:
If the noAnim flag is set.
 o getSkip
 public boolean getSkip()
Check if the animationis in the skip mode.

Returns:
Returns if the animation is in the 'SKIP' . . 'UNTIL' mode.
 o addDrawingObj
 public void addDrawingObj(DrawingObj obj)
Adds a drawing object to the canvas.

Parameters:
obj - The object to be added.
 o isObjExist
 public boolean isObjExist(DrawingObj obj)
Checks if a certain object has already been added to the drawing panel.

Parameters:
obj - The drawing object to be checked.
Returns:
Returns TRUE if the drawing object has been added; FALSE otherwise.
 o removeObj
 public boolean removeObj(DrawingObj obj)
Remove a drawing object which matches the parameter.

Parameters:
obj - The drawing object to be removed.
Returns:
TRUE if the object has been successfully deleted; FALSE otherwise.
 o addCom
 public void addCom(ComBox com)
Adds a commentary box to the drawing panel.

Parameters:
com - The commentary box to be added.
 o isComExist
 public boolean isComExist(ComBox com)
Check if a commentary box has already been added to the drawing panel.

Parameters:
com - The commentary box to be checked.
Returns:
Returns TRUE if the commentary box has been added; FALSE otherwise.
 o removeCom
 public void removeCom(ComBox com)
Remove the commentary box.

Parameters:
com - The combox to be removed.
 o setAnimStep
 public void setAnimStep(int step)
Set the animation step, i.e. the number of step for an object to move from one point to another.

Parameters:
step - The number of animation step.
 o animate
 public void animate(DrawingObj obj,
                     Vector pts)
Animate a single drawing object through a sequence of points specified by the Vector construction. Each element of the vector is of type Point, where the first is the source and the last is the destination of the trajectory to be animated on the object.

Parameters:
obj - The drawing object to be move.
pts - The trajectory the drawing object is to be moved.
 o animate
 public void animate(DrawingObj objs[],
                     Vector pts[])
Animate a list of drawing objects store in an array. The trajectories of these objects are passed in through the second parameter. The size of the arrays passed in through both parameters should be equal. Otherwise, nothing will be performed. The number of points in all the trajectories must be equal too.

Parameters:
objs - Array holding the drawing objects to be animated.
pts - Array holding the trajectories of the drawing objects.