|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectLocaleUtils
public class LocaleUtils
Provides localized text strings to GUI elements. This class hides most of the fiddly bits
associated with Locale and ResourceBundle from other gt-swing classes.
You do not create instances of this class, it is basically just a wrapper around static data.
Text strings are stored in properties files as per standard Java internationalization. All files
are located in the org/geotools/swing/locale
directory of the swing module.
An application wishing to display GUI elements in a non-default locale must call either setLocale(Locale) or setLocale(List) before constructing any GUI elements which display localized text. At present, this class does not support switching locales for components that have already been constructed.
Clients retrieve text strings by specifying the base name of the relevant properties file and a key as shown here:
String localizedText = LocaleUtils.getValue("CursorTool", "ZoomInTool");
Adding support for a new language simply involves adding the new locale to all or some of the
properties files. If the locale is only provided for some files, it will be recorded by as
partially supported and used where available.
You can set a single working locale with setLocale(Locale). If the specified locale is only partially supported, the getValue(String, String) method will fall back to the default Locale.ROOT when retrieving text strings lacking this locale. Alternatively, you can specify a list of locales in order of preference using the setLocale(List) method.
If the setLocale
method is not called, the locale defaults to
Locale.ROOT (which is English language in the properties files distributed
with GeoTools).
Method Summary | |
---|---|
static String |
getValue(String baseFileName,
String key)
Retrieves a GUI text string identified by the base name of a properties file and a key within that file. |
static boolean |
isFullySupportedLocale(Locale locale)
Tests whether the given Locale is fully supported (ie. has been
provided for every GUI text string properties file. |
static boolean |
isSupportedLocale(Locale locale)
Tests whether the given Locale is supported. |
static void |
setLocale(List<Locale> preferredLocales)
Sets the preferred locales for text string retrieval. |
static void |
setLocale(Locale preferredLocale)
Sets a single preferred locale for text string retrieval. |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static boolean isFullySupportedLocale(Locale locale)
Locale
is fully supported (ie. has been
provided for every GUI text string properties file.
locale
- the locale
true
if fully supported; false
if partially or
not supportedpublic static boolean isSupportedLocale(Locale locale)
Locale
is supported. A locale is treated
as supported if it has been provided for at least one GUI text string
properties file.
locale
- the locale
true
if the locale is at least partially supportedisFullySupportedLocale(Locale)
public static void setLocale(Locale preferredLocale)
preferredLocale
is null
the working locale will be set
to Locale.ROOT.
preferredLocale
- the localepublic static void setLocale(List<Locale> preferredLocales)
preferredLocales
is null
or empty, the working locale will be set to Locale.ROOT.
preferredLocales
- locales in descending order of preferencepublic static String getValue(String baseFileName, String key)
String localName = LocaleUtils.getValue("CursorTool", "ZoomIn");
baseFileName
- base name of the properties file containing the text stringkey
- key for the text string
MissingResourceException
- if the baseFileName:key
pair
cannot be found
IllegalArgumentException
- if either argument is null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |