objectdraw
Class JDrawingCanvas

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by objectdraw.JDrawingCanvas
All Implemented Interfaces:
ComponentListener, ImageObserver, MenuContainer, Serializable, EventListener, DrawingCanvas
Direct Known Subclasses:
FrameCanvas

public class JDrawingCanvas
extends JComponent
implements DrawingCanvas, ComponentListener

A JDrawingCanvas is a Swing GUI component designed for displaying simple graphics created by instantiating members of subclasses of the Drawable class. A similar AWTDrawingCanvas is provided to support use of the Abstract Windowing Toolkit. Both of these classes implement the DrawingCanvas interface and delegate most of the work of maintaining a description of the graphics being displayed to an object of the CanvasManager class.

Version:
1.1.1 released February 2005
See Also:
DrawingCanvas, AWTDrawingCanvas, Serialized Form

Nested Class Summary
 
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.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static Dimension DEFAULT_PREFERRED_SIZE
          default size for a JDrawingCanvas
 int REPAINT_DELAY
          The amount by which repaint requests should be delayed
 
Fields inherited from class javax.swing.JComponent
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
accessibleContext, 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
JDrawingCanvas()
          Creates a new DrawingCanvas.
JDrawingCanvas(Dimension size)
          Creates a new DrawingCanvas.
JDrawingCanvas(int width, int height)
          Creates a new DrawingCanvas.
 
Method Summary
 void clear()
          Removes all objects from the DrawingCanvas.
 void componentHidden(ComponentEvent e)
          Invoked when component has been hidden.
 void componentMoved(ComponentEvent e)
          Invoked when component has been moved.
 void componentResized(ComponentEvent e)
          Invoked when component has been resized.
 void componentShown(ComponentEvent e)
          Invoked when component has been shown.
 void disableAutoRepaint()
          Requests that the DrawingCanvas not be automatically repainted after every change.
 void enableAutoRepaint()
          Requests that the DrawingCanvas to be automatically repainted after every change without specifically calling repaint().
 CanvasManager getCanvasContent()
          Retrieves the CanvasManager that keeps track of all of the Drawable objects currently associated with this DrawingCanvas.
 DrawableIterator getDrawableIterator()
          Creates and returns an iterator of all the objects on the DrawingCanvas
 Dimension getPreferredSize()
          Retrieves the object's preferred size.
 boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height)
          Repaints the component when the image has changed.
 void paint(Graphics g)
          Paints the canvas by calling the real paint method of the CanvasManager
 void repaint()
          Requests that the contents of the canvas be redrawn.
 void update(Graphics g)
          Paints the canvas.
 
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, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, 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, updateUI
 
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, 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, getAccessibleContext, 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, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface objectdraw.DrawingCanvas
addComponentListener, addKeyListener, addMouseListener, addMouseMotionListener, createImage, getGraphics, getHeight, getSize, getWidth, prepareImage, requestFocus, requestFocusInWindow, setBackground, setForeground
 

Field Detail

DEFAULT_PREFERRED_SIZE

public static final Dimension DEFAULT_PREFERRED_SIZE
default size for a JDrawingCanvas


REPAINT_DELAY

public final int REPAINT_DELAY
The amount by which repaint requests should be delayed

See Also:
Constant Field Values
Constructor Detail

JDrawingCanvas

public JDrawingCanvas()
Creates a new DrawingCanvas.


JDrawingCanvas

public JDrawingCanvas(Dimension size)
Creates a new DrawingCanvas.

Parameters:
size - the canvas' preferred dimensions

JDrawingCanvas

public JDrawingCanvas(int width,
                      int height)
Creates a new DrawingCanvas.

Parameters:
width - the canvas' preferred width
height - the canvas' preferred height
Method Detail

clear

public void clear()
Description copied from interface: DrawingCanvas
Removes all objects from the DrawingCanvas.

Specified by:
clear in interface DrawingCanvas

componentHidden

public void componentHidden(ComponentEvent e)
Invoked when component has been hidden.

Specified by:
componentHidden in interface ComponentListener
Parameters:
e - event triggered by hiding

componentMoved

public void componentMoved(ComponentEvent e)
Invoked when component has been moved.

Specified by:
componentMoved in interface ComponentListener
Parameters:
e - event triggered by moving

componentResized

public void componentResized(ComponentEvent e)
Invoked when component has been resized.

Specified by:
componentResized in interface ComponentListener
Parameters:
e - event triggered by resizing

componentShown

public void componentShown(ComponentEvent e)
Invoked when component has been shown.

Specified by:
componentShown in interface ComponentListener
Parameters:
e - event triggered by showing

disableAutoRepaint

public void disableAutoRepaint()
Description copied from interface: DrawingCanvas
Requests that the DrawingCanvas not be automatically repainted after every change. When this mode is enabled, an explicit call to repaint() must be made in order to see changes made to the objects displayed on the DrawingCanvas. By default, auto-repaint is enabled in a newly constructed DrawingCanvas.

Specified by:
disableAutoRepaint in interface DrawingCanvas

enableAutoRepaint

public void enableAutoRepaint()
Description copied from interface: DrawingCanvas
Requests that the DrawingCanvas to be automatically repainted after every change without specifically calling repaint(). This is the default setting.

Specified by:
enableAutoRepaint in interface DrawingCanvas

getCanvasContent

public CanvasManager getCanvasContent()
Description copied from interface: DrawingCanvas
Retrieves the CanvasManager that keeps track of all of the Drawable objects currently associated with this DrawingCanvas.

Specified by:
getCanvasContent in interface DrawingCanvas
Returns:
the DrawingCanvas' manager

getDrawableIterator

public DrawableIterator getDrawableIterator()
Description copied from interface: DrawingCanvas
Creates and returns an iterator of all the objects on the DrawingCanvas

Specified by:
getDrawableIterator in interface DrawingCanvas
Returns:
an iterator of all of the CanvasManager's objects

getPreferredSize

public Dimension getPreferredSize()
Retrieves the object's preferred size.

Overrides:
getPreferredSize in class JComponent
Returns:
the object's preferred size

imageUpdate

public boolean imageUpdate(Image img,
                           int infoflags,
                           int x,
                           int y,
                           int width,
                           int height)
Repaints the component when the image has changed.

Specified by:
imageUpdate in interface ImageObserver
Overrides:
imageUpdate in class Component
Parameters:
img - - the image being observed
infoflags - - see imageUpdate for more information
x - - the x coordinate
y - - the y coordinate
width - - the width
height - - the height
Returns:
false if the infoflags indicate that the image is completely loaded; true otherwise.

paint

public void paint(Graphics g)
Paints the canvas by calling the real paint method of the CanvasManager

Overrides:
paint in class JComponent
Parameters:
g - the canvas' graphics context.

repaint

public void repaint()
Description copied from interface: DrawingCanvas
Requests that the contents of the canvas be redrawn. It is not necessary to invoke this method unless disableAutoRepaint() has been invoked. In its default state, a DrawingCanvas redraws the display automatically after any change occurs.

Specified by:
repaint in interface DrawingCanvas
Overrides:
repaint in class Component

update

public void update(Graphics g)
Paints the canvas.

Overrides:
update in class JComponent
Parameters:
g - the canvas' graphics context