ciips.animation
Class DrawingPanel

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Panel
              extended byciips.animation.BasicDrawingPanel
                  extended byciips.animation.DrawingPanel
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class DrawingPanel
extends BasicDrawingPanel

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:
AlgAnimFrame.getDrawingPanel(), DrawingObj, Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class ciips.animation.BasicDrawingPanel
offGraphics, offscreen, offscreensize, predecessor, pref_size
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
DrawingPanel()
          Creates a panel with white background and initializes the fonts to be used during the animation.
DrawingPanel(int width, int height)
          Constructor which allows the default height and width to be overridden
 
Method Summary
 void addCom(ComBox com)
          Adds a commentary box to the drawing panel.
 void addDrawingObj(DrawingObj obj)
          Adds a drawing object to the canvas.
 void animate(DrawingObj[] objs, java.util.Vector[] pts)
          Animate a list of drawing objects store in an array.
 void animate(DrawingObj a, Trajectory t)
          Animate a single drawing object along a trajectory
 void animate(DrawingObj obj, java.util.Vector pts)
          Animate a single drawing object through a sequence of points specified by the Vector construction.
 void delay()
          Invoke a delay for a certain duration specified by setDelay(int).
 java.awt.Font getBigFont()
          Returns the font objects initialized during the class initialization, which can be readily used during the animation.
 java.awt.Font getFixFont()
          Return font objects initialized during the class initialization, which can be readily used during the animation.
 java.awt.Font getHugeFont()
          Return font objects initialized during the class initialization, which can be readily used during the animation.
 boolean getNoAnim()
          Check if the noAnim flag is set.
 int getOffset()
          Get the number of pixel towards the edge of the panel which are not going to be drawn.
 int getPanelHeight()
          Get the height of the drawing panel.
 int getPanelWidth()
          Get the width of the drawing panel.
 boolean getSkip()
          Check if the animationis in the skip mode.
 java.awt.Font getSmallFont()
          Return font objects initialized during the class initialization, which can be readily used during the animation.
 java.awt.Font getTinyFont()
          Return font objects initialized during the class initialization, which can be readily used during the animation.
 void init()
          Initialize the commentary boxes and drawing objects, removing all of them from the drawing panel.
 boolean isComExist(ComBox com)
          Check if a commentary box has already been added to the drawing panel.
 boolean isObjExist(DrawingObj obj)
          Checks if a certain object has already been added to the drawing panel.
 void paint(java.awt.Graphics g)
          Method to draw objects on the drawing panel.
 void redraw()
          Calls repaint() followed by delay().
 void removeAllCom()
          Remove all commentary boxes
 void removeCom(ComBox com)
          Remove the commentary box.
 boolean removeObj(DrawingObj obj)
          Remove a drawing object which matches the parameter.
 void setAnimStep(int step)
          Set the animation step, i.e.
 void setDelay(int delay)
          Set the delay duration between animation update.
 void setNoAnim(boolean noAnim)
          Disable or enable animation.
 void setSkip(boolean skip)
          Set if the animation is in the 'SKIP' .
 void shortDelay()
          Causing a short delay of 1/3 of the normal delay duration.
 void update(java.awt.Graphics g)
          This method is invoked when the repaint() method is called.
 
Methods inherited from class ciips.animation.BasicDrawingPanel
clear, drawFromOffscreen, getImage, getOffScreenGraphics, getPreferredSize, makeOffScreenBuffer, setImage, setPredecessor, setPreferredSize, shuffleDown
 
Methods inherited from class java.awt.Panel
addNotify, getAccessibleContext
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

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()

DrawingPanel

public DrawingPanel(int width,
                    int height)
Constructor which allows the default height and width to be overridden

Method Detail

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(int)

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.

Overrides:
redraw in class BasicDrawingPanel

update

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

Parameters:
g - Graphical context

paint

public void paint(java.awt.Graphics g)
Method to draw objects on the drawing panel.

Overrides:
paint in class BasicDrawingPanel

getBigFont

public java.awt.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 java.awt.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 java.awt.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 java.awt.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 java.awt.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)
Disable or enable animation.

Parameters:
noAnim - true is animation is to be disabled, false otherwise.

getNoAnim

public boolean getNoAnim()
Check if the noAnim flag is set.

Returns:
true 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.

removeAllCom

public void removeAllCom()
Remove all commentary boxes


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,
                    java.util.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 a,
                    Trajectory t)
Animate a single drawing object along a trajectory


animate

public void animate(DrawingObj[] objs,
                    java.util.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.