net.clackrouter.jgraph.pad.resources
Class Translator

java.lang.Object
  extended by net.clackrouter.jgraph.pad.resources.Translator

public class Translator
extends java.lang.Object

Contains ResourceBundle objects. The first (deepest) bundle is the Graphpad bundle. If a user wants to use Graphpad as a framework he can push his own bundle with the pushBundle method. Requests will procnetre with the following logic: The translator asks the highest bundle for a localized text string. If the bundle has no entry for the specified key. The next bundle will ask for the key. If the deepest bundle hasn't a value for the key the key will return.


Field Summary
protected static java.util.Stack bundleNames
          Contains ResourceBundle names The first bundlename is the Graphpad bundle.
protected static java.util.Stack bundles
          Contains ResourceBundle objects.
protected static DefaultResourceBundle defaultBundle
          Resouce Bundle with proper names.
protected static java.util.Vector listeners
          Container for the registered LocaleChangeListener.
protected static boolean logNotFoundResources
          The translator creates outputs on the System.err if a resource wasn't found and this boolean is true
 
Constructor Summary
Translator()
           
 
Method Summary
static void addLocaleChangeListener(LocaleChangeListener listener)
          Adds a locale change listener to this Translator.
static DefaultResourceBundle getDefaultResourceBundle()
          Returns the resouce bundle with the proper names.
static java.util.Locale getLocale()
          Returns the current locale
static java.lang.String getString(int bundleIndex, java.lang.String sKey)
          Returns the localized String for the key.
static java.lang.String getString(int bundleIndex, java.lang.String sKey, java.lang.Object[] oValues)
          Returns the localized String for the key.
static java.lang.String getString(java.lang.String sKey)
          Returns the localized String for the key.
static java.lang.String getString(java.lang.String sKey, java.lang.Object[] values)
          Returns the localized String for the key.
static boolean isLogNotFoundResources()
          Returns the logNotFoundResources.
static void popBundle()
          Pops the highest bundle on the stack
static void pushBundle(java.lang.String filename)
          Pushes the specified bundle on the stack.
static void reloadBundles()
          Reloads the bundles at the stack by using the default locale.
static void removeBundle(int index)
          removes the specified bundle
static void removeLocaleChangeListener(LocaleChangeListener listener)
          Removes the registered Listener
static void setLocale(java.util.Locale locale)
          Sets the new locale and fires events to the locale change listener.
static void setLogNotFoundResources(boolean logNotFoundResources)
          Sets the logNotFoundResources.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listeners

protected static java.util.Vector listeners
Container for the registered LocaleChangeListener.

See Also:
LocaleChangeListener

logNotFoundResources

protected static boolean logNotFoundResources
The translator creates outputs on the System.err if a resource wasn't found and this boolean is true


bundles

protected static java.util.Stack bundles
Contains ResourceBundle objects. The first bundle is the Graphpad bundle. If a user wants to use Graphpad as a framework he can push his own bundle.


bundleNames

protected static java.util.Stack bundleNames
Contains ResourceBundle names The first bundlename is the Graphpad bundle. If a user wants to use Graphpad as a framework he can push his own bundle.


defaultBundle

protected static DefaultResourceBundle defaultBundle
Resouce Bundle with proper names.

Constructor Detail

Translator

public Translator()
Method Detail

getDefaultResourceBundle

public static DefaultResourceBundle getDefaultResourceBundle()
Returns the resouce bundle with the proper names.


getString

public static java.lang.String getString(java.lang.String sKey)
Returns the localized String for the key. If the String wasn't found the method will return the Key but not null.

Parameters:
sKey - Key for the localized String.

getString

public static java.lang.String getString(int bundleIndex,
                                         java.lang.String sKey)
Returns the localized String for the key. If the String wasn't found the method will return null.

Parameters:
bundleIndex - The bundle index for the request. The method requests the bundle at the specified position and at all deeper positions.
sKey - Key for the localized String.

getString

public static java.lang.String getString(java.lang.String sKey,
                                         java.lang.Object[] values)
Returns the localized String for the key. If the String wasn't found the method will return the key but not null.

Parameters:
sKey - Key for the localized String.
values - Object array for placeholders.
See Also:
MessageFormat.format(String, Object[])

getString

public static java.lang.String getString(int bundleIndex,
                                         java.lang.String sKey,
                                         java.lang.Object[] oValues)
Returns the localized String for the key. If the String wasn't found the method will return an empty String but not null and will log on the System.err the key String, if logNotFoundResources is true.

Parameters:
sKey - Key for the localized String.
oValues - Object array for placeholders.
See Also:
MessageFormat.format(String, Object[])

addLocaleChangeListener

public static void addLocaleChangeListener(LocaleChangeListener listener)
Adds a locale change listener to this Translator. If the local changes, this translator will fire locale change events.


removeLocaleChangeListener

public static void removeLocaleChangeListener(LocaleChangeListener listener)
Removes the registered Listener


getLocale

public static java.util.Locale getLocale()
Returns the current locale


setLocale

public static void setLocale(java.util.Locale locale)
Sets the new locale and fires events to the locale change listener.


reloadBundles

public static void reloadBundles()
Reloads the bundles at the stack by using the default locale.


pushBundle

public static void pushBundle(java.lang.String filename)
Pushes the specified bundle on the stack. An example for a bundle file name is 'org.jgraph.pad.resources.Graphpad'. Don't add the suffix of the filename, the language or country code.

See Also:
ResourceBundle.getBundle(java.lang.String)

popBundle

public static void popBundle()
Pops the highest bundle on the stack


removeBundle

public static void removeBundle(int index)
removes the specified bundle


isLogNotFoundResources

public static boolean isLogNotFoundResources()
Returns the logNotFoundResources.

Returns:
boolean

setLogNotFoundResources

public static void setLogNotFoundResources(boolean logNotFoundResources)
Sets the logNotFoundResources.

Parameters:
logNotFoundResources - The logNotFoundResources to set