skrueger.i8n
Class Translation

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<String,String>
          extended by skrueger.i8n.Translation
All Implemented Interfaces:
Serializable, Cloneable, Map<String,String>

public class Translation
extends HashMap<String,String>

Represents a HashMap of translations. toString() returns the appropriate translation

Author:
@author Stefan Alfons Krüger
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Field Summary
static String DEFAULT_KEY
           
protected static List<PropertyChangeListener> listeners
           
static String LOCALECHANGE_PROPERTY
           
static String NO_TRANSLATION
           
 
Constructor Summary
Translation()
          Sometimes Translations are optional, like for keywords.
Translation(List<String> languages, String defaultTranslation)
          Initializes a new Translation, an uses the given String to initialize the Translation for all languages codes passed.
Translation(String defaultTranslation)
          Initializes a new Translation with a default translation if a simple text is passed.
 
Method Summary
static void addLocaleChangeListener(PropertyChangeListener propertyChangeListener)
          PropertyChangeListener can be registered to be informed when the Locale changed.
 void addTranslationChangeListener(ActionListener actionListener)
           
 Translation clone()
           
 Translation copy(Translation backup)
          Copy this Translation to another Translation e.g. for editing
static void fireLocaleChangeEvents()
          Informs all registered PropertyChangeListeners about a change of the the Locale.
 void fireTranslationChangedEvents(String lang)
           
 void fromOneLine(String oneLineCoded)
          Fills the Translation with the values coded into the String Format of String is: "de{Baum}en{tree}" If oneLineCoded is empty or null, NO TRANSLATION is set.
static String getActiveLang()
          Get the two-letter language sting that is active
 String put(String lang, String value)
           
 boolean removeTranslationChangeListener(ActionListener actionListener)
           
static void setActiveLang(String newLang)
          Set up the Translation-system to use language.
static void setActiveLang(String newLang, boolean setDefaultLocale)
          Set up the Translation-system to use language.
 String toOneLine()
          Exports the Translations to a String of the Format: "de{Baum}en{tree}"
 String toString()
          Returns the right translation by using the activeLang field.
 
Methods inherited from class java.util.HashMap
clear, containsKey, containsValue, entrySet, get, isEmpty, keySet, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

LOCALECHANGE_PROPERTY

public static final String LOCALECHANGE_PROPERTY
See Also:
Constant Field Values

NO_TRANSLATION

public static final String NO_TRANSLATION
See Also:
Constant Field Values

DEFAULT_KEY

public static final String DEFAULT_KEY
See Also:
Constant Field Values

listeners

protected static List<PropertyChangeListener> listeners
Constructor Detail

Translation

public Translation(String defaultTranslation)
Initializes a new Translation with a default translation if a simple text is passed. If a "oneLine" text is parsed, it is interpreted. Other translations may be added later - this is a HashMap

Parameters:
defaultTranslation -
See Also:
Translation(List languages, String defaultTranslation) {

Translation

public Translation(List<String> languages,
                   String defaultTranslation)
Initializes a new Translation, an uses the given String to initialize the Translation for all languages codes passed. The translations can be changed later


Translation

public Translation()
Sometimes Translations are optional, like for keywords.

Method Detail

clone

public Translation clone()
Overrides:
clone in class HashMap<String,String>

getActiveLang

public static String getActiveLang()
Get the two-letter language sting that is active


setActiveLang

public static void setActiveLang(String newLang)
Set up the Translation-system to use language. If a change is performed, events are fired to listeners. Nothing is done if the new language equals the old language. The system's default locale is changed.

Parameters:
newLang - The ISO Code of the new active language

setActiveLang

public static void setActiveLang(String newLang,
                                 boolean setDefaultLocale)
Set up the Translation-system to use language. If a change is performed, events are fired to listeners. Nothing is done if the new language equals the old language.

Parameters:
newLang - The ISO Code of the new active language
setDefaultLocale - Shall the system's default locale be changed?

fromOneLine

public void fromOneLine(String oneLineCoded)
Fills the Translation with the values coded into the String Format of String is: "de{Baum}en{tree}"


toOneLine

public String toOneLine()
Exports the Translations to a String of the Format: "de{Baum}en{tree}"


toString

public String toString()
Returns the right translation by using the activeLang field. If no translation is set, an ugly String NO_TRANSLATION will re returned. This might be changed for the final release. If the correct language was not found, any entry in the Translation HashMap will be returned, that contains more than an empty string.

Overrides:
toString in class AbstractMap<String,String>

copy

public Translation copy(Translation backup)
Copy this Translation to another Translation e.g. for editing

Returns:
the destination Translation

addLocaleChangeListener

public static void addLocaleChangeListener(PropertyChangeListener propertyChangeListener)
PropertyChangeListener can be registered to be informed when the Locale changed.

Parameters:
propertyChangeListener -

fireLocaleChangeEvents

public static void fireLocaleChangeEvents()
Informs all registered PropertyChangeListeners about a change of the the Locale.


addTranslationChangeListener

public void addTranslationChangeListener(ActionListener actionListener)

removeTranslationChangeListener

public boolean removeTranslationChangeListener(ActionListener actionListener)

fireTranslationChangedEvents

public void fireTranslationChangedEvents(String lang)

put

public String put(String lang,
                  String value)
Specified by:
put in interface Map<String,String>
Overrides:
put in class HashMap<String,String>