com.bbn.openmap
Class BasicI18n

java.lang.Object
  extended by com.bbn.openmap.BasicI18n
All Implemented Interfaces:
I18n, java.io.Serializable

public class BasicI18n
extends java.lang.Object
implements I18n, java.io.Serializable

Basic implementation of internationalization support.

This class backs the I18n interface by I18n.property files that it expects to find in each package.

This class provides a mechanism for creating the I18n.property files that it expects to use in the application. If the 'i18n.create' flag is set in the Debug class, then this class will track what resource bundle property files were searched for, and what values were returned for requested keys. The dumpCreatedResourceBundles() method will cause the resource bundles to be written out, where they can be modified to change the strings displayed in the GUI. If the 'i18n.default' flag is set, then 'I18N.properties' files will be created. If that flag is not set, then the name of the files will be modified for the locale currently set for the application (i.e. I18N_en_US.properties for the US locale). You can add the I18nFileCreateMenuItem to an application to trigger the dumpCreatedResourceBundles() method.

See Also:
Serialized Form

Field Summary
protected  java.util.Hashtable createHash
           
static java.lang.String DEBUG
          Debug string, 'i18n'
static java.lang.String DEBUG_CREATE
          Debug string that causes the BasicI18n class to keep track of resource property files and strings it looks for, as well as their defaults.
static java.lang.String DEBUG_CREATE_DEFAULT
          If set, created ResourceBundle files will not have the local suffixes added to them.
static java.lang.String ResourceFileNamePrefix
          All properties files containing string should be contained in a file called I18N.properties.
 
Fields inherited from interface com.bbn.openmap.I18n
MNEMONIC, TEXT, TITLE, TOOLTIP
 
Constructor Summary
BasicI18n()
          Create a BasicI18n object from the default locale.
BasicI18n(java.util.Locale loc)
          Create a BasicI18n object with given locale.
 
Method Summary
 void dumpCreatedResourceBundles()
          If called, will bring up a JFileChooser so you can pick a location to dump the resource files that were searched for, with values that were found or the defaults provided in the code.
 void dumpCreatedResourceBundles(java.lang.String location)
          Will dump the resource bundle property files searched for by this class, along with the contents that were returned or with the defaults provided by the application.
 void fill(java.lang.Object requestor)
          Fill in all of the fields of the given object that are of known types (see the set(...) methods of this class) with values obtained from the appropriate ResourceBundle.
 java.lang.String get(java.lang.Class requestor, java.lang.String field, int type, java.lang.String defaultString)
          Get the string associated with the given class/field/type.
 java.lang.String get(java.lang.Class requestor, java.lang.String field, int type, java.lang.String defaultString, java.lang.Object param1)
          Method to get a parameterized String, as if by MessageFormat.
 java.lang.String get(java.lang.Class requestor, java.lang.String field, int type, java.lang.String defaultString, java.lang.Object[] params)
          Method to get a parameterized String, as if by MessageFormat.
 java.lang.String get(java.lang.Class requestor, java.lang.String field, int type, java.lang.String defaultString, java.lang.Object param1, java.lang.Object param2)
          Method to get a parameterized String, as if by MessageFormat.
 java.lang.String get(java.lang.Class requestor, java.lang.String field, java.lang.String defaultString)
          Get the string associated with the given class/field (Defaults to TEXT for the type).
 java.lang.String get(java.lang.Class requestor, java.lang.String field, java.lang.String defaultString, java.lang.Object param1)
          Method to get a parameterized String, as if by MessageFormat.
 java.lang.String get(java.lang.Class requestor, java.lang.String field, java.lang.String defaultString, java.lang.Object[] params)
          Method to get a parameterized String, as if by MessageFormat.
 java.lang.String get(java.lang.Class requestor, java.lang.String field, java.lang.String defaultString, java.lang.Object param1, java.lang.Object param2)
          Method to get a parameterized String, as if by MessageFormat.
 java.lang.String get(java.lang.Object requestor, java.lang.String field, int type, java.lang.String defaultString)
          Get the string associated with the given object/field/type.
 java.lang.String get(java.lang.Object requestor, java.lang.String field, int type, java.lang.String defaultString, java.lang.Object param1)
          Method to get a parameterized String, as if by MessageFormat.
 java.lang.String get(java.lang.Object requestor, java.lang.String field, int type, java.lang.String defaultString, java.lang.Object[] params)
          Method to get a parameterized String, as if by MessageFormat.
 java.lang.String get(java.lang.Object requestor, java.lang.String field, int type, java.lang.String defaultString, java.lang.Object param1, java.lang.Object param2)
          Method to get a parameterized String, as if by MessageFormat.
 java.lang.String get(java.lang.Object requestor, java.lang.String field, java.lang.String defaultString)
          Get the string associated with the given object/field (Defaults to TEXT for the type).
 java.lang.String get(java.lang.Object requestor, java.lang.String field, java.lang.String defaultString, java.lang.Object param1)
          Method to get a parameterized String, as if by MessageFormat.
 java.lang.String get(java.lang.Object requestor, java.lang.String field, java.lang.String defaultString, java.lang.Object[] params)
          Method to get a parameterized String, as if by MessageFormat.
 java.lang.String get(java.lang.Object requestor, java.lang.String field, java.lang.String defaultString, java.lang.Object param1, java.lang.Object param2)
          Method to get a parameterized String, as if by MessageFormat.
protected  java.util.Hashtable getCreateHash()
           
protected  java.lang.String getInternal(java.lang.Class requestor, java.lang.String field, int type)
          Obtain a String from the underlying data for the given class/field/type.
protected  int getMNEMONIC(java.lang.Object requestor, java.lang.String field, int defaultInt, boolean verbose)
          Get text for the given component.
protected  java.lang.String getTEXT(java.lang.Object requestor, java.lang.String field, java.lang.String defaultString)
          Get text for the given component.
protected  java.lang.String getTITLE(java.lang.Object requestor, java.lang.String field, java.lang.String defaultString)
          Get title for the given component.
 void set(java.lang.Object requestor, java.lang.String field)
          Set the textual properties on a Swing component that is a member of a given class, from values in the ResourceBundle associated with that class.
 void set(java.lang.Object requestor, java.lang.String field, javax.swing.JButton comp)
          Set the textual properties from values in the appropriate ResourceBundle.
 void set(java.lang.Object requestor, java.lang.String field, javax.swing.JComponent comp)
          Set the textual properties from values in the appropriate ResourceBundle.
 void set(java.lang.Object requestor, java.lang.String field, javax.swing.JDialog comp)
          Set the textual properties from values in the appropriate ResourceBundle.
 void set(java.lang.Object requestor, java.lang.String field, javax.swing.JFrame comp)
          Set the textual properties from values in the appropriate ResourceBundle.
 void set(java.lang.Object requestor, java.lang.String field, javax.swing.JLabel comp)
          Set the textual properties from values in the appropriate ResourceBundle.
 void set(java.lang.Object requestor, java.lang.String field, javax.swing.JMenu comp)
          Set the textual properties from values in the appropriate ResourceBundle.
 void set(java.lang.Object requestor, java.lang.String field, javax.swing.JMenuItem comp)
          Set the textual properties from values in the appropriate ResourceBundle.
protected  void setForBundleCreation(java.lang.Class requestor, java.lang.String field, int type, java.lang.String defaultString)
          Obtain a String from the underlying data for the given class/field/type.
protected  void setTOOLTIP(java.lang.Object requestor, java.lang.String field, javax.swing.JComponent comp)
          Set a tooltip on the given component if it has one.
static java.lang.String shortClassName(java.lang.Class c)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static final java.lang.String DEBUG
Debug string, 'i18n'

See Also:
Constant Field Values

DEBUG_CREATE

public static final java.lang.String DEBUG_CREATE
Debug string that causes the BasicI18n class to keep track of resource property files and strings it looks for, as well as their defaults. These files can be created by calling dumpCreatedResourceBundles().

See Also:
Constant Field Values

DEBUG_CREATE_DEFAULT

public static final java.lang.String DEBUG_CREATE_DEFAULT
If set, created ResourceBundle files will not have the local suffixes added to them. Otherwise, the locale set in I18n will be used and appended.

See Also:
Constant Field Values

ResourceFileNamePrefix

public static final java.lang.String ResourceFileNamePrefix
All properties files containing string should be contained in a file called I18N.properties. This string defines the I18N.

See Also:
Constant Field Values

createHash

protected transient java.util.Hashtable createHash
Constructor Detail

BasicI18n

public BasicI18n()
Create a BasicI18n object from the default locale.


BasicI18n

public BasicI18n(java.util.Locale loc)
Create a BasicI18n object with given locale.

Method Detail

get

public java.lang.String get(java.lang.Object requestor,
                            java.lang.String field,
                            java.lang.String defaultString)
Description copied from interface: I18n
Get the string associated with the given object/field (Defaults to TEXT for the type).

Specified by:
get in interface I18n
Parameters:
requestor - object containing the code requesting the String (typically thisfield - the field the String belongs to. Typically this will be the variable name referring to the String or the Swing object that uses the String (like a button or a label).
defaultString - what to use if the resource can't be found.

get

public java.lang.String get(java.lang.Object requestor,
                            java.lang.String field,
                            int type,
                            java.lang.String defaultString)
Description copied from interface: I18n
Get the string associated with the given object/field/type.

Specified by:
get in interface I18n
Parameters:
requestor - object containing the code requesting the String (typically thisfield - the field the String belongs to. Typically this will be the variable name referring to the Swing object that uses the String (like a button or a label).
type - which specific slot in the Swing object the string pertains to. One of TEXT, TOOLTIP or MNEMONIC.
defaultString - what to use if the resource can't be found.

get

public java.lang.String get(java.lang.Class requestor,
                            java.lang.String field,
                            java.lang.String defaultString)
Description copied from interface: I18n
Get the string associated with the given class/field (Defaults to TEXT for the type).

Specified by:
get in interface I18n
Parameters:
requestor - the class of the object containing the code requesting the String (typically Foo.classfield - the field the String belongs to. Typically this will be the variable name referring to the String or the Swing object that uses the String (like a button or a label).
defaultString - what to use if the resource can't be found.

get

public java.lang.String get(java.lang.Class requestor,
                            java.lang.String field,
                            int type,
                            java.lang.String defaultString)
Description copied from interface: I18n
Get the string associated with the given class/field/type.

Specified by:
get in interface I18n
Parameters:
requestor - the classof the object containing the code requesting the String (typically Foo.classfield - the field the String belongs to. Typically this will be the variable name referring to the Swing object that uses the String (like a button or a label).
type - which specific slot in the Swing object the string pertains to. One of TEXT, TOOLTIP or MNEMONIC.
defaultString - what to use if the resource can't be found.

getCreateHash

protected java.util.Hashtable getCreateHash()

get

public java.lang.String get(java.lang.Object requestor,
                            java.lang.String field,
                            java.lang.String defaultString,
                            java.lang.Object param1)
Description copied from interface: I18n
Method to get a parameterized String, as if by MessageFormat.

Specified by:
get in interface I18n
See Also:
MessageFormat

get

public java.lang.String get(java.lang.Object requestor,
                            java.lang.String field,
                            int type,
                            java.lang.String defaultString,
                            java.lang.Object param1)
Description copied from interface: I18n
Method to get a parameterized String, as if by MessageFormat.

Specified by:
get in interface I18n
See Also:
MessageFormat

get

public java.lang.String get(java.lang.Class requestor,
                            java.lang.String field,
                            java.lang.String defaultString,
                            java.lang.Object param1)
Description copied from interface: I18n
Method to get a parameterized String, as if by MessageFormat.

Specified by:
get in interface I18n
See Also:
MessageFormat

get

public java.lang.String get(java.lang.Class requestor,
                            java.lang.String field,
                            int type,
                            java.lang.String defaultString,
                            java.lang.Object param1)
Description copied from interface: I18n
Method to get a parameterized String, as if by MessageFormat.

Specified by:
get in interface I18n
See Also:
MessageFormat

get

public java.lang.String get(java.lang.Object requestor,
                            java.lang.String field,
                            java.lang.String defaultString,
                            java.lang.Object param1,
                            java.lang.Object param2)
Description copied from interface: I18n
Method to get a parameterized String, as if by MessageFormat.

Specified by:
get in interface I18n
See Also:
MessageFormat

get

public java.lang.String get(java.lang.Object requestor,
                            java.lang.String field,
                            int type,
                            java.lang.String defaultString,
                            java.lang.Object param1,
                            java.lang.Object param2)
Description copied from interface: I18n
Method to get a parameterized String, as if by MessageFormat.

Specified by:
get in interface I18n
See Also:
MessageFormat

get

public java.lang.String get(java.lang.Class requestor,
                            java.lang.String field,
                            java.lang.String defaultString,
                            java.lang.Object param1,
                            java.lang.Object param2)
Description copied from interface: I18n
Method to get a parameterized String, as if by MessageFormat.

Specified by:
get in interface I18n
See Also:
MessageFormat

get

public java.lang.String get(java.lang.Class requestor,
                            java.lang.String field,
                            int type,
                            java.lang.String defaultString,
                            java.lang.Object param1,
                            java.lang.Object param2)
Description copied from interface: I18n
Method to get a parameterized String, as if by MessageFormat.

Specified by:
get in interface I18n
See Also:
MessageFormat

get

public java.lang.String get(java.lang.Object requestor,
                            java.lang.String field,
                            java.lang.String defaultString,
                            java.lang.Object[] params)
Description copied from interface: I18n
Method to get a parameterized String, as if by MessageFormat.

Specified by:
get in interface I18n
See Also:
MessageFormat

get

public java.lang.String get(java.lang.Object requestor,
                            java.lang.String field,
                            int type,
                            java.lang.String defaultString,
                            java.lang.Object[] params)
Description copied from interface: I18n
Method to get a parameterized String, as if by MessageFormat.

Specified by:
get in interface I18n
See Also:
MessageFormat

get

public java.lang.String get(java.lang.Class requestor,
                            java.lang.String field,
                            java.lang.String defaultString,
                            java.lang.Object[] params)
Description copied from interface: I18n
Method to get a parameterized String, as if by MessageFormat.

Specified by:
get in interface I18n
See Also:
MessageFormat

get

public java.lang.String get(java.lang.Class requestor,
                            java.lang.String field,
                            int type,
                            java.lang.String defaultString,
                            java.lang.Object[] params)
Description copied from interface: I18n
Method to get a parameterized String, as if by MessageFormat.

Specified by:
get in interface I18n
See Also:
MessageFormat

set

public void set(java.lang.Object requestor,
                java.lang.String field,
                javax.swing.JLabel comp)
Description copied from interface: I18n
Set the textual properties from values in the appropriate ResourceBundle.

Specified by:
set in interface I18n
Parameters:
requestor - object containing the code requesting the String (typically thisfield - the field the String belongs to. Typically this will be the variable name referring to the comp parameter.
comp - the component whose properties are being set.

set

public void set(java.lang.Object requestor,
                java.lang.String field,
                javax.swing.JButton comp)
Description copied from interface: I18n
Set the textual properties from values in the appropriate ResourceBundle.

Specified by:
set in interface I18n
Parameters:
requestor - object containing the code requesting the String (typically thisfield - the field the String belongs to. Typically this will be the variable name referring to the comp parameter.
comp - the component whose properties are being set.

set

public void set(java.lang.Object requestor,
                java.lang.String field,
                javax.swing.JMenu comp)
Description copied from interface: I18n
Set the textual properties from values in the appropriate ResourceBundle.

Specified by:
set in interface I18n
Parameters:
requestor - object containing the code requesting the String (typically thisfield - the field the String belongs to. Typically this will be the variable name referring to the comp parameter.
comp - the component whose properties are being set.

set

public void set(java.lang.Object requestor,
                java.lang.String field,
                javax.swing.JMenuItem comp)
Description copied from interface: I18n
Set the textual properties from values in the appropriate ResourceBundle.

Specified by:
set in interface I18n
Parameters:
requestor - object containing the code requesting the String (typically thisfield - the field the String belongs to. Typically this will be the variable name referring to the comp parameter.
comp - the component whose properties are being set.

set

public void set(java.lang.Object requestor,
                java.lang.String field,
                javax.swing.JDialog comp)
Description copied from interface: I18n
Set the textual properties from values in the appropriate ResourceBundle.

Specified by:
set in interface I18n
Parameters:
requestor - object containing the code requesting the String (typically thisfield - the field the String belongs to. Typically this will be the variable name referring to the comp parameter.
comp - the component whose properties are being set.

set

public void set(java.lang.Object requestor,
                java.lang.String field,
                javax.swing.JFrame comp)
Description copied from interface: I18n
Set the textual properties from values in the appropriate ResourceBundle.

Specified by:
set in interface I18n
Parameters:
requestor - object containing the code requesting the String (typically thisfield - the field the String belongs to. Typically this will be the variable name referring to the comp parameter.
comp - the component whose properties are being set.

set

public void set(java.lang.Object requestor,
                java.lang.String field,
                javax.swing.JComponent comp)
Description copied from interface: I18n
Set the textual properties from values in the appropriate ResourceBundle.

Note: This method just looks for a TitledBorder on the component.

Specified by:
set in interface I18n
Parameters:
requestor - object containing the code requesting the String (typically thisfield - the field the String belongs to. Typically this will be the variable name referring to the comp parameter.
comp - the component whose properties are being set.

set

public void set(java.lang.Object requestor,
                java.lang.String field)
Description copied from interface: I18n
Set the textual properties on a Swing component that is a member of a given class, from values in the ResourceBundle associated with that class. Note that the field must contain an object of a known type (see the other set(...) methods of this class).

The setting of the values of this field will be accomplished by calling the appropriate set(...) method on this class.

Specified by:
set in interface I18n
Parameters:
requestor - object containing the code requesting the Component setup (typically thisfield - the variable name of the component being setup.

fill

public void fill(java.lang.Object requestor)
Description copied from interface: I18n
Fill in all of the fields of the given object that are of known types (see the set(...) methods of this class) with values obtained from the appropriate ResourceBundle.

The setting of the values of this field will be accomplished by calling the appropriate set(...) method on this class.

Specified by:
fill in interface I18n

setTOOLTIP

protected void setTOOLTIP(java.lang.Object requestor,
                          java.lang.String field,
                          javax.swing.JComponent comp)
Set a tooltip on the given component if it has one.


getTEXT

protected java.lang.String getTEXT(java.lang.Object requestor,
                                   java.lang.String field,
                                   java.lang.String defaultString)
Get text for the given component.


getTITLE

protected java.lang.String getTITLE(java.lang.Object requestor,
                                    java.lang.String field,
                                    java.lang.String defaultString)
Get title for the given component.


getMNEMONIC

protected int getMNEMONIC(java.lang.Object requestor,
                          java.lang.String field,
                          int defaultInt,
                          boolean verbose)
Get text for the given component.


getInternal

protected java.lang.String getInternal(java.lang.Class requestor,
                                       java.lang.String field,
                                       int type)
Obtain a String from the underlying data for the given class/field/type.

Returns:
null if the data can't be found -- defaulting happens above here.

setForBundleCreation

protected void setForBundleCreation(java.lang.Class requestor,
                                    java.lang.String field,
                                    int type,
                                    java.lang.String defaultString)
Obtain a String from the underlying data for the given class/field/type. The default is set in the propertyFileProperties. This method is called when the debugging flag is set, indicating that a new resource directory should be created for all classes that use 18n resources.


dumpCreatedResourceBundles

public void dumpCreatedResourceBundles()
If called, will bring up a JFileChooser so you can pick a location to dump the resource files that were searched for, with values that were found or the defaults provided in the code. This will only do something if the BasicI18n class was accessed with the 'i18n.create' flag set in the Debug class.


dumpCreatedResourceBundles

public void dumpCreatedResourceBundles(java.lang.String location)
Will dump the resource bundle property files searched for by this class, along with the contents that were returned or with the defaults provided by the application.

Parameters:
location - directory location to use as the root for resource bundle file hierarchy.

shortClassName

public static java.lang.String shortClassName(java.lang.Class c)


Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details