Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class ncsa.horizon.viewer.ImageCanvas

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Canvas
              |
              +--ncsa.horizon.viewer.ImageCanvas
Subclasses:
GraphicalImageCanvas

public class ImageCanvas
extends java.awt.Canvas
implements ImageCanvas.Modes, java.lang.Cloneable
A Canvas object for displaying images. Features include To use this canvas to display a stack of images, one first adds each image to the canvas using the addImage() method. The order in which they are added determines the layering order. Images added first are drawn first and thus appear on the bottom of the stack; the last image appears as the top most image. One will only actually see the lower images if the upper ones are partially transparent. The added images are not actually displayed until the displayImages() method is called. The clear() method empties the current stack of images and clears the canvas.

The placement and sizing of the image is controlled by the display mode, set using setMode(). These modes (defined in the ImageCanvas.Modes interface) are:

The painting of the images is done using a double-buffering technique. Thus, this canvas is helpful when one wants to overlay graphics that require freqent updates (e.g. a cursor). The buffer will only be updated with a call to displayImages() or when the canvas is resized.

See Also:
Serialized Form

Inner Class Summary
static  ImageCanvas.Modes
           
 
Field Summary
int mode
          Indicates the mode in which the Images are painted
java.awt.Font msgfont
          The font used for the message
java.awt.Image offscreen
          Points to the off-screen Image used for double buffering
java.awt.Dimension prefSize
          The variable preferred size of the Canvas
boolean redrawImages
          Boolean to indicate if the offImage needs to be repainted
static int SIZE_IMAGE_CENTER
          Deprecated. Trim the image to the Canvas size (centered)
static int SIZE_IMAGE_FIT
          Deprecated. Fit the image to the Canvas size (default)
static int SIZE_IMAGE_FLUSH
          Deprecated. Scale the image to the Canvas size (flush top/left)
static int SIZE_IMAGE_SCALE
          Deprecated. Scale the image to the Canvas size (centered)
static int SIZE_IMAGE_TRUNCATE
          Deprecated. Trim the image to the Canvas size (flush top/left)
java.util.Vector views
          The Vector containing all the Images which were added to the Canvas
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
ImageCanvas(int w, int h)
           
ImageCanvas(java.awt.Dimension sz)
           
 
Method Summary
void addImage(java.awt.Image im)
          Add an image to the current set of Images displayed by the Canvas.
void clear()
          Clear the canvas.
void displayImages()
          Display the current Images.
int getMode()
          return the mode being used by this canvas
java.awt.Dimension getPreferredSize()
          Gets the preferred size of the Canvas which is the same as the size it was created with.
java.awt.Rectangle getViewBounds(int width, int height)
          Return a rectangle specifying the bounds within the display component that an image of a given size would be painted.
boolean offPaint()
          Paint the off screen image.
void paint(java.awt.Graphics g)
           
boolean paintImage(java.awt.Graphics g, java.awt.Image im)
           
void paintMessage(java.awt.Graphics g, java.lang.String msg)
          print a message on using the Graphics object.
void setBounds(int x, int y, int width, int height)
           
void setMode(int mode)
          Set the display mode for sizing and placing the image in the canvas.
void setPreferredSize(java.awt.Dimension prefSize)
          Allows the parent Container to set the preferred size of the Canvas according to its preference.
void setPreferredSize(int w, int h)
          Allows the parent Container to set the preferred size of the Canvas according to its preference.
void update(java.awt.Graphics g)
           
java.awt.Dimension viewSize(int wd, int ht)
          determine the dimesions necessary to fit an image of width wd and height ht into the display canvas (while preserving the aspect ratio).
 
Methods inherited from class java.awt.Canvas
addNotify, paint
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getParent, getPeer, getPreferredSize, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paint, paramString, postEvent, preferredSize, prepareImage, prepareImage, printAll, print, processComponentEvent, processEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Field Detail

SIZE_IMAGE_FIT

public static final int SIZE_IMAGE_FIT
Deprecated. use FIT instead.
Fit the image to the Canvas size (default)

SIZE_IMAGE_CENTER

public static final int SIZE_IMAGE_CENTER
Deprecated. use CENTER instead.
Trim the image to the Canvas size (centered)

SIZE_IMAGE_TRUNCATE

public static final int SIZE_IMAGE_TRUNCATE
Deprecated. use FLUSH instead.
Trim the image to the Canvas size (flush top/left)

SIZE_IMAGE_SCALE

public static final int SIZE_IMAGE_SCALE
Deprecated. use SCALED_CENTER instead.
Scale the image to the Canvas size (centered)

SIZE_IMAGE_FLUSH

public static final int SIZE_IMAGE_FLUSH
Deprecated. use SCALED_FLUSH instead.
Scale the image to the Canvas size (flush top/left)

views

protected java.util.Vector views
The Vector containing all the Images which were added to the Canvas

mode

protected int mode
Indicates the mode in which the Images are painted

offscreen

protected java.awt.Image offscreen
Points to the off-screen Image used for double buffering

msgfont

protected java.awt.Font msgfont
The font used for the message

prefSize

protected java.awt.Dimension prefSize
The variable preferred size of the Canvas

redrawImages

protected boolean redrawImages
Boolean to indicate if the offImage needs to be repainted
Constructor Detail

ImageCanvas

public ImageCanvas(int w,
                   int h)

ImageCanvas

public ImageCanvas(java.awt.Dimension sz)
Method Detail

getPreferredSize

public java.awt.Dimension getPreferredSize()
Gets the preferred size of the Canvas which is the same as the size it was created with.
Overrides:
getPreferredSize in class java.awt.Component

setPreferredSize

public void setPreferredSize(java.awt.Dimension prefSize)
Allows the parent Container to set the preferred size of the Canvas according to its preference.

setPreferredSize

public void setPreferredSize(int w,
                             int h)
Allows the parent Container to set the preferred size of the Canvas according to its preference.

addImage

public void addImage(java.awt.Image im)
Add an image to the current set of Images displayed by the Canvas. The resulting Image represents a series of layered Images. The master Image should be added last.

displayImages

public void displayImages()
Display the current Images.

clear

public void clear()
Clear the canvas. This method also releases references to images being displayed.

update

public void update(java.awt.Graphics g)
Overrides:
update in class java.awt.Component

paint

public void paint(java.awt.Graphics g)
Overrides:
paint in class java.awt.Canvas

offPaint

protected boolean offPaint()
Paint the off screen image.
Returns:
boolean true if painting was successful; false if images are still loading.

paintImage

protected boolean paintImage(java.awt.Graphics g,
                             java.awt.Image im)

paintMessage

protected void paintMessage(java.awt.Graphics g,
                            java.lang.String msg)
print a message on using the Graphics object. Message is placed over a white rectangle to that it can be seen.

getViewBounds

public java.awt.Rectangle getViewBounds(int width,
                               int height)
Return a rectangle specifying the bounds within the display component that an image of a given size would be painted.

viewSize

public java.awt.Dimension viewSize(int wd,
                          int ht)
determine the dimesions necessary to fit an image of width wd and height ht into the display canvas (while preserving the aspect ratio).

getMode

public int getMode()
return the mode being used by this canvas

setMode

public void setMode(int mode)
Set the display mode for sizing and placing the image in the canvas.
Parameters:
mode - one of the display modes defined by this class

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Overrides:
setBounds in class java.awt.Component

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD