com.artima.place.attribute
Class Icons

java.lang.Object
  |
  +--com.artima.place.attribute.Icons
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class Icons
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

A set of localizable icons.

The icon images must be arrays of bytes in a resource bundle, with names composed of the iconKey passed to a constructor of this class plus one of the following four suffixes, which are for convenience defined as constants in this class:

For example, if an Icons object is constructed with an iconKey of "calcIcon", the color 16 by 16 pixel icon byte array should be named "calcIconColor16" in the resource bundle.

See Also:
Serialized Form

Inner Class Summary
static class Icons.Cache
          Contains cached icons and their Locale, the cache for a Icons object.
 
Field Summary
static int ICON_COLOR_16x16
          Constant to indicate a 16 x 16 color icon.
static int ICON_COLOR_32x32
          Constant to indicate a 32 x 32 color icon.
static int ICON_MONO_16x16
          Constant to indicate a 16 x 16 monochrome icon.
static int ICON_MONO_32x32
          Constant to indicate a 32 x 32 monochrome icon.
static java.lang.String SUFFIX_COLOR_16x16
          Convenience constant for the suffix applied to the icon key passed to a constructor of this class to form the actual key passed to a resource bundle to retrieve a 16 by 16 color icon.
static java.lang.String SUFFIX_COLOR_32x32
          Convenience constant for the suffix applied to the icon key passed to a constructor of this class to form the actual key passed to a resource bundle to retrieve a 32 by 32 color icon.
static java.lang.String SUFFIX_MONO_16x16
          Convenience constant for the suffix applied to the icon key passed to a constructor of this class to form the actual key passed to a resource bundle to retrieve a 16 by 16 monochrome icon.
static java.lang.String SUFFIX_MONO_32x32
          Convenience constant for the suffix applied to the icon key passed to a constructor of this class to form the actual key passed to a resource bundle to retrieve a 32 by 32 monochrome icon.
 
Constructor Summary
Icons(java.util.Locale cachedLocale, byte[] cachedColor16Icon, byte[] cachedColor32Icon, byte[] cachedMono16Icon, byte[] cachedMono32Icon)
          Constructs a new Icons with passed cached icon images for the passed locale, and no icon key or resource bundle loader.
Icons(ResourceBundleLoader loader, java.lang.String iconKey)
          Constructs a new Icons with passed resource bundle loader, icon key, and no cached icon images.
Icons(ResourceBundleLoader loader, java.lang.String iconKey, java.util.Locale cachedLocale, byte[] cachedColor16Icon, byte[] cachedColor32Icon, byte[] cachedMono16Icon, byte[] cachedMono32Icon)
          Constructs a new Icons with passed resource bundle loader, icon key, and cached icon images (for the passed locale).
 
Method Summary
 java.lang.Object clone()
          Clones this Icons.
 boolean equals(java.lang.Object o)
          Compares this Icons to the passed object for equality.
 Icons.Cache getCache()
          Returns this Icons's Cache, or null if none exists.
 byte[] getIcon(int iconKind)
          Gets an array of bytes containing the image of an icon for this resource, suitable for presentation to users, under the current locale.
 byte[] getIcon(int iconKind, java.util.Locale desiredLocale)
          Gets a URL for the image file of an icon for this resource, suitable for presentation to users, under the passed locale.
 java.lang.String getIconKey()
          Returns the String icon key contained in this Icons, or null if none exists.
 ResourceBundleLoader getResourceBundleLoader()
          Returns the ResourceBundleLoader contained in this Icons, or null if none exists.
 boolean hasCache()
          Indicates whether this Icons object has a cached icons and their Locale.
 int hashCode()
          Returns a hash code for this object.
 boolean hasResources()
          Indicates whether this Icons object has a ResourceBundleLoader and String icon key.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ICON_COLOR_16x16

public static final int ICON_COLOR_16x16
Constant to indicate a 16 x 16 color icon. (Same value as java.beans.BeanInfo.ICON_COLOR_16x16.)

ICON_COLOR_32x32

public static final int ICON_COLOR_32x32
Constant to indicate a 32 x 32 color icon. (Same value as java.beans.BeanInfo.ICON_COLOR_32x32.)

ICON_MONO_16x16

public static final int ICON_MONO_16x16
Constant to indicate a 16 x 16 monochrome icon. (Same value as java.beans.BeanInfo.ICON_MONO_16x16.)

ICON_MONO_32x32

public static final int ICON_MONO_32x32
Constant to indicate a 32 x 32 monochrome icon. (Same value as java.beans.BeanInfo.ICON_MONO_32x32.)

SUFFIX_COLOR_16x16

public static final java.lang.String SUFFIX_COLOR_16x16
Convenience constant for the suffix applied to the icon key passed to a constructor of this class to form the actual key passed to a resource bundle to retrieve a 16 by 16 color icon.

SUFFIX_COLOR_32x32

public static final java.lang.String SUFFIX_COLOR_32x32
Convenience constant for the suffix applied to the icon key passed to a constructor of this class to form the actual key passed to a resource bundle to retrieve a 32 by 32 color icon.

SUFFIX_MONO_16x16

public static final java.lang.String SUFFIX_MONO_16x16
Convenience constant for the suffix applied to the icon key passed to a constructor of this class to form the actual key passed to a resource bundle to retrieve a 16 by 16 monochrome icon.

SUFFIX_MONO_32x32

public static final java.lang.String SUFFIX_MONO_32x32
Convenience constant for the suffix applied to the icon key passed to a constructor of this class to form the actual key passed to a resource bundle to retrieve a 32 by 32 monochrome icon.
Constructor Detail

Icons

public Icons(ResourceBundleLoader loader,
             java.lang.String iconKey)
Constructs a new Icons with passed resource bundle loader, icon key, and no cached icon images.
Parameters:
loader - the ResourceBundleLoader which can load ResourceBundles for this Icons.
iconKey - a String that forms the base of the String keys with which the byte[] resource can be retrieved from a ResourceBundle provided by the ResourceBundleLoader
Throws:
NullPointerException - if either of the passed loader or iconKey references are null

Icons

public Icons(ResourceBundleLoader loader,
             java.lang.String iconKey,
             java.util.Locale cachedLocale,
             byte[] cachedColor16Icon,
             byte[] cachedColor32Icon,
             byte[] cachedMono16Icon,
             byte[] cachedMono32Icon)
Constructs a new Icons with passed resource bundle loader, icon key, and cached icon images (for the passed locale).
Parameters:
loader - the ResourceBundleLoader which can load ResourceBundles for this Icons.
iconKey - a String that forms the base of the String keys with which the byte[] resource can be retrieved from a ResourceBundle provided by the ResourceBundleLoader
cachedLocale - the Locale of the icons passed as cachedColor16Icon, cachedColor32Icon, cachedMono16Icon, and cachedMono32Icon.
cachedColor16Icon - the 16x16 color icon, whose locale is passed as cachedLocale, that should be cached by this Icons.
cachedColor32Icon - the 32x32 color icon, whose locale is passed as cachedLocale, that should be cached by this Icons.
cachedMono16Icon - the 16x16 monochrome icon, whose locale is passed as cachedLocale, that should be cached by this Icons.
cachedMono32Icon - the 32x32 monochrome icon, whose locale is passed as cachedLocale, that should be cached by this Icons.
Throws:
NullPointerException - if any of passed loader, iconKey, cachedLocale, or cached...Icon references are null

Icons

public Icons(java.util.Locale cachedLocale,
             byte[] cachedColor16Icon,
             byte[] cachedColor32Icon,
             byte[] cachedMono16Icon,
             byte[] cachedMono32Icon)
Constructs a new Icons with passed cached icon images for the passed locale, and no icon key or resource bundle loader. (Because this Icons info object contains no resource bundle loader, it also requires no icon key with which to look up an icon resource in a resource bundle.
Parameters:
cachedLocale - the Locale of the icons passed as cachedColor16Icon, cachedColor32Icon, cachedMono16Icon, and cachedMono32Icon.
cachedColor16Icon - the 16x16 color icon, whose locale is passed as cachedLocale, that should be cached by this Icons.
cachedColor32Icon - the 32x32 color icon, whose locale is passed as cachedLocale, that should be cached by this Icons.
cachedMono16Icon - the 16x16 monochrome icon, whose locale is passed as cachedLocale, that should be cached by this Icons.
cachedMono32Icon - the 32x32 monochrome icon, whose locale is passed as cachedLocale, that should be cached by this Icons.
Throws:
NullPointerException - if any of passed cachedLocale, or cached...Icon references are null
Method Detail

getIcon

public byte[] getIcon(int iconKind)
Gets an array of bytes containing the image of an icon for this resource, suitable for presentation to users, under the current locale. (The image file is likely either a GIF or JPG file, but could be any image file format.) The valid parameter values are the same as for the getIcon method of java.beans.BeanInfo, which for convenience are also declared in this class: ICON_COLOR_16x16, ICON_COLOR_32x32, ICON_MONO_16x16, ICON_MONO_32x32.
Parameters:
iconKind - the kind of icon to be returned (one of ICON_COLOR_16x16, ICON_COLOR_32x32, ICON_MONO_16x16, or ICON_MONO_32x32).
Returns:
the bytes of an icon image file for this resource
Throws:
java.util.MissingResourceException - if the icon image can't be retrieved successfully

getIcon

public byte[] getIcon(int iconKind,
                      java.util.Locale desiredLocale)
Gets a URL for the image file of an icon for this resource, suitable for presentation to users, under the passed locale. (The image file is likely either a GIF or JPG file, but could be any image file format.) The valid parameter values are the same as for the getIcon method of java.beans.BeanInfo, which for convenience are also declared in this interface: ICON_COLOR_16x16, ICON_COLOR_32x32, ICON_MONO_16x16, ICON_MONO_32x32.
Parameters:
iconKind - the kind of icon to be returned (one of ICON_COLOR_16x16, ICON_COLOR_32x32, ICON_MONO_16x16, or ICON_MONO_32x32).
desiredLocale - the locale for which an appropriate icon is desired.
Returns:
the bytes of an icon image file for this resource
Throws:
java.util.MissingResourceException - if the icon image can't be retrieved successfully

equals

public boolean equals(java.lang.Object o)
Compares this Icons to the passed object for equality. To be semantically equal, the class of the passed object must be Icons, the passed object's cached icon images must be semantically equal to this object's cached icon images, the passed object's icon key must be semantically to this object's icon key, and the equals method of Icons's superclass must return true.
Overrides:
equals in class java.lang.Object
Parameters:
an - object to compare to this Icons.
Returns:
true if this Icons is semantically equal to the passed Icons.

hashCode

public int hashCode()
Returns a hash code for this object.
Overrides:
hashCode in class java.lang.Object
Returns:
the hash code

clone

public java.lang.Object clone()
Clones this Icons.
Overrides:
clone in class java.lang.Object
Returns:
a clone of this object

getCache

public Icons.Cache getCache()
Returns this Icons's Cache, or null if none exists. This method will return null only if this Icons object contains no cached icons. Otherwise, this method will return a Icons.Cache object containing this object's cached icons and the Locale of those cached icons (the "cached locale").
Returns:
a reference to the Icons.Cache, which contains this object's cached icons and locale, or null if this object contains no cache

hasResources

public boolean hasResources()
Indicates whether this Icons object has a ResourceBundleLoader and String icon key.
Returns:
true if this Icons object has a ResourceBundleLoader and String icon key.

hasCache

public boolean hasCache()
Indicates whether this Icons object has a cached icons and their Locale.
Returns:
true if this Icons object has a cached icons and their Locale.

getResourceBundleLoader

public ResourceBundleLoader getResourceBundleLoader()
Returns the ResourceBundleLoader contained in this Icons, or null if none exists.
Returns:
a ResourceBundleLoader, or null if this object contains no ResourceBundleLoader.

getIconKey

public java.lang.String getIconKey()
Returns the String icon key contained in this Icons, or null if none exists.
Returns:
a String icon key, or null if this object contains no icon key.