|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.northwestern.at.utils.Resources
public class Resources
Retrieves text from a global string resource bundle.
Many items in the utils classes require textual information. This class provides a simple mechanism for consolidating the location of the text via a resource bundle. Wherever a text string would normally be used in the code, a reference to the "get" methods of this class should be used instead.
For example, when creating a button, instead of writing
JButton button = new JButton( "bogus" );
write
JButton button = new JButton( Resources.get( "bogus" , "bogus" ) );
instead. The first string is the name of the resource, and
the second is a default value, typically in English.
The file "utils.properties" contains strings in English and is found in the resources/ subdirectory underneath this class. You may add corresponding properties files for other languages, and call one of the "setLocale" methods here to use these other properties files. For example, to define French strings, create the file resources/utils_fr.properties and call:
Resources.setLocale( "fr" );
to use your French strings.
If you define an alternative properties file for another language, you should provide translation for all the strings defined in en.properties . Undefined strings will revert the to default values in English declared in the "get" method calls.
Field Summary | |
---|---|
protected static java.util.Locale |
defaultLocale
Default locale. |
protected static java.util.ResourceBundle |
resourceBundle
String resource bundle. |
protected static java.lang.String |
resourceName
Resource base name. |
Constructor Summary | |
---|---|
protected |
Resources()
Don't allow instantiation, do allow overrides. |
Method Summary | |
---|---|
static java.lang.String |
get(java.lang.String resourceName)
Get string from ResourceBundle. |
static java.lang.String |
get(java.lang.String resourceName,
java.lang.String defaultValue)
Get string from ResourceBundle. |
static java.lang.String[] |
gets(java.lang.String resourceName,
java.lang.String[] defaults)
Parse ResourceBundle for a String array. |
static void |
setLocale(java.util.Locale locale)
Set the resource bundle to use based upon the locale. |
static void |
setLocale(java.lang.String language)
Set the translation language using the language name. |
static void |
setLocale(java.lang.String language,
java.lang.String country)
Set the translation language using the language name and country. |
static java.lang.String[] |
tokenize(java.lang.String input)
Split string into a series of substrings on whitespace boundries. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static java.lang.String resourceName
protected static java.util.ResourceBundle resourceBundle
protected static java.util.Locale defaultLocale
Constructor Detail |
---|
protected Resources()
Method Detail |
---|
public static void setLocale(java.util.Locale locale)
locale
- Locate specifying language and country. public static void setLocale(java.lang.String language, java.lang.String country)
language
- The java style language name.
Example: French is "fr".country
- The java style country name.
Example: France is "FR". public static void setLocale(java.lang.String language)
language
- The java style language name.
Example: French is "fr". public static java.lang.String get(java.lang.String resourceName, java.lang.String defaultValue)
resourceName
- Name of resource to retrieve.defaultValue
- Default value for resource.
Underline "_" characters are replaced by spaces.
public static java.lang.String get(java.lang.String resourceName)
resourceName
- Name of resource to retrieve.
Underline "_" characters are replaced by spaces.
public static java.lang.String[] gets(java.lang.String resourceName, java.lang.String[] defaults)
resourceName
- Name of resource.defaults
- Array of default string values.
public static java.lang.String[] tokenize(java.lang.String input)
input
- Input string.
This is useful for retrieving an array of strings from the resource file. Underline "_" characters are replaced by spaces.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |