edu.neu.ccs.gui
Class ImagePaintable

java.lang.Object
  |
  +--edu.neu.ccs.gui.AbstractPaintable
        |
        +--edu.neu.ccs.gui.ImagePaintable
All Implemented Interfaces:
Paintable, SupportsPropertyChange

public class ImagePaintable
extends AbstractPaintable

An ImagePaintable creates an AbstractPaintable using an image, image icon, filename, or URL.

Specifically, an ImagePaintable object may be created using one of the following:

In 2.3.2, the method getBounds2D was modified to use the default Bounds2D rectangle if that rectangle is non-null before making any other tests or computations.

In 2.3.3, the code was made parallel to that of the new class ImagePaintableLite. The class ImagePaintable retains image data throughout the life time of an instance and thus may paint more rapidly at the cost of larger memory footprint.

Since:
2.3
See Also:
ImagePaintableLite

Field Summary
static String SET_IMAGE
          Bound property name for set image.
static String SET_TOP_LEFT_CORNER
          Bound property name for set top left point.
 
Fields inherited from class edu.neu.ccs.gui.AbstractPaintable
SET_DEFAULT_BOUNDS2D, SET_DEFAULT_CENTER, SET_OPACITY, SET_VISIBLE
 
Constructor Summary
ImagePaintable()
          The default constructor that does not specify the image.
ImagePaintable(Image image)
          The constructor to specify the image directly.
ImagePaintable(Image image, double x, double y)
          The constructor to specify the image directly and the top left corner (x, y).
ImagePaintable(ImageIcon imageicon)
          The constructor to specify the image by image icon.
ImagePaintable(ImageIcon imageicon, double x, double y)
          The constructor to specify the image by image icon and the top left corner (x, y).
ImagePaintable(ImageIcon imageicon, Point2D corner)
          The constructor to specify the image by image icon and the top left corner.
ImagePaintable(Image image, Point2D corner)
          The constructor to specify the image directly and the top left corner.
ImagePaintable(String filename)
          The constructor to specify the image by file name.
ImagePaintable(String filename, double x, double y)
          The constructor to specify the image by file name and the top left corner (x, y).
ImagePaintable(String filename, Point2D corner)
          The constructor to specify the image by file name and the top left corner.
ImagePaintable(URL url)
          The constructor to specify the image by URL.
ImagePaintable(URL url, double x, double y)
          The constructor to specify the image by URL and the top left corner (x, y).
ImagePaintable(URL url, Point2D corner)
          The constructor to specify the image by URL and the top left corner.
 
Method Summary
 boolean contains(double x, double y)
          Tests if a point specified by coordinates is inside the paintable.
 Rectangle2D getBounds2D()
          Returns the bounds of the paintable based on the default settings or on more detailed computations.
 Point2D getCenter()
          If the value of getDefaultCenter is non-null, then this value is returned.
 Image getImage()
          Returns the encapsulated image.
 int getImageHeight()
          Returns the image height.
 int getImageWidth()
          Returns the image width.
 Point2D getTopLeftCorner()
          Returns a copy of the top left corner.
 void paint(Graphics g)
          Paints onto a Graphics context using information from this object.
 void setImage(Image image)
          Sets the image directly.
 void setImageByFileName(String filename)
          Sets the image by file name.
 void setImageByImageIcon(ImageIcon imageicon)
          Sets the image by image icon.
 void setImageByURL(URL url)
          Sets the image by URL.
 void setTopLeftCorner(double x, double y)
          Sets the top left corner with the given corner (x, y).
 void setTopLeftCorner(Point2D corner)
          Sets the top left corner with the given corner.
 
Methods inherited from class edu.neu.ccs.gui.AbstractPaintable
addForwardingListener, addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListeners, addPropertyChangeListeners, applyOpacity, contains, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getDefaultBounds2D, getDefaultCenter, getForwardingListener, getOpacity, getPreparedGraphics2D, getPropertyChangeListeners, getPropertyChangeListeners, hasListeners, isVisible, possiblyContains, removeAndAddForwardingListener, removeForwardingListener, removePropertyChangeListener, removePropertyChangeListener, setDefaultBounds2D, setDefaultCenter, setOpacity, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SET_IMAGE

public static final String SET_IMAGE
Bound property name for set image.

See Also:
Constant Field Values

SET_TOP_LEFT_CORNER

public static final String SET_TOP_LEFT_CORNER
Bound property name for set top left point.

See Also:
Constant Field Values
Constructor Detail

ImagePaintable

public ImagePaintable()

The default constructor that does not specify the image.

Other constructors:


ImagePaintable

public ImagePaintable(Image image)

The constructor to specify the image directly.

Parameters:
image - the image
See Also:
ImagePaintable()

ImagePaintable

public ImagePaintable(Image image,
                      Point2D corner)

The constructor to specify the image directly and the top left corner.

Parameters:
image - the image
corner - the top left corner
See Also:
ImagePaintable()

ImagePaintable

public ImagePaintable(Image image,
                      double x,
                      double y)

The constructor to specify the image directly and the top left corner (x, y).

Parameters:
image - the image
x - the x-coordinate of the top left corner
y - the y-coordinate of the top left corner
See Also:
ImagePaintable()

ImagePaintable

public ImagePaintable(ImageIcon imageicon)

The constructor to specify the image by image icon.

Parameters:
imageicon - the imageicon to define the image
See Also:
ImagePaintable()

ImagePaintable

public ImagePaintable(ImageIcon imageicon,
                      Point2D corner)

The constructor to specify the image by image icon and the top left corner.

Parameters:
imageicon - the imageicon to define the image
corner - the top left corner
See Also:
ImagePaintable()

ImagePaintable

public ImagePaintable(ImageIcon imageicon,
                      double x,
                      double y)

The constructor to specify the image by image icon and the top left corner (x, y).

Parameters:
imageicon - the imageicon to define the image
x - the x-coordinate of the top left corner
y - the y-coordinate of the top left corner
See Also:
ImagePaintable()

ImagePaintable

public ImagePaintable(String filename)

The constructor to specify the image by file name.

Parameters:
filename - the filename for the file with the image
See Also:
ImagePaintable()

ImagePaintable

public ImagePaintable(String filename,
                      Point2D corner)

The constructor to specify the image by file name and the top left corner.

Parameters:
filename - the filename for the file with the image
corner - the top left corner
See Also:
ImagePaintable()

ImagePaintable

public ImagePaintable(String filename,
                      double x,
                      double y)

The constructor to specify the image by file name and the top left corner (x, y).

Parameters:
filename - the filename for the file with the image
x - the x-coordinate of the top left corner
y - the y-coordinate of the top left corner
See Also:
ImagePaintable()

ImagePaintable

public ImagePaintable(URL url)

The constructor to specify the image by URL.

Parameters:
url - the URL location for the image
See Also:
ImagePaintable()

ImagePaintable

public ImagePaintable(URL url,
                      Point2D corner)
The constructor to specify the image by URL and the top left corner.

Parameters:
url - the URL location for the image
corner - the top left corner
See Also:
ImagePaintable()

ImagePaintable

public ImagePaintable(URL url,
                      double x,
                      double y)
The constructor to specify the image by URL and the top left corner (x, y).

Parameters:
url - the URL location for the image
x - the x-coordinate of the top left corner
y - the y-coordinate of the top left corner
See Also:
ImagePaintable()
Method Detail

paint

public final void paint(Graphics g)

Paints onto a Graphics context using information from this object.

If the current image is null, this method will not paint.

Specified by:
paint in interface Paintable
Specified by:
paint in class AbstractPaintable
Parameters:
g - the graphics context on which to paint
See Also:
AbstractPaintable.getPreparedGraphics2D(Graphics)

getBounds2D

public final Rectangle2D getBounds2D()

Returns the bounds of the paintable based on the default settings or on more detailed computations.

If the value of getDefaultBounds2D is non-null, then this value is returned.

Otherwise, if the current image is null, this method returns a rectangle of zero width and height located at the top-left corner.

Otherwise, this method returns a copy of the 2-dimensional bounds of the image region as defined by the image width and height and by the top-left corner.

Specified by:
getBounds2D in interface Paintable
Specified by:
getBounds2D in class AbstractPaintable
Returns:
a copy of the 2-dimensional bounds of the image region
See Also:
getTopLeftCorner(), getImageWidth(), getImageHeight(), AbstractPaintable.setDefaultBounds2D(Rectangle2D), AbstractPaintable.getDefaultBounds2D()

getCenter

public Point2D getCenter()

If the value of getDefaultCenter is non-null, then this value is returned.

Otherwise, this method returns the value computed by the method inherited from its superclass.

Specified by:
getCenter in interface Paintable
Overrides:
getCenter in class AbstractPaintable
Returns:
a copy of the center of the paint region
See Also:
AbstractPaintable.getCenter(), AbstractPaintable.setDefaultCenter(Point2D), AbstractPaintable.getDefaultCenter()

contains

public final boolean contains(double x,
                              double y)

Tests if a point specified by coordinates is inside the paintable.

This method returns true if and only if:

Parameters:
x - the x-coordinate of the point
y - the y-coordinate of the point
Returns:
whether or not a specified point is inside the paintable

setImage

public final void setImage(Image image)

Sets the image directly.

Fires property change: SET_IMAGE.

Parameters:
image - the image
See Also:
setImageByImageIcon(ImageIcon), setImageByFileName(String), setImageByURL(URL), getImage()

setImageByImageIcon

public final void setImageByImageIcon(ImageIcon imageicon)

Sets the image by image icon.

If the image icon is null, the encapsulated image is set to null.

Fires property change: SET_IMAGE.

Parameters:
imageicon - the imageicon to define the image
See Also:
setImage(Image), setImageByFileName(String), setImageByURL(URL), getImage()

setImageByFileName

public final void setImageByFileName(String filename)

Sets the image by file name.

If the file name is null, the encapsulated image is set to null.

Fires property change: SET_IMAGE.

Parameters:
filename - the filename for the file with the image
See Also:
setImage(Image), setImageByImageIcon(ImageIcon), setImageByURL(URL), getImage()

setImageByURL

public final void setImageByURL(URL url)

Sets the image by URL.

If the url is null, the encapsulated image is set to null.

Fires property change: SET_IMAGE.

Parameters:
url - the URL location for the image
See Also:
setImage(Image), setImageByImageIcon(ImageIcon), setImageByFileName(String), getImage()

getImage

public final Image getImage()
Returns the encapsulated image.

Returns:
the encapsulated image
See Also:
setImage(Image), setImageByImageIcon(ImageIcon), setImageByFileName(String), setImageByURL(URL)

setTopLeftCorner

public final void setTopLeftCorner(Point2D corner)

Sets the top left corner with the given corner.

A null parameter is ignored.

Fires property change: SET_TOP_LEFT_CORNER.

Parameters:
corner - the top left corner
See Also:
setTopLeftCorner(double, double), getTopLeftCorner()

setTopLeftCorner

public final void setTopLeftCorner(double x,
                                   double y)

Sets the top left corner with the given corner (x, y).

Fires property change: SET_TOP_LEFT_CORNER.

Parameters:
x - the x-coordinate of the top left corner
y - the y-coordinate of the top left corner
See Also:
setTopLeftCorner(Point2D), getTopLeftCorner()

getTopLeftCorner

public final Point2D getTopLeftCorner()

Returns a copy of the top left corner.

Returns:
a copy of the top left corner
See Also:
setTopLeftCorner(Point2D), setTopLeftCorner(double, double)

getImageWidth

public final int getImageWidth()

Returns the image width.

If the current image is null, this method returns 0.

Returns:
the image width
See Also:
getImageHeight()

getImageHeight

public final int getImageHeight()

Returns the image height.

If the current image is null, this method returns 0.

Returns:
the image height
See Also:
getImageWidth()