org.tigris.gef.util
Class Localizer

java.lang.Object
  extended by org.tigris.gef.util.Localizer

public class Localizer
extends java.lang.Object

This class manages the resource bundle files needed to localize the application. All registered resource files are searched in order to find the localization of a given string.


Field Summary
protected static java.lang.String SHORTCUT_MODIFIER
          AWT has no standard way to name the platforms default menu shortcut modifier for a KeyStroke, so the localizer replaces each occurence of "shortcut" with Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
 
Constructor Summary
Localizer()
           
 
Method Summary
static void addLocale(java.util.Locale locale)
          The method addLocale adds a new locale to the set of known locales for the application.
static void addResource(java.lang.String binding, java.lang.String resourceName)
          The method adds a new resource under the given name.
static void addResource(java.lang.String binding, java.lang.String resourceName, java.lang.ClassLoader loader)
           
static void addResource(java.lang.String binding, java.lang.String resourceName, java.util.Locale locale)
           
static void addResource(java.lang.String binding, java.lang.String resourceName, java.util.Locale locale, java.lang.ClassLoader loader)
           
static boolean containsKey(java.lang.String binding, java.lang.String key)
          Check if a resource contains a specific key (for the current default locale)
static boolean containsKey(java.lang.String binding, java.lang.String key, java.util.Locale locale, java.util.Map resources)
           
static boolean containsLocale(java.util.Locale locale)
          This method tests, if the given locale is registered.
static boolean containsResource(java.lang.String resource)
          This method tests, if a resource with the given name is registered.
static java.util.Locale getCurrentLocale()
          The method returns the current locale.
static java.util.Set getKeys(java.lang.String binding)
          Returns a Set that contains all keys (strings) defined in the given resource (for the current default locale)
static java.util.Map getResourcesFor(java.util.Locale locale)
          The method returns all resources for the given locale.
static javax.swing.KeyStroke getShortcut(java.lang.String binding, java.lang.String key)
          This function returns a localized menu shortcut key to the specified key.
static javax.swing.KeyStroke getShortcut(java.lang.String binding, java.lang.String key, java.util.Locale locale, java.util.Map resources)
           
static java.lang.String localize(java.lang.String binding, java.lang.String key)
          This function returns a localized string corresponding to the specified key.
static java.lang.String localize(java.lang.String binding, java.lang.String key, java.util.Locale locale, java.util.Map resources)
           
static void removeLocale(java.util.Locale locale)
          The method removes the given locale from the list of known locales.
static void removeResource(java.lang.String binding)
          The method removes the given resource from the list of used resources.
static void switchCurrentLocale(java.util.Locale locale)
          The method changes the current locale to the given one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SHORTCUT_MODIFIER

protected static final java.lang.String SHORTCUT_MODIFIER
AWT has no standard way to name the platforms default menu shortcut modifier for a KeyStroke, so the localizer replaces each occurence of "shortcut" with Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()

See Also:
Constant Field Values
Constructor Detail

Localizer

public Localizer()
Method Detail

containsResource

public static boolean containsResource(java.lang.String resource)
This method tests, if a resource with the given name is registered.

Parameters:
resource - Name of the resource to be tested.
Returns:
True, if a resource with the given name is registered, otherwise false.

containsLocale

public static boolean containsLocale(java.util.Locale locale)
This method tests, if the given locale is registered.

Parameters:
locale - Locale to be tested.
Returns:
True, if the given locale is registered, otherwise false.

addLocale

public static void addLocale(java.util.Locale locale)
The method addLocale adds a new locale to the set of known locales for the application. For a new locale, all known ResourceBundles are added when possible.

See Also:
ResourceBundle, Locale

switchCurrentLocale

public static void switchCurrentLocale(java.util.Locale locale)
The method changes the current locale to the given one. The resources bound to the given locale are also preloaded. If the given locale is not already registered, it will be registered automatically.

See Also:
Locale

getCurrentLocale

public static java.util.Locale getCurrentLocale()
The method returns the current locale.

Returns:
The current locale

getResourcesFor

public static java.util.Map getResourcesFor(java.util.Locale locale)
The method returns all resources for the given locale.

Parameters:
locale - Resources are searched for this locale.
Returns:
Map of all resources and their names bound to the given locale.

addResource

public static void addResource(java.lang.String binding,
                               java.lang.String resourceName)
                        throws java.util.MissingResourceException
The method adds a new resource under the given name. The resource is preloaded and bound to every registered locale.

Parameters:
resourceName - Name of the resource to be registered.
binding - Name under which the resource should be registered.
Throws:
java.util.MissingResourceException

addResource

public static void addResource(java.lang.String binding,
                               java.lang.String resourceName,
                               java.lang.ClassLoader loader)
                        throws java.util.MissingResourceException
Throws:
java.util.MissingResourceException

addResource

public static void addResource(java.lang.String binding,
                               java.lang.String resourceName,
                               java.util.Locale locale)
                        throws java.util.MissingResourceException
Throws:
java.util.MissingResourceException

addResource

public static void addResource(java.lang.String binding,
                               java.lang.String resourceName,
                               java.util.Locale locale,
                               java.lang.ClassLoader loader)
                        throws java.util.MissingResourceException
Throws:
java.util.MissingResourceException

removeLocale

public static void removeLocale(java.util.Locale locale)
The method removes the given locale from the list of known locales. If the locale is the current locale, the current locale is switched to the systems default locale.

Parameters:
locale - Locale to be removed.

removeResource

public static void removeResource(java.lang.String binding)
The method removes the given resource from the list of used resources. Any binding from any locale to that resource is also removed.

Parameters:
binding - Name under which the resource to be removed is registered.

localize

public static java.lang.String localize(java.lang.String binding,
                                        java.lang.String key)
This function returns a localized string corresponding to the specified key. Searching goes through all registered ResourceBundles

Parameters:
binding - ResourceBundles to search in.
key - String to be localized.
Returns:
First localization for the given string found in the registered ResourceBundles, the key itself if no localization has been found.

localize

public static java.lang.String localize(java.lang.String binding,
                                        java.lang.String key,
                                        java.util.Locale locale,
                                        java.util.Map resources)

containsKey

public static boolean containsKey(java.lang.String binding,
                                  java.lang.String key)
Check if a resource contains a specific key (for the current default locale)

Parameters:
binding -
key -
Returns:
true if the key is contained.

containsKey

public static boolean containsKey(java.lang.String binding,
                                  java.lang.String key,
                                  java.util.Locale locale,
                                  java.util.Map resources)

getKeys

public static java.util.Set getKeys(java.lang.String binding)
Returns a Set that contains all keys (strings) defined in the given resource (for the current default locale)

Parameters:
binding - the resource name whose keys should be returned
Returns:
a Set containing all keys. Will never return null, but an empty Set if no resource was found or it contains no keys.

getShortcut

public static javax.swing.KeyStroke getShortcut(java.lang.String binding,
                                                java.lang.String key)
This function returns a localized menu shortcut key to the specified key.

Parameters:
binding - Name of resource to be searched.
key - Shortcut string to be localized.
Returns:
Localized KeyStroke object.

getShortcut

public static javax.swing.KeyStroke getShortcut(java.lang.String binding,
                                                java.lang.String key,
                                                java.util.Locale locale,
                                                java.util.Map resources)