edu.neu.ccs.gui
Class ImagePaintableLite

java.lang.Object
  extended byedu.neu.ccs.gui.AbstractPaintable
      extended byedu.neu.ccs.gui.ImagePaintableLite
All Implemented Interfaces:
JPTConstants, Paintable, SupportsPropertyChange, SwingConstants

public class ImagePaintableLite
extends AbstractPaintable

An ImagePaintableLite creates a Paintable using an image filename or an image URL.

To save memory, an ImagePaintableLite does not cache its image but rather retrieves its image as needed for paint operations. Thus the class trades time for space. This design enables a program to access a much larger collection of images at one time than would be possible by directly using the Java classes Image or ImageIcon or the JPT class ImagePaintable. These other classes all retain the bit data for an image and thus entail a high memory cost.

In 2.3.5, the class was refactored to be consistent with the new Paintable interface and the new AbstractPaintable class.

In 2.4.0, this class was updated to be consistent with refinements to the Paintable interface.

Since:
2.3.3
Version:
2.4.0
See Also:
ImagePaintable

Field Summary
private  int height
          The image height.
private  String imageFileName
          The image file name.
private  URL imageURL
          The image URL.
static String SET_IMAGE
          Bound property name for set image.
static String SET_TOP_LEFT_CORNER
          Bound property name for set top left point.
private  int width
          The image width.
private  double xCorner
          The top left corner x-position.
private  double yCorner
          The top left corner y-position.
 
Fields inherited from class edu.neu.ccs.gui.AbstractPaintable
SET_BACKGROUND_PAINT, SET_BACKGROUND_TILE
 
Fields inherited from interface edu.neu.ccs.gui.Paintable
REMOVE_PAINTABLE, SET_CLIPPING_SHAPE, SET_DEFAULT_BOUNDS2D, SET_DEFAULT_CENTER, SET_DEFAULT_ORIGINAL_BOUNDS2D, SET_DEFAULT_ORIGINAL_CENTER, SET_MUTATOR, SET_OPACITY, SET_PAINTABLE, SET_VISIBLE, SHIFT_PAINTABLE
 
Fields inherited from interface edu.neu.ccs.util.JPTConstants
ABOVE, ALIGNMENT, BELOW, BOTTOM_LEFT, BOTTOM_RIGHT, DEFAULT, FONT, INPUT_PROPERTIES, MANDATORY, OPTIONAL, ORIENTATION, TOP_LEFT, TOP_RIGHT, VALUE
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Constructor Summary
ImagePaintableLite()
          The default constructor that does not specify the image.
ImagePaintableLite(String filename)
          The constructor to specify the image by an image file name.
ImagePaintableLite(String filename, double x, double y)
          The constructor to specify the image by an image file name and the top left corner (x, y).
ImagePaintableLite(String filename, Point2D corner)
          The constructor to specify the image by an image file name and the top left corner.
ImagePaintableLite(URL url)
          The constructor to specify the image by an image URL.
ImagePaintableLite(URL url, double x, double y)
          The constructor to specify the image by an image URL and the top left corner (x, y).
ImagePaintableLite(URL url, Point2D corner)
          The constructor to specify the image by an image URL and the top left corner.
 
Method Summary
private  Image fetchImage()
          Returns the current image associated with a file name or URL or returns null if the current image is undefined.
private  ImageIcon fetchImageIcon()
          Returns the current image icon associated with a file name or URL or returns null if the current image is undefined.
 XRect getActualBounds2D()
          Returns the actual bounds of the original paintable or null if the paintable is effectively empty.
 int getImageHeight()
          Returns the image height.
 int getImageWidth()
          Returns the image width.
 Point2D getTopLeftCorner()
          Returns a copy of the top left corner.
 boolean originalContains(double x, double y)
          Tests if a point specified by coordinates is inside the original paintable without mutation.
 void originalPaint(Graphics g)
          Paints onto a Graphics context using information from this object but without the use of the mutator transform.
 void setImageByFileName(String filename)
          Sets the image by file name.
 void setImageByURL(URL url)
          Sets the image by URL.
private  void setImageSizeParameters()
          Sets the image width and height based on the current image or sets this data to (0, 0) if the current image is undefined.
 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, addPostMutation, addPostMutation, addPreMutation, addPreMutation, addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListeners, addPropertyChangeListeners, affinetransform, applyOpacity, clearBackgroundPaint, clearBackgroundTile, clearBothBackgrounds, contains, contains, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackgroundPaint, getBackgroundTile, getBounds2D, getCenter, getCorner, getDefaultBounds2D, getDefaultCenter, getDefaultOriginalBounds2D, getDefaultOriginalCenter, getForwardingListener, getMutator, getMutatorInverse, getOpacity, getOriginalBounds2D, getOriginalCenter, getPreparedGraphics2D, getPropertyChangeListeners, getPropertyChangeListeners, glide, glidereflect, hasListeners, hreflect, isVisible, lineartransform, makeSnapshot, move, move, moveCenterTo, moveCenterTo, moveCornerTo, moveCornerTo, mutate, mutate, originalContains, paint, paintAsTiles, paintAsTiles, paintAsTiles, paintAt, paintAt, paintAt, paintAt, possiblyContains, reflect, removeAndAddForwardingListener, removeForwardingListener, removePropertyChangeListener, removePropertyChangeListener, rotate, scale, scale, setBackgroundPaint, setBackgroundTile, setDefaultBounds2D, setDefaultCenter, setDefaultOriginalBounds2D, setDefaultOriginalCenter, setMutator, setMutator, setOpacity, setVisible, shear, vreflect
 
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

imageFileName

private String imageFileName
The image file name.


imageURL

private URL imageURL
The image URL.


xCorner

private double xCorner
The top left corner x-position.


yCorner

private double yCorner
The top left corner y-position.


width

private int width
The image width.


height

private int height
The image height.

Constructor Detail

ImagePaintableLite

public ImagePaintableLite()

The default constructor that does not specify the image.

Other constructors:


ImagePaintableLite

public ImagePaintableLite(String filename)

The constructor to specify the image by an image file name.

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

ImagePaintableLite

public ImagePaintableLite(String filename,
                          Point2D corner)

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

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

ImagePaintableLite

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

The constructor to specify the image by an image 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:
ImagePaintableLite()

ImagePaintableLite

public ImagePaintableLite(URL url)

The constructor to specify the image by an image URL.

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

ImagePaintableLite

public ImagePaintableLite(URL url,
                          Point2D corner)

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

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

ImagePaintableLite

public ImagePaintableLite(URL url,
                          double x,
                          double y)

The constructor to specify the image by an image 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:
ImagePaintableLite()
Method Detail

originalPaint

public final void originalPaint(Graphics g)

Paints onto a Graphics context using information from this object but without the use of the mutator transform.

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

If the image cannot be loaded, this method will not paint.

Specified by:
originalPaint in interface Paintable
Specified by:
originalPaint in class AbstractPaintable
Parameters:
g - the graphics context on which to paint

getActualBounds2D

public final XRect getActualBounds2D()

Returns the actual bounds of the original paintable or null if the paintable is effectively empty.

Specified by:
getActualBounds2D in interface Paintable
Specified by:
getActualBounds2D in class AbstractPaintable

originalContains

public final boolean originalContains(double x,
                                      double y)

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

Specified by:
originalContains in interface Paintable
Specified by:
originalContains in class AbstractPaintable
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 original paintable

setImageByFileName

public final void setImageByFileName(String filename)

Sets the image by file name.

Fires property change: SET_IMAGE.

Parameters:
filename - the filename for the file with the image

setImageByURL

public final void setImageByURL(URL url)

Sets the image by URL.

Fires property change: SET_IMAGE.

Parameters:
url - the URL location for the image

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

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

getTopLeftCorner

public final Point2D getTopLeftCorner()

Returns a copy of the top left corner.

Returns:
a copy of the top left corner

getImageWidth

public final int getImageWidth()

Returns the image width.

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

Returns:
the image width

getImageHeight

public final int getImageHeight()

Returns the image height.

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

Returns:
the image height

fetchImageIcon

private final ImageIcon fetchImageIcon()

Returns the current image icon associated with a file name or URL or returns null if the current image is undefined.

Returns:
the current image icon

fetchImage

private final Image fetchImage()

Returns the current image associated with a file name or URL or returns null if the current image is undefined.

Returns:
the current image

setImageSizeParameters

private final void setImageSizeParameters()

Sets the image width and height based on the current image or sets this data to (0, 0) if the current image is undefined.

Fires property change: SET_IMAGE.