org.vizzini.ui
Class ResourceProvider

java.lang.Object
  extended by org.vizzini.ui.ResourceProvider

public class ResourceProvider
extends Object

Provides locale specific resources. This class searches resource bundles, where the resource bundles can "inherit" from parent resource bundles. Parents are specified in the properties file with the key represented by PARENT_BUNDLE_NAME_KEY.

If a locale other than the default is desired, it must be set using setLocale() prior to calling get().

Since:
v0.1
Version:
v0.3
Author:
Jeffrey M. Thompson

Field Summary
static String CONFIG_BUNDLE_NAME
          Standard configuration resources filename.
protected static String PARENT_BUNDLE_NAME_KEY
          Parent resource bundle name key.
static String STRING_BUNDLE_NAME
          Standard string resources filename.
 
Constructor Summary
protected ResourceProvider(String bundleName)
          Construct this object.
 
Method Summary
static void clear()
          Clear all instances so they can be recreated.
static String convertToBundleName(Class aClass, String bundleFilename)
          Convert the given class and bundle filename into a fully qualified bundle name.
protected static ResourceProvider createInstance(Class aClass, String bundleFilename)
          Create a resource provider instance.
protected static ResourceProvider createInstance(String bundleName)
          Create a resource provider instance.
static ResourceProvider get(Class aClass, String bundleFilename)
          Return the instance associated with the given bundle name.
static ResourceProvider get(String bundleName)
          Return the instance associated with the given bundle name.
 AudioClip getAudioClip(String key)
          Return the audio clip specified by the given key.
 boolean getBoolean(String key)
          Return the boolean specified by the given key.
 boolean getBoolean(String key, boolean defaultValue)
          Return the boolean specified by the given key, or the given default value if the key is not found.
 Class getClass(String key)
          Return the Class specified by the given key.
 Color getColor(String key)
          Return the color specified by the given key.
 Color getColor(String key, Color defaultColor)
          Return the color specified by the given key, or the given default color if the key is not found.
 Font getFont(String key)
          Return the font specified by the given key.
 Font getFont(String key, Font defaultFont)
          Return the font specified by the given key, or the given default font if the key is not found.
 Icon getIcon(String key)
          Return the icon specified by the given key.
 int getInt(String key)
          Return the int specified by the given key.
 int getInt(String key, int defaultValue)
          Return the int specified by the given key, or the given default value if the key is not found.
protected  int getIntFromString(String string)
          Return an integer from the given string.
 String getString(String key)
          Return the string specified by the given key.
 String getString(String key, String defaultString)
          Return the string specified by the given key, or the given default string if the key is not found.
static void remove(String bundleName)
          Remove the instance associated with the given bundle name so that it can be recreated.
static void setLocale(Locale locale)
          Set the locale.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STRING_BUNDLE_NAME

public static final String STRING_BUNDLE_NAME
Standard string resources filename.

See Also:
Constant Field Values

CONFIG_BUNDLE_NAME

public static final String CONFIG_BUNDLE_NAME
Standard configuration resources filename.

See Also:
Constant Field Values

PARENT_BUNDLE_NAME_KEY

protected static final String PARENT_BUNDLE_NAME_KEY
Parent resource bundle name key.

See Also:
Constant Field Values
Constructor Detail

ResourceProvider

protected ResourceProvider(String bundleName)
Construct this object. This method is protected to prevent other code from creating instances.

Since:
v0.1
Method Detail

clear

public static void clear()
Clear all instances so they can be recreated.

Since:
v0.1

convertToBundleName

public static String convertToBundleName(Class aClass,
                                         String bundleFilename)
Convert the given class and bundle filename into a fully qualified bundle name.

Parameters:
aClass - Class from which to extract the fully qualified package name.
bundleFilename - Simple filename of the bundle.
Returns:
The fully qualified bundle name.
Since:
v0.1

get

public static ResourceProvider get(String bundleName)
Return the instance associated with the given bundle name.

Parameters:
bundleName - Fully qualified bundle name.
Since:
v0.1

get

public static ResourceProvider get(Class aClass,
                                   String bundleFilename)
Return the instance associated with the given bundle name.

Since:
v0.1

remove

public static void remove(String bundleName)
Remove the instance associated with the given bundle name so that it can be recreated.

Since:
v0.1

setLocale

public static void setLocale(Locale locale)
Set the locale.

Since:
v0.1

getAudioClip

public AudioClip getAudioClip(String key)
Return the audio clip specified by the given key.

Since:
v0.1

getBoolean

public boolean getBoolean(String key)
Return the boolean specified by the given key.

Since:
v0.1

getBoolean

public boolean getBoolean(String key,
                          boolean defaultValue)
Return the boolean specified by the given key, or the given default value if the key is not found.

Since:
v0.1

getClass

public Class getClass(String key)
Return the Class specified by the given key.

Since:
v0.1

getColor

public Color getColor(String key)
Return the color specified by the given key.

Since:
v0.1

getColor

public Color getColor(String key,
                      Color defaultColor)
Return the color specified by the given key, or the given default color if the key is not found.

Since:
v0.1

getFont

public Font getFont(String key)
Return the font specified by the given key.

Since:
v0.1

getFont

public Font getFont(String key,
                    Font defaultFont)
Return the font specified by the given key, or the given default font if the key is not found.

Since:
v0.1

getIcon

public Icon getIcon(String key)
Return the icon specified by the given key.

Since:
v0.1

getInt

public int getInt(String key)
Return the int specified by the given key.

Since:
v0.1

getInt

public int getInt(String key,
                  int defaultValue)
Return the int specified by the given key, or the given default value if the key is not found.

Since:
v0.1

getString

public String getString(String key)
Return the string specified by the given key.

Since:
v0.1

getString

public String getString(String key,
                        String defaultString)
Return the string specified by the given key, or the given default string if the key is not found.

Since:
v0.1

createInstance

protected static ResourceProvider createInstance(String bundleName)
Create a resource provider instance.

Since:
v0.1

createInstance

protected static ResourceProvider createInstance(Class aClass,
                                                 String bundleFilename)
Create a resource provider instance.

Since:
v0.1

getIntFromString

protected int getIntFromString(String string)
Return an integer from the given string.

Since:
v0.1


Copyright 2007 Vizzini.org. All Rights Reserved. 2007.12.25.03.00.02