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

Constructor Index

 o Translator()
Constructs a new transtor.
 o Translator(Dictionary)
Constructs a new transtor with the specified dictionary.

Method Index

 o addAfterTranslateListener(AfterTranslateListener)
Adds the specified after translate listener to receive after translate events from this translator.
 o addBeforeTranslateListener(BeforeTranslateListener)
Adds the specified before translate listener to receive before translate events from this translator.
 o addDefaultTargets()
Adds the most common targets propeties.
 o addRestrictObjectListener(RestrictObjectListener)
Adds the specified restrict object listener to receive object restriction events from this translator.
 o addRestrictPropertyListener(RestrictPropertyListener)
Adds the specified restrict property listener to receive property restriction events from this translator.
 o addTarget(Target)
Adds a new target to the target list.
 o addTranslateObjectListener(TranslateObjectListener)
Adds the specified object translate listener to receive after translate events from this translator.
 o checkLayout(Container)
 o dispose()
Disposes the translator.
 o doTranslateString(Object, String, String)
Gets the translates for the property of the given object.
 o finalize()
Disposes of this translator once it is no longer referenced.
 o getDictionary()
Gets the dictionary.
 o getHost()
Gets the host container.
 o getTargetCount()
Gets the target count.
 o getTargets()
Gets the targets in a single string.
 o getTargets(int)
Gets an individual target.
 o getTargetsArray()
Gets the targets.
 o getTranslateTextComponents()
Gets the state of text component translation.
 o getTranslation(int)
Gets the translation.
 o getUpdateLocale()
Gets the update locale property flag.
 o hostTranslated()
 o languageChanged(DictionaryEventObject)
The dictionary calls this method after either language or locale has been changed.
 o processObject(Object)
Checks if the translation of an object is restricted.
 o removeAfterTranslateListener(AfterTranslateListener)
Removes the after translate listener so it no longer receives after translate events from this translator.
 o removeBeforeTranslateListener(BeforeTranslateListener)
Removes the before translate listener so it no longer receives before translate events from this translator.
 o removeRestrictObjectListener(RestrictObjectListener)
Removes the restrict object listener so it no longer receives object restriction events from this translator.
 o removeRestrictPropertyListener(RestrictPropertyListener)
Removes the restrict property listener so it no longer receives property restriction events from this translator.
 o removeTarget(int)
Removes a target form the target list.
 o removeTarget(Target)
Removes a target form the target list.
 o removeTranslateObjectListener(TranslateObjectListener)
Removes the object translate listener so it no longer receives after translate events from this translator.
 o setDictionary(Dictionary)
Sets the dictionary.
 o setHost(Container)
Sets the host container.
 o setTargets(int, Target)
Sets an individual target.
 o setTargets(String)
Sets the targets.
 o setTargets(Target[])
Sets the targets.
 o setTranslateTextComponents(boolean)
Enables or disables the translation of text components.
 o setUpdateLocale(boolean)
Sets the update locale property flag.
 o stringToTarget(String)
Converts the given string to a target.
 o targetToString(Target, boolean)
Converts the given target to a string.
 o translate()
Translates the host container.
 o translateMenu()
Translates the menu of the host.
 o translateObject(Object)
Translate the object.
 o translateProperty(Object, PropertyDescriptor, int)
Translates the property of the bean.

Constructors

 o Translator
 public Translator()
Constructs a new transtor.

 o Translator
 public Translator(Dictionary dictionary)
Constructs a new transtor with the specified dictionary.

Parameters:
dictionary - the dictionary for the translator

Methods

 o 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
 o finalize
 protected void finalize()
Disposes of this translator once it is no longer referenced.

Overrides:
finalize in class Object
See Also:
dispose
 o getTranslation
 protected TranslatorTranslation getTranslation(int index)
Gets the translation.

 o 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
 o translateProperty
 protected void translateProperty(Object object,
                                  PropertyDescriptor property,
                                  int type)
Translates the property of the bean.

 o 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
 o 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
 o checkLayout
 protected void checkLayout(Container conteiner)
 o hostTranslated
 protected void hostTranslated()
 o translateMenu
 protected void translateMenu()
Translates the menu of the host.

 o 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.

 o setHost
 public void setHost(Container value)
Sets the host container. This is the container that the translator translates.

 o getHost
 public Container getHost()
Gets the host container.

 o 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.

 o getUpdateLocale
 public boolean getUpdateLocale()
Gets the update locale property flag.

 o 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.

 o getTranslateTextComponents
 public boolean getTranslateTextComponents()
Gets the state of text component translation.

 o setDictionary
 public void setDictionary(Dictionary value)
Sets the dictionary. This is the dictionary that the translator uses when translating strings.

 o getDictionary
 public Dictionary getDictionary()
Gets the dictionary.

 o 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").

 o stringToTarget
 public static Target stringToTarget(String str)
Converts the given string to a target. The string format must be [+|-][*|componentType].[*|propertyName] (e.g. "+*.text").

 o getTargets
 public String getTargets()
Gets the targets in a single string.

See Also:
getTargets, getTargetsArray
 o setTargets
 public void setTargets(String str)
Sets the targets.

See Also:
setTargets, setTargets
 o setTargets
 public void setTargets(int index,
                        Target target)
Sets an individual target.

See Also:
setTargets, setTargets
 o getTargets
 public Target getTargets(int index)
Gets an individual target.

See Also:
getTargets, getTargetsArray, getTargetsCount
 o 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
 o getTargetsArray
 public Target[] getTargetsArray()
Gets the targets.

See Also:
getTargets, getTargets
 o getTargetCount
 public int getTargetCount()
Gets the target count.

See Also:
addTarget
 o addTarget
 public void addTarget(Target target)
Adds a new target to the target list.

See Also:
setTargets, removeTarget, removeTarget
 o removeTarget
 public void removeTarget(int index)
Removes a target form the target list.

See Also:
addTarget
 o removeTarget
 public void removeTarget(Target target)
Removes a target form the target list.

See Also:
addTarget
 o addDefaultTargets
 public void addDefaultTargets()
Adds the most common targets propeties.

See Also:
addTarget, setTargets
 o languageChanged
 public void languageChanged(DictionaryEventObject event)
The dictionary calls this method after either language or locale has been changed. The translator retranslates itself.

 o addBeforeTranslateListener
 public synchronized void addBeforeTranslateListener(BeforeTranslateListener l)
Adds the specified before translate listener to receive before translate events from this translator.

 o removeBeforeTranslateListener
 public synchronized void removeBeforeTranslateListener(BeforeTranslateListener l)
Removes the before translate listener so it no longer receives before translate events from this translator.

 o addAfterTranslateListener
 public synchronized void addAfterTranslateListener(AfterTranslateListener l)
Adds the specified after translate listener to receive after translate events from this translator.

 o removeAfterTranslateListener
 public synchronized void removeAfterTranslateListener(AfterTranslateListener l)
Removes the after translate listener so it no longer receives after translate events from this translator.

 o addTranslateObjectListener
 public synchronized void addTranslateObjectListener(TranslateObjectListener l)
Adds the specified object translate listener to receive after translate events from this translator.

 o removeTranslateObjectListener
 public synchronized void removeTranslateObjectListener(TranslateObjectListener l)
Removes the object translate listener so it no longer receives after translate events from this translator.

 o addRestrictObjectListener
 public synchronized void addRestrictObjectListener(RestrictObjectListener l)
Adds the specified restrict object listener to receive object restriction events from this translator.

 o removeRestrictObjectListener
 public synchronized void removeRestrictObjectListener(RestrictObjectListener l)
Removes the restrict object listener so it no longer receives object restriction events from this translator.

 o addRestrictPropertyListener
 public synchronized void addRestrictPropertyListener(RestrictPropertyListener l)
Adds the specified restrict property listener to receive property restriction events from this translator.

 o 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