graphics
Class DrawingCanvas

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by containers.Panel
                      extended by graphics.DrawingCanvas
All Implemented Interfaces:
IContainer, ISizeable, MouseListener, MouseMotionListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible

public class DrawingCanvas
extends Panel
implements MouseListener, MouseMotionListener, IContainer, ISizeable

This is a Panel that acts as a container for Graphics. Place graphics onto this.

Author:
Michael Kozelsky Created on: Aug 1, 2006 DrawingCanvas.java
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Component
Component.BaselineResizeBehavior
 
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
DrawingCanvas()
          Creates a new instance of DrawingCanvas with no Graphics on it.
 
Method Summary
 void add(IGraphic g)
          Adds a Graphic onto the DrawingCanvas.
 Collection<IGraphic> getAllGraphics()
          Gets a Collection of all the Graphics on this DrawingCanvas
 Point getCenterLocation()
          Gets the center of the DrawingCanvas
 void mouseClicked(MouseEvent e)
          Called when the mouse is clicked on the DrawingCanvas, delegates to the appropriate Graphic
 void mouseDragged(MouseEvent e)
           
 void mouseEntered(MouseEvent e)
          Called when the mouse is entered onto the DrawingCanvas, does nothing
 void mouseExited(MouseEvent e)
          Called when the mouse exits the DrawingCanvas, does nothing
 void mouseMoved(MouseEvent e)
          Called when the mouse was moved on the DrawingCanvas, calls entered, exited, moved on appropriate graphics
 void mousePressed(MouseEvent e)
          Called when the mouse is pressed on the DrawingCanvas, delegates to the appropriate Graphic
 void mouseReleased(MouseEvent e)
          Called when the mouse is released on the DrawingCanvas, delegates to the appropriate Graphic
 void paintComponent(Graphics gs)
          Partially overrides the paint method to paint all of it's graphics as well as itself
 Point randomPoint()
          Find a random point on this DrawingCanvas
 void remove(IGraphic g)
          Removes a Graphic from the DrawingCanvas.
 void removeAllGraphics()
          Removes all the graphics from this DrawingCanvas, making it empty.
 void setLocation(Point p)
          Sets the Location of this DrawingCanvas to a specified point.
 
Methods inherited from class containers.Panel
getColor, getDimension, setColor, setDimension
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, 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, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, 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, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, 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
 
Methods inherited from interface graphics.IContainer
getDimension, repaint, repaint
 
Methods inherited from interface java.awt.image.ImageObserver
imageUpdate
 
Methods inherited from interface graphics.ISizeable
getDimension, setDimension
 

Constructor Detail

DrawingCanvas

public DrawingCanvas()
Creates a new instance of DrawingCanvas with no Graphics on it. The default size is (100,100)

Method Detail

mouseClicked

public void mouseClicked(MouseEvent e)
Called when the mouse is clicked on the DrawingCanvas, delegates to the appropriate Graphic

Specified by:
mouseClicked in interface MouseListener
Parameters:
e - The MouseEvent that did the clicking
See Also:
MouseListener.mouseClicked(java.awt.event.MouseEvent)

mousePressed

public void mousePressed(MouseEvent e)
Called when the mouse is pressed on the DrawingCanvas, delegates to the appropriate Graphic

Specified by:
mousePressed in interface MouseListener
Parameters:
e - The MouseEvent that did the pressing
See Also:
MouseListener.mousePressed(java.awt.event.MouseEvent)

mouseReleased

public void mouseReleased(MouseEvent e)
Called when the mouse is released on the DrawingCanvas, delegates to the appropriate Graphic

Specified by:
mouseReleased in interface MouseListener
Parameters:
e - The MouseEvent that did the releasing
See Also:
MouseListener.mouseReleased(java.awt.event.MouseEvent)

mouseEntered

public void mouseEntered(MouseEvent e)
Called when the mouse is entered onto the DrawingCanvas, does nothing

Specified by:
mouseEntered in interface MouseListener
Parameters:
e - The MouseEvent that did the entering
See Also:
MouseListener.mouseEntered(java.awt.event.MouseEvent)

mouseExited

public void mouseExited(MouseEvent e)
Called when the mouse exits the DrawingCanvas, does nothing

Specified by:
mouseExited in interface MouseListener
Parameters:
e - The MouseEvent that did the exiting
See Also:
MouseListener.mouseExited(java.awt.event.MouseEvent)

mouseDragged

public void mouseDragged(MouseEvent e)
Specified by:
mouseDragged in interface MouseMotionListener
Parameters:
e -
See Also:
MouseMotionListener.mouseDragged(java.awt.event.MouseEvent)

mouseMoved

public void mouseMoved(MouseEvent e)
Called when the mouse was moved on the DrawingCanvas, calls entered, exited, moved on appropriate graphics

Specified by:
mouseMoved in interface MouseMotionListener
Parameters:
e - The MouseEvent that did the moving
See Also:
MouseMotionListener.mouseMoved(java.awt.event.MouseEvent)

setLocation

public void setLocation(Point p)
Sets the Location of this DrawingCanvas to a specified point. Probably won't work nicely with Layouts

Overrides:
setLocation in class Component
Parameters:
p - The Point at which to place this DrawingCanvas
See Also:
Component.setLocation(java.awt.Point)

getCenterLocation

public Point getCenterLocation()
Gets the center of the DrawingCanvas

Returns:
a java.awt.Point at the center of the DrawingCanvas

add

public void add(IGraphic g)
Adds a Graphic onto the DrawingCanvas. Graphics are added so that the most recently added one will be on top of any others

Specified by:
add in interface IContainer
Parameters:
g - The Graphic to add to this DrawingCanvas
See Also:
IContainer.add(graphics.IGraphic)

remove

public void remove(IGraphic g)
Removes a Graphic from the DrawingCanvas.

Specified by:
remove in interface IContainer
Parameters:
g - The Graphic to remove
See Also:
IContainer.remove(graphics.IGraphic)

getAllGraphics

public Collection<IGraphic> getAllGraphics()
Gets a Collection of all the Graphics on this DrawingCanvas

Returns:
a java.util.Collection of Graphics

removeAllGraphics

public void removeAllGraphics()
Removes all the graphics from this DrawingCanvas, making it empty.


paintComponent

public void paintComponent(Graphics gs)
Partially overrides the paint method to paint all of it's graphics as well as itself

Overrides:
paintComponent in class JComponent
Parameters:
gs - The java.awt.Graphics object that will paint the Graphics
See Also:
Component.paint(java.awt.Graphics)

randomPoint

public Point randomPoint()
Find a random point on this DrawingCanvas

Returns:
a java.awt.Point that represents a random location on this DrawingCanvas