org.gjt.btools.image
Class StandardImage

java.lang.Object
  |
  +--org.gjt.btools.image.StandardImage

public class StandardImage
extends java.lang.Object

Represents a standard image that may be requested multiple times. The same ImageIcon will be returned for every request; thus only one copy is ever loaded at a time.

The internal ImageIcon will not be created until it is first requested through image(). Each following request will return the same ImageIcon, thus saving time and memory. Calling finalImage() or discardImage() will cause the internal ImageIcon to be discarded; this will save memory but a subsequent call to getImage() will require a new ImageIcon to be created.


Constructor Summary
StandardImage(java.lang.String location)
          Creates a new standard image representing the image at the specified location.
StandardImage(java.lang.String location, java.lang.Class loaderClass)
          Creates a new standard image representing the image at the specified location.
 
Method Summary
 void discardImage()
          Discards the internally stored ImageIcon representing this image.
 javax.swing.ImageIcon finalImage()
          Returns and discards the ImageIcon containing this image.
 javax.swing.ImageIcon image()
          Returns the ImageIcon containing this image.
static javax.swing.ImageIcon makeImageIcon(java.lang.String location)
          Creates a new image icon representing the image resource at the given location.
static javax.swing.ImageIcon makeImageIcon(java.lang.String location, java.lang.Class loaderClass)
          Creates a new image icon representing the image resource at the given location.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StandardImage

public StandardImage(java.lang.String location)
Creates a new standard image representing the image at the specified location. The system class loader will be used to locate the image resource.

Parameters:
location - the location of the image this object will represent.

StandardImage

public StandardImage(java.lang.String location,
                     java.lang.Class loaderClass)
Creates a new standard image representing the image at the specified location. The class loader for the given class will be used to locate the image resource.

Parameters:
location - the location of the image this object will represent.
loaderClass - the class whose class loader will be used to locate the image resource.
Method Detail

image

public javax.swing.ImageIcon image()
Returns the ImageIcon containing this image. If the image has not already been loaded, it will be loaded now. The ImageIcon will be stored so the same ImageIcon can be returned for future requests.

Returns:
the ImageIcon containing this image.

finalImage

public javax.swing.ImageIcon finalImage()
Returns and discards the ImageIcon containing this image. This routine should be used when it is known that this image will not be requested again. The image returned will no longer be stored by this object. Thus memory will be saved, but any future request for this image will require a new ImageIcon to be created.

Returns:
the ImageIcon containing this image.

discardImage

public void discardImage()
Discards the internally stored ImageIcon representing this image. This routine should be used when it is known that this image will not be requested again. Memory will be saved, but any future request for this image will require a new ImageIcon to be created.


makeImageIcon

public static javax.swing.ImageIcon makeImageIcon(java.lang.String location)
Creates a new image icon representing the image resource at the given location. The system class loader will be used to locate the image resource.

Parameters:
location - the location of the image resource.
Returns:
the new image icon.

makeImageIcon

public static javax.swing.ImageIcon makeImageIcon(java.lang.String location,
                                                  java.lang.Class loaderClass)
Creates a new image icon representing the image resource at the given location. The class loader for the given class will be used to locate the image resource.

Parameters:
location - the location of the image resource.
loaderClass - the class whose class loader will be used to locate the image resource.
Returns:
the new image icon.


Copyright © 1998-2001, Ben Burton
This software is released under the GNU Public License.
For further information, or to submit a bug or other problem, please contact Ben Burton (bab@debian.org).