com.alee.managers.language
Class LanguageManager

java.lang.Object
  extended by com.alee.managers.language.LanguageManager
All Implemented Interfaces:
LanguageConstants

public final class LanguageManager
extends java.lang.Object
implements LanguageConstants

This manager allows you to quickly setup changeable lanugage onto different components and to listen to application-wide language change events. Language could be either loaded from structured xml files or added directly from the application by adding Dictionary type objects into this manager.

Be aware of the fact that all equal key-language pairs will be merged and collected into a global data map. The original list of dictionaries will be preserved and will not be modified, but all translation will be taken from global data map.

Author:
Mikle Garin
See Also:
How to use LanguageManager

Field Summary
static java.lang.String DEFAULT
          Default WebLaF language.
static javax.swing.ImageIcon other
          Unknown language icon.
 
Fields inherited from interface com.alee.managers.language.LanguageConstants
ARABIC, ENGLISH, FRENCH, GERMAN, POLISH, PORTUGUESE, RUSSIAN, SPANISH
 
Constructor Summary
LanguageManager()
           
 
Method Summary
static Dictionary addDictionary(java.lang.Class nearClass, java.lang.String resource)
          Adds new language dictionary into LanguageManager.
static Dictionary addDictionary(Dictionary dictionary)
          Adds new language dictionary into LanguageManager.
static Dictionary addDictionary(java.io.File file)
          Adds new language dictionary into LanguageManager.
static Dictionary addDictionary(java.lang.String path)
          Adds new language dictionary into LanguageManager.
static Dictionary addDictionary(java.net.URL url)
          Adds new language dictionary into LanguageManager.
static void addLanguageKeyListener(java.lang.String key, LanguageKeyListener listener)
           
static void addLanguageListener(LanguageListener listener)
           
static void addSupportedLanguage(java.lang.String language)
           
static void addSupportedLanguage(java.lang.String language, Dictionary dictionary)
           
static void changeOrientation()
           
static void clearDictionaries()
          Removes all added dictionaries including WebLaF ones.
static void clearSupportedLanguages()
           
static java.lang.String combineWithContainerKeys(java.awt.Component component, java.lang.String key)
          Language container methods
static java.lang.String get(java.awt.Component component, java.lang.String key)
          Component value request methods
static java.lang.String get(java.lang.String key)
          Value request methods
static java.lang.String getComponentKey(java.awt.Component component)
           
static java.lang.String getDefaultLanguageKey()
          Default system language key
static TooltipType getDefaultTooltipType()
          Default tooltip type
static java.util.List<Dictionary> getDictionaries()
          Loaded dictionaries
static Dictionary getDictionary(java.lang.String id)
          Returns dictionary for the specified ID or null if it was not found.
static Dictionary getGlobalDictionary()
          Global dictionary that aggregates all added dictionaries, records and values
static java.lang.String getLanguage()
          Language methods
static java.lang.String getLanguageContainerKey(java.awt.Container container)
           
static javax.swing.ImageIcon getLanguageIcon(java.lang.String language)
          Language icon
static java.util.Map<java.lang.String,java.util.List<LanguageKeyListener>> getLanguageKeyListeners()
          Language key listeners operations
static java.util.List<LanguageListener> getLanguageListeners()
          Language listeners operations
static LanguageUpdater getLanguageUpdater(java.awt.Component component)
           
static java.lang.Character getMnemonic(java.awt.Component component, java.lang.String key)
           
static java.lang.Character getMnemonic(java.lang.String key)
           
static Value getNotNullValue(java.awt.Component component, java.lang.String key)
           
static Value getNotNullValue(java.awt.Component component, java.lang.String key, java.lang.String additionalKey)
           
static Value getNotNullValue(java.lang.String key)
           
static java.awt.ComponentOrientation getOppositeOrientation()
          Returns orientation opposite to current global component orientation.
static java.awt.ComponentOrientation getOrientation()
           
static java.util.List<java.lang.String> getSupportedLanguages()
          Supported languages
static java.util.List<java.lang.String> getSupportedLanguages(Dictionary dictionary)
          Returns list of languages supported by the specified dictionary.
static java.util.List<java.lang.String> getSupportedLanguages(java.lang.String dictionaryId)
          Returns list of languages supported by the dictionary with the specified ID.
static java.lang.String getSystemLanguageKey()
           
static Value getValue(java.awt.Component component, java.lang.String key)
           
static Value getValue(java.awt.Component component, java.lang.String key, java.lang.String additionalKey)
           
static Value getValue(java.lang.String key)
           
static void initialize()
          Initializes LanguageManager settings.
static boolean isCurrentLanguage(java.lang.String language)
           
static boolean isDictionaryAdded(Dictionary dictionary)
          Returns whether specified dictionary is added or not.
static boolean isDictionaryAdded(java.lang.String id)
          Returns whether dictionary with the specified ID is added or not.
static boolean isLeftToRight()
          Global default orientation
static boolean isRegisteredComponent(java.awt.Component component)
           
static void loadDefaultDictionary()
          Loads default WebLaF dictionary.
static Dictionary loadDictionary(java.lang.Class nearClass, java.lang.String resource)
          Loads dictionary from xml
static Dictionary loadDictionary(java.io.File file)
           
static Dictionary loadDictionary(java.lang.String path)
           
static Dictionary loadDictionary(java.net.URL url)
           
static void registerComponent(java.awt.Component component, java.lang.String key, java.lang.Object... data)
          Components registration
static void registerLanguageContainer(java.awt.Container container, java.lang.String key)
           
static void registerLanguageUpdater(java.awt.Component component, LanguageUpdater updater)
           
static void registerLanguageUpdater(LanguageUpdater updater)
          Components language updaters registration
static Dictionary removeDictionary(Dictionary dictionary)
          Removes dictionary from LanguageManager.
static Dictionary removeDictionary(java.lang.String id)
          Removes dictionary from LanguageManager.
static void removeLanguageKeyListener(LanguageKeyListener listener)
           
static void removeLanguageKeyListeners(java.lang.String key)
           
static void removeLanguageListener(LanguageListener listener)
           
static void removeSupportedLanguage(java.lang.String language)
           
static void setDefaultTooltipType(TooltipType defaultTooltipType)
           
static void setLanguage(java.lang.String language)
           
static javax.swing.ImageIcon setLanguageIcon(java.lang.String language, javax.swing.ImageIcon icon)
          Sets icon for the specified language.
static void setOrientation(boolean leftToRight)
           
static void setOrientation(java.awt.ComponentOrientation orientation)
           
static void setSupportedLanguages(java.util.Collection<java.lang.String> supportedLanguages)
           
static void setSupportedLanguages(java.lang.String... supportedLanguages)
           
static void unregisterComponent(java.awt.Component component)
           
static void unregisterLanguageContainer(java.awt.Container container)
           
static void unregisterLanguageUpdater(java.awt.Component component)
           
static void unregisterLanguageUpdater(LanguageUpdater updater)
           
static void updateAllComponents()
          Components language update methods
static void updateAllComponents(java.util.List<java.lang.String> keys)
           
static void updateComponent(java.awt.Component component, java.lang.Object... data)
           
static void updateComponent(java.awt.Component component, java.lang.String key, java.lang.Object... data)
           
static void updateComponentsTree(java.awt.Component component)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

other

public static final javax.swing.ImageIcon other
Unknown language icon.


DEFAULT

public static java.lang.String DEFAULT
Default WebLaF language. You can set different value here before initializing WebLaF to decrease amount of UI updates. If possible default language is taken from system properties.

Constructor Detail

LanguageManager

public LanguageManager()
Method Detail

initialize

public static void initialize()
Initializes LanguageManager settings.


loadDefaultDictionary

public static void loadDefaultDictionary()
Loads default WebLaF dictionary.


getSupportedLanguages

public static java.util.List<java.lang.String> getSupportedLanguages()
Supported languages


setSupportedLanguages

public static void setSupportedLanguages(java.util.Collection<java.lang.String> supportedLanguages)

setSupportedLanguages

public static void setSupportedLanguages(java.lang.String... supportedLanguages)

addSupportedLanguage

public static void addSupportedLanguage(java.lang.String language)

addSupportedLanguage

public static void addSupportedLanguage(java.lang.String language,
                                        Dictionary dictionary)

removeSupportedLanguage

public static void removeSupportedLanguage(java.lang.String language)

clearSupportedLanguages

public static void clearSupportedLanguages()

registerComponent

public static void registerComponent(java.awt.Component component,
                                     java.lang.String key,
                                     java.lang.Object... data)
Components registration


updateComponentsTree

public static void updateComponentsTree(java.awt.Component component)

unregisterComponent

public static void unregisterComponent(java.awt.Component component)

isRegisteredComponent

public static boolean isRegisteredComponent(java.awt.Component component)

getComponentKey

public static java.lang.String getComponentKey(java.awt.Component component)

registerLanguageUpdater

public static void registerLanguageUpdater(LanguageUpdater updater)
Components language updaters registration


unregisterLanguageUpdater

public static void unregisterLanguageUpdater(LanguageUpdater updater)

registerLanguageUpdater

public static void registerLanguageUpdater(java.awt.Component component,
                                           LanguageUpdater updater)

unregisterLanguageUpdater

public static void unregisterLanguageUpdater(java.awt.Component component)

getLanguageUpdater

public static LanguageUpdater getLanguageUpdater(java.awt.Component component)

updateAllComponents

public static void updateAllComponents()
Components language update methods


updateAllComponents

public static void updateAllComponents(java.util.List<java.lang.String> keys)

updateComponent

public static void updateComponent(java.awt.Component component,
                                   java.lang.Object... data)

updateComponent

public static void updateComponent(java.awt.Component component,
                                   java.lang.String key,
                                   java.lang.Object... data)

getLanguageIcon

public static javax.swing.ImageIcon getLanguageIcon(java.lang.String language)
Language icon


setLanguageIcon

public static javax.swing.ImageIcon setLanguageIcon(java.lang.String language,
                                                    javax.swing.ImageIcon icon)
Sets icon for the specified language.

Parameters:
language - language to set icon for
icon - language icon
Returns:
icon previously set for this language

getDefaultTooltipType

public static TooltipType getDefaultTooltipType()
Default tooltip type


setDefaultTooltipType

public static void setDefaultTooltipType(TooltipType defaultTooltipType)

getLanguage

public static java.lang.String getLanguage()
Language methods


isCurrentLanguage

public static boolean isCurrentLanguage(java.lang.String language)

setLanguage

public static void setLanguage(java.lang.String language)

isLeftToRight

public static boolean isLeftToRight()
Global default orientation


getOrientation

public static java.awt.ComponentOrientation getOrientation()

getOppositeOrientation

public static java.awt.ComponentOrientation getOppositeOrientation()
Returns orientation opposite to current global component orientation.

Returns:
orientation opposite to current global component orientation

setOrientation

public static void setOrientation(boolean leftToRight)

setOrientation

public static void setOrientation(java.awt.ComponentOrientation orientation)

changeOrientation

public static void changeOrientation()

getGlobalDictionary

public static Dictionary getGlobalDictionary()
Global dictionary that aggregates all added dictionaries, records and values


getDictionaries

public static java.util.List<Dictionary> getDictionaries()
Loaded dictionaries


loadDictionary

public static Dictionary loadDictionary(java.lang.Class nearClass,
                                        java.lang.String resource)
Loads dictionary from xml


loadDictionary

public static Dictionary loadDictionary(java.net.URL url)

loadDictionary

public static Dictionary loadDictionary(java.lang.String path)

loadDictionary

public static Dictionary loadDictionary(java.io.File file)

addDictionary

public static Dictionary addDictionary(java.lang.Class nearClass,
                                       java.lang.String resource)
Adds new language dictionary into LanguageManager. This method call may cause a lot of UI updates depending on amount of translations contained. If added dictionary contains records with existing keys they will override previously added ones.

Parameters:
nearClass - class to look near for the dictionary file
resource - path to dictionary file
Returns:
newly added dictionary

addDictionary

public static Dictionary addDictionary(java.net.URL url)
Adds new language dictionary into LanguageManager. This method call may cause a lot of UI updates depending on amount of translations contained. If added dictionary contains records with existing keys they will override previously added ones.

Parameters:
url - dictionary file url
Returns:
newly added dictionary

addDictionary

public static Dictionary addDictionary(java.lang.String path)
Adds new language dictionary into LanguageManager. This method call may cause a lot of UI updates depending on amount of translations contained. If added dictionary contains records with existing keys they will override previously added ones.

Parameters:
path - path to dictionary file
Returns:
newly added dictionary

addDictionary

public static Dictionary addDictionary(java.io.File file)
Adds new language dictionary into LanguageManager. This method call may cause a lot of UI updates depending on amount of translations contained. If added dictionary contains records with existing keys they will override previously added ones.

Parameters:
file - dictionary file
Returns:
newly added dictionary

addDictionary

public static Dictionary addDictionary(Dictionary dictionary)
Adds new language dictionary into LanguageManager. This method call may cause a lot of UI updates depending on amount of translations contained. If added dictionary contains records with existing keys they will override previously added ones.

Parameters:
dictionary - dictionary to add
Returns:
newly added dictionary

removeDictionary

public static Dictionary removeDictionary(java.lang.String id)
Removes dictionary from LanguageManager. This method call may cause a lot of UI updates depending on amount of translations contained.

Parameters:
id - ID of the dictionary to remove
Returns:
removed dictionary

removeDictionary

public static Dictionary removeDictionary(Dictionary dictionary)
Removes dictionary from LanguageManager. This method call may cause a lot of UI updates depending on amount of translations contained.

Parameters:
dictionary - dictionary to remove
Returns:
removed dictionary

isDictionaryAdded

public static boolean isDictionaryAdded(Dictionary dictionary)
Returns whether specified dictionary is added or not.

Parameters:
dictionary - dictionary to look for
Returns:
true if dictionary is added, false otherwise

isDictionaryAdded

public static boolean isDictionaryAdded(java.lang.String id)
Returns whether dictionary with the specified ID is added or not.

Parameters:
id - ID of the dictionary to look for
Returns:
true if dictionary is added, false otherwise

getDictionary

public static Dictionary getDictionary(java.lang.String id)
Returns dictionary for the specified ID or null if it was not found.

Parameters:
id - ID of the dictionary to look for
Returns:
dictionary for the specified ID or null if it was not found

clearDictionaries

public static void clearDictionaries()
Removes all added dictionaries including WebLaF ones. You can always restore WebLaF dictionary by calling loadDefaultDictionary () method in LanguageManager.

See Also:
loadDefaultDictionary()

getSupportedLanguages

public static java.util.List<java.lang.String> getSupportedLanguages(java.lang.String dictionaryId)
Returns list of languages supported by the dictionary with the specified ID.

Parameters:
dictionaryId - dictionary ID
Returns:
list of languages supported by the dictionary with the specified ID

getSupportedLanguages

public static java.util.List<java.lang.String> getSupportedLanguages(Dictionary dictionary)
Returns list of languages supported by the specified dictionary.

Parameters:
dictionary - dictionary
Returns:
list of languages supported by the specified dictionary

get

public static java.lang.String get(java.lang.String key)
Value request methods


getMnemonic

public static java.lang.Character getMnemonic(java.lang.String key)

getValue

public static Value getValue(java.lang.String key)

getNotNullValue

public static Value getNotNullValue(java.lang.String key)

get

public static java.lang.String get(java.awt.Component component,
                                   java.lang.String key)
Component value request methods


getMnemonic

public static java.lang.Character getMnemonic(java.awt.Component component,
                                              java.lang.String key)

getValue

public static Value getValue(java.awt.Component component,
                             java.lang.String key)

getNotNullValue

public static Value getNotNullValue(java.awt.Component component,
                                    java.lang.String key)

getValue

public static Value getValue(java.awt.Component component,
                             java.lang.String key,
                             java.lang.String additionalKey)

getNotNullValue

public static Value getNotNullValue(java.awt.Component component,
                                    java.lang.String key,
                                    java.lang.String additionalKey)

combineWithContainerKeys

public static java.lang.String combineWithContainerKeys(java.awt.Component component,
                                                        java.lang.String key)
Language container methods


registerLanguageContainer

public static void registerLanguageContainer(java.awt.Container container,
                                             java.lang.String key)

unregisterLanguageContainer

public static void unregisterLanguageContainer(java.awt.Container container)

getLanguageContainerKey

public static java.lang.String getLanguageContainerKey(java.awt.Container container)

getDefaultLanguageKey

public static java.lang.String getDefaultLanguageKey()
Default system language key


getSystemLanguageKey

public static java.lang.String getSystemLanguageKey()

getLanguageListeners

public static java.util.List<LanguageListener> getLanguageListeners()
Language listeners operations


addLanguageListener

public static void addLanguageListener(LanguageListener listener)

removeLanguageListener

public static void removeLanguageListener(LanguageListener listener)

getLanguageKeyListeners

public static java.util.Map<java.lang.String,java.util.List<LanguageKeyListener>> getLanguageKeyListeners()
Language key listeners operations


addLanguageKeyListener

public static void addLanguageKeyListener(java.lang.String key,
                                          LanguageKeyListener listener)

removeLanguageKeyListener

public static void removeLanguageKeyListener(LanguageKeyListener listener)

removeLanguageKeyListeners

public static void removeLanguageKeyListeners(java.lang.String key)