net.clackrouter.jgraph.utils.gui
Class LocaleChangeAdapter

java.lang.Object
  extended by net.clackrouter.jgraph.utils.gui.LocaleChangeAdapter
All Implemented Interfaces:
LocaleChangeListener, ProperNameProvider, TranslatorConstants

public class LocaleChangeAdapter
extends java.lang.Object
implements LocaleChangeListener, ProperNameProvider, TranslatorConstants

The adapter is a listener for local change events. If you change the locale at the translator then this adapter will update all registered GUI Elements. To register a GUI Element you can use the addContainer(Container) method. To unregister a GUI Element you can use the removeContainer(Container) method. A typical frame implementation can look like this:

  public class MyFrame extend JFrame {
 
                public MyFrame(){
                        setName("MyFrame");
                        JButton b = new JButton();
                        b.setName("OK");
                        getContentPane().add(b);
 
                        // after con catting the whole GUI tree
                        // register the frame for locale
                        // events
                        // The LocalChangeAdapter will update
                        // all labels and co automatically
                        LocaleChangeAdapter.addContainer(this);
                        pack();
                        setVisible(true);
                }
 
                public void dispose(){
                        super.dispose();
                        // unregister the locale change adapter
                        LocaleChangeAdapter.removeContainer(this);
                }
  }
  
Furthermore this class is a proper name provider for proper names from the swing gui. For example the look and feel names are proper names and we do not need to add the look and feel names at each property language file. This class contains this proper names.


Field Summary
protected static java.util.Vector containers
          vector with all registered containers
static java.lang.String DONT_SET_MNEMONIC
          Key for the special jcomponent client property.
static java.lang.String DONT_SET_TOOL_TIP_TEXT
          Key for the special jcomponent client property.
protected static LocaleChangeAdapter localeChangeAdapter
          A reference to the default locale change adapter
static java.lang.String SET_TEXT_IF_ICON_NOT_AVAILABLE
          Key for the special jcomponent client property.
 
Fields inherited from interface net.clackrouter.jgraph.pad.resources.TranslatorConstants
PREFIX_COMPONENT, PREFIX_MESSAGE_ERROR, PREFIX_MESSAGE_INFORMATION, PREFIX_MESSAGE_WARING, SUFFIX_ACCELERATOR, SUFFIX_ACTION, SUFFIX_ICON, SUFFIX_IMAGE, SUFFIX_LABEL, SUFFIX_MENU, SUFFIX_MNEMONIC, SUFFIX_TEXT, SUFFIX_TITLE, SUFFIX_TOOL_TIP_TEXT
 
Constructor Summary
LocaleChangeAdapter()
          Creates a new local change adapter and registers itself at the translator for a locale change listener and for a proper name provider.
 
Method Summary
static void addContainer(java.awt.Container comp)
          Adds a container to the control of the local change adapter
 java.util.Enumeration getKeys()
          returns the keys for the proper names
protected static LocaleChangeAdapter getLocaleChangeAdapter()
          returns the default local change adapter
 java.lang.String getString(java.lang.String key)
          returns the value for a proper name key
 void localeChanged(LocaleChangeEvent e)
          Will be called from the translator if a locale was changed
static void removeContainer(java.awt.Container comp)
          Removes a container from the control of the local change adapter
static void updateComponent(java.awt.Component comp)
          This method will be called from the updateContainer method.
static void updateContainer(java.awt.Container oComp)
          This method will be called from the localeChanged method or it will be called recursively.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SET_TEXT_IF_ICON_NOT_AVAILABLE

public static final java.lang.String SET_TEXT_IF_ICON_NOT_AVAILABLE
Key for the special jcomponent client property. If the JComponent contains a client property with this key and a true Boolean object, then the local change adapter will display the Text only if an icon is not available

See Also:
Constant Field Values

DONT_SET_TOOL_TIP_TEXT

public static final java.lang.String DONT_SET_TOOL_TIP_TEXT
Key for the special jcomponent client property. If the JComponent contains a client property with this key and a true Boolean object, then the local change adapter will not set the ToolTipText

See Also:
Constant Field Values

DONT_SET_MNEMONIC

public static final java.lang.String DONT_SET_MNEMONIC
Key for the special jcomponent client property. If the JComponent contains a client property with this key and a true Boolean object, then the local change adapter will not set the mnemonic

See Also:
Constant Field Values

localeChangeAdapter

protected static LocaleChangeAdapter localeChangeAdapter
A reference to the default locale change adapter


containers

protected static java.util.Vector containers
vector with all registered containers

Constructor Detail

LocaleChangeAdapter

public LocaleChangeAdapter()
Creates a new local change adapter and registers itself at the translator for a locale change listener and for a proper name provider.

Method Detail

getLocaleChangeAdapter

protected static LocaleChangeAdapter getLocaleChangeAdapter()
returns the default local change adapter

Returns:
the default adapter

addContainer

public static void addContainer(java.awt.Container comp)
Adds a container to the control of the local change adapter

Parameters:
comp - the specified container

removeContainer

public static void removeContainer(java.awt.Container comp)
Removes a container from the control of the local change adapter

Parameters:
comp - the specified container

localeChanged

public void localeChanged(LocaleChangeEvent e)
Will be called from the translator if a locale was changed

Specified by:
localeChanged in interface LocaleChangeListener

updateContainer

public static void updateContainer(java.awt.Container oComp)
This method will be called from the localeChanged method or it will be called recursively. The method will update the container and all children with the new locale values.

Parameters:
oComp - the concerning container
See Also:
localeChanged(LocaleChangeEvent)

updateComponent

public static void updateComponent(java.awt.Component comp)
This method will be called from the updateContainer method. The method will update the component with the new locale values.

Parameters:
comp - the concerning component
See Also:
updateContainer(Container)

getKeys

public java.util.Enumeration getKeys()
returns the keys for the proper names

Specified by:
getKeys in interface ProperNameProvider

getString

public java.lang.String getString(java.lang.String key)
returns the value for a proper name key

Specified by:
getString in interface ProperNameProvider