ach
Class ImgCanvas

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Canvas
          extended byach.ImgCanvas
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, ImgComponentIntf, java.awt.MenuContainer, java.io.Serializable

public class ImgCanvas
extends java.awt.Canvas
implements ImgComponentIntf

ImgCanvas.java
Copyright (c) 1999-2002 Helge Hackbarth, All Rights Reserved.
Extends Canvas with comfortable image display functions and automatic drawing of background patterns. This component is heavyweight. In order to use the same functionality but as lightweight component e.g. for a JInternalFrame please use class ImgComponent.

THE AUTHOR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THE AUTHOR SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 boolean clearBackground
          Flag if background is simply cleared or drawn with a black-and-white pattern
 boolean clearBeforePaint
          Flag if canvas needs to be cleared before paint.
 boolean needsFocus
          Flag if canvas needs to request focus (e.g. in order to receive events in JDK 1.0).
 
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
ImgCanvas(java.awt.Container parent)
          constructor for ImgCanvas
ImgCanvas(java.awt.Container parent, java.awt.image.ImageObserver observer)
          constructor for ImgCanvas chaining to additional image observer
 
Method Summary
 void checkFocus()
          request focus if boolean var needsFocus is set true
 void drawError(java.lang.String errorMsg)
          schedule a repaint that will draw an error messages (may contain \r\n)
 void drawImage(java.awt.Image img, int x, int y)
          schedule a repaint with drawing the given image (not scaled)
 void drawImage(java.awt.Image img, int x, int y, int width, int height, int hints)
          schedule a repaint with drawing the given image (scaled)
 void drawShapes(ShapeList sl)
          draw vector graphics objects
 void fitInImage(java.awt.Image img, java.awt.Dimension imgDim, int hints)
          schedule a repaint with an image proportionally scaled to fit in canvas
 boolean getDoubleBuffering()
          Retrieve current setting of double buffering mode
 java.awt.Dimension getMinimumSize()
           
 java.awt.Image getOffscreen()
          Get offscreen image
 java.awt.Dimension getPreferredSize()
           
 boolean imageUpdate(java.awt.Image img, int flags, int x, int y, int w, int h)
          Image canvas is a modified ImageObserver to retry after ABORT and to be able to chain in another ImageObserver
 java.awt.Dimension minimumSize()
           
 void paint(java.awt.Graphics g)
          the paint method of the image canvas
 java.awt.Dimension preferredSize()
           
 void requestFocus()
           
 void resize(java.awt.Dimension d)
           
 void resize(int width, int height)
           
 void setBackground(java.awt.Color c)
           
 void setBackgroundExclusion(int x, int y, int width, int height)
          Specify the area that has to be excluded from drawing the background
 void setDoubleBuffering(boolean dblBufMode)
          Enable or disable double buffering when component is painted
 void setSize(java.awt.Dimension d)
           
 void setSize(int width, int height)
           
 void update(java.awt.Graphics g)
          the update method of the image canvas (calling paint()); drawing of the background is controlled by clearBeforePaint-flag
 
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, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, 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, repaint, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, 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
 

Field Detail

needsFocus

public boolean needsFocus
Flag if canvas needs to request focus (e.g. in order to receive events in JDK 1.0).


clearBeforePaint

public boolean clearBeforePaint
Flag if canvas needs to be cleared before paint. This class automatically draws a background pattern around the image, so usually clearing the background before painting is not necessary


clearBackground

public boolean clearBackground
Flag if background is simply cleared or drawn with a black-and-white pattern

Constructor Detail

ImgCanvas

public ImgCanvas(java.awt.Container parent)
constructor for ImgCanvas

Parameters:
parent - is the container where this canvas is to be embedded

ImgCanvas

public ImgCanvas(java.awt.Container parent,
                 java.awt.image.ImageObserver observer)
constructor for ImgCanvas chaining to additional image observer

Parameters:
parent - is the container where this canvas is to be embedded
observer - additional image observer to be chained in at drawImage
Method Detail

setDoubleBuffering

public void setDoubleBuffering(boolean dblBufMode)
Enable or disable double buffering when component is painted

Specified by:
setDoubleBuffering in interface ImgComponentIntf
Parameters:
dblBufMode - true to enable double buffering, false otherwise

getDoubleBuffering

public boolean getDoubleBuffering()
Retrieve current setting of double buffering mode

Specified by:
getDoubleBuffering in interface ImgComponentIntf
Returns:
true if double buffering is enabled, false otherwise

getOffscreen

public java.awt.Image getOffscreen()
Get offscreen image

Specified by:
getOffscreen in interface ImgComponentIntf
Returns:
image representing the current double buffer screen or null

minimumSize

public java.awt.Dimension minimumSize()

getMinimumSize

public java.awt.Dimension getMinimumSize()

preferredSize

public java.awt.Dimension preferredSize()

getPreferredSize

public java.awt.Dimension getPreferredSize()

resize

public void resize(java.awt.Dimension d)
Specified by:
resize in interface ImgComponentIntf

resize

public void resize(int width,
                   int height)
Specified by:
resize in interface ImgComponentIntf

setSize

public void setSize(java.awt.Dimension d)
Specified by:
setSize in interface ImgComponentIntf

setSize

public void setSize(int width,
                    int height)
Specified by:
setSize in interface ImgComponentIntf

setBackground

public void setBackground(java.awt.Color c)
Specified by:
setBackground in interface ImgComponentIntf

setBackgroundExclusion

public void setBackgroundExclusion(int x,
                                   int y,
                                   int width,
                                   int height)
Specify the area that has to be excluded from drawing the background

Specified by:
setBackgroundExclusion in interface ImgComponentIntf
Parameters:
x - the X-coordinate of the excluded area
y - the Y-coordinate of the excluded area
width - the width of the excluded area
height - the height of the excluded area

checkFocus

public void checkFocus()
Description copied from interface: ImgComponentIntf
request focus if boolean var needsFocus is set true

Specified by:
checkFocus in interface ImgComponentIntf

drawImage

public void drawImage(java.awt.Image img,
                      int x,
                      int y,
                      int width,
                      int height,
                      int hints)
schedule a repaint with drawing the given image (scaled)

Specified by:
drawImage in interface ImgComponentIntf
Parameters:
img - the image to be drawn
x - the X-coordinate of the image relative to canvas
y - the Y-coordinate of the image relative to canvas
width - the scaled width of the image
height - the scaled height of the image
hints - options for scaling method, see getScaledInstance (e.g. SCALE_SMOOTH)
See Also:
Image.getScaledInstance(int width, int height, int hints)

drawImage

public void drawImage(java.awt.Image img,
                      int x,
                      int y)
schedule a repaint with drawing the given image (not scaled)

Specified by:
drawImage in interface ImgComponentIntf
Parameters:
img - the image to be drawn
x - the X-coordinate of the image relative to canvas
y - the Y-coordinate of the image relative to canvas

fitInImage

public void fitInImage(java.awt.Image img,
                       java.awt.Dimension imgDim,
                       int hints)
schedule a repaint with an image proportionally scaled to fit in canvas

Specified by:
fitInImage in interface ImgComponentIntf
Parameters:
img - the image to be drawn
imgDim - the size of the image
hints - options for scaling method, see getScaledInstance (e.g. SCALE_SMOOTH)
See Also:
Image.getScaledInstance(int width, int height, int hints)

drawError

public void drawError(java.lang.String errorMsg)
schedule a repaint that will draw an error messages (may contain \r\n)

Specified by:
drawError in interface ImgComponentIntf
Parameters:
errorMsg - the error message

drawShapes

public void drawShapes(ShapeList sl)
draw vector graphics objects

Specified by:
drawShapes in interface ImgComponentIntf

requestFocus

public void requestFocus()

paint

public void paint(java.awt.Graphics g)
the paint method of the image canvas

Specified by:
paint in interface ImgComponentIntf

update

public void update(java.awt.Graphics g)
the update method of the image canvas (calling paint()); drawing of the background is controlled by clearBeforePaint-flag

Specified by:
update in interface ImgComponentIntf

imageUpdate

public boolean imageUpdate(java.awt.Image img,
                           int flags,
                           int x,
                           int y,
                           int w,
                           int h)
Image canvas is a modified ImageObserver to retry after ABORT and to be able to chain in another ImageObserver

Specified by:
imageUpdate in interface ImgComponentIntf