Package diva.canvas.toolbox
Class ImageFigure
- java.lang.Object
-
- diva.canvas.AbstractFigure
-
- 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$
- Author:
- Michael Shilman
-
-
Constructor Summary
Constructors Constructor Description ImageFigure()
Create an empty image figure.ImageFigure(java.awt.Image i)
Create an image figure displaying the given image.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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
-
-
-
-
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 interfaceFigure
- Overrides:
getOrigin
in classAbstractFigure
- 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 interfaceFigure
- Specified by:
getShape
in classAbstractFigure
- Returns:
- the outline shape of this figure
-
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 interfacejava.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 interfaceVisibleComponent
- Specified by:
paint
in classAbstractFigure
- Parameters:
g
- The 2D graphics object that this object it to be painted upon.
-
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 interfaceFigure
- Specified by:
transform
in classAbstractFigure
- Parameters:
t
- The transform to be used.
-
-