diva.canvas.toolbox
Class ImageFigure

java.lang.Object
  extended by diva.canvas.AbstractFigure
      extended by diva.canvas.toolbox.ImageFigure
All Implemented Interfaces:
CanvasComponent, Figure, VisibleComponent, UserObjectContainer, java.awt.image.ImageObserver

public class ImageFigure
extends AbstractFigure
implements java.awt.image.ImageObserver

A figure which draws a user-specified image.

Version:
$Id: ImageFigure.java 39592 2005-10-24 19:09:12Z cxh $
Author:
Michael Shilman

Field Summary
private  boolean _centered
          Indicator of whether this figure should be centered on its origin.
private  int _height
          The height of the figure.
private  java.awt.Image _image
          The image of this figure.
private  int _width
          The width of the figure.
private  java.awt.geom.AffineTransform _xf
          The local transform
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ImageFigure()
          Create an empty image figure.
ImageFigure(java.awt.Image i)
          Create an image figure displaying the given image.
 
Method Summary
 java.awt.Image getImage()
          Return the figure's image.
 java.awt.geom.Point2D getOrigin()
          Return the origin of the figure in the enclosing transform context.
 java.awt.Shape getShape()
          Return the rectangular shape of the image, or a small rectangle if the image is null.
 boolean imageUpdate(java.awt.Image image, int infoflags, int x, int y, int width, int height)
          This method, which is required by the ImageObserver interface, is called if something has changed in a background loading of the image.
 boolean isCentered()
          Return whether the figure should be centered on its origin.
 void paint(java.awt.Graphics2D g)
          Paint the figure's image.
 void setCentered(boolean centered)
          Specify whether the figure should be centered on its origin.
 void setImage(java.awt.Image i)
          Set the figure's image.
 void transform(java.awt.geom.AffineTransform t)
          Perform an affine transform on this image.
 
Methods inherited from class diva.canvas.AbstractFigure
contains, getBounds, getInteractor, getLayer, getParent, getToolTipText, getTransformContext, getUserObject, hit, intersects, isVisible, paint, repaint, repaint, setInteractor, setParent, setToolTipText, setUserObject, setVisible, translate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_centered

private boolean _centered
Indicator of whether this figure should be centered on its origin. By default, this class is not centered.


_height

private int _height
The height of the figure.


_image

private java.awt.Image _image
The image of this figure.


_width

private int _width
The width of the figure.


_xf

private java.awt.geom.AffineTransform _xf
The local transform

Constructor Detail

ImageFigure

public ImageFigure()
Create an empty image figure.


ImageFigure

public ImageFigure(java.awt.Image i)
Create an image figure displaying the given image. This needs to be called in the Swing thread.

Method Detail

getImage

public java.awt.Image getImage()
Return the figure's image.


getOrigin

public java.awt.geom.Point2D getOrigin()
Return the origin of the figure in the enclosing transform context. This overrides the base class to return the center of the shape, if the figure is centered, or the origin of the shape if the figure is not centered.

Specified by:
getOrigin in interface Figure
Overrides:
getOrigin in class AbstractFigure
Returns:
The origin of the figure.
See Also:
AbstractFigure.getBounds()

getShape

public java.awt.Shape getShape()
Return the rectangular shape of the image, or a small rectangle if the image is null. NOTE: You cannot rely on the return value unless the image has been fully rendered.

Specified by:
getShape in interface Figure
Specified by:
getShape in class AbstractFigure

imageUpdate

public boolean imageUpdate(java.awt.Image image,
                           int infoflags,
                           int x,
                           int y,
                           int width,
                           int height)
This method, which is required by the ImageObserver interface, is called if something has changed in a background loading of the image. It simply calls repaint().

Specified by:
imageUpdate in interface java.awt.image.ImageObserver
Parameters:
image - The image being observed.
infoflags - The bitwise inclusive OR of the following flags: WIDTH, HEIGHT, PROPERTIES, SOMEBITS, FRAMEBITS, ALLBITS, ERROR, ABORT.
x - The x coordinate of the image.
y - The y coordinate of the image.
width - The width of the image.
height - The height of the image.
Returns:
False if the infoflags indicate that the image is completely loaded; true otherwise.

isCentered

public boolean isCentered()
Return whether the figure should be centered on its origin.

Returns:
False If the origin of the figure, as returned by getOrigin(), is the upper left corner.
See Also:
getOrigin(), setCentered(boolean)

paint

public void paint(java.awt.Graphics2D g)
Paint the figure's image.

Specified by:
paint in interface VisibleComponent
Specified by:
paint in class AbstractFigure

setCentered

public void setCentered(boolean centered)
Specify whether the figure should be centered on its origin. By default, it is.

Parameters:
centered - False to make the origin of the figure, as returned by getOrigin(), be the upper left corner.
See Also:
getOrigin()

setImage

public void setImage(java.awt.Image i)
Set the figure's image. This should be called only from the Swing thread.

Parameters:
i - The image.

transform

public void transform(java.awt.geom.AffineTransform t)
Perform an affine transform on this image.

Specified by:
transform in interface Figure
Specified by:
transform in class AbstractFigure