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
-
DrawingPanel()
- Creates a panel with white background and initializes the fonts
to be used during the animation.
-
addCom(ComBox)
- Adds a commentary box to the drawing panel.
-
addDrawingObj(DrawingObj)
- Adds a drawing object to the canvas.
-
animate(DrawingObj, Vector)
- Animate a single drawing object through a sequence of points
specified by the
Vector
construction.
-
animate(DrawingObj[], Vector[])
- Animate a list of drawing objects store in an array.
-
delay()
- Invoke a delay for a certain duration specified by
setDelay(int)
.
-
getBigFont()
- Returns the font objects initialized during the class initialization,
which
can be readily used during the animation.
-
getFixFont()
- Return font objects initialized during the class initialization, which
can be readily used during the animation.
-
getHugeFont()
- Return font objects initialized during the class initialization, which
can be readily used during the animation.
-
getNoAnim()
- Check if the noAnim flag is set.
-
getOffset()
- Get the number of pixel towards the edge of the panel which are not
going to be drawn.
-
getPanelHeight()
- Get the height of the drawing panel.
-
getPanelWidth()
- Get the width of the drawing panel.
-
getPreferredSize()
- Returns the initial preferred size of the drawing panel.
-
getSkip()
- Check if the animationis in the skip mode.
-
getSmallFont()
- Return font objects initialized during the class initialization, which
can be readily used during the animation.
-
getTinyFont()
- Return font objects initialized during the class initialization, which
can be readily used during the animation.
-
init()
- Initialize the commentary boxes and drawing objects,
removing all of them from the drawing panel.
-
isComExist(ComBox)
- Check if a commentary box has already been added to the drawing panel.
-
isObjExist(DrawingObj)
- Checks if a certain object has already been added to the drawing
panel.
-
paint(Graphics)
- Method to draw objects on the drawing panel.
-
redraw()
- Calls repaint() followed by delay().
-
removeCom(ComBox)
- Remove the commentary box.
-
removeObj(DrawingObj)
- Remove a drawing object which matches the parameter.
-
setAnimStep(int)
- Set the animation step, i.e.
-
setDelay(int)
- Set the delay duration between animation update.
-
setNoAnim(boolean)
- Set if the animation is disable.
-
setSkip(boolean)
- Set if the animation is in the 'SKIP' .
-
shortDelay()
- Causing a short delay of 1/3 of the normal delay duration.
-
update(Graphics)
- This method is invoked when the
repaint()
method is called.
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
init
public void init()
- Initialize the commentary boxes and drawing objects,
removing all of them from the drawing panel.
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.
delay
public void delay()
- Invoke a delay for a certain duration specified by
setDelay(int)
.
- See Also:
- setDelay
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.
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.
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
paint
public void paint(Graphics g)
- Method to draw objects on the drawing panel.
- Overrides:
- paint in class Container
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
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.
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
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
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
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
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.
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.
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.
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.
setNoAnim
public void setNoAnim(boolean noAnim)
- Set if the animation is disable.
- Parameters:
- noAnim - TRUE is animation is disabled; FALSE otherwise.
getNoAnim
public boolean getNoAnim()
- Check if the noAnim flag is set.
- Returns:
- If the noAnim flag is set.
getSkip
public boolean getSkip()
- Check if the animationis in the skip mode.
- Returns:
- Returns if the animation is in the 'SKIP' . . 'UNTIL' mode.
addDrawingObj
public void addDrawingObj(DrawingObj obj)
- Adds a drawing object to the canvas.
- Parameters:
- obj - The object to be added.
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.
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.
addCom
public void addCom(ComBox com)
- Adds a commentary box to the drawing panel.
- Parameters:
- com - The commentary box to be added.
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.
removeCom
public void removeCom(ComBox com)
- Remove the commentary box.
- Parameters:
- com - The combox to be removed.
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.
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.
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.