CIDER Toolkit
Version 0.2.0

au.edu.monash.csse.tonyj.cider.canvas
Class TokenCanvas

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--TokenCanvas
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
Direct Known Subclasses:
InterpretedTokenCanvas

public class TokenCanvas
extends javax.swing.JPanel

This class implements a token canvas which contains a collection of tokens in a stack. When asked to draw itself, the token canvas goes through the tokens in the stack in order, getting each one to draw itself (with tokens at the top of the stack drawn over tokens at the bottom). The order of the tokens in the stack can be changed, and tokens can be added to or removed from the canvas.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
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
TokenCanvas(java.awt.Dimension d)
          Creates a new TokenCanvas object.
TokenCanvas(int width, int height)
          Creates a new TokenCanvas object.
 
Method Summary
 boolean add(DrawableToken t)
          Adds a token to the bottom of the stack.
 void clear()
          Removes all tokens from the stack.
 java.awt.Color getBackground()
          Returns the background colour of the canvas.
 DrawableToken getBottomToken()
          Returns the token at the bottom of the stack, or null if the stack is empty.
 int getNumTokens()
          Returns the number of tokens in the stack
 DrawableToken getToken(int index)
          Returns the token at the specified location in the stack, or null if no token is at that index.
 java.util.List getTokensContaining(double x, double y)
          Searches the tokens to see if any contain the specified co-ordinates.
 DrawableToken getTopToken()
          Returns the token at the top of the stack, or null if the stack is empty.
 int indexOf(DrawableToken t)
          Returns the location in the stack of the specified token, or -1 if it is not in the stack.
 boolean move(int index, DrawableToken t)
          Moves a token to a specific location in the stack.
 boolean moveToBottom(DrawableToken t)
          Moves a token to the bottom of the stack.
 boolean moveToTop(DrawableToken t)
          Moves a token to the top of the stack.
 void paintComponent(java.awt.Graphics g)
          Draws the current list of tokens in the order they appear on the stack.
 boolean remove(DrawableToken t)
          Removes a token from the stack.
 void setBackground(java.awt.Color c)
          Sets the background colour of the canvas.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TokenCanvas

public TokenCanvas(java.awt.Dimension d)
Creates a new TokenCanvas object.

Parameters:
d - The dimensions of the new canvas.

TokenCanvas

public TokenCanvas(int width,
                   int height)
Creates a new TokenCanvas object.

Parameters:
width - The width of the new canvas.
height - The height of the new canvas.
Method Detail

setBackground

public void setBackground(java.awt.Color c)
Sets the background colour of the canvas.

Overrides:
setBackground in class javax.swing.JComponent

getBackground

public java.awt.Color getBackground()
Returns the background colour of the canvas.

Overrides:
getBackground in class java.awt.Component

paintComponent

public void paintComponent(java.awt.Graphics g)
Draws the current list of tokens in the order they appear on the stack.

Overrides:
paintComponent in class javax.swing.JComponent

add

public boolean add(DrawableToken t)
Adds a token to the bottom of the stack.

Parameters:
t - The token to be added.
Returns:
true if successful, or false if the token is null or already in the stack.

moveToTop

public boolean moveToTop(DrawableToken t)
Moves a token to the top of the stack.

Parameters:
t - The token to be moved.
Returns:
true if successful, or false if the token is not in the stack.

moveToBottom

public boolean moveToBottom(DrawableToken t)
Moves a token to the bottom of the stack.

Parameters:
t - The token to be moved.
Returns:
true if successful, or false if the token is not in the stack.

move

public boolean move(int index,
                    DrawableToken t)
Moves a token to a specific location in the stack. If an invalid index is specified the token will be placed at the bottom of the stack.

Parameters:
index - Location in the stack in the range 0 (top) to getNumTokens() - 1 (bottom).
t - The token to be moved.
Returns:
true if successful, or false if the token is not in the stack.

remove

public boolean remove(DrawableToken t)
Removes a token from the stack.

Parameters:
t - The token to be removed.
Returns:
true if successful, or false if the token is not in the stack.

clear

public void clear()
Removes all tokens from the stack.


getNumTokens

public int getNumTokens()
Returns the number of tokens in the stack


getTopToken

public DrawableToken getTopToken()
Returns the token at the top of the stack, or null if the stack is empty.


getBottomToken

public DrawableToken getBottomToken()
Returns the token at the bottom of the stack, or null if the stack is empty.


getToken

public DrawableToken getToken(int index)
Returns the token at the specified location in the stack, or null if no token is at that index.

Parameters:
index - Location in the stack in the range 0 (top) to getNumTokens() - 1 (bottom).

indexOf

public int indexOf(DrawableToken t)
Returns the location in the stack of the specified token, or -1 if it is not in the stack.

Parameters:
t - The token whose location is being sought.
Returns:
Location if token is found, -1 if token is not found.

getTokensContaining

public java.util.List getTokensContaining(double x,
                                          double y)
Searches the tokens to see if any contain the specified co-ordinates.

Parameters:
x - The x co-ordinate.
y - The y co-ordinate.
Returns:
A list of tokens that contain the specified co-ordinates in the order they appear on the stack (top at start of list).

CIDER Toolkit
Version 0.2.0