public final class UILanguageManager extends Object
UILanguageManager
is an extension over LanguageManager
that offers extensive Swing components translation support.
UILanguageManager
provides various ways of translating components that are registered within this manager and also dynamically
updating their translation upon Language
or Dictionary
changes.LanguageManager
,
Language
,
Dictionary
,
LanguageUpdater
Constructor and Description |
---|
UILanguageManager() |
Modifier and Type | Method and Description |
---|---|
static void |
addDictionaryListener(JComponent component,
DictionaryListener listener)
Adds new
DictionaryListener tied to the specified JComponent . |
static void |
addLanguageListener(JComponent component,
LanguageListener listener)
Adds new
LanguageListener tied to the specified JComponent . |
static String |
getComponentKey(JComponent component)
Returns language key which was used to register specified component.
|
static String |
getInitialText(String key,
Object... data)
Returns proper initial component text.
|
static Icon |
getLanguageIcon(Language language)
|
static LanguageUpdater |
getLanguageUpdater(Class<? extends JComponent> clazz)
Returns
LanguageUpdater currently used for the specified component class. |
static LanguageUpdater |
getLanguageUpdater(JComponent component)
Returns
LanguageUpdater currently used for the specified component. |
static Icon |
getLocaleIcon(Locale locale)
|
static void |
initialize()
Initializes LanguageManager settings.
|
static boolean |
isCheckComponentsTextForTranslations()
Returns whether or not text-containing components should check passed text for translation or not.
|
static boolean |
isRegisteredComponent(JComponent component)
Returns whether component is registered for language updates or not.
|
static void |
registerComponent(JComponent component,
String key,
Object... data)
Registers component for language updates.
|
static void |
registerInitialLanguage(LanguageMethods component,
String key,
Object... data)
Registers proper initial component language key.
|
static void |
registerLanguageUpdater(JComponent component,
LanguageUpdater updater)
Registers custom
LanguageUpdater for specific JComponent . |
static void |
registerLanguageUpdater(LanguageUpdater updater)
Register custom
LanguageUpdater . |
static void |
removeDictionaryListener(JComponent component,
DictionaryListener listener)
Removes
DictionaryListener tied to the specified JComponent . |
static void |
removeDictionaryListeners(JComponent component)
Removes all
DictionaryListener s tied to the specified JComponent . |
static void |
removeLanguageListener(JComponent component,
LanguageListener listener)
Removes
LanguageListener tied to the specified JComponent . |
static void |
removeLanguageListeners(JComponent component)
Removes all
LanguageListener s tied to the specified JComponent . |
static void |
setCheckComponentsTextForTranslations(boolean check)
Sets whether or not text-containing components should check passed text for translation or not.
|
static Icon |
setLanguageIcon(Language language,
Icon icon)
|
static Icon |
setLocaleIcon(Locale locale,
Icon icon)
|
static void |
unregisterComponent(JComponent component)
Unregisters component from language updates.
|
static void |
unregisterLanguageUpdater(JComponent component)
Unregisters
JComponent 's custom LanguageUpdater . |
static void |
unregisterLanguageUpdater(LanguageUpdater updater)
Unregister custom
LanguageUpdater . |
static void |
updateComponent(JComponent component,
Object... data)
Forces
JComponent language update. |
static void |
updateComponent(JComponent component,
String key,
Object... data)
Forces
JComponent language update. |
static void |
updateComponents()
Forces full language update for all registered components.
|
static void |
updateComponents(Set<String> keys)
Forces language update for components with the specified keys.
|
public static void initialize()
public static boolean isCheckComponentsTextForTranslations()
true
if text-containing components should check passed text for translation, false
otherwisepublic static void setCheckComponentsTextForTranslations(boolean check)
check
- whether or not text-containing components should check passed text for translation or not@Nullable public static Icon setLanguageIcon(@NotNull Language language, @Nullable Icon icon)
@Nullable public static Icon setLocaleIcon(@NotNull Locale locale, @Nullable Icon icon)
public static void registerLanguageUpdater(@NotNull LanguageUpdater updater)
LanguageUpdater
.
Each LanguageUpdater
is tied to a certain component class and can perform language updates only for that component type.updater
- new LanguageUpdater
LanguageUpdater
public static void unregisterLanguageUpdater(@NotNull LanguageUpdater updater)
LanguageUpdater
.updater
- LanguageUpdater
to unregisterpublic static void registerLanguageUpdater(@NotNull JComponent component, @NotNull LanguageUpdater updater)
LanguageUpdater
for specific JComponent
.component
- JComponent
to register LanguageUpdater
forupdater
- custom LanguageUpdater
public static void unregisterLanguageUpdater(@NotNull JComponent component)
JComponent
's custom LanguageUpdater
.component
- JComponent
to unregister custom LanguageUpdater
from@NotNull public static LanguageUpdater getLanguageUpdater(@NotNull JComponent component)
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.component
- component to retrieve LanguageUpdater
forLanguageUpdater
currently used for the specified component@NotNull public static LanguageUpdater getLanguageUpdater(@NotNull Class<? extends JComponent> clazz)
LanguageUpdater
currently used for the specified component class.
In case LanguageUpdater
cannot be found for the specified component an exception will be thrown.clazz
- component class to retrieve LanguageUpdater
forLanguageUpdater
currently used for the specified component class@Nullable public static String getInitialText(@Nullable String key, @NotNull Object... data)
key
- text provided into component constructordata
- language data, may not be passedpublic static void registerInitialLanguage(@NotNull LanguageMethods component, @Nullable String key, @NotNull Object... data)
component
- translated componentkey
- text provided into component constructordata
- language data, may not be passedpublic static void registerComponent(@NotNull JComponent component, @NotNull String key, @Nullable Object... data)
component
- component to registerkey
- component language keydata
- component language dataLanguageUpdater
public static void unregisterComponent(@NotNull JComponent component)
component
- component to unregisterpublic static boolean isRegisteredComponent(@NotNull JComponent component)
component
- component to checktrue
if component is registered for language updates, false
otherwise@Nullable public static String getComponentKey(@NotNull JComponent component)
component
- component to retrieve language key forpublic static void updateComponents()
public static void updateComponents(@NotNull Set<String> keys)
keys
- language keys of the components to updatepublic static void updateComponent(@NotNull JComponent component, @Nullable Object... data)
JComponent
language update.component
- JComponent
to updatedata
- new formatting datapublic static void updateComponent(@NotNull JComponent component, @NotNull String key, @Nullable Object... data)
JComponent
language update.component
- JComponent
to updatekey
- new language keydata
- new formatting datapublic static void addLanguageListener(@NotNull JComponent component, @NotNull LanguageListener listener)
LanguageListener
tied to the specified JComponent
.
Unlike LanguageManager.addLanguageListener(LanguageListener)
using this method will not store hard references
to the LanguageListener
outside of the JComponent
to avoid any mermory leaks. So if specified JComponent
will for instance be destroyed provided LanguageListener
will also be destroyed.component
- JComponent
to tie LanguageListener
tolistener
- LanguageListener
to addpublic static void removeLanguageListener(@NotNull JComponent component, @NotNull LanguageListener listener)
LanguageListener
tied to the specified JComponent
.component
- JComponent
to remove tied LanguageListener
fromlistener
- LanguageListener
to removepublic static void removeLanguageListeners(@NotNull JComponent component)
LanguageListener
s tied to the specified JComponent
.component
- JComponent
to remove all tied LanguageListener
s frompublic static void addDictionaryListener(@NotNull JComponent component, @NotNull DictionaryListener listener)
DictionaryListener
tied to the specified JComponent
.
Unlike LanguageManager.addDictionaryListener(DictionaryListener)
using this method will not store hard references
to the DictionaryListener
outside of the JComponent
to avoid any mermory leaks. So if specified JComponent
will for instance be destroyed provided DictionaryListener
will also be destroyed.component
- JComponent
to tie DictionaryListener
tolistener
- DictionaryListener
to addpublic static void removeDictionaryListener(@NotNull JComponent component, @NotNull DictionaryListener listener)
DictionaryListener
tied to the specified JComponent
.component
- JComponent
to remove tied DictionaryListener
fromlistener
- DictionaryListener
to removepublic static void removeDictionaryListeners(@NotNull JComponent component)
DictionaryListener
s tied to the specified JComponent
.component
- JComponent
to remove all tied DictionaryListener
s fromCopyright © 2020. All rights reserved.