org.nakedobjects.object
Class ImageIcon

java.lang.Object
  extended byorg.nakedobjects.object.ImageIcon

public class ImageIcon
extends java.lang.Object

A indexed cache for Image objects. Images are retrieved from as resources, from the jar or zip file, or directly off the disk. A default image is kept in memory in case the forementioned methods fail to find a specified image. The default image is unknown.gif and will normally be found in the toolkit file unless it has been specifically built without it (that is the toolkit is supplied with a default image inside the jar file).


Field Summary
static int NORMAL
          For an image that is normal sized (32 x 32 pixels) this constant should be passed to getImageIcon() the ImageIcon constructors.
static int SMALL
          For an image that is small (16 x 16 pixels) this constant should be passed to getImageIcon() the ImageIcon constructors.
 
Constructor Summary
ImageIcon(java.awt.Image image, java.lang.String name, int size, java.lang.String status)
          Constructor for building an ImageIcon.
 
Method Summary
static java.lang.String getDirectory()
           
 java.awt.Image getImage()
          Returns the java.awt.Image object that this object is holding.
static ImageIcon getImageIcon(java.lang.String name, int size, java.lang.String status)
          Gets an ImageIcon object with the specified details.
 java.lang.String getName()
          The name of this image.
static java.awt.Image loadImage(java.lang.String name)
          Load a java.awt.Image object using the file name name.
static java.awt.Image loadImage(java.lang.String name, int size, java.lang.String status)
          Load a java.awt.Image object using the file name name.
 void setImage(java.awt.Image image)
          Sets Image object that this object is holding.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NORMAL

public static final int NORMAL
For an image that is normal sized (32 x 32 pixels) this constant should be passed to getImageIcon() the ImageIcon constructors.

See Also:
Constant Field Values

SMALL

public static final int SMALL
For an image that is small (16 x 16 pixels) this constant should be passed to getImageIcon() the ImageIcon constructors.

See Also:
Constant Field Values
Constructor Detail

ImageIcon

public ImageIcon(java.awt.Image image,
                 java.lang.String name,
                 int size,
                 java.lang.String status)
Constructor for building an ImageIcon. An Image, which will be the Image passed back to clients in the future, and name, size and status, which together give the ImageIcon a unique reference are used to create an ImageIcon. This constructor is normally called by getImageIcon() but can be called directly if an Image icon needs to be created in an indirect manner. Ie, the image to be used is already loaded - eg, after filtering - or the image to be used does not want to use the concatonated name, size and status as it reference.

Method Detail

getDirectory

public static java.lang.String getDirectory()

getImage

public java.awt.Image getImage()
Returns the java.awt.Image object that this object is holding.


getImageIcon

public static ImageIcon getImageIcon(java.lang.String name,
                                     int size,
                                     java.lang.String status)
Gets an ImageIcon object with the specified details. If the image is not cached the image is loaded using loadImage() with the parameters name, size and status being concatenated with ".gif" to form a file name. Eg, where name is "customer", size is SMALL and status is "" the image sought will be customer16.gif; if the name order, size is NORMAL and status is "fulfilled" then the reference would be order32fulfilled.gif.

Returns:
the corresponding ImageIcon or null if no image found.

getName

public java.lang.String getName()
The name of this image. This name is not unique as it is shared by all the ImageIcons that also have this name but differ in size and status.


loadImage

public static java.awt.Image loadImage(java.lang.String name)
Load a java.awt.Image object using the file name name. This method attempts to load the image from the jar/zip file this class was loaded from ie, your application, and then from the file system as a file if can't be found as a resource. If neither method works the default image is returned.

See Also:
Class.getResource(String)

loadImage

public static java.awt.Image loadImage(java.lang.String name,
                                       int size,
                                       java.lang.String status)
Load a java.awt.Image object using the file name name. This method attempts to load the image from the jar/zip file this class was loaded from ie, your application, and then from the file system as a file if can't be found as a resource. If neither method works the default image is returned.

See Also:
Class.getResource(String)

setImage

public void setImage(java.awt.Image image)
Sets Image object that this object is holding.


toString

public java.lang.String toString()