|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectkiwi.util.ResourceManager
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:
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 |
private java.util.Hashtable images
private java.util.Hashtable textures
private java.util.Hashtable sounds
private java.util.Hashtable icons
private java.util.Hashtable bundles
private ResourceLoader loader
private static ResourceManager kiwiResourceManager
private static final java.lang.String IMAGE_PATH
private static final java.lang.String SOUND_PATH
private static final java.lang.String HTML_PATH
private static final java.lang.String THEME_PATH
private static final java.lang.String TEXTURE_PATH
private static final java.lang.String PROPERTY_PATH
private static final java.lang.String RESBUNDLE_PATH
public static final java.lang.String RESBUNDLE_EXT
public static final java.lang.String THEME_EXT
Constructor Detail |
public ResourceManager(java.lang.Class clazz)
ResourceManager
.
clazz
- The resource anchor class.Method Detail |
public static ResourceManager getKiwiResourceManager()
public void clearImageCache()
public void clearIconCache()
public void clearTextureCache()
public void clearAudioClipCache()
public void clearResourceBundleCache()
public javax.swing.Icon getIcon(java.lang.String name)
Icon
resource. This is a convenience
method that makes a call to getImage()
and then wraps the
result in a Swing ImageIcon
object.
name
- The name of the resource.
Icon
for the specified image. If an icon for this
image has previously been constructed, the cached copy is returned.
ResourceNotFoundException
- If the resource was not
found.ImageIcon
public java.awt.Image getImage(java.lang.String name)
Image
resource. If the named image has
previously been loaded, a cached copy is returned.
name
- The name of the resource.
Image
object representing the resource.
ResourceNotFoundException
- If the resource was not
found.public java.awt.Image getTexture(java.lang.String name)
name
- The name of the resource.
Image
object representing the resource.
ResourceNotFoundException
- If the resource was not
found.public java.net.URL getURL(java.lang.String name)
URL
resource.
name
- The name of the resource.
ResourceNotFoundException
- If the resource was not
found.public AudioClip getSound(java.lang.String name)
AudioClip
resource. If the named sound
has previously been loaded, a cached copy is returned.
name
- The name of the resource.
AudioClip
object representing the resource.
ResourceNotFoundException
- If the resource was not
found.public java.util.Properties getProperties(java.lang.String name)
Properties
resource.
name
- The name of the resource.
Properties
object representing the resource.
ResourceNotFoundException
- If the resource was not
found.public LocaleData getResourceBundle(java.lang.String name) throws ResourceNotFoundException
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.
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.
LocaleData
object representing the resource.
If the resource bundle has been previously loaded, a cached copy is
returned.
ResourceNotFoundException
- If the resource was not
found.public LocaleData getResourceBundle(java.lang.String name, java.util.Locale locale) throws ResourceNotFoundException
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.
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.
LocaleData
object representing the resource.
ResourceNotFoundException
- If the resource was not
found.public ColorTheme getTheme(java.lang.String name)
ColorTheme
resource.
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.
ColorTheme
object representing the resource.
ResourceNotFoundException
- If the resource was not
found.public java.io.InputStream getStream(java.lang.String name) throws ResourceNotFoundException
name
- The name of the resource.
InputStream
from which the resource can be read.
ResourceNotFoundException
- If the resource was not
found.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |