com.townleyenterprises.common
Class ResourceLoader

java.lang.Object
  extended bycom.townleyenterprises.common.ResourceLoader
All Implemented Interfaces:
ResourceProvider

public class ResourceLoader
extends java.lang.Object
implements ResourceProvider

This class provides a way to access Java resource strings from a location relative to a specific class. This class assumes that all resources are located in a sub-directory under the current package called 'resources'. Thus, in Unix, the resource strings for com.foo.MyClass will be located in: com/foo/resources/strings.properties and the images will be located under com/foo/resources/.

This class supports a system property which will control how missing resources are reported. The property is:

Version:
$Id: ResourceLoader.java,v 1.3 2004/08/11 16:19:01 atownley Exp $
Author:
Andrew S. Townley

Constructor Summary
ResourceLoader(java.lang.Class cls)
          This constructor takes a class to use as the basis for finding resources.
ResourceLoader(java.lang.Class cls, java.util.Locale locale)
          This constructor takes a class to use as the basis for finding resources for the specific locale.
ResourceLoader(java.lang.Class cls, java.lang.String name)
          This version of the constructor is used to load resource settings from an arbitrarily named resource property file.
ResourceLoader(java.lang.Class cls, java.lang.String name, java.util.Locale locale)
          This version of the constructor is used to load resource settings from an arbitrarily named resource property file.
ResourceLoader(java.lang.Object obj)
          The constructor takes an object to use as the basis for finding resources.
 
Method Summary
 javax.swing.ImageIcon getIcon(java.lang.String key)
          This method is used to load an image for the default locale.
 javax.swing.ImageIcon getIcon(java.lang.String key, java.util.Locale locale)
          This method is used to load an image for the specified locale and key.
 java.util.Collection getKeys()
          This method returns the collection of keys for the resource provider.
 java.util.ResourceBundle getResourceBundle()
          This method returns the reference to the bundle for the default locale for this instance.
 java.util.ResourceBundle getResourceBundle(java.util.Locale locale)
          This method is used to get a direct reference to the resource bundle.
 java.lang.String getString(java.lang.String key)
          This method is used to find a given resource string.
 java.lang.String getString(java.lang.String key, java.util.Locale locale)
          This method is used to find a given resource string based on the specified locale.
 java.lang.String toString()
          Provide some clue as to what we're doing and who we are.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ResourceLoader

public ResourceLoader(java.lang.Object obj)
The constructor takes an object to use as the basis for finding resources.

Parameters:
obj - the object to provide the base resource location

ResourceLoader

public ResourceLoader(java.lang.Class cls)
This constructor takes a class to use as the basis for finding resources.

Parameters:
cls - the class providing the base resource location

ResourceLoader

public ResourceLoader(java.lang.Class cls,
                      java.util.Locale locale)
This constructor takes a class to use as the basis for finding resources for the specific locale.

Parameters:
cls - the class providing the base resource location
locale - the locale of the resources to load

ResourceLoader

public ResourceLoader(java.lang.Class cls,
                      java.lang.String name)
This version of the constructor is used to load resource settings from an arbitrarily named resource property file.

Parameters:
cls - the class providing the base resource location
name - the name of the resources

ResourceLoader

public ResourceLoader(java.lang.Class cls,
                      java.lang.String name,
                      java.util.Locale locale)
This version of the constructor is used to load resource settings from an arbitrarily named resource property file.

Parameters:
cls - the class providing the base resource location
name - the name of the resources
locale - the locale to use
Method Detail

getString

public java.lang.String getString(java.lang.String key)
This method is used to find a given resource string.

Specified by:
getString in interface ResourceProvider
Parameters:
key - the resource string key. If the key can't be found or the resulting string is empty, the key is returned.
Returns:
the string for the key

getString

public java.lang.String getString(java.lang.String key,
                                  java.util.Locale locale)
Description copied from interface: ResourceProvider
This method is used to find a given resource string based on the specified locale.

Specified by:
getString in interface ResourceProvider
Parameters:
key - the resource string key
locale - the locale
Returns:
the string for the key

getIcon

public javax.swing.ImageIcon getIcon(java.lang.String key)
This method is used to load an image for the default locale.

Specified by:
getIcon in interface ResourceProvider
Parameters:
key - the image key
Returns:
the ImageIcon

getIcon

public javax.swing.ImageIcon getIcon(java.lang.String key,
                                     java.util.Locale locale)
This method is used to load an image for the specified locale and key.

Specified by:
getIcon in interface ResourceProvider
Parameters:
key - the image key
locale - the locale
Returns:
the ImageIcon

getKeys

public java.util.Collection getKeys()
Description copied from interface: ResourceProvider
This method returns the collection of keys for the resource provider.

Specified by:
getKeys in interface ResourceProvider

getResourceBundle

public java.util.ResourceBundle getResourceBundle()
This method returns the reference to the bundle for the default locale for this instance.

Returns:
the bundle

getResourceBundle

public java.util.ResourceBundle getResourceBundle(java.util.Locale locale)
This method is used to get a direct reference to the resource bundle.

Parameters:
locale - the specific locale
Returns:
the resource bundle

toString

public java.lang.String toString()
Provide some clue as to what we're doing and who we are.



Copyright © 2002-2004, Andrew S. Townley and Townley Enterprises. All Rights Reserved.
This project is hosted on http://te-code.sourceforge.net.