org.xnap.commons.i18n
Class I18nManager

java.lang.Object
  extended by org.xnap.commons.i18n.I18nManager

public class I18nManager
extends Object

Manager class that maintains a set of I18n objects and LocaleChangeListener objects.

The locale of all managed I18n objects can be changed by invoking setDefaultLocale(Locale).

Since:
0.9
Author:
Felix Berger, Steffen Pingel

Method Summary
 void add(I18n i18n)
          Adds i18n to the list of managed I18n objects.
 void addLocaleChangeListener(LocaleChangeListener listener)
          Adds a listener that is notified when the default locale has been changed.
 void addWeakLocaleChangeListener(LocaleChangeListener listener)
          Adds a listener that is notified when the default locale has been changed using a WeakReference.
protected  void fireLocaleChangedEvent(Locale newLocale)
          Notifies listeners of a locale change.
static I18nManager getInstance()
          Returns the global I18Manger singleton.
 void remove(I18n i18n)
          Removes i18n from the list of managed I18n objects.
 void removeLocaleChangeListener(LocaleChangeListener listener)
          Removes listener from the list of objects that are notified when the locale has changed.
 void setDefaultLocale(Locale locale)
          Sets the locale for all I18n instances that were instantiated through the factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static I18nManager getInstance()
Returns the global I18Manger singleton.

Returns:
the I18Manger instance
Since:
0.9

add

public void add(I18n i18n)
Adds i18n to the list of managed I18n objects.

Parameters:
i18n - the I18n instance
Since:
0.9
See Also:
setDefaultLocale(Locale), remove(I18n)

setDefaultLocale

public void setDefaultLocale(Locale locale)
Sets the locale for all I18n instances that were instantiated through the factory.

Use this method to globally change the locale for all I18n based translations.

NOTE: This only works if the objects that display messages do not cache translated messages.

Parameters:
locale - the new default locale
Since:
0.9
See Also:
I18n.setLocale(Locale)

addLocaleChangeListener

public void addLocaleChangeListener(LocaleChangeListener listener)
Adds a listener that is notified when the default locale has been changed.

Parameters:
listener - the listener
Since:
0.9
See Also:
setDefaultLocale(Locale)

addWeakLocaleChangeListener

public void addWeakLocaleChangeListener(LocaleChangeListener listener)
Adds a listener that is notified when the default locale has been changed using a WeakReference. The listener is removed when it has been cleaned up by the garbage collection.

This is useful for temporary objects that may have an indeterminate lifetime such as dialogs.

Parameters:
listener - the listener
Since:
0.9
See Also:
setDefaultLocale(Locale)

remove

public void remove(I18n i18n)
Removes i18n from the list of managed I18n objects.

Parameters:
i18n - the I18n instance
Since:
0.9
See Also:
add(I18n)

removeLocaleChangeListener

public void removeLocaleChangeListener(LocaleChangeListener listener)
Removes listener from the list of objects that are notified when the locale has changed.

Parameters:
listener - the listener
Since:
0.9

fireLocaleChangedEvent

protected void fireLocaleChangedEvent(Locale newLocale)
Notifies listeners of a locale change.

Parameters:
newLocale - new locale
Since:
0.9


Copyright © 2004-2007 Gettext Commons Team. All Rights Reserved.