objectdraw
Class VisibleImage

java.lang.Object
  extended by objectdraw.Drawable
      extended by objectdraw.Drawable2D
          extended by objectdraw.Resizable2D
              extended by objectdraw.VisibleImage
All Implemented Interfaces:
Serializable, Drawable2DInterface, DrawableInterface, Resizable2DInterface

public class VisibleImage
extends Resizable2D
implements Resizable2DInterface

A VisibleImage represents an Image that can be drawn on the canvas.

Version:
1.1.1 released February 2005
See Also:
Serialized Form

Field Summary
protected  DrawingCanvas canvas
          The convas on which the Image is displayed
protected  Image image
          The object's image data.
 
Fields inherited from class objectdraw.Drawable
color, shown
 
Constructor Summary
VisibleImage(Image image, double x, double y, double width, double height, DrawingCanvas canvas)
          Creates a new VisibleImage object.
VisibleImage(Image image, double x, double y, DrawingCanvas canvas)
          Creates a new VisibleImage object.
VisibleImage(Image image, Location origin, double width, double height, DrawingCanvas canvas)
          Creates a new VisibleImage object.
VisibleImage(Image image, Location origin, DrawingCanvas canvas)
          Creates a new VisibleImage object.
 
Method Summary
 void addToCanvas(DrawingCanvas canvas)
          Places an existing object on a specified DrawingCanvas.
(package private)  void draw(Graphics g)
          Draws the object.
(package private)  Bounds getBounds()
          Retrieves the bounding rectangle of the object.
 double getHeight()
          Get the height of a graphical object
 Image getImage()
          Access the (unscaled) Image currently displayed by this VisibleImage
 double getWidth()
          Get the width of a graphical object
 void move(double dx, double dy)
          Moves the object within the canvas in the x and y direction by the amounts specified as parameters.
 void moveTo(Location location)
          Moves the object within the canvas to the specified Location
(package private)  void setBounds(Bounds b)
           
 void setHeight(double height)
          Sets the height of the object's bounding rectangle
 void setImage(Image newImage)
          Change the Image displayed by this VisibleImage
 void setSize(double width, double height)
          Sets the width and height of the rectangle bounding the object.
 void setWidth(double width)
          Sets the width of the object's bounding rectangle
 
Methods inherited from class objectdraw.Drawable2D
contains, getLocation, getX, getY, overlaps
 
Methods inherited from class objectdraw.Drawable
clearCanvasContent, getCanvas, getColor, hide, isHidden, moveTo, removeFromCanvas, sendBackward, sendForward, sendToBack, sendToFront, setCanvasContent, setColor, setStateChanged, show
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface objectdraw.Drawable2DInterface
getLocation, getX, getY, overlaps
 
Methods inherited from interface objectdraw.DrawableInterface
contains, getCanvas, getColor, hide, isHidden, moveTo, removeFromCanvas, sendBackward, sendForward, sendToBack, sendToFront, setColor, show
 

Field Detail

canvas

protected DrawingCanvas canvas
The convas on which the Image is displayed


image

protected Image image
The object's image data.

Constructor Detail

VisibleImage

public VisibleImage(Image image,
                    double x,
                    double y,
                    double width,
                    double height,
                    DrawingCanvas canvas)
Creates a new VisibleImage object.

Parameters:
image - the image to display
x - coordinate of the upper left corner of the bounding rectangle
y - coordinate of the upper left corner of the bounding rectangle
width - the width of the bounding rectangle
height - the height of the bounding rectangle
canvas - the canvas in which the image is created

VisibleImage

public VisibleImage(Image image,
                    double x,
                    double y,
                    DrawingCanvas canvas)
Creates a new VisibleImage object.

Parameters:
image - the image to display
x - coordinate of the upper left corner of the bounding rectangle
y - coordinate of the upper left corner of the bounding rectangle
canvas - the canvas in which the image is created

VisibleImage

public VisibleImage(Image image,
                    Location origin,
                    double width,
                    double height,
                    DrawingCanvas canvas)
Creates a new VisibleImage object.

Parameters:
image - the image to display
origin - the upper left corner of the bounding rectangle
width - the width of the bounding rectangle
height - the height of the bounding rectangle
canvas - the canvas in which the image is created

VisibleImage

public VisibleImage(Image image,
                    Location origin,
                    DrawingCanvas canvas)
Creates a new VisibleImage object.

Parameters:
image - the image to display
origin - the upper left corner of the bounding rectangle
canvas - the canvas in which the image is created
Method Detail

addToCanvas

public void addToCanvas(DrawingCanvas canvas)
Description copied from interface: DrawableInterface
Places an existing object on a specified DrawingCanvas. This method will fail if the object is already on a canvas. Therefore, to move an object from one canvas to another one must use removeFromCanvas() followed by addToCanvas. This method can also be invoked to place a Drawable object on a DrawingCanvas after the object is loaded from a file or other stream.

Specified by:
addToCanvas in interface DrawableInterface
Overrides:
addToCanvas in class Drawable
Parameters:
canvas - the canvas on which the object should be drawn

draw

void draw(Graphics g)
Draws the object.

Overrides:
draw in class Drawable2D
Parameters:
g - the graphics context into which the object is drawn

getBounds

Bounds getBounds()
Retrieves the bounding rectangle of the object.

Specified by:
getBounds in class Drawable2D
Returns:
the bounding rectangle

getHeight

public double getHeight()
Description copied from interface: Drawable2DInterface
Get the height of a graphical object

Specified by:
getHeight in interface Drawable2DInterface
Specified by:
getHeight in class Drawable2D
Returns:
the height of the object's bounding rectangle

getImage

public Image getImage()
Access the (unscaled) Image currently displayed by this VisibleImage

Returns:
the image currently displayed by this VisibleImage

getWidth

public double getWidth()
Description copied from interface: Drawable2DInterface
Get the width of a graphical object

Specified by:
getWidth in interface Drawable2DInterface
Specified by:
getWidth in class Drawable2D
Returns:
the width of the object's bounding rectangle

move

public void move(double dx,
                 double dy)
Description copied from interface: DrawableInterface
Moves the object within the canvas in the x and y direction by the amounts specified as parameters.

Specified by:
move in interface DrawableInterface
Overrides:
move in class Resizable2D
Parameters:
dx - the amount to move in the x-direction.
dy - the amount to move in the y-direction.

moveTo

public void moveTo(Location location)
Description copied from interface: DrawableInterface
Moves the object within the canvas to the specified Location

Specified by:
moveTo in interface DrawableInterface
Overrides:
moveTo in class Resizable2D
Parameters:
location - the destination for moving the object.

setBounds

void setBounds(Bounds b)
Specified by:
setBounds in class Resizable2D

setHeight

public void setHeight(double height)
Description copied from interface: Resizable2DInterface
Sets the height of the object's bounding rectangle

Specified by:
setHeight in interface Resizable2DInterface
Specified by:
setHeight in class Resizable2D
Parameters:
height - the new height of the bounding rectangle

setImage

public void setImage(Image newImage)
Change the Image displayed by this VisibleImage

Parameters:
newImage - the Image to be displayed

setSize

public void setSize(double width,
                    double height)
Description copied from interface: Resizable2DInterface
Sets the width and height of the rectangle bounding the object.

Specified by:
setSize in interface Resizable2DInterface
Specified by:
setSize in class Resizable2D
Parameters:
width - the new width of the bounding rectangle
height - the new height of the bounding rectangle

setWidth

public void setWidth(double width)
Description copied from interface: Resizable2DInterface
Sets the width of the object's bounding rectangle

Specified by:
setWidth in interface Resizable2DInterface
Specified by:
setWidth in class Resizable2D
Parameters:
width - the new width of the bounding rectangle