Package eu.bandm.tools.muli
Class Selection
java.lang.Object
eu.bandm.tools.muli.Selection
Represents a preference list of languages, to control translation
for a GUI, or sim.
A static list of priorities is given at construction time.
The language with the highest priority (= the "current language"
of a running application) can be changed any time to a member
of this list.
The rest of the priority list is then used for fall-back.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
The top-most language currently selected.static final String
A language which is understood everywhere.protected final Set
<Selection.Listener> All subscribing Listeners.The list currently used for the search for translations.The list currently used for the search for translations.The priority list of languages. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a listener as subsrciber.The currently selected language.boolean
isMuLi()
Whether more than one language is provided in the priority list.void
Remove a listener as subsrciber.void
setLanguage
(String lang) Select the current language.void
setPriorities
(String... langs) Re-define the sequence of supported languages and the default preferences.
-
Field Details
-
LINGUA_FRANCA
A language which is understood everywhere. It contains names which are never translated, because they are product names or ISO-defined entities, or sim.- See Also:
-
currentLanguage
The top-most language currently selected. (Normally all GUI elements will appear in this language, if possible. If not, the priority list is searched instead.) -
priorities
The priority list of languages. Is set when constructing, and can be altered later. -
preferences
The list currently used for the search for translations. This is auxiliary data, optimized for searching, calculated fromsetLanguage(java.lang.String)
and the language priority list. -
prefs
The list currently used for the search for translations. This is an unmodifiable life view which will change according tosetLanguage(java.lang.String)
, etc. -
listeners
All subscribing Listeners. They will be notified whenever the selected language or the preference order changes.
-
-
Constructor Details
-
Selection
Sets the priority list of languages. The current language is set to the first (=highest priority) element in the list.- Parameters:
langs
- a non-empty priority list of languages.- Throws:
NullPointerException
- if null is contained in the arguments
-
Selection
Sets the priority list of languages. The current language is set to the first (=highest priority) element in the list. (Beware this-escape when subclassig; callsupdatePreferences()
.)- Parameters:
langs
- a non-empty priority list of languages.- Throws:
IllegalArgumentException
- if null is contained in the list
-
-
Method Details
-
getCurrentLanguage
The currently selected language.- Returns:
- the currently selected language.
-
isMuLi
public boolean isMuLi()Whether more than one language is provided in the priority list.- Returns:
- whether more than one language is provided in the priority list.
-
addListener
Add a listener as subsrciber. Is idempotent: multiple calls have no further effect.- Parameters:
rec
- the subscribing listener.
-
removeListener
Remove a listener as subsrciber. Is idempotent: multiple calls have no further effect.- Parameters:
rec
- the no longer subscribing listener. If it is not subscribing, there is no effect.
-
setLanguage
Select the current language. The new prefrence sequence is calculated. Iff it differs, the listeners are notified.- Parameters:
lang
- the new current language.- Throws:
IllegalStateException
- if the language is not in the language priority list.
-
setPriorities
Re-define the sequence of supported languages and the default preferences. The current language is set to the first (=highest priority) element in the list.- Parameters:
langs
- list of languages- Throws:
IllegalArgumentException
- if a null value is contained in the arguments
-