kiwi.util
Class ResourceManager

java.lang.Object
  extended bykiwi.util.ResourceManager

public class ResourceManager
extends java.lang.Object

This class provides base functionality for a resource manager; it includes support for the caching of images and sounds, and provides convenience methods for retrieving other types of resources. All resources are retrieved relative to an anchor class. The resource manager assumes that images will be within an "images" directory, textures within a "textures" directory, sounds within a "sounds" directory, URL-based references within an "html" directory, properties within a "properties" directory, resource bundles within a "locale" directory, and color theme definitions within a "themes" directory.

The Kiwi library includes a resource library of its own; the resources within the library are accessible through the internal ResourceManager, a reference to which may be obtained via a call to kiwi.util.KiwiUtils.getResourceManager(). Links to index files of some of the resources are listed below:

Author:
Mark Lindner, PING Software Group
See Also:
ResourceLoader

Field Summary
private  java.util.Hashtable bundles
           
private static java.lang.String HTML_PATH
           
private  java.util.Hashtable icons
           
private static java.lang.String IMAGE_PATH
           
private  java.util.Hashtable images
           
private static ResourceManager kiwiResourceManager
           
private  ResourceLoader loader
           
private static java.lang.String PROPERTY_PATH
           
static java.lang.String RESBUNDLE_EXT
          The file extension for resource bundles.
private static java.lang.String RESBUNDLE_PATH
           
private static java.lang.String SOUND_PATH
           
private  java.util.Hashtable sounds
           
private static java.lang.String TEXTURE_PATH
           
private  java.util.Hashtable textures
           
static java.lang.String THEME_EXT
          The file extension for color themes.
private static java.lang.String THEME_PATH
           
 
Constructor Summary
ResourceManager(java.lang.Class clazz)
          Construct a new ResourceManager.
 
Method Summary
 void clearAudioClipCache()
          Clear the audio clip resource cache.
 void clearIconCache()
          Clear the icon resource cache.
 void clearImageCache()
          Clear the image resource cache.
 void clearResourceBundleCache()
          Clear the resource bundle cache.
 void clearTextureCache()
          Clear the texture resource cache.
 javax.swing.Icon getIcon(java.lang.String name)
          Retrieve an internal Icon resource.
 java.awt.Image getImage(java.lang.String name)
          Retrieve an internal Image resource.
static ResourceManager getKiwiResourceManager()
           
 java.util.Properties getProperties(java.lang.String name)
          Get a reference to a Properties resource.
 LocaleData getResourceBundle(java.lang.String name)
          Get a reference to a LocaleData object for the default locale.
 LocaleData getResourceBundle(java.lang.String name, java.util.Locale locale)
          Get a reference to a LocaleData object for a specified locale.
 AudioClip getSound(java.lang.String name)
          Retrieve an internal AudioClip resource.
 java.io.InputStream getStream(java.lang.String name)
          Get a stream to a resource.
 java.awt.Image getTexture(java.lang.String name)
          Retrieve an internal texture resource.
 ColorTheme getTheme(java.lang.String name)
          Get a reference to a ColorTheme resource.
 java.net.URL getURL(java.lang.String name)
          Retrieve an internal URL resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

images

private java.util.Hashtable images

textures

private java.util.Hashtable textures

sounds

private java.util.Hashtable sounds

icons

private java.util.Hashtable icons

bundles

private java.util.Hashtable bundles

loader

private ResourceLoader loader

kiwiResourceManager

private static ResourceManager kiwiResourceManager

IMAGE_PATH

private static final java.lang.String IMAGE_PATH
See Also:
Constant Field Values

SOUND_PATH

private static final java.lang.String SOUND_PATH
See Also:
Constant Field Values

HTML_PATH

private static final java.lang.String HTML_PATH
See Also:
Constant Field Values

THEME_PATH

private static final java.lang.String THEME_PATH
See Also:
Constant Field Values

TEXTURE_PATH

private static final java.lang.String TEXTURE_PATH
See Also:
Constant Field Values

PROPERTY_PATH

private static final java.lang.String PROPERTY_PATH
See Also:
Constant Field Values

RESBUNDLE_PATH

private static final java.lang.String RESBUNDLE_PATH
See Also:
Constant Field Values

RESBUNDLE_EXT

public static final java.lang.String RESBUNDLE_EXT
The file extension for resource bundles.

See Also:
Constant Field Values

THEME_EXT

public static final java.lang.String THEME_EXT
The file extension for color themes.

See Also:
Constant Field Values
Constructor Detail

ResourceManager

public ResourceManager(java.lang.Class clazz)
Construct a new ResourceManager.

Parameters:
clazz - The resource anchor class.
Method Detail

getKiwiResourceManager

public static ResourceManager getKiwiResourceManager()

clearImageCache

public void clearImageCache()
Clear the image resource cache.


clearIconCache

public void clearIconCache()
Clear the icon resource cache.


clearTextureCache

public void clearTextureCache()
Clear the texture resource cache.


clearAudioClipCache

public void clearAudioClipCache()
Clear the audio clip resource cache.


clearResourceBundleCache

public void clearResourceBundleCache()
Clear the resource bundle cache.


getIcon

public javax.swing.Icon getIcon(java.lang.String name)
Retrieve an internal Icon resource. This is a convenience method that makes a call to getImage() and then wraps the result in a Swing ImageIcon object.

Parameters:
name - The name of the resource.
Returns:
An Icon for the specified image. If an icon for this image has previously been constructed, the cached copy is returned.
Throws:
ResourceNotFoundException - If the resource was not found.
See Also:
ImageIcon

getImage

public java.awt.Image getImage(java.lang.String name)
Retrieve an internal Image resource. If the named image has previously been loaded, a cached copy is returned.

Parameters:
name - The name of the resource.
Returns:
The Image object representing the resource.
Throws:
ResourceNotFoundException - If the resource was not found.

getTexture

public java.awt.Image getTexture(java.lang.String name)
Retrieve an internal texture resource. If the named texture has previously been loaded, a cached copy is returned.

Parameters:
name - The name of the resource.
Returns:
The Image object representing the resource.
Throws:
ResourceNotFoundException - If the resource was not found.

getURL

public java.net.URL getURL(java.lang.String name)
Retrieve an internal URL resource.

Parameters:
name - The name of the resource.
Returns:
A URL for the resource.
Throws:
ResourceNotFoundException - If the resource was not found.

getSound

public AudioClip getSound(java.lang.String name)
Retrieve an internal AudioClip resource. If the named sound has previously been loaded, a cached copy is returned.

Parameters:
name - The name of the resource.
Returns:
The AudioClip object representing the resource.
Throws:
ResourceNotFoundException - If the resource was not found.

getProperties

public java.util.Properties getProperties(java.lang.String name)
Get a reference to a Properties resource.

Parameters:
name - The name of the resource.
Returns:
The Properties object representing the resource.
Throws:
ResourceNotFoundException - If the resource was not found.

getResourceBundle

public LocaleData getResourceBundle(java.lang.String name)
                             throws ResourceNotFoundException
Get a reference to a LocaleData object for the default locale. The locale naming convention basename_language_country_variant is supported; a search is performed starting with the most specific name and ending with the most generic.

Parameters:
name - The name of the resource; this should be the base name of the resource bundle; the appropriate locale country, language, and variant codes and the ".msg" extension will be automatically appended to the name.
Returns:
The LocaleData object representing the resource. If the resource bundle has been previously loaded, a cached copy is returned.
Throws:
ResourceNotFoundException - If the resource was not found.

getResourceBundle

public LocaleData getResourceBundle(java.lang.String name,
                                    java.util.Locale locale)
                             throws ResourceNotFoundException
Get a reference to a LocaleData object for a specified locale. The locale naming convention basename_language_country_variant is supported; a search is performed starting with the most specific name and ending with the most generic. If the resource bundle has been previously loaded, a cached copy is returned.

Parameters:
name - The name of the resource; this should be the base name of the resource bundle; the appropriate locale contry, language, and variant codes and the ".msg" extension will be automatically appended to the name.
locale - The locale for the resource.
Returns:
The LocaleData object representing the resource.
Throws:
ResourceNotFoundException - If the resource was not found.

getTheme

public ColorTheme getTheme(java.lang.String name)
Get a reference to a ColorTheme resource.

Parameters:
name - The name of the resource; this should be the base name of the color theme; the ".thm" extension will be automatically appended to the name.
Returns:
The ColorTheme object representing the resource.
Throws:
ResourceNotFoundException - If the resource was not found.

getStream

public java.io.InputStream getStream(java.lang.String name)
                              throws ResourceNotFoundException
Get a stream to a resource.

Parameters:
name - The name of the resource.
Returns:
An InputStream from which the resource can be read.
Throws:
ResourceNotFoundException - If the resource was not found.
Since:
Kiwi 1.3