Class Selection

java.lang.Object
eu.bandm.tools.muli.Selection

public class Selection extends Object
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.
  • Field Details

    • LINGUA_FRANCA

      public static final String 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

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

      protected final List<String> priorities
      The priority list of languages. Is set when constructing, and can be altered later.
    • preferences

      protected final List<String> preferences
      The list currently used for the search for translations. This is auxiliary data, optimized for searching, calculated from setLanguage(java.lang.String) and the language priority list.
    • prefs

      public final List<String> prefs
      The list currently used for the search for translations. This is an unmodifiable life view which will change according to setLanguage(java.lang.String), etc.
    • listeners

      protected final Set<Selection.Listener> listeners
      All subscribing Listeners. They will be notified whenever the selected language or the preference order changes.
  • Constructor Details

    • Selection

      public Selection(String... langs)
      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

      public Selection(List<String> langs)
      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; calls updatePreferences().)
      Parameters:
      langs - a non-empty priority list of languages.
      Throws:
      IllegalArgumentException - if null is contained in the list
  • Method Details

    • getCurrentLanguage

      public String 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

      public void addListener(Selection.Listener rec)
      Add a listener as subsrciber. Is idempotent: multiple calls have no further effect.
      Parameters:
      rec - the subscribing listener.
    • removeListener

      public void removeListener(Selection.Listener rec)
      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

      public void setLanguage(String lang)
      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

      public void setPriorities(String... langs)
      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