EarthWeb
Developer.com
Site
windows 2000
visual c++
java
visual basic
javascripts
recommend it
 
Book
thinking in java
 
Interact
forum
guest book
jobs
jokes
what's new

share code
 
Resource
add resource
modify resource
new resource
 

[Internet Jobs]
-----
Java by E-mail:

Get the weekly e-mail highlights on Java!
-----
-

kiwi.util
Class ResourceManager

java.lang.Object
  |
  +--kiwi.util.ResourceManager

public class ResourceManager
extends 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:

Version:
1.2 (1/99)
Author:
Mark Lindner, PING Software Group
See Also:
ResourceLoader

Field Summary
static String RESBUNDLE_EXT
          The file extension for resource bundles.
static String THEME_EXT
          The file extension for color themes.
 
Constructor Summary
ResourceManager(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.
 Icon getIcon(String name)
          Retrieve an internal Icon resource.
 Image getImage(String name)
          Retrieve an internal Image resource.
 Properties getProperties(String name)
          Get a reference to a Properties resource.
 LocaleData getResourceBundle(String name)
          Get a reference to a LocaleData object for the default locale.
 LocaleData getResourceBundle(String name, Locale locale)
          Get a reference to a LocaleData object for a specified locale.
 AudioClip getSound(String name)
          Retrieve an internal AudioClip resource.
 Image getTexture(String name)
          Retrieve an internal texture resource.
 ColorTheme getTheme(String name)
          Get a reference to a ColorTheme resource.
 URL getURL(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

RESBUNDLE_EXT

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

THEME_EXT

public static final String THEME_EXT
The file extension for color themes.
Constructor Detail

ResourceManager

public ResourceManager(Class clazz)
Construct a new ResourceManager.
Parameters:
clazz - The resource anchor class.
Method Detail

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 Icon getIcon(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 Image getImage(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 Image getTexture(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 URL getURL(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(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 Properties getProperties(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(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 contry, 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(String name,
                                    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(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.


internet.commerce