java.lang.Objectobjectdraw.ObjectDrawObject
objectdraw.ObjectDrawShape
objectdraw.ObjectDrawRectangularShape
objectdraw.VisibleImage
public class VisibleImage
A VisibleImage
is an image that can be placed on a canvas. To construct it you
must retrieve an Image
object, most likely using the getImage()
method of Controller
. Like other shapes that implement the
Drawable2DInterface
, the shape of the image as it is drawn on the canvas is
defined by a top left corner, plus a width and height. However, it is also possible to
retrieve the actual dimensions of the image, or to not specify the width and height for the
image and thus allow it to take its natural size.
Constructor Summary | |
---|---|
VisibleImage(Image image,
double x,
double y,
double width,
double height,
DrawingCanvas canvas)
Construct a VisibleImage to display the given image, with its top left corner
at (x , y ) and scaled to fit in a rectangle of the given
width and height . |
|
VisibleImage(Image image,
double x,
double y,
DrawingCanvas canvas)
Construct a VisibleImage to display the given image, with its top left corner
at (x , y ), drawn the same size as in the image file. |
|
VisibleImage(Image image,
Location point,
double width,
double height,
DrawingCanvas canvas)
Construct a VisibleImage to display the given image, with its top left corner
at point and scaled to fit in a rectangle of the given
width and height . |
|
VisibleImage(Image image,
Location point,
DrawingCanvas canvas)
Construct a VisibleImage to display the given image, with its top left corner
at point , drawn the same size as in the image file. |
|
VisibleImage(Image image,
Location corner1,
Location corner2,
DrawingCanvas canvas)
Construct a VisibleImage to display the given image, stretching between
the points corner1 and corner2 . |
Method Summary | |
---|---|
void |
addToCanvas(DrawingCanvas c)
Place this object on the specified canvas. |
boolean |
contains(Location point)
Return true if the given location is inside this object, false
otherwise. |
static BufferedImage |
createBufferedCopy(Image image)
Return a copy of this Image as a BufferedImage . |
DrawingCanvas |
getCanvas()
Return the canvas that this object is on. |
Color |
getColor()
Return the color of this object. |
double |
getDoubleHeight()
Return the height of the rectangle bounding this object, in double precision. |
double |
getDoubleWidth()
Return the height of the rectangle bounding this object, in double precision. |
double |
getDoubleX()
Get this object's x coordinate, in double precision. |
double |
getDoubleY()
Get this object's y coordinate, in double precision. |
int |
getHeight()
Return the width of the rectangle bounding this object. |
Image |
getImage()
Get the Image object belonging to this VisibleImage . |
int |
getImageHeight()
Get the actual height in pixels of the image file that this VisibleImage
draws. |
int |
getImageWidth()
Get the actual width in pixels of the image file that this VisibleImage
draws. |
Location |
getLocation()
Get this object's location. |
int |
getWidth()
Return the height of the rectangle bounding this object. |
int |
getX()
Get this object's x coordinate. |
int |
getY()
Get this object's y coordinate. |
void |
hide()
Make this object invisible. |
boolean |
isHidden()
Return true if this object has been rendered invisible with a call to its
hide() method, false if it is still being drawn. |
void |
move(double dx,
double dy)
Shift (translate) this object left or right by an amount dx , and up or
down by an amount dy . |
void |
moveTo(double x,
double y)
Move the reference point of this object to the given location. |
void |
moveTo(Location point)
Move the reference point of this object to the given location. |
boolean |
overlaps(Drawable2DInterface other)
Return true if the rectangle bounding this object overlaps with the
rectangle bounding another object; false otherwise. |
void |
removeFromCanvas()
Remove this object from its canvas. |
void |
sendBackward()
Move this object one step backward in the draw order, causing it to be drawn underneath the objects that are in front of it. |
void |
sendForward()
Move this object one step forward in the draw order, causing it to be drawn on top of the objects that are behind it. |
void |
sendToBack()
Move this object to the very back of the draw order, causing it to be drawn underneath all the other objects. |
void |
sendToFront()
Move this object to the very front of the draw order, causing it to be drawn on top of all the other objects. |
void |
setColor(Color c)
Change the color of this object. |
void |
setHeight(double h)
Set the height of this object, leaving its top edge in place and stretching the bottom. |
void |
setImage(Image image)
Change the Image object belonging to this VisibleImage . |
void |
setSize(double width,
double height)
Set the width and height of this object. |
void |
setWidth(double w)
Set the width of this object, leaving its left edge in place and stretching the right. |
void |
show()
Make an object visible again after it had been hidden. |
String |
toString()
Return a string describing how this object might be constructed. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public VisibleImage(Image image, double x, double y, double width, double height, DrawingCanvas canvas)
VisibleImage
to display the given image, with its top left corner
at (x
, y
) and scaled to fit in a rectangle of the given
width
and height
.
image
- Image
to be displayedx
- x coordinate of the top left cornery
- y coordinate of the top left cornerwidth
- width to which the image should be scaledheight
- height to which the image should be scaledcanvas
- DrawingCanvas
on which to place this imagepublic VisibleImage(Image image, double x, double y, DrawingCanvas canvas)
VisibleImage
to display the given image, with its top left corner
at (x
, y
), drawn the same size as in the image file.
image
- Image
to be displayedx
- x coordinate of the top left cornery
- y coordinate of the top left cornercanvas
- DrawingCanvas
on which to place this imagepublic VisibleImage(Image image, Location point, double width, double height, DrawingCanvas canvas)
VisibleImage
to display the given image, with its top left corner
at point
and scaled to fit in a rectangle of the given
width
and height
.
image
- Image
to be displayedpoint
- Location
of the top left cornerwidth
- width to which the image should be scaledheight
- height to which the image should be scaledcanvas
- DrawingCanvas
on which to place this imagepublic VisibleImage(Image image, Location point, DrawingCanvas canvas)
VisibleImage
to display the given image, with its top left corner
at point
, drawn the same size as in the image file.
image
- Image
to be displayedpoint
- Location
of the top left cornercanvas
- DrawingCanvas
on which to place this imagepublic VisibleImage(Image image, Location corner1, Location corner2, DrawingCanvas canvas)
VisibleImage
to display the given image, stretching between
the points corner1
and corner2
.
image
- Image
to be displayedcorner1
- Location
of one cornercorner2
- Location
of the opposite cornercanvas
- DrawingCanvas
on which to place this imageMethod Detail |
---|
public void addToCanvas(DrawingCanvas c)
null
the object is simply removed from its current canvas.
addToCanvas
in interface DrawableInterface
addToCanvas
in class objectdraw.ObjectDrawShape
c
- DrawingCanvas
to place this object onpublic boolean contains(Location point)
true
if the given location is inside this object, false
otherwise. Because Line
s and FramedArc
s have no "inside", a
point is considered to be contained in one of them as long as it is within a few pixels
of the line.
contains
in interface DrawableInterface
contains
in class objectdraw.ObjectDrawRectangularShape
point
- Location
to test
public static BufferedImage createBufferedCopy(Image image)
Image
as a BufferedImage
.
This allows you to easily manipulate the actual pixel data that makes up that image. A typical
usage would be to replace the image of a VisibleImage
with a buffered copy so that you
can then manipulate its pixels:
Image image = getImage("picture.jpg");
BufferedImage buffer = VisibleImage.createBufferedCopy(image);
new VisibleImage(image, 0, 0, canvas);
BufferedImage
copy of the given Image
.public DrawingCanvas getCanvas()
null
.
getCanvas
in interface DrawableInterface
getCanvas
in class objectdraw.ObjectDrawShape
DrawingCanvas
that this object is on.public Color getColor()
getColor
in interface DrawableInterface
getColor
in class objectdraw.ObjectDrawShape
Color
of this objectpublic double getDoubleHeight()
getDoubleHeight
in interface Drawable2DInterface
getDoubleHeight
in class objectdraw.ObjectDrawRectangularShape
public double getDoubleWidth()
getDoubleWidth
in interface Drawable2DInterface
getDoubleWidth
in class objectdraw.ObjectDrawRectangularShape
public double getDoubleX()
getDoubleX
in interface LocatableInterface
getDoubleX
in class objectdraw.ObjectDrawRectangularShape
public double getDoubleY()
getDoubleY
in interface LocatableInterface
getDoubleY
in class objectdraw.ObjectDrawRectangularShape
public int getHeight()
getHeight
in interface Drawable2DInterface
getHeight
in class objectdraw.ObjectDrawRectangularShape
public Image getImage()
Image
object belonging to this VisibleImage
.
Image
object belonging to this VisibleImage
public int getImageHeight()
VisibleImage
draws. This might not be the same as getHeight()
, in which case the
image is being scaled when it is drawn.
public int getImageWidth()
VisibleImage
draws. This might not be the same as getWidth()
, in which case the
image is being scaled when it is drawn.
public Location getLocation()
Location
object
will have the same effect as moving the object. So, the following two lines
of code are equivalent:
object.move(10, 20);
object.getLocation().translate(10, 20);
Location
offset by some
amount from the Location
of this object, without actually
moving this object, use the offset()
method in Location
,
which creates a new Location
.
getLocation
in interface LocatableInterface
getLocation
in class objectdraw.ObjectDrawRectangularShape
Location
of this object.public int getWidth()
getWidth
in interface Drawable2DInterface
getWidth
in class objectdraw.ObjectDrawRectangularShape
public int getX()
getX
in interface LocatableInterface
getX
in class objectdraw.ObjectDrawRectangularShape
public int getY()
getY
in interface LocatableInterface
getY
in class objectdraw.ObjectDrawRectangularShape
public void hide()
hide
in interface DrawableInterface
hide
in class objectdraw.ObjectDrawShape
public boolean isHidden()
true
if this object has been rendered invisible with a call to its
hide()
method, false
if it is still being drawn.
isHidden
in interface DrawableInterface
isHidden
in class objectdraw.ObjectDrawShape
public void move(double dx, double dy)
dx
, and up or
down by an amount dy
. A negative dx
indicates a shift to the
left; a negative dy
indicates a shift up
move
in interface DrawableInterface
move
in class objectdraw.ObjectDrawShape
dx
- amount of x translationdy
- amount of y translationpublic void moveTo(double x, double y)
moveTo
in interface DrawableInterface
moveTo
in class objectdraw.ObjectDrawShape
x
- x coordinate to move toy
- y coordinate to move topublic void moveTo(Location point)
moveTo
in interface DrawableInterface
moveTo
in class objectdraw.ObjectDrawShape
point
- Location
to move topublic boolean overlaps(Drawable2DInterface other)
true
if the rectangle bounding this object overlaps with the
rectangle bounding another object; false
otherwise.
overlaps
in interface Drawable2DInterface
overlaps
in class objectdraw.ObjectDrawRectangularShape
other
- another two dimensional object to check for overlapping with
public void removeFromCanvas()
removeFromCanvas
in interface DrawableInterface
removeFromCanvas
in class objectdraw.ObjectDrawShape
public void sendBackward()
sendBackward
in interface DrawableInterface
sendBackward
in class objectdraw.ObjectDrawShape
public void sendForward()
sendForward
in interface DrawableInterface
sendForward
in class objectdraw.ObjectDrawShape
public void sendToBack()
sendToBack
in interface DrawableInterface
sendToBack
in class objectdraw.ObjectDrawShape
public void sendToFront()
sendToFront
in interface DrawableInterface
sendToFront
in class objectdraw.ObjectDrawShape
public void setColor(Color c)
setColor
in interface DrawableInterface
setColor
in class objectdraw.ObjectDrawShape
c
- new Color
for this objectpublic void setHeight(double h)
setHeight
in interface Resizable2DInterface
setHeight
in class objectdraw.ObjectDrawRectangularShape
h
- new heightpublic void setImage(Image image)
Image
object belonging to this VisibleImage
.
image
- new Image
objectpublic void setSize(double width, double height)
setSize
in interface Resizable2DInterface
setSize
in class objectdraw.ObjectDrawRectangularShape
width
- new widthheight
- new heightpublic void setWidth(double w)
setWidth
in interface Resizable2DInterface
setWidth
in class objectdraw.ObjectDrawRectangularShape
w
- new widthpublic void show()
show
in interface DrawableInterface
show
in class objectdraw.ObjectDrawShape
public String toString()
toString
in class objectdraw.ObjectDrawObject