All Packages Class Hierarchy This Package Previous Next Index
Class multilizer.Translator
java.lang.Object
|
+----multilizer.Translator
- public class Translator
- extends Object
- implements Serializable, DictionaryListener
A class that iterates every property of the host component and all its sub components.
If it find any String or String[] typed property that matches the targets it translates
the property. The translator can also update the Locale property of the compoment to
match the current locale.
The Dictionary
property specifies the dictionary that the translator uses to translate the strings.
The Targets
property specifies what components and the properties the translator should translate.
If you do not want to update the Locale properties set the
UpdateLocale
property false.
Call the translate
method to specify the host component and to translate it.
An example:
Translator translator = new Translator();
translator.setDictionary(dictionary);
translator.setHost(this);
translator.addTarget(new Target("", "locale"));
translator.addTarget(new Target("", "text"));
translator.addTarget(new Target("", "label"));
translator.addTarget(new Target("", "title"));
translator.addTarget(new Target("", "items"));
translator.addTarget(new Target("", "labels"));
try
{
translator.translate(this);
}
catch (Exception e)
{
}
- See Also:
- Dictionary, BidiTranslator, SwingTranslator, SwingBidiTranslator
-
Translator()
- Constructs a new transtor.
-
Translator(Dictionary)
- Constructs a new transtor with the specified dictionary.
-
addAfterTranslateListener(AfterTranslateListener)
- Adds the specified after translate listener to receive after translate events from this translator.
-
addBeforeTranslateListener(BeforeTranslateListener)
- Adds the specified before translate listener to receive before translate events from this translator.
-
addDefaultTargets()
- Adds the most common targets propeties.
-
addRestrictObjectListener(RestrictObjectListener)
- Adds the specified restrict object listener to receive object restriction events from this translator.
-
addRestrictPropertyListener(RestrictPropertyListener)
- Adds the specified restrict property listener to receive property restriction events from this translator.
-
addTarget(Target)
- Adds a new target to the target list.
-
addTranslateObjectListener(TranslateObjectListener)
- Adds the specified object translate listener to receive after translate events from this translator.
-
checkLayout(Container)
-
-
dispose()
- Disposes the translator.
-
doTranslateString(Object, String, String)
- Gets the translates for the property of the given object.
-
finalize()
- Disposes of this translator once it is no longer referenced.
-
getDictionary()
- Gets the dictionary.
-
getHost()
- Gets the host container.
-
getTargetCount()
- Gets the target count.
-
getTargets()
- Gets the targets in a single string.
-
getTargets(int)
- Gets an individual target.
-
getTargetsArray()
- Gets the targets.
-
getTranslateTextComponents()
- Gets the state of text component translation.
-
getTranslation(int)
- Gets the translation.
-
getUpdateLocale()
- Gets the update locale property flag.
-
hostTranslated()
-
-
languageChanged(DictionaryEventObject)
- The dictionary calls this method after either language or locale has been changed.
-
processObject(Object)
- Checks if the translation of an object is restricted.
-
removeAfterTranslateListener(AfterTranslateListener)
- Removes the after translate listener so it no longer receives after translate events from this translator.
-
removeBeforeTranslateListener(BeforeTranslateListener)
- Removes the before translate listener so it no longer receives before translate events from this translator.
-
removeRestrictObjectListener(RestrictObjectListener)
- Removes the restrict object listener so it no longer receives object restriction events from this translator.
-
removeRestrictPropertyListener(RestrictPropertyListener)
- Removes the restrict property listener so it no longer receives property restriction events from this translator.
-
removeTarget(int)
- Removes a target form the target list.
-
removeTarget(Target)
- Removes a target form the target list.
-
removeTranslateObjectListener(TranslateObjectListener)
- Removes the object translate listener so it no longer receives after translate events from this translator.
-
setDictionary(Dictionary)
- Sets the dictionary.
-
setHost(Container)
- Sets the host container.
-
setTargets(int, Target)
- Sets an individual target.
-
setTargets(String)
- Sets the targets.
-
setTargets(Target[])
- Sets the targets.
-
setTranslateTextComponents(boolean)
- Enables or disables the translation of text components.
-
setUpdateLocale(boolean)
- Sets the update locale property flag.
-
stringToTarget(String)
- Converts the given string to a target.
-
targetToString(Target, boolean)
- Converts the given target to a string.
-
translate()
- Translates the host container.
-
translateMenu()
- Translates the menu of the host.
-
translateObject(Object)
- Translate the object.
-
translateProperty(Object, PropertyDescriptor, int)
- Translates the property of the bean.
Translator
public Translator()
- Constructs a new transtor.
Translator
public Translator(Dictionary dictionary)
- Constructs a new transtor with the specified dictionary.
- Parameters:
- dictionary - the dictionary for the translator
dispose
public void dispose()
- Disposes the translator.
This method must be called to release the resources that are used for the translator.
- See Also:
- finalize
finalize
protected void finalize()
- Disposes of this translator once it is no longer referenced.
- Overrides:
- finalize in class Object
- See Also:
- dispose
getTranslation
protected TranslatorTranslation getTranslation(int index)
- Gets the translation.
doTranslateString
protected String doTranslateString(Object object,
String property,
String value)
- Gets the translates for the property of the given object.
- Parameters:
- object - the object where the property belongs to
- property - the name of the property
- value - the current value of the property
- Returns:
- the value of the property in the active language
translateProperty
protected void translateProperty(Object object,
PropertyDescriptor property,
int type)
- Translates the property of the bean.
processObject
protected boolean processObject(Object object)
- Checks if the translation of an object is restricted. If not call the
translateObject method that translates the object.
- Returns:
- true if the object was translated. false of the translation was restricted.
- See Also:
- translateObject
translateObject
protected void translateObject(Object object)
- Translate the object. If your component or the 3rd party component that you use
is so compled that the translator can not translate it automatically, you must
derive a new translator and override this method.
- See Also:
- processObject
checkLayout
protected void checkLayout(Container conteiner)
hostTranslated
protected void hostTranslated()
translateMenu
protected void translateMenu()
- Translates the menu of the host.
translate
public void translate()
- Translates the host container. To call this method you must:
1) open the dictionary if not already open.
2) set the Dictionary property.
3) set the Targets property.
4) set the Host property.
The method translates the host and sets the translator to the dictionary listener.
This makes the translator to translate the host automatically after the dictionary has changed the language.
If you do not want to have the automatic retranslation,
remove this translator from the dictionary event list by calling the
removeLanguageChangeListener method.
setHost
public void setHost(Container value)
- Sets the host container. This is the container that the translator translates.
getHost
public Container getHost()
- Gets the host container.
setUpdateLocale
public void setUpdateLocale(boolean value)
- Sets the update locale property flag.
If this is true the translator changes the Locale property of every component
to match the active locale. Default is false.
getUpdateLocale
public boolean getUpdateLocale()
- Gets the update locale property flag.
setTranslateTextComponents
public void setTranslateTextComponents(boolean value)
- Enables or disables the translation of text components.
If this is true the translator translates the text components
(e.g. TextComponent, TextField and TextArea).
Default is false.
getTranslateTextComponents
public boolean getTranslateTextComponents()
- Gets the state of text component translation.
setDictionary
public void setDictionary(Dictionary value)
- Sets the dictionary. This is the dictionary that the translator uses when translating strings.
getDictionary
public Dictionary getDictionary()
- Gets the dictionary.
targetToString
public static String targetToString(Target target,
boolean longFormat)
- Converts the given target to a string.
The short string format is
[+|-][*|componentType].[*|propertyName]
(e.g. "+*.text").
The long string format is [include |exclude ][*|componentType].[*|propertyName]
(e.g. "include *.text").
stringToTarget
public static Target stringToTarget(String str)
- Converts the given string to a target.
The string format must be
[+|-][*|componentType].[*|propertyName]
(e.g. "+*.text").
getTargets
public String getTargets()
- Gets the targets in a single string.
- See Also:
- getTargets, getTargetsArray
setTargets
public void setTargets(String str)
- Sets the targets.
- See Also:
- setTargets, setTargets
setTargets
public void setTargets(int index,
Target target)
- Sets an individual target.
- See Also:
- setTargets, setTargets
getTargets
public Target getTargets(int index)
- Gets an individual target.
- See Also:
- getTargets, getTargetsArray, getTargetsCount
setTargets
public void setTargets(Target targets[])
- Sets the targets.
The target list determines what components and properties the translator should translate.
There can be as many targets as it takes to cover the translation of every component.
- See Also:
- setTargets, setTargets, addTarget
getTargetsArray
public Target[] getTargetsArray()
- Gets the targets.
- See Also:
- getTargets, getTargets
getTargetCount
public int getTargetCount()
- Gets the target count.
- See Also:
- addTarget
addTarget
public void addTarget(Target target)
- Adds a new target to the target list.
- See Also:
- setTargets, removeTarget, removeTarget
removeTarget
public void removeTarget(int index)
- Removes a target form the target list.
- See Also:
- addTarget
removeTarget
public void removeTarget(Target target)
- Removes a target form the target list.
- See Also:
- addTarget
addDefaultTargets
public void addDefaultTargets()
- Adds the most common targets propeties.
- See Also:
- addTarget, setTargets
languageChanged
public void languageChanged(DictionaryEventObject event)
- The dictionary calls this method after either language or locale has been changed.
The translator retranslates itself.
addBeforeTranslateListener
public synchronized void addBeforeTranslateListener(BeforeTranslateListener l)
- Adds the specified before translate listener to receive before translate events from this translator.
removeBeforeTranslateListener
public synchronized void removeBeforeTranslateListener(BeforeTranslateListener l)
- Removes the before translate listener so it no longer receives before translate events from this translator.
addAfterTranslateListener
public synchronized void addAfterTranslateListener(AfterTranslateListener l)
- Adds the specified after translate listener to receive after translate events from this translator.
removeAfterTranslateListener
public synchronized void removeAfterTranslateListener(AfterTranslateListener l)
- Removes the after translate listener so it no longer receives after translate events from this translator.
addTranslateObjectListener
public synchronized void addTranslateObjectListener(TranslateObjectListener l)
- Adds the specified object translate listener to receive after translate events from this translator.
removeTranslateObjectListener
public synchronized void removeTranslateObjectListener(TranslateObjectListener l)
- Removes the object translate listener so it no longer receives after translate events from this translator.
addRestrictObjectListener
public synchronized void addRestrictObjectListener(RestrictObjectListener l)
- Adds the specified restrict object listener to receive object restriction events from this translator.
removeRestrictObjectListener
public synchronized void removeRestrictObjectListener(RestrictObjectListener l)
- Removes the restrict object listener so it no longer receives object restriction events from this translator.
addRestrictPropertyListener
public synchronized void addRestrictPropertyListener(RestrictPropertyListener l)
- Adds the specified restrict property listener to receive property restriction events from this translator.
removeRestrictPropertyListener
public synchronized void removeRestrictPropertyListener(RestrictPropertyListener l)
- Removes the restrict property listener so it no longer receives property restriction events from this translator.
All Packages Class Hierarchy This Package Previous Next Index