com.artima.place.info
Class Icons

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

public class Icons
extends LocalizableInfo

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

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.
 byte[] getIcon(int iconKind)
          Gets a URL for the image file 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.
 int hashCode()
          Returns a hash code for this object.
 void purge()
          Purge away information about undesired locales.
 void purge(java.util.Locale preserveLocale)
          Purge away information about all locales except the passed desired locale.
 
Methods inherited from class com.artima.place.info.LocalizableInfo
clearCachedLocale, clearResourceBundleLoader, compareObjectsOrNull, getBestFitLocale, getBestFitLocale, getCachedLocale, getResourceBundleLoader, getSupportedLocales, hasCachedLocale, hasResourceBundleLoader, setCachedLocale, stripResourceBundleLoader, useCache
 
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

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.

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.
Method Detail

getIcon

public byte[] getIcon(int iconKind)
Gets a URL for the image file 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 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).
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

purge

public void purge()
Purge away information about undesired locales. If no cache exists, this method first fills the cache based on the default locale. If a cache currently exists, that cache will be left intact. Once a cache is in place, this method will clear the resource bundle loader.
Overrides:
purge in class LocalizableInfo

purge

public void purge(java.util.Locale preserveLocale)
Purge away information about all locales except the passed desired locale. This method first makes sure the cache is appropriate to the passed desired locale. Once the cache is in place, this method will clear the resource bundle loader.
Overrides:
purge in class LocalizableInfo
Parameters:
preserveLocale - a locale to preserve in this Icons.

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 LocalizableInfo
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 LocalizableInfo
Returns:
the hash code

clone

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