com.alee.managers.language
Class LanguageManager

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

public 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
protected static boolean checkComponentsTextForTranslations
          Whether or not components should check that text passed into their constructors is a translation key or not.
static java.lang.String COMPONENT_LANGUAGE_LISTENER_KEY
           
static java.lang.String COMPONENT_UPDATER_KEY
          Keys used to store custom data in JComponent.
protected static java.util.Map<java.awt.Component,java.lang.String> componentKeysCache
          Calculated components cache map.
protected static java.util.Map<javax.swing.JComponent,java.lang.ref.WeakReference<LanguageListener>> componentLanguageListeners
          Language changes listeners.
protected static java.util.Map<javax.swing.JComponent,java.lang.String> components
          Components registered for auto-translation.
protected static java.util.Map<javax.swing.JComponent,java.lang.Object[]> componentsData
          Object data provided with component language key.
protected static java.util.Map<java.awt.Component,javax.swing.event.AncestorListener> componentsListeners
          Components ancestor listeners used to update component keys cache.
protected static java.lang.Object componentsLock
          Component operations synchronization object.
protected static java.util.Map<javax.swing.JComponent,java.lang.ref.WeakReference<LanguageUpdater>> customUpdaters
          Component-specific language updaters.
protected static java.lang.String DEFAULT
          Default WebLaF language.
protected static TooltipType defaultTooltipType
          Default tooltip type used to display tooltips provided inside language files.
protected static java.util.List<Dictionary> dictionaries
          List of all added dictionaries.
protected static java.util.Map<java.lang.String,Dictionary> dictionariesCache
          All dictionaries cached by their special source ID.
protected static java.util.Map<java.lang.String,Value> globalCache
          Global values map that contains merged translations for currently selected language.
protected static Dictionary globalDictionary
          Global dictionary merged from all added dictionaries.
protected static boolean initialized
          Manager initialization mark.
protected static java.lang.String language
          Currently used language.
protected static java.util.Map<java.awt.Container,java.lang.String> languageContainers
          Registered language containers.
protected static java.lang.Object languageContainersLock
          Language container operations synchronization object.
protected static java.util.Map<java.lang.String,javax.swing.ImageIcon> languageIcons
          Language icons.
protected static java.util.Map<java.lang.String,java.util.List<LanguageKeyListener>> languageKeyListeners
          Language key changes listeners.
protected static java.lang.Object languageKeyListenersLock
          Language key listeners operations synchronization object.
protected static java.util.List<LanguageListener> languageListeners
          Language changes listeners.
protected static java.lang.Object languageListenersLock
          Language listeners operations synchronization object.
protected static LanguageUpdaterComparator languageUpdaterComparator
          Special comparator for sorting LanguageUpdaters list.
static javax.swing.ImageIcon other
          Unknown language icon.
protected static java.util.List<java.lang.String> supportedLanguages
          Predefined list of languages supported by WebLaF.
protected static java.lang.Object supportedLanguagesLock
          Supported languages operations synchronization object.
protected static TooltipLanguageSupport tooltipLanguageSupport
          Currrent tooltip support.
protected static java.util.List<LanguageUpdater> updaters
          Registered language updaters.
protected static java.util.Map<java.lang.Class,LanguageUpdater> updatersCache
          Language updaters cache by specific class types.
protected static java.lang.Object updatersLock
          LanguageUpdater operations synchronization object.
 
Fields inherited from interface com.alee.managers.language.LanguageConstants
ARABIC, ENGLISH, FRENCH, GERMAN, ITALIAN, POLISH, PORTUGUESE, RUSSIAN, SPANISH, TURKISH
 
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.lang.String cacheKey, Dictionary dictionary)
          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)
          Adds language key listener.
static void addLanguageListener(javax.swing.JComponent component, LanguageListener listener)
          Adds language listener for the specified component.
static void addLanguageListener(LanguageListener listener)
          Adds new language listener.
static void addSupportedLanguage(java.lang.String language)
          Adds supported language.
static void addSupportedLanguage(java.lang.String language, Dictionary dictionary)
          Adds supported language and new dictionary.
protected static void clearCache()
          Clears global dictionaries cache.
static void clearDictionaries()
          Removes all added dictionaries including WebLaF ones.
static void clearSupportedLanguages()
          Clears list of supported languages.
static java.lang.String combineWithContainerKeys(javax.swing.JComponent component, java.lang.String key)
          Returns component language key combined with its containers keys.
protected static java.lang.String combineWithContainerKeysImpl(javax.swing.JComponent component, java.lang.String key)
          Returns component language key combined with its containers keys.
static boolean contains(java.lang.String key)
          Returns whether specified language key exists or not.
protected static void fireAllLanguageKeysUpdated()
          Fires language key updated event for all language keys.
protected static void fireDictionariesCleared()
          Fires dictionaries cleared event whenever all dictionaries are removed from LanguageManager.
protected static void fireDictionaryAdded(Dictionary dictionary)
          Fires dictionary added event whenever new dictionary is added into LanguageManager.
protected static void fireDictionaryRemoved(Dictionary dictionary)
          Fires dictionary removed event whenever dictionary is removed from LanguageManager.
protected static void fireLanguageChanged(java.lang.String oldLang, java.lang.String newLang)
          Fires language changed event whenever current language changes.
protected static void fireLanguageKeyUpdated(java.lang.String key)
          Fires language key updated event whenever specified dictionary key is updated with new translation.
static java.lang.String get(javax.swing.JComponent component, java.lang.String key)
          Returns component translation.
static java.lang.String get(java.lang.String key)
          Returns translation for the specified language key.
static java.lang.String get(java.lang.String key, java.lang.Object... data)
          Returns translation for the specified language key.
static java.lang.String getComponentKey(javax.swing.JComponent component)
          Returns component language key.
static java.util.Map<java.awt.Component,LanguageListener> getComponentLanguageListeners()
          Returns component language listeners.
static java.lang.String getDefaultLanguage()
          Returns default language.
static java.lang.String getDefaultLanguageKey()
          Returns default language key.
static TooltipType getDefaultTooltipType()
          Returns default tooltip type.
static java.util.List<Dictionary> getDictionaries()
          Returns all dictionaries added into LanguageManager.
static Dictionary getDictionary(java.lang.String id)
          Returns dictionary for the specified ID or null if it was not found.
static java.lang.String getDictionaryCacheKey(java.lang.Class nearClass, java.lang.String resource)
          Returns dictionary cache key.
static java.lang.String getDictionaryCacheKey(java.io.File file)
          Returns dictionary cache key.
static java.lang.String getDictionaryCacheKey(java.lang.String path)
          Returns dictionary cache key.
static java.lang.String getDictionaryCacheKey(java.net.URL url)
          Returns dictionary cache key.
static Dictionary getGlobalDictionary()
          Returns global dictionary that aggregates all added dictionaries.
static java.lang.String getLanguage()
          Returns currently used language.
static java.lang.String getLanguageContainerKey(java.awt.Container container)
          Returns language container key for the specified container.
static javax.swing.ImageIcon getLanguageIcon(java.lang.String language)
          Returns icon for the specified language.
static java.util.Map<java.lang.String,java.util.List<LanguageKeyListener>> getLanguageKeyListeners()
          Returns language key listeners.
static java.util.List<LanguageListener> getLanguageListeners()
          Returns language listeners.
static java.lang.String getLanguageTitle(java.lang.String language)
          Returns language title in that language translation.
static LanguageUpdater getLanguageUpdater(javax.swing.JComponent component)
          Returns LanguageUpdater currently used for the specified component.
static java.util.Locale getLocale(java.lang.String language)
          Returns Locale for the specified language.
static java.lang.Character getMnemonic(javax.swing.JComponent component, java.lang.String key)
          Returns component mnemonic.
static java.lang.Character getMnemonic(java.lang.String key)
          Returns mnemonic for the specified language key.
static Value getNotNullValue(javax.swing.JComponent component, java.lang.String key)
          Returns non-null component language value.
static Value getNotNullValue(javax.swing.JComponent component, java.lang.String key, java.lang.String additionalKey)
          Returns non-null component language value.
static Value getNotNullValue(java.lang.String key)
          Returns non-null value for the specified language key.
static java.util.List<java.lang.String> getSupportedLanguages()
          Returns list of currently 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()
          Returns system language key.
static TooltipLanguageSupport getTooltipLanguageSupport()
          Returns current tooltip language support.
static Value getValue(javax.swing.JComponent component, java.lang.String key)
          Returns component language value.
static Value getValue(javax.swing.JComponent component, java.lang.String key, java.lang.String additionalKey)
          Returns component language value.
static Value getValue(java.lang.String key)
          Returns value for the specified language key.
static void initialize()
          Initializes LanguageManager settings.
static boolean isCheckComponentsTextForTranslations()
          Returns whether or not components should check that text passed into their constructors is a translation key or not.
static boolean isCurrentLanguage(java.lang.String language)
          Returns whether the specified language is currently used or not.
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 isRegisteredComponent(javax.swing.JComponent component)
          Returns whether component is registered for language updates or not.
static void loadDefaultDictionary()
          Loads default WebLaF dictionary.
static Dictionary loadDictionary(java.lang.Class nearClass, java.lang.String resource)
          Returns dictionary loaded from the specified location near class.
static Dictionary loadDictionary(java.io.File file)
          Returns dictionary loaded from the specified file.
static Dictionary loadDictionary(java.lang.String path)
          Returns dictionary loaded from the specified file path.
static Dictionary loadDictionary(java.net.URL url)
          Returns dictionary loaded from the specified URL.
static java.lang.Object[] parseData(java.lang.Object... data)
          Returns language data transformed into its final form.
protected static void rebuildCache()
          Rebuilds global dictionaries cache from a scratch.
static void registerComponent(javax.swing.JComponent component, java.lang.String key, java.lang.Object... data)
          Registers component for language updates.
static void registerLanguageContainer(java.awt.Container container, java.lang.String key)
          Registers language container key.
static void registerLanguageUpdater(javax.swing.JComponent component, LanguageUpdater updater)
          Registers custom LanguageUpdater for specific component.
static void registerLanguageUpdater(LanguageUpdater updater)
          Register custom LanguageUpdater.
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)
          Removes language key listener
static void removeLanguageKeyListeners(java.lang.String key)
          Removes language key listener.
static void removeLanguageListener(javax.swing.JComponent component)
          Removes language listener from the specified component.
static void removeLanguageListener(LanguageListener listener)
          Removes language listener.
static void removeSupportedLanguage(java.lang.String language)
          Removes supported language.
static void setCheckComponentsTextForTranslations(boolean check)
          Sets whether or not components should check that text passed into their constructors is a translation key or not.
static void setDefaultLanguage(java.lang.String lang)
          Sets default language.
static void setDefaultTooltipType(TooltipType defaultTooltipType)
          Sets default tooltip type.
static void setLanguage(java.lang.String language)
          Sets currently used language.
static javax.swing.ImageIcon setLanguageIcon(java.lang.String language, javax.swing.ImageIcon icon)
          Sets icon for the specified language.
static void setSupportedLanguages(java.util.Collection<java.lang.String> supportedLanguages)
          Sets supported languages.
static void setSupportedLanguages(java.lang.String... supportedLanguages)
          Sets supported languages.
static void setTooltipLanguageSupport(TooltipLanguageSupport support)
          Sets tooltip language support.
static void switchLanguage()
          Switches current language to next language in supported languages list.
static void unregisterComponent(javax.swing.JComponent component)
          Unregisters component from language updates.
static void unregisterLanguageContainer(java.awt.Container container)
          Unregisters language container key.
static void unregisterLanguageUpdater(javax.swing.JComponent component)
          Unregisters component's custom LanguageUpdater.
static void unregisterLanguageUpdater(LanguageUpdater updater)
          Unregister custom LanguageUpdater.
protected static void updateCache(Dictionary dictionary)
          Updates global dictionaries cache with the specified dictionary.
protected static void updateCache(java.lang.String prefix, Dictionary dictionary)
          Updates global dictionaries cache with the specified dictionary.
static void updateComponent(javax.swing.JComponent component, java.lang.Object... data)
          Forces component language update.
static void updateComponent(javax.swing.JComponent component, java.lang.String key, java.lang.Object... data)
          Forces component language update.
protected static void updateComponentKey(javax.swing.JComponent component)
          Updates component language key according to its container keys.
static void updateComponents()
          Forces full language update for all registered components.
static void updateComponents(java.util.List<java.lang.String> keys)
          Forces language update for components with the specified keys.
static void updateComponentsTree(javax.swing.JComponent component)
          Updates components tree language keys according to their container keys.
protected static void updateLocale()
          Updates Locale according to currently used language.
 
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.


COMPONENT_UPDATER_KEY

public static final java.lang.String COMPONENT_UPDATER_KEY
Keys used to store custom data in JComponent.

See Also:
Constant Field Values

COMPONENT_LANGUAGE_LISTENER_KEY

public static final java.lang.String COMPONENT_LANGUAGE_LISTENER_KEY
See Also:
Constant Field Values

supportedLanguagesLock

protected static final java.lang.Object supportedLanguagesLock
Supported languages operations synchronization object.


supportedLanguages

protected static final java.util.List<java.lang.String> supportedLanguages
Predefined list of languages supported by WebLaF. You can register additional languages using LanguageManager methods. Make sure you add proper translations for those languages though.

See Also:
getSupportedLanguages(), addSupportedLanguage(String), addSupportedLanguage(String, com.alee.managers.language.data.Dictionary), setSupportedLanguages(java.util.Collection), setSupportedLanguages(String...)

DEFAULT

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

See Also:
setDefaultLanguage(String), getDefaultLanguage()

language

protected static java.lang.String language
Currently used language.

See Also:
getLanguage(), setLanguage(String)

defaultTooltipType

protected static TooltipType defaultTooltipType
Default tooltip type used to display tooltips provided inside language files. If exact tooltip type is not specified inside specific translation this type will be used.

See Also:
getDefaultTooltipType(), setDefaultTooltipType(com.alee.managers.language.data.TooltipType)

languageListenersLock

protected static final java.lang.Object languageListenersLock
Language listeners operations synchronization object.


languageListeners

protected static final java.util.List<LanguageListener> languageListeners
Language changes listeners.

See Also:
LanguageListener, getLanguageListeners(), addLanguageListener(LanguageListener), removeLanguageListener(LanguageListener)

componentLanguageListeners

protected static final java.util.Map<javax.swing.JComponent,java.lang.ref.WeakReference<LanguageListener>> componentLanguageListeners
Language changes listeners.

See Also:
LanguageListener, getLanguageListeners(), addLanguageListener(LanguageListener), removeLanguageListener(LanguageListener)

languageKeyListenersLock

protected static final java.lang.Object languageKeyListenersLock
Language key listeners operations synchronization object.


languageKeyListeners

protected static final java.util.Map<java.lang.String,java.util.List<LanguageKeyListener>> languageKeyListeners
Language key changes listeners. Avoid using a lot of these as they might dramatically reduce application performance.

See Also:
LanguageKeyListener, getLanguageKeyListeners(), addLanguageKeyListener(String, LanguageKeyListener), removeLanguageKeyListener(LanguageKeyListener), removeLanguageKeyListeners(String)

globalDictionary

protected static Dictionary globalDictionary
Global dictionary merged from all added dictionaries. Used to store current dictionaries merge result and as a result improve translations retrieval speed.


globalCache

protected static final java.util.Map<java.lang.String,Value> globalCache
Global values map that contains merged translations for currently selected language. It gets updated on any dictionaries change or global language change.


dictionaries

protected static final java.util.List<Dictionary> dictionaries
List of all added dictionaries.

See Also:
addDictionary(Class, String), addDictionary(com.alee.managers.language.data.Dictionary), addDictionary(java.io.File), addDictionary(String), addDictionary(java.net.URL), removeDictionary(String), removeDictionary(com.alee.managers.language.data.Dictionary), getDictionaries()

dictionariesCache

protected static final java.util.Map<java.lang.String,Dictionary> dictionariesCache
All dictionaries cached by their special source ID. Used to track already added dictionaries and avoid their duplicate versions.


componentsLock

protected static final java.lang.Object componentsLock
Component operations synchronization object.


components

protected static final java.util.Map<javax.swing.JComponent,java.lang.String> components
Components registered for auto-translation. Specific implementations of LanguageUpdater interface used to translate them.

See Also:
registerComponent(javax.swing.JComponent, String, Object...), updateComponent(javax.swing.JComponent, Object...), updateComponent(javax.swing.JComponent, String, Object...), unregisterComponent(javax.swing.JComponent), isRegisteredComponent(javax.swing.JComponent)

componentsData

protected static final java.util.Map<javax.swing.JComponent,java.lang.Object[]> componentsData
Object data provided with component language key. It is used to format the final translation string.

See Also:
registerComponent(javax.swing.JComponent, String, Object...), unregisterComponent(javax.swing.JComponent), updateComponent(javax.swing.JComponent, Object...), updateComponent(javax.swing.JComponent, String, Object...)

componentKeysCache

protected static final java.util.Map<java.awt.Component,java.lang.String> componentKeysCache
Calculated components cache map. It is getting filled and updated automatically when key is requested.

See Also:
updateComponentKey(javax.swing.JComponent)

componentsListeners

protected static final java.util.Map<java.awt.Component,javax.swing.event.AncestorListener> componentsListeners
Components ancestor listeners used to update component keys cache.


languageContainersLock

protected static final java.lang.Object languageContainersLock
Language container operations synchronization object.


languageContainers

protected static final java.util.Map<java.awt.Container,java.lang.String> languageContainers
Registered language containers. Language containers are used to apply language prefix to all container childs with translation. It is used for both manual and automatic translation through language updaters.

See Also:
getLanguageContainerKey(java.awt.Container), registerLanguageContainer(java.awt.Container, String), unregisterLanguageContainer(java.awt.Container), combineWithContainerKeys(javax.swing.JComponent, String)

updatersLock

protected static final java.lang.Object updatersLock
LanguageUpdater operations synchronization object.


languageUpdaterComparator

protected static final LanguageUpdaterComparator languageUpdaterComparator
Special comparator for sorting LanguageUpdaters list.


updaters

protected static final java.util.List<LanguageUpdater> updaters
Registered language updaters. Language updaters are used to automatically update specific components translation when language changes occur.

See Also:
getLanguageUpdater(javax.swing.JComponent), registerLanguageUpdater(com.alee.managers.language.updaters.LanguageUpdater), unregisterLanguageUpdater(com.alee.managers.language.updaters.LanguageUpdater)

customUpdaters

protected static final java.util.Map<javax.swing.JComponent,java.lang.ref.WeakReference<LanguageUpdater>> customUpdaters
Component-specific language updaters. These are used only for the components they are bound to.

See Also:
getLanguageUpdater(javax.swing.JComponent), registerLanguageUpdater(javax.swing.JComponent, com.alee.managers.language.updaters.LanguageUpdater), unregisterLanguageUpdater(javax.swing.JComponent)

updatersCache

protected static final java.util.Map<java.lang.Class,LanguageUpdater> updatersCache
Language updaters cache by specific class types. Used to improve LanguageUpdater retrieval speed for language requests. This cache gets fully updated when any language updater is added or removed.


languageIcons

protected static final java.util.Map<java.lang.String,javax.swing.ImageIcon> languageIcons
Language icons. Supported language icons can be loaded without any effort as they are included in WebLaF library. Custom language icons can be provided from the code using setLanguageIcon(String, javax.swing.ImageIcon) method.

See Also:
setLanguageIcon(String, javax.swing.ImageIcon)

tooltipLanguageSupport

protected static TooltipLanguageSupport tooltipLanguageSupport
Currrent tooltip support. This is a custom support object that provides tooltips according to language files.


checkComponentsTextForTranslations

protected static boolean checkComponentsTextForTranslations
Whether or not components should check that text passed into their constructors is a translation key or not.


initialized

protected static boolean initialized
Manager initialization mark.

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()
Returns list of currently supported languages. By default it contains list of languages supported by WebLaF, but it can be modified.

Returns:
list of currently supported languages

setSupportedLanguages

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

Parameters:
supportedLanguages - collection of supported languages

setSupportedLanguages

public static void setSupportedLanguages(java.lang.String... supportedLanguages)
Sets supported languages.

Parameters:
supportedLanguages - supported languages

addSupportedLanguage

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

Parameters:
language - new supported language

addSupportedLanguage

public static void addSupportedLanguage(java.lang.String language,
                                        Dictionary dictionary)
Adds supported language and new dictionary.

Parameters:
language - new supported language
dictionary - new dictionary

removeSupportedLanguage

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

Parameters:
language - supported language to remove

clearSupportedLanguages

public static void clearSupportedLanguages()
Clears list of supported languages.


registerComponent

public static void registerComponent(javax.swing.JComponent component,
                                     java.lang.String key,
                                     java.lang.Object... data)
Registers component for language updates. This component language will be automatically updated using existing LanguageUpdater.

Parameters:
component - component to register
key - component language key
data - component language data
See Also:
LanguageUpdater

updateComponentsTree

public static void updateComponentsTree(javax.swing.JComponent component)
Updates components tree language keys according to their container keys.

Parameters:
component - component to update

updateComponentKey

protected static void updateComponentKey(javax.swing.JComponent component)
Updates component language key according to its container keys.

Parameters:
component - component to update

unregisterComponent

public static void unregisterComponent(javax.swing.JComponent component)
Unregisters component from language updates.

Parameters:
component - component to unregister

isRegisteredComponent

public static boolean isRegisteredComponent(javax.swing.JComponent component)
Returns whether component is registered for language updates or not.

Parameters:
component - component to check
Returns:
true if component is registered for language updates, false otherwise

getComponentKey

public static java.lang.String getComponentKey(javax.swing.JComponent component)
Returns component language key. Note that this is the key which was used to register the component. Its actual language key might be different in case there is a language container under this component.

Parameters:
component - component to retrieve language key for
Returns:
component language key

registerLanguageUpdater

public static void registerLanguageUpdater(LanguageUpdater updater)
Register custom LanguageUpdater. Each LanguageUpdater is tied to a certain component class and can perform language updates only for that component type.

Parameters:
updater - new LanguageUpdater
See Also:
LanguageUpdater

unregisterLanguageUpdater

public static void unregisterLanguageUpdater(LanguageUpdater updater)
Unregister custom LanguageUpdater.

Parameters:
updater - LanguageUpdater to unregister

registerLanguageUpdater

public static void registerLanguageUpdater(javax.swing.JComponent component,
                                           LanguageUpdater updater)
Registers custom LanguageUpdater for specific component.

Parameters:
component - component to register LanguageUpdater for
updater - custom LanguageUpdater

unregisterLanguageUpdater

public static void unregisterLanguageUpdater(javax.swing.JComponent component)
Unregisters component's custom LanguageUpdater.

Parameters:
component - component to unregister custom LanguageUpdater from

getLanguageUpdater

public static LanguageUpdater getLanguageUpdater(javax.swing.JComponent component)
Returns LanguageUpdater currently used for the specified component. This method might return either a custom per-component LanguageUpdater or global LanguageUpdater. In case LanguageUpdater cannot be found for the specified component an exception will be thrown.

Parameters:
component - component to retrieve LanguageUpdater for
Returns:
LanguageUpdater currently used for the specified component

updateComponents

public static void updateComponents()
Forces full language update for all registered components.


updateComponents

public static void updateComponents(java.util.List<java.lang.String> keys)
Forces language update for components with the specified keys.

Parameters:
keys - language keys of the components to update

updateComponent

public static void updateComponent(javax.swing.JComponent component,
                                   java.lang.Object... data)
Forces component language update.

Parameters:
component - component to update
data - component language data

updateComponent

public static void updateComponent(javax.swing.JComponent component,
                                   java.lang.String key,
                                   java.lang.Object... data)
Forces component language update.

Parameters:
component - component to update
key - component language key
data - component language data

parseData

public static java.lang.Object[] parseData(java.lang.Object... data)
Returns language data transformed into its final form.

Parameters:
data - language data to process
Returns:
language data transformed into its final form

getLanguageIcon

public static javax.swing.ImageIcon getLanguageIcon(java.lang.String language)
Returns icon for the specified language. By default there are icons only for languages supported by WebLaF.

Parameters:
language - language to retrieve icon for
Returns:
icon for the specified language

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

getLanguageTitle

public static java.lang.String getLanguageTitle(java.lang.String language)
Returns language title in that language translation.

Parameters:
language - language to get title for
Returns:
language title in that language translation

getTooltipLanguageSupport

public static TooltipLanguageSupport getTooltipLanguageSupport()
Returns current tooltip language support.

Returns:
current tooltip language support
See Also:
TooltipLanguageSupport, SwingTooltipLanguageSupport

setTooltipLanguageSupport

public static void setTooltipLanguageSupport(TooltipLanguageSupport support)
Sets tooltip language support.

Parameters:
support - new tooltip language support
See Also:
TooltipLanguageSupport, SwingTooltipLanguageSupport

getDefaultTooltipType

public static TooltipType getDefaultTooltipType()
Returns default tooltip type. This tooltip type is used for all tooltips which doesn't have a specified type in language file.

Returns:
default tooltip type
See Also:
TooltipType

setDefaultTooltipType

public static void setDefaultTooltipType(TooltipType defaultTooltipType)
Sets default tooltip type. This tooltip type is used for all tooltips which doesn't have a specified type in language file.

Parameters:
defaultTooltipType - new default tooltip type
See Also:
TooltipType

getDefaultLanguage

public static java.lang.String getDefaultLanguage()
Returns default language. This language is used when LanguageManager is initialized.

Returns:
default language

setDefaultLanguage

public static void setDefaultLanguage(java.lang.String lang)
Sets default language. This language is used when LanguageManager is initialized.

Parameters:
lang - new default language

getLanguage

public static java.lang.String getLanguage()
Returns currently used language.

Returns:
currently used language

isCurrentLanguage

public static boolean isCurrentLanguage(java.lang.String language)
Returns whether the specified language is currently used or not.

Parameters:
language - language to check
Returns:
true if the specified language is currently used, false otherwise

setLanguage

public static void setLanguage(java.lang.String language)
Sets currently used language. In case LanguageManager is not yet initialized this will simply set default language

Parameters:
language - new language

switchLanguage

public static void switchLanguage()
Switches current language to next language in supported languages list.


updateLocale

protected static void updateLocale()
Updates Locale according to currently used language.


getLocale

public static java.util.Locale getLocale(java.lang.String language)
Returns Locale for the specified language.

Parameters:
language - language to return Locale for
Returns:
Locale for the specified language

getGlobalDictionary

public static Dictionary getGlobalDictionary()
Returns global dictionary that aggregates all added dictionaries.

Returns:
global dictionary that aggregates all added dictionaries

getDictionaries

public static java.util.List<Dictionary> getDictionaries()
Returns all dictionaries added into LanguageManager.

Returns:
all dictionaries added into LanguageManager

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

getDictionaryCacheKey

public static java.lang.String getDictionaryCacheKey(java.lang.Class nearClass,
                                                     java.lang.String resource)
Returns dictionary cache key.

Parameters:
nearClass - class to look near for the dictionary file
resource - path to dictionary file
Returns:
dictionary cache key

loadDictionary

public static Dictionary loadDictionary(java.lang.Class nearClass,
                                        java.lang.String resource)
Returns dictionary loaded from the specified location near class.

Parameters:
nearClass - class near which dictionary XML is located
resource - dictionary XML file
Returns:
dictionary loaded from the specified location near class

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

getDictionaryCacheKey

public static java.lang.String getDictionaryCacheKey(java.net.URL url)
Returns dictionary cache key.

Parameters:
url - dictionary file url
Returns:
dictionary cache key

loadDictionary

public static Dictionary loadDictionary(java.net.URL url)
Returns dictionary loaded from the specified URL.

Parameters:
url - URL to load dictionary from
Returns:
dictionary loaded from the specified URL

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

getDictionaryCacheKey

public static java.lang.String getDictionaryCacheKey(java.lang.String path)
Returns dictionary cache key.

Parameters:
path - path to dictionary file
Returns:
dictionary cache key

loadDictionary

public static Dictionary loadDictionary(java.lang.String path)
Returns dictionary loaded from the specified file path.

Parameters:
path - file path to load dictionary from
Returns:
dictionary loaded from the specified file path

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

getDictionaryCacheKey

public static java.lang.String getDictionaryCacheKey(java.io.File file)
Returns dictionary cache key.

Parameters:
file - dictionary file
Returns:
dictionary cache key

loadDictionary

public static Dictionary loadDictionary(java.io.File file)
Returns dictionary loaded from the specified file.

Parameters:
file - file to load dictionary from
Returns:
dictionary loaded from the specified file

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

addDictionary

public static Dictionary addDictionary(java.lang.String cacheKey,
                                       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:
cacheKey - dictionary cache key
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)
Returns translation for the specified language key.

Parameters:
key - language key to retrieve translation for
Returns:
translation for the specified language key

get

public static java.lang.String get(java.lang.String key,
                                   java.lang.Object... data)
Returns translation for the specified language key.

Parameters:
key - language key to retrieve translation for
data - language data
Returns:
translation for the specified language key

getMnemonic

public static java.lang.Character getMnemonic(java.lang.String key)
Returns mnemonic for the specified language key.

Parameters:
key - language key to retrieve mnemonic for
Returns:
mnemonic for the specified language key

getValue

public static Value getValue(java.lang.String key)
Returns value for the specified language key.

Parameters:
key - language key to retrieve value for
Returns:
value for the specified language key

getNotNullValue

public static Value getNotNullValue(java.lang.String key)
Returns non-null value for the specified language key.

Parameters:
key - language key to retrieve value for
Returns:
non-null value for the specified language key

contains

public static boolean contains(java.lang.String key)
Returns whether specified language key exists or not.

Parameters:
key - language key to check
Returns:
whether specified language key exists or not

get

public static java.lang.String get(javax.swing.JComponent component,
                                   java.lang.String key)
Returns component translation.

Parameters:
component - component to retrieve translation for
key - component language key
Returns:
component translation

getMnemonic

public static java.lang.Character getMnemonic(javax.swing.JComponent component,
                                              java.lang.String key)
Returns component mnemonic.

Parameters:
component - component to retrieve mnemonic for
key - component language key
Returns:
component mnemonic

getValue

public static Value getValue(javax.swing.JComponent component,
                             java.lang.String key)
Returns component language value.

Parameters:
component - component to retrieve language value for
key - component language key
Returns:
component language value

getNotNullValue

public static Value getNotNullValue(javax.swing.JComponent component,
                                    java.lang.String key)
Returns non-null component language value.

Parameters:
component - component to retrieve language value for
key - component language key
Returns:
non-null component language value

getValue

public static Value getValue(javax.swing.JComponent component,
                             java.lang.String key,
                             java.lang.String additionalKey)
Returns component language value.

Parameters:
component - component to retrieve language value for
key - component language key
additionalKey - additional language key
Returns:
component language value

getNotNullValue

public static Value getNotNullValue(javax.swing.JComponent component,
                                    java.lang.String key,
                                    java.lang.String additionalKey)
Returns non-null component language value.

Parameters:
component - component to retrieve language value for
key - component language key
additionalKey - additional language key
Returns:
non-null component language value

combineWithContainerKeys

public static java.lang.String combineWithContainerKeys(javax.swing.JComponent component,
                                                        java.lang.String key)
Returns component language key combined with its containers keys.

Parameters:
component - component to retrieve language key for
key - component language key
Returns:
component language key combined with its containers keys

combineWithContainerKeysImpl

protected static java.lang.String combineWithContainerKeysImpl(javax.swing.JComponent component,
                                                               java.lang.String key)
Returns component language key combined with its containers keys.

Parameters:
component - component to retrieve language key for
key - component language key
Returns:
component language key combined with its containers keys

registerLanguageContainer

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

Parameters:
container - container to register
key - language container key

unregisterLanguageContainer

public static void unregisterLanguageContainer(java.awt.Container container)
Unregisters language container key.

Parameters:
container - container to unregister

getLanguageContainerKey

public static java.lang.String getLanguageContainerKey(java.awt.Container container)
Returns language container key for the specified container.

Parameters:
container - container to retrieve language container key for
Returns:
language container key for the specified container

rebuildCache

protected static void rebuildCache()
Rebuilds global dictionaries cache from a scratch. This is required for cases when dictionary changes cannot be tracked or when current language changes.


clearCache

protected static void clearCache()
Clears global dictionaries cache.


updateCache

protected static void updateCache(Dictionary dictionary)
Updates global dictionaries cache with the specified dictionary.

Parameters:
dictionary - dictionary to update cache with

updateCache

protected static void updateCache(java.lang.String prefix,
                                  Dictionary dictionary)
Updates global dictionaries cache with the specified dictionary.

Parameters:
prefix - dictionary prefix
dictionary - dictionary to update cache with

isCheckComponentsTextForTranslations

public static boolean isCheckComponentsTextForTranslations()
Returns whether or not components should check that text passed into their constructors is a translation key or not.

Returns:
true if components should check that text passed into their constructor is a translation key or not, false otherwise

setCheckComponentsTextForTranslations

public static void setCheckComponentsTextForTranslations(boolean check)
Sets whether or not components should check that text passed into their constructors is a translation key or not.

Parameters:
check - whether or not components should check that text passed into their constructors is a translation key or not

getDefaultLanguageKey

public static java.lang.String getDefaultLanguageKey()
Returns default language key.

Returns:
default language key

getSystemLanguageKey

public static java.lang.String getSystemLanguageKey()
Returns system language key.

Returns:
system language key

getLanguageListeners

public static java.util.List<LanguageListener> getLanguageListeners()
Returns language listeners.

Returns:
language listeners

addLanguageListener

public static void addLanguageListener(LanguageListener listener)
Adds new language listener.

Parameters:
listener - new language listener

removeLanguageListener

public static void removeLanguageListener(LanguageListener listener)
Removes language listener.

Parameters:
listener - language listener to remove

getComponentLanguageListeners

public static java.util.Map<java.awt.Component,LanguageListener> getComponentLanguageListeners()
Returns component language listeners.

Returns:
component language listeners

addLanguageListener

public static void addLanguageListener(javax.swing.JComponent component,
                                       LanguageListener listener)
Adds language listener for the specified component.

Parameters:
component - component to add language listener for
listener - new language listener

removeLanguageListener

public static void removeLanguageListener(javax.swing.JComponent component)
Removes language listener from the specified component.

Parameters:
component - component to remove language listener from

fireLanguageChanged

protected static void fireLanguageChanged(java.lang.String oldLang,
                                          java.lang.String newLang)
Fires language changed event whenever current language changes.

Parameters:
oldLang - old language
newLang - new language

fireDictionaryAdded

protected static void fireDictionaryAdded(Dictionary dictionary)
Fires dictionary added event whenever new dictionary is added into LanguageManager.

Parameters:
dictionary - new dictionary

fireDictionaryRemoved

protected static void fireDictionaryRemoved(Dictionary dictionary)
Fires dictionary removed event whenever dictionary is removed from LanguageManager.

Parameters:
dictionary - removed dictionary

fireDictionariesCleared

protected static void fireDictionariesCleared()
Fires dictionaries cleared event whenever all dictionaries are removed from LanguageManager.


getLanguageKeyListeners

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

Returns:
language key listeners

addLanguageKeyListener

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

Parameters:
key - language key to register listener for
listener - new language key listener

removeLanguageKeyListener

public static void removeLanguageKeyListener(LanguageKeyListener listener)
Removes language key listener

Parameters:
listener - language key listener to remove

removeLanguageKeyListeners

public static void removeLanguageKeyListeners(java.lang.String key)
Removes language key listener.

Parameters:
key - language key to remove listeners for

fireLanguageKeyUpdated

protected static void fireLanguageKeyUpdated(java.lang.String key)
Fires language key updated event whenever specified dictionary key is updated with new translation.

Parameters:
key - updated language key

fireAllLanguageKeysUpdated

protected static void fireAllLanguageKeysUpdated()
Fires language key updated event for all language keys.