objectdraw
Class AWTDrawingCanvas

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Canvas
          extended by objectdraw.AWTDrawingCanvas
All Implemented Interfaces:
ComponentListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, DrawingCanvas
Direct Known Subclasses:
AWTFrameCanvas

public class AWTDrawingCanvas
extends Canvas
implements DrawingCanvas, ComponentListener

An AWTDrawingCanvas is an AWT GUI component designed for displaying simple graphics created by constructing Lines, FilledOvals, FilledRects, or any of the other objectdraw classes that implement DrawableInterface. A similar JDrawingCanvas is provided to support use of Swing. 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, JDrawingCanvas, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Canvas
Canvas.AccessibleAWTCanvas
 
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 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
AWTDrawingCanvas()
          Creates a new DrawingCanvas.
AWTDrawingCanvas(Dimension size)
          Creates a new DrawingCanvas.
AWTDrawingCanvas(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
 int getHeight()
          Determine the current height of a DrawingCanvas.
 Dimension getPreferredSize()
          Retrieves the drawing canvas' preferred size.
 int getWidth()
          Determine the current width of a DrawingCanvas.
 boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height)
          Notifies the CanvasManager of a change in the state of an image being loaded and then calls the native java method imageUpdate.
 void paint(Graphics g)
          Paints the canvas by calling the real paint method in the CanvasManager
 void repaint()
          Requests that the contents of the canvas be redrawn.
 void update(Graphics g)
          Paints the canvas.
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getX, getY, gotFocus, handleEvent, hasFocus, hide, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
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, getSize, 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

AWTDrawingCanvas

public AWTDrawingCanvas()
Creates a new DrawingCanvas.


AWTDrawingCanvas

public AWTDrawingCanvas(Dimension size)
Creates a new DrawingCanvas.

Parameters:
size - the canvas' preferred dimensions

AWTDrawingCanvas

public AWTDrawingCanvas(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

getHeight

public int getHeight()
Description copied from interface: DrawingCanvas
Determine the current height of a DrawingCanvas.

Specified by:
getHeight in interface DrawingCanvas
Overrides:
getHeight in class Component
Returns:
an int referring to the height of the Drawingcanvas.

getPreferredSize

public Dimension getPreferredSize()
Retrieves the drawing canvas' preferred size.

Overrides:
getPreferredSize in class Component
Returns:
the canvas' preferred size

getWidth

public int getWidth()
Description copied from interface: DrawingCanvas
Determine the current width of a DrawingCanvas.

Specified by:
getWidth in interface DrawingCanvas
Overrides:
getWidth in class Component
Returns:
an int referring to the width of the Drawingcanvas.

imageUpdate

public boolean imageUpdate(Image img,
                           int infoflags,
                           int x,
                           int y,
                           int width,
                           int height)
Notifies the CanvasManager of a change in the state of an image being loaded and then calls the native java method imageUpdate.

Specified by:
imageUpdate in interface ImageObserver
Overrides:
imageUpdate in class Component
Parameters:
img - the image being observed.
infoflags - - see Sun documentation 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 in the CanvasManager

Overrides:
paint in class Canvas
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 Canvas
Parameters:
g - the canvas' graphics context