objectdraw
Class VisibleImage

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

public class VisibleImage
extends objectdraw.Resizable2D
implements Resizable2DInterface

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

Version:
1.1.2 released July 2006
See Also:
Serialized Form

Constructor Summary
VisibleImage(java.awt.Image image, double x, double y, double width, double height, DrawingCanvas canvas)
          Creates a new VisibleImage object.
VisibleImage(java.awt.Image image, double x, double y, DrawingCanvas canvas)
          Creates a new VisibleImage object.
VisibleImage(java.awt.Image image, Location origin, double width, double height, DrawingCanvas canvas)
          Creates a new VisibleImage object.
VisibleImage(java.awt.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.
 boolean contains(Location point)
          Determines if a particular position on the DrawingCanvas is contained within the object.
 DrawingCanvas getCanvas()
          Determine which (if any) DrawingCanvas this object is positioned on
 java.awt.Color getColor()
          Retrieves the color of the object.
 double getHeight()
          Get the height of a graphical object
 java.awt.Image getImage()
          Access the (unscaled) Image currently displayed by this VisibleImage
 Location getLocation()
          Get a graphical object's position
 double getWidth()
          Get the width of a graphical object
 double getX()
          Get the x coordinate of left edge of rectangle bounding the object
 double getY()
          Get the y coordinate of top edge of rectangle bounding the object
 void hide()
          Temporarily hides an object on a DrawingCanvas from view.
 boolean isHidden()
          Determine whether an object is currently visible on its canvas
 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(double x, double y)
          Moves the object within the canvas to the x and y coordinates provided.
 void moveTo(Location location)
          Moves the object within the canvas to the specified Location
 boolean overlaps(Drawable2DInterface item)
          Determines if another Drawable's bounding rectangle overlaps with this object's bounding rectangle.
 void removeFromCanvas()
          Permanently removes the object from the canvas it is currently on.
 void sendBackward()
          Sends the object backward.
 void sendForward()
          Sends the object forward.
 void sendToBack()
          Sends the object to the back.
 void sendToFront()
          Sends the object to the front.
 void setColor(java.awt.Color c)
          Sets the color of the object.
 void setHeight(double height)
          Sets the height of the object's bounding rectangle
 void setImage(java.awt.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
 void show()
          Shows the object if it has been hidden.
 
Methods inherited from class java.lang.Object
equals, 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
 

Constructor Detail

VisibleImage

public VisibleImage(java.awt.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

VisibleImage

public VisibleImage(java.awt.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(java.awt.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(java.awt.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
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

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

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

getImage

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

Returns:
the image currently displayed by this VisibleImage

setImage

public void setImage(java.awt.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

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

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

getWidth

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

Specified by:
getWidth in interface Drawable2DInterface

getHeight

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

Specified by:
getHeight in interface Drawable2DInterface

getX

public double getX()
Description copied from interface: Drawable2DInterface
Get the x coordinate of left edge of rectangle bounding the object

Specified by:
getX in interface Drawable2DInterface
Returns:
the x coordinate of the upper left corner of the object's bounding rectangle

getY

public double getY()
Description copied from interface: Drawable2DInterface
Get the y coordinate of top edge of rectangle bounding the object

Specified by:
getY in interface Drawable2DInterface
Returns:
the y coordinate of the upper left corner of the object's bounding rectangle

getLocation

public Location getLocation()
Description copied from interface: Drawable2DInterface
Get a graphical object's position

Specified by:
getLocation in interface Drawable2DInterface
Returns:
the location of the upper left corner of the object's bounding rectangle

contains

public boolean contains(Location point)
Description copied from interface: DrawableInterface
Determines if a particular position on the DrawingCanvas is contained within the object.

Specified by:
contains in interface DrawableInterface

overlaps

public boolean overlaps(Drawable2DInterface item)
Description copied from interface: Drawable2DInterface
Determines if another Drawable's bounding rectangle overlaps with this object's bounding rectangle.

Specified by:
overlaps in interface Drawable2DInterface
Parameters:
item - the other object
Returns:
true if item intersects this object; false otherwise.

removeFromCanvas

public void removeFromCanvas()
Description copied from interface: DrawableInterface
Permanently removes the object from the canvas it is currently on. If you want to just make an object temporarily invisible, use hide() instead.

Specified by:
removeFromCanvas in interface DrawableInterface

getCanvas

public DrawingCanvas getCanvas()
Description copied from interface: DrawableInterface
Determine which (if any) DrawingCanvas this object is positioned on

Specified by:
getCanvas in interface DrawableInterface
Returns:
the DrawingCanvas holding this object or null if it the object is not currently associated with any canvas

hide

public void hide()
Description copied from interface: DrawableInterface
Temporarily hides an object on a DrawingCanvas from view. This method should only be used if the object may later be made visible again using the show() method. If the goal is to remove an object from the display permanently, the removeFromCanvas() method should be used instead.

Specified by:
hide in interface DrawableInterface

show

public void show()
Description copied from interface: DrawableInterface
Shows the object if it has been hidden.

Specified by:
show in interface DrawableInterface

isHidden

public boolean isHidden()
Description copied from interface: DrawableInterface
Determine whether an object is currently visible on its canvas

Specified by:
isHidden in interface DrawableInterface
Returns:
true if the object is currently hidden.

moveTo

public void moveTo(double x,
                   double y)
Description copied from interface: DrawableInterface
Moves the object within the canvas to the x and y coordinates provided.

Specified by:
moveTo in interface DrawableInterface
Parameters:
x - horizontal coordinate of destination.
y - horizontal coordinate of destination.

setColor

public void setColor(java.awt.Color c)
Description copied from interface: DrawableInterface
Sets the color of the object.

Specified by:
setColor in interface DrawableInterface
Parameters:
c - the color.

getColor

public java.awt.Color getColor()
Description copied from interface: DrawableInterface
Retrieves the color of the object.

Specified by:
getColor in interface DrawableInterface
Returns:
the object's color.

sendForward

public void sendForward()
Description copied from interface: DrawableInterface
Sends the object forward.

Specified by:
sendForward in interface DrawableInterface

sendBackward

public void sendBackward()
Description copied from interface: DrawableInterface
Sends the object backward.

Specified by:
sendBackward in interface DrawableInterface

sendToFront

public void sendToFront()
Description copied from interface: DrawableInterface
Sends the object to the front.

Specified by:
sendToFront in interface DrawableInterface

sendToBack

public void sendToBack()
Description copied from interface: DrawableInterface
Sends the object to the back.

Specified by:
sendToBack in interface DrawableInterface