Package jmri.managers

Class JmriUserPreferencesManager

    • Method Detail

      • setSaveAllowed

        public void setSaveAllowed​(boolean saveAllowed)
        Description copied from interface: UserPreferencesManager
        Set if saving preferences is allowed. When setting true, preferences will be saved immediately if needed.

        Note only set false if a number of preferences will be set together to avoid excessive disk I/O while setting preferences.

        Note remember to allow saving as soon as blocking saving is no longer needed.

        Specified by:
        setSaveAllowed in interface UserPreferencesManager
        Parameters:
        saveAllowed - true to allow saving; false to block saving
      • setSimplePreferenceState

        public void setSimplePreferenceState​(java.lang.String name,
                                             boolean state)
        This is used to remember the last selected state of a checkBox and thus allow that checkBox to be set to a true state when it is next initialized. This can also be used anywhere else that a simple yes/no, true/false type preference needs to be stored.

        It should not be used for remembering if a user wants to suppress a message as there is no means in the GUI for the user to reset the flag. setPreferenceState() should be used in this instance The name is free-form, but to avoid ambiguity it should start with the package name (package.Class) for the primary using class.

        Specified by:
        setSimplePreferenceState in interface UserPreferencesManager
        Parameters:
        name - A unique name to identify the state being stored
        state - simple boolean.
      • getSimplePreferenceState

        public boolean getSimplePreferenceState​(java.lang.String name)
        Description copied from interface: UserPreferencesManager
        Enquire as to the state of a user preference.

        Preferences that have not been set will be considered to be false.

        The name is free-form, but to avoid ambiguity it should start with the package name (package.Class) for the primary using class.

        Specified by:
        getSimplePreferenceState in interface UserPreferencesManager
        Parameters:
        name - the name of the preference
        Returns:
        the state or false if never set
      • setPreferenceState

        public void setPreferenceState​(java.lang.String strClass,
                                       java.lang.String item,
                                       boolean state)
        Description copied from interface: UserPreferencesManager
        Used to save the state of checkboxes which can suppress messages from being displayed. This method should be used by the initiating code in conjunction with the preferenceItemDetails. Here the items are stored against a specific class and access to change them is made available via the GUI, in the preference manager.

        The strClass parameter does not have to be the exact class name of the initiating code, but can be one where the information is related and therefore can be grouped together with.

        Both the strClass and item although free form, should make up a unique reference.

        Specified by:
        setPreferenceState in interface UserPreferencesManager
        Parameters:
        strClass - The class that this preference should be stored or grouped with.
        item - The specific item that is to be stored
        state - Boolean state of the item.
      • getPreferenceState

        public boolean getPreferenceState​(java.lang.String strClass,
                                          java.lang.String item)
        Description copied from interface: UserPreferencesManager
        Returns the state of a given item registered against a specific class or item.
        Specified by:
        getPreferenceState in interface UserPreferencesManager
        Parameters:
        strClass - name of the class for this preference
        item - name of the item for which the state is being retrieved
        Returns:
        the state or false if not set
      • setPreferenceItemDetails

        public final void setPreferenceItemDetails​(java.lang.String strClass,
                                                   java.lang.String item,
                                                   java.lang.String description)
        Description copied from interface: UserPreferencesManager
        Register details about a particular preference, so that it can be displayed in the GUI and provide a meaning full description when presented to the user.
        Specified by:
        setPreferenceItemDetails in interface UserPreferencesManager
        Parameters:
        strClass - A string form of the class that the preference is stored or grouped with
        item - The specific item that is being stored
        description - A meaningful description of the item that the user will understand
      • getPreferenceList

        public java.util.ArrayList<java.lang.String> getPreferenceList​(java.lang.String strClass)
        Description copied from interface: UserPreferencesManager
        Returns a list of preferences that are registered against a specific class.
        Specified by:
        getPreferenceList in interface UserPreferencesManager
        Parameters:
        strClass - the class name
        Returns:
        the list of preference names
      • getPreferenceItemName

        public java.lang.String getPreferenceItemName​(java.lang.String strClass,
                                                      int n)
        Description copied from interface: UserPreferencesManager
        Returns the itemName of the n preference in the given class
        Specified by:
        getPreferenceItemName in interface UserPreferencesManager
        Parameters:
        strClass - the name of the class
        n - the position in an array
        Returns:
        the name of the preference or null if non-existent
      • setSessionPreferenceState

        public void setSessionPreferenceState​(java.lang.String name,
                                              boolean state)
        Used to surpress messages for a particular session, the information is not stored, can not be changed via the GUI.

        This can be used to help prevent over loading the user with repetitive error messages such as turnout not found while loading a panel file due to a connection failing. The name is free-form, but to avoid ambiguity it should start with the package name (package.Class) for the primary using class.

        Specified by:
        setSessionPreferenceState in interface UserPreferencesManager
        Parameters:
        name - A unique identifer for preference.
        state - suppression state of the item.
      • getSessionPreferenceState

        public boolean getSessionPreferenceState​(java.lang.String name)
        Description copied from interface: UserPreferencesManager
        Enquire as to the state of a user preference for the current session.

        Preferences that have not been set will be considered to be false.

        The name is free-form, but to avoid ambiguity it should start with the package name (package.Class) for the primary using class.

        Specified by:
        getSessionPreferenceState in interface UserPreferencesManager
        Parameters:
        name - the name of the preference
        Returns:
        the state or false if not set
      • showInfoMessage

        public void showInfoMessage​(java.lang.String title,
                                    java.lang.String message,
                                    java.lang.String strClass,
                                    java.lang.String item)
        Show an info message ("don't forget ...") with a given dialog title and user message. Use a given preference name to determine whether to show it in the future. The combination of the classString and item parameters should form a unique value.
        Specified by:
        showInfoMessage in interface UserPreferencesManager
        Parameters:
        title - message Box title
        message - message to be displayed
        strClass - name of the calling class
        item - name of the specific item this is used for
      • showErrorMessage

        public void showErrorMessage​(java.lang.String title,
                                     java.lang.String message,
                                     java.lang.String strClass,
                                     java.lang.String item,
                                     boolean sessionOnly,
                                     boolean alwaysRemember)
        Show an info message ("don't forget ...") with a given dialog title and user message. Use a given preference name to determine whether to show it in the future. added flag to indicate that the message should be suppressed JMRI session only. The classString and item parameters should form a unique value
        Specified by:
        showErrorMessage in interface UserPreferencesManager
        Parameters:
        title - Message Box title
        message - Message to be displayed
        strClass - String value of the calling class
        item - String value of the specific item this is used for
        sessionOnly - Means this message will be suppressed in this JMRI session and not be remembered
        alwaysRemember - Means that the suppression of the message will be saved
      • showInfoMessage

        public void showInfoMessage​(java.lang.String title,
                                    java.lang.String message,
                                    java.lang.String strClass,
                                    java.lang.String item,
                                    boolean sessionOnly,
                                    boolean alwaysRemember)
        Show an info message ("don't forget ...") with a given dialog title and user message. Use a given preference name to determine whether to show it in the future. added flag to indicate that the message should be suppressed JMRI session only. The classString and item parameters should form a unique value
        Specified by:
        showInfoMessage in interface UserPreferencesManager
        Parameters:
        title - Message Box title
        message - Message to be displayed
        strClass - String value of the calling class
        item - String value of the specific item this is used for
        sessionOnly - Means this message will be suppressed in this JMRI session and not be remembered
        alwaysRemember - Means that the suppression of the message will be saved
      • showWarningMessage

        public void showWarningMessage​(java.lang.String title,
                                       java.lang.String message,
                                       java.lang.String strClass,
                                       java.lang.String item,
                                       boolean sessionOnly,
                                       boolean alwaysRemember)
        Show an info message ("don't forget ...") with a given dialog title and user message. Use a given preference name to determine whether to show it in the future. added flag to indicate that the message should be suppressed JMRI session only. The classString and item parameters should form a unique value
        Specified by:
        showWarningMessage in interface UserPreferencesManager
        Parameters:
        title - Message Box title
        message - Message to be displayed
        strClass - String value of the calling class
        item - String value of the specific item this is used for
        sessionOnly - Means this message will be suppressed in this JMRI session and not be remembered
        alwaysRemember - Means that the suppression of the message will be saved
      • showMessage

        protected void showMessage​(java.lang.String title,
                                   java.lang.String message,
                                   java.lang.String strClass,
                                   java.lang.String item,
                                   boolean sessionOnly,
                                   boolean alwaysRemember,
                                   int type)
      • setComboBoxLastSelection

        public void setComboBoxLastSelection​(java.lang.String comboBoxName,
                                             java.lang.String lastValue)
        Description copied from interface: UserPreferencesManager
        Set the last selected value in a given combo box.

        The name is free-form, but to avoid ambiguity it should start with the package name (package.Class) for the primary using class, followed by an identifier for the combo box.

        Specified by:
        setComboBoxLastSelection in interface UserPreferencesManager
        Parameters:
        comboBoxName - the combo box name
        lastValue - the selected value
      • getCheckboxPreferenceState

        public boolean getCheckboxPreferenceState​(java.lang.String name,
                                                  boolean defaultState)
        Description copied from interface: UserPreferencesManager
        Enquire as to the state of a user preference.

        Preferences that have not been set will be considered to be defaultState.

        The name is free-form, but to avoid ambiguity it should start with the package name (package.Class) for the primary using class.

        Specified by:
        getCheckboxPreferenceState in interface UserPreferencesManager
        Parameters:
        name - the name of the preference
        defaultState - the default state if not set
        Returns:
        the state or defaultState if never set
      • setCheckboxPreferenceState

        public void setCheckboxPreferenceState​(java.lang.String name,
                                               boolean state)
        Description copied from interface: UserPreferencesManager
        This is used to remember the last selected state of a checkBox and thus allow that checkBox to be set to a true state when it is next initialized. This can also be used anywhere else that a simple yes/no, true/false type preference needs to be stored.

        It should not be used for remembering if a user wants to suppress a message as there is no means in the GUI for the user to reset the flag. setPreferenceState() should be used in this instance The name is free-form, but to avoid ambiguity it should start with the package name (package.Class) for the primary using class.

        Specified by:
        setCheckboxPreferenceState in interface UserPreferencesManager
        Parameters:
        name - A unique name to identify the state being stored
        state - simple boolean
      • setChangeMade

        public void setChangeMade​(boolean fireUpdate)
      • isLoading

        protected boolean isLoading()
        Check if this object is loading preferences from storage.
        Returns:
        true if loading preferences; false otherwise
      • setSaveWindowSize

        public void setSaveWindowSize​(java.lang.String strClass,
                                      boolean b)
        Description copied from interface: UserPreferencesManager
        Set if window sizes should be saved for a given class. Method has no effect if strClass is null or equals jmri.util.JmriJFrame.
        Specified by:
        setSaveWindowSize in interface UserPreferencesManager
        Parameters:
        strClass - name of the class
        b - true if window sizes should be saved; false otherwise
      • setSaveWindowLocation

        public void setSaveWindowLocation​(java.lang.String strClass,
                                          boolean b)
        Description copied from interface: UserPreferencesManager
        Set if window locations should be saved for a given class. Method has no effect if strClass is null or equals jmri.util.JmriJFrame.
        Specified by:
        setSaveWindowLocation in interface UserPreferencesManager
        Parameters:
        strClass - name of the class
        b - true if window locations should be saved; false otherwise
      • setWindowLocation

        public void setWindowLocation​(java.lang.String strClass,
                                      java.awt.Point location)
        Description copied from interface: UserPreferencesManager
        Saves the last location of a given component on the screen.

        The jmri.util.JmriJFrame, will automatically use the class name of the frame if the class name returned is equal to jmri.util.JmriJFrame, the location is not stored

        Specified by:
        setWindowLocation in interface UserPreferencesManager
        Parameters:
        strClass - This is a unique identifier for window location being saved
        location - The x,y location of the window given in a Point
      • setWindowSize

        public void setWindowSize​(java.lang.String strClass,
                                  java.awt.Dimension dim)
        Description copied from interface: UserPreferencesManager
        Saves the last size of a given component on the screen

        The jmri.util.JmriJFrame, will automatically use the class name of the frame if the class name returned is equal to jmri.util.JmriJFrame, the size is not stored

        Specified by:
        setWindowSize in interface UserPreferencesManager
        Parameters:
        strClass - This is a unique identifier for window size being saved
        dim - The width, height size of the window given in a Dimension
      • setProperty

        public void setProperty​(java.lang.String strClass,
                                java.lang.String key,
                                java.lang.Object value)
        Description copied from interface: UserPreferencesManager
        Attach a key/value pair to the given class, which can be retrieved later. These are not bound properties as yet, and don't throw events on modification. Key must not be null.
        Specified by:
        setProperty in interface UserPreferencesManager
        Parameters:
        strClass - class to use
        key - Prior to 4.3.5, this could be an Object.
        value - value to use
      • getProperty

        public java.lang.Object getProperty​(java.lang.String strClass,
                                            java.lang.String key)
        Description copied from interface: UserPreferencesManager
        Retrieve the value associated with a key in a given class If no value has been set for that key, returns null.
        Specified by:
        getProperty in interface UserPreferencesManager
        Parameters:
        strClass - class to use
        key - item to retrieve
        Returns:
        stored value
      • hasProperties

        public boolean hasProperties​(java.lang.String strClass)
        Description copied from interface: UserPreferencesManager
        Check if there are properties for the given class
        Specified by:
        hasProperties in interface UserPreferencesManager
        Parameters:
        strClass - class to check
        Returns:
        true if properties for strClass are maintained; false otherwise
      • setClassDescription

        public void setClassDescription​(java.lang.String strClass)
        Given that we know the class as a string, we will try and attempt to gather details about the preferences that has been added, so that we can make better sense of the details in the preferences window.

        This looks for specific methods within the class called "getClassDescription" and "setMessagePreferencesDetails". If found it will invoke the methods, this will then trigger the class to send details about its preferences back to this code.

        Specified by:
        setClassDescription in interface UserPreferencesManager
        Parameters:
        strClass - description to use for the class
      • setMessageItemDetails

        public void setMessageItemDetails​(java.lang.String strClass,
                                          java.lang.String item,
                                          java.lang.String description,
                                          java.util.HashMap<java.lang.Integer,​java.lang.String> options,
                                          int defaultOption)
        Add descriptive details about a specific message box, so that if it needs to be reset in the preferences, then it is easily identifiable. displayed to the user in the preferences GUI.
        Specified by:
        setMessageItemDetails in interface UserPreferencesManager
        Parameters:
        strClass - String value of the calling class/group
        item - String value of the specific item this is used for.
        description - A meaningful description that can be used in a label to describe the item
        options - A map of the integer value of the option against a meaningful description.
        defaultOption - The default option for the given item.
      • getChoiceOptions

        public java.util.HashMap<java.lang.Integer,​java.lang.String> getChoiceOptions​(java.lang.String strClass,
                                                                                            java.lang.String item)
        Description copied from interface: UserPreferencesManager
        Returns a map of the value against description of the different items in a given class. This information can then be used to build a Combo box.
        Specified by:
        getChoiceOptions in interface UserPreferencesManager
        Parameters:
        strClass - Class or group of the given item
        item - the item which we wish to return the details about.
        Returns:
        map of choices
      • getChoiceDescription

        public java.lang.String getChoiceDescription​(java.lang.String strClass,
                                                     java.lang.String item)
        Description copied from interface: UserPreferencesManager
        Get the a meaningful description of a given item in a given class or group.
        Specified by:
        getChoiceDescription in interface UserPreferencesManager
        Parameters:
        strClass - the class name
        item - the item name
        Returns:
        the item description
      • setMultipleChoiceOption

        public void setMultipleChoiceOption​(java.lang.String strClass,
                                            java.lang.String choice,
                                            java.lang.String value)
        Description copied from interface: UserPreferencesManager
        Sets the value of a given item in a given class, by its string description.
        Specified by:
        setMultipleChoiceOption in interface UserPreferencesManager
        Parameters:
        strClass - the class name
        choice - the item name
        value - the item value description
      • getClassName

        protected final java.lang.String getClassName()