|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap<K,V>
java.util.HashMap<String,String>
skrueger.i8n.Translation
public class Translation
Represents a HashMap
of translations. toString() returns the
appropriate translation
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 |
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)
The listeneras are stored in a WeakHashSet ! |
static boolean |
checkValid(Translation translationToCheck)
Checks if the String s stored in the Translation are all
valid. |
Translation |
clone()
|
Translation |
copy()
Creates a new instance of T and copies all values. |
Translation |
copyTo(Translation translation2)
Copy this Translation to another Translation e.g. for
editing |
static void |
fireLocaleChangeEvents()
Informs all registered PropertyChangeListener s about a change of
the the Locale . |
void |
fireTranslationChangedEvents(String lang)
|
void |
fromOneLine(InternationalString iString)
|
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)
|
static boolean |
removeLocaleChangeListener(PropertyChangeListener propertyChangeListener)
PropertyChangeListener can be registered to be informed when the
Locale changed. |
boolean |
removeTranslationChangeListener(ActionListener actionListener)
The listeneras are stored in a WeakHashSet ! |
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 |
---|
public static final String LOCALECHANGE_PROPERTY
public static final String NO_TRANSLATION
public static final String DEFAULT_KEY
protected staticlisteners
Constructor Detail |
---|
public Translation(String defaultTranslation)
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
defaultTranslation
- Translation(List languages, String
defaultTranslation) {
public Translation(List<String> languages, String defaultTranslation)
Translation
, an uses the given String to
initialize the Translation
for all languages codes passed.
The translations can be changed later
public Translation()
Method Detail |
---|
public Translation clone()
clone
in class HashMap<String,String>
public static String getActiveLang()
public static void setActiveLang(String newLang)
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.
newLang
- The ISO Code of the new active languagepublic static void setActiveLang(String newLang, boolean setDefaultLocale)
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.
newLang
- The ISO Code of the new active languagesetDefaultLocale
- Shall the system's default locale be changed?public void fromOneLine(String oneLineCoded)
Translation
with the values coded into the String
Format of String
is: "de{Baum}en{tree}"
public String toOneLine()
public String toString()
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.
toString
in class AbstractMap<String,String>
public static void addLocaleChangeListener(PropertyChangeListener propertyChangeListener)
PropertyChangeListener
can be registered to be informed when the
Locale
changed.WeakHashMap
, so you have to keep a
reference to the listener or it will be removed!
propertyChangeListener
- A PropertyChangeListener
that will be called when
setActiveLang(String)
changes the language.public static boolean removeLocaleChangeListener(PropertyChangeListener propertyChangeListener)
PropertyChangeListener
can be registered to be informed when the
Locale
changed.WeakHashMap
, so you have to keep a
reference to the listener or it will be removed!
propertyChangeListener
- A PropertyChangeListener
that will be called when
setActiveLang(String)
changes the language.public static void fireLocaleChangeEvents()
PropertyChangeListener
s about a change of
the the Locale
.
public void addTranslationChangeListener(ActionListener actionListener)
WeakHashSet
! So you HAVE TO KEEP a
reference as long as you need the listener.
public boolean removeTranslationChangeListener(ActionListener actionListener)
WeakHashSet
! You don't have to
remove the listener, as long as you throw away the reference to the
listener.
public void fireTranslationChangedEvents(String lang)
public String put(String lang, String value)
put
in interface Map<String,String>
put
in class HashMap<String,String>
public void fromOneLine(InternationalString iString)
public Translation copyTo(Translation translation2)
Translation
to another Translation
e.g. for
editing
copyTo
in interface Copyable<Translation>
Translation
public Translation copy()
Copyable
copy
in interface Copyable<Translation>
public static boolean checkValid(Translation translationToCheck)
String
s stored in the Translation
are all
valid.
true
if all good
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |