cse115.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 cse115.graphics.DrawingCanvas
All Implemented Interfaces:
IContainer, Sizeable, MouseListener, MouseMotionListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible

public class DrawingCanvas
extends JPanel
implements MouseListener, MouseMotionListener, IContainer, Sizeable

This is a JPanel 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.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, 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(Graphic g)
          Adds a Graphic onto the DrawingCanvas.
 Collection<Graphic> getAllGraphics()
          Gets a Collection of all the Graphics on this DrawingCanvas
 Point getCenterLocation()
          Gets the center of the DrawingCanvas
 Color getColor()
          Gets the Color of this DrawingCanvas
 Dimension getDimension()
          Gets the Dimension of this 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 paint(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(Graphic g)
          Removes a Graphic from the DrawingCanvas.
 void removeAllGraphics()
           
 void setColor(Color color)
          Sets the Color of this DrawingCanvas
 void setDimension(Dimension dimension)
          Sets the Dimension of this DrawingCanvas
 void setLocation(Point p)
          Sets the Location of this DrawingCanvas to a specified point.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, 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, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, 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, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, 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, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface cse115.graphics.IContainer
repaint, repaint
 
Methods inherited from interface java.awt.image.ImageObserver
imageUpdate
 

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)

setDimension

public void setDimension(Dimension dimension)
Sets the Dimension of this DrawingCanvas

Specified by:
setDimension in interface Sizeable
Parameters:
dimension -

getDimension

public Dimension getDimension()
Gets the Dimension of this DrawingCanvas

Specified by:
getDimension in interface IContainer
Specified by:
getDimension in interface Sizeable
Returns:
a java.awt.Dimension representing the current Dimension

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

setColor

public void setColor(Color color)
Sets the Color of this DrawingCanvas

Parameters:
color -

getColor

public Color getColor()
Gets the Color of this DrawingCanvas

Returns:
A java.awt.Color representing the Color of this DrawingCanvas

add

public void add(Graphic 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(cse115.graphics.Graphic)

remove

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

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

getAllGraphics

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

Returns:
a java.util.Collection of Graphics

removeAllGraphics

public void removeAllGraphics()

paint

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

Overrides:
paint 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