jmri.managers
Class DefaultUserMessagePreferences

java.lang.Object
  extended by jmri.jmrit.XmlFile
      extended by jmri.managers.DefaultUserMessagePreferences
All Implemented Interfaces:
UserPreferencesManager

@NotThreadSafe
public class DefaultUserMessagePreferences
extends XmlFile
implements UserPreferencesManager

Basic Implementation of the User Preferences Manager.

The User Message Preference Manager keeps track of the options that a user has selected in messages where they have selected "Remember this setting for next time"

Author:
Kevin Dickerson Copyright (C) 2010

Field Summary
 
Fields inherited from class jmri.jmrit.XmlFile
dtdLocation, xsltLocation
 
Method Summary
 void addComboBoxLastSelection(String comboBoxName, String lastValue)
          Adds the last selection of a combo box.
 void addPropertyChangeListener(PropertyChangeListener l)
           
 void allowSave()
           
 void disallowSave()
           
 void displayRememberMsg()
           
 void finishLoading()
           
 boolean getChangeMade()
           
 String getChoiceDescription(String strClass, String item)
          Returns the a meaningful description of a given item in a given class or group.
 String getChoiceName(String strClass, int n)
          Returns the nth item name in a given class
 HashMap<Integer,String> getChoiceOptions(String strClass, String item)
          Returns a map of the value against description of the different items in a given class.
 String getClassDescription()
           
 String getClassDescription(String strClass)
          Returns the description of a class/group registered with the preferences.
protected  String getClassName()
           
 String getComboBoxLastSelection(int n)
          returns the ComboBox Value at position n
 String getComboBoxLastSelection(String comboBoxName)
          returns the last selected value in a given combobox
 String getComboBoxName(int n)
          returns the ComboBox Name at position n
 int getComboBoxSelectionSize()
          returns the number of comboBox options saved
static DefaultUserMessagePreferences getInstance()
           
 int getMultipleChoiceDefaultOption(String strClass, String choice)
          Returns the default value of a given item in a given class
 ArrayList<String> getMultipleChoiceList(String strClass)
          Returns a list of all the multiple choice items registered with a given class.
 int getMultipleChoiceOption(String strClass, String item)
          Returns the current value of a given item in a given class
 int getMultipleChoiceSize(String strClass)
          Returns the number of Mulitple Choice items registered with a given class.
 String getPreferenceItemDescription(String strClass, String item)
          Returns the description of the given item preference in the given class
 String getPreferenceItemName(String strClass, int n)
          Returns the itemName of the n preference in the given class
 ArrayList<String> getPreferenceList(String strClass)
          Returns a list of preferences that are registered against a specific class.
 ArrayList<String> getPreferencesClasses()
          Returns a list of the classes registered with the preference manager.
 int getPreferencesSize(String strClass)
          returns the combined size of both types of items registered.
 boolean getPreferenceState(String strClass, String item)
          Returns the state of a given item registered against a specific class or item.
 Object getProperty(String strClass, Object key)
          Retrieve the value associated with a key in a given class If no value has been set for that key, returns null.
 Set<Object> getPropertyKeys(String strClass)
          Retrieve the complete current set of keys for a given class.
 boolean getSaveWindowLocation(String strClass)
           
 boolean getSaveWindowSize(String strClass)
           
 Dimension getScreen()
           
 boolean getSessionPreferenceState(String name)
          Enquire as to the state of a user preference for the current session.
 boolean getSimplePreferenceState(String name)
          Enquire as to the state of a user preference.
 ArrayList<String> getSimplePreferenceStateList()
          Returns an ArrayList of the checkbox states set as true.
 ArrayList<String> getWindowList()
           
 Point getWindowLocation(String strClass)
          Returns the x,y location of a given Window
 Dimension getWindowSize(String strClass)
          Returns the width, height size of a given Window
 boolean isWindowPositionSaved(String strClass)
          Do we have a saved window position for the class
 void messageItemDetails(String strClass, String item, String description, HashMap<Integer,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.
 void messageItemDetails(String strClass, String item, String description, String[] msgOption, int[] msgNumber, 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.
protected  void notifyPropertyChangeListener(String property, Object oldValue, Object newValue)
           
 void preferenceItemDetails(String strClass, String item, String description)
          Register details about a perticular preference, so that it can be displayed in the GUI and provide a meaning full description when presented to the user.
 void readUserPreferences()
           
 void removePropertyChangeListener(PropertyChangeListener l)
           
 void resetChangeMade()
           
 void setChangeMade(boolean fireUpdate)
           
 void setClassDescription(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.
 void setComboBoxLastSelection(String comboBoxName, String lastValue)
          sets the last selected value in a given combobox
 void setLoading()
           
 void setMultipleChoiceOption(String strClass, String choice, int value)
          Sets the value of a given item in a given class, by its integer value
 void setMultipleChoiceOption(String strClass, String choice, String value)
          Sets the value of a given item in a given class, by its string description
 void setPreferenceState(String strClass, String item, boolean state)
          Used to save the state of checkboxes which can suppress messages from being displayed.
 void setProperty(String strClass, Object key, Object value)
          Attach a key/value pair to the given class, which can be retrieved later.
 void setSaveWindowLocation(String strClass, boolean b)
           
 void setSaveWindowSize(String strClass, boolean b)
           
 void setSessionPreferenceState(String name, boolean state)
          Used to surpress messages for a perticular session, the information is not stored, can not be changed via the GUI.
 void setSimplePreferenceState(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 initialised.
 void setWindowLocation(String strClass, Point location)
          Saves the last location of a given component on the screen.
 void setWindowSize(String strClass, Dimension dim)
          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
 void showInfoMessage(String title, String message, String strClass, String item)
          Show an info message ("don't forget ...")
 void showInfoMessage(String title, String message, String strClass, String item, boolean sessionOnly, boolean alwaysRemember, Level level)
          Show an info message ("don't forget ...")
 
Methods inherited from class jmri.jmrit.XmlFile
addDefaultInfo, backupFileName, checkFile, createFileNameWithDate, dumpElement, ensurePrefsPresent, findFile, getBuilder, getRootViaURI, getVerify, makeBackupFile, makeBackupFile, newDocument, newDocument, prefsDir, reportError1, reportError2, resourcesDir, revertBackupFile, rootFromFile, rootFromName, rootFromURL, scriptsDir, setScriptsFileLocationDefault, setUserFileLocationDefault, setVerify, userFileChooser, userFileChooser, userFileChooser, userFileChooser, userFileLocationDefault, writeXML, xmlDir
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static DefaultUserMessagePreferences getInstance()

allowSave

public void allowSave()
Specified by:
allowSave in interface UserPreferencesManager

disallowSave

public void disallowSave()
Specified by:
disallowSave in interface UserPreferencesManager

getScreen

public Dimension getScreen()
Specified by:
getScreen in interface UserPreferencesManager

setSimplePreferenceState

public void setSimplePreferenceState(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 initialised. 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(String name)
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

getSimplePreferenceStateList

public ArrayList<String> getSimplePreferenceStateList()
Returns an ArrayList of the checkbox states set as true.

Specified by:
getSimplePreferenceStateList in interface UserPreferencesManager

setPreferenceState

public void setPreferenceState(String strClass,
                               String item,
                               boolean state)
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(String strClass,
                                  String item)
Returns the state of a given item registered against a specific class or item.

Specified by:
getPreferenceState in interface UserPreferencesManager

preferenceItemDetails

public void preferenceItemDetails(String strClass,
                                  String item,
                                  String description)
Register details about a perticular preference, so that it can be displayed in the GUI and provide a meaning full description when presented to the user.

Specified by:
preferenceItemDetails 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 decription of the item that the user will understand.

getPreferenceList

public ArrayList<String> getPreferenceList(String strClass)
Returns a list of preferences that are registered against a specific class.

Specified by:
getPreferenceList in interface UserPreferencesManager

getPreferenceItemName

public String getPreferenceItemName(String strClass,
                                    int n)
Returns the itemName of the n preference in the given class

Specified by:
getPreferenceItemName in interface UserPreferencesManager

getPreferenceItemDescription

public String getPreferenceItemDescription(String strClass,
                                           String item)
Returns the description of the given item preference in the given class

Specified by:
getPreferenceItemDescription in interface UserPreferencesManager

setSessionPreferenceState

public void setSessionPreferenceState(String name,
                                      boolean state)
Used to surpress messages for a perticular 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 -

getSessionPreferenceState

public boolean getSessionPreferenceState(String name)
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

showInfoMessage

public void showInfoMessage(String title,
                            String message,
                            String strClass,
                            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 classString & 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

showInfoMessage

public void showInfoMessage(String title,
                            String message,
                            String strClass,
                            String item,
                            boolean sessionOnly,
                            boolean alwaysRemember,
                            Level level)
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 & 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
level - Used to determine the type of messagebox that will be used.

addComboBoxLastSelection

public void addComboBoxLastSelection(String comboBoxName,
                                     String lastValue)
Adds the last selection of a 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 combobox

Specified by:
addComboBoxLastSelection in interface UserPreferencesManager

getComboBoxLastSelection

public String getComboBoxLastSelection(String comboBoxName)
returns the last selected value in a given combobox

Specified by:
getComboBoxLastSelection in interface UserPreferencesManager

setComboBoxLastSelection

public void setComboBoxLastSelection(String comboBoxName,
                                     String lastValue)
sets the last selected value in a given combobox

Specified by:
setComboBoxLastSelection in interface UserPreferencesManager

getComboBoxSelectionSize

public int getComboBoxSelectionSize()
returns the number of comboBox options saved

Specified by:
getComboBoxSelectionSize in interface UserPreferencesManager

getComboBoxName

public String getComboBoxName(int n)
returns the ComboBox Name at position n

Specified by:
getComboBoxName in interface UserPreferencesManager

getComboBoxLastSelection

public String getComboBoxLastSelection(int n)
returns the ComboBox Value at position n

Specified by:
getComboBoxLastSelection in interface UserPreferencesManager

getChangeMade

public boolean getChangeMade()

setChangeMade

public void setChangeMade(boolean fireUpdate)

resetChangeMade

public void resetChangeMade()
Specified by:
resetChangeMade in interface UserPreferencesManager

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)
Specified by:
removePropertyChangeListener in interface UserPreferencesManager

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener l)
Specified by:
addPropertyChangeListener in interface UserPreferencesManager

notifyPropertyChangeListener

protected void notifyPropertyChangeListener(String property,
                                            Object oldValue,
                                            Object newValue)

setLoading

public void setLoading()
Specified by:
setLoading in interface UserPreferencesManager

finishLoading

public void finishLoading()
Specified by:
finishLoading in interface UserPreferencesManager

displayRememberMsg

public void displayRememberMsg()

getWindowLocation

public Point getWindowLocation(String strClass)
Description copied from interface: UserPreferencesManager
Returns the x,y location of a given Window

Specified by:
getWindowLocation in interface UserPreferencesManager

getWindowSize

public Dimension getWindowSize(String strClass)
Description copied from interface: UserPreferencesManager
Returns the width, height size of a given Window

Specified by:
getWindowSize in interface UserPreferencesManager

getSaveWindowSize

public boolean getSaveWindowSize(String strClass)
Specified by:
getSaveWindowSize in interface UserPreferencesManager

getSaveWindowLocation

public boolean getSaveWindowLocation(String strClass)
Specified by:
getSaveWindowLocation in interface UserPreferencesManager

setSaveWindowSize

public void setSaveWindowSize(String strClass,
                              boolean b)
Specified by:
setSaveWindowSize in interface UserPreferencesManager

setSaveWindowLocation

public void setSaveWindowLocation(String strClass,
                                  boolean b)
Specified by:
setSaveWindowLocation in interface UserPreferencesManager

setWindowLocation

public void setWindowLocation(String strClass,
                              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(String strClass,
                          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

getWindowList

public ArrayList<String> getWindowList()
Specified by:
getWindowList in interface UserPreferencesManager

setProperty

public void setProperty(String strClass,
                        Object key,
                        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

getProperty

public Object getProperty(String strClass,
                          Object 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

getPropertyKeys

public Set<Object> getPropertyKeys(String strClass)
Description copied from interface: UserPreferencesManager
Retrieve the complete current set of keys for a given class.

Specified by:
getPropertyKeys in interface UserPreferencesManager

isWindowPositionSaved

public boolean isWindowPositionSaved(String strClass)
Description copied from interface: UserPreferencesManager
Do we have a saved window position for the class

Specified by:
isWindowPositionSaved in interface UserPreferencesManager
Returns:
true if the window position details are stored, false if not.

getClassDescription

public String getClassDescription(String strClass)
Returns the description of a class/group registered with the preferences.

Specified by:
getClassDescription in interface UserPreferencesManager

getPreferencesClasses

public ArrayList<String> getPreferencesClasses()
Returns a list of the classes registered with the preference manager.

Specified by:
getPreferencesClasses in interface UserPreferencesManager

setClassDescription

public void setClassDescription(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 "setMessagePreferenceDetails". 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

messageItemDetails

public void messageItemDetails(String strClass,
                               String item,
                               String description,
                               String[] msgOption,
                               int[] msgNumber,
                               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:
messageItemDetails 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
msgOption - Description of each option valid option.
msgNumber - The references number against which the Description is refering too.
defaultOption - The default option for the given item.

messageItemDetails

public void messageItemDetails(String strClass,
                               String item,
                               String description,
                               HashMap<Integer,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:
messageItemDetails 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 HashMap<Integer,String> getChoiceOptions(String strClass,
                                                String item)
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.

getMultipleChoiceSize

public int getMultipleChoiceSize(String strClass)
Returns the number of Mulitple Choice items registered with a given class.

Specified by:
getMultipleChoiceSize in interface UserPreferencesManager

getMultipleChoiceList

public ArrayList<String> getMultipleChoiceList(String strClass)
Returns a list of all the multiple choice items registered with a given class.

Specified by:
getMultipleChoiceList in interface UserPreferencesManager

getChoiceName

public String getChoiceName(String strClass,
                            int n)
Returns the nth item name in a given class

Specified by:
getChoiceName in interface UserPreferencesManager

getChoiceDescription

public String getChoiceDescription(String strClass,
                                   String item)
Returns the a meaningful description of a given item in a given class or group.

Specified by:
getChoiceDescription in interface UserPreferencesManager

getMultipleChoiceOption

public int getMultipleChoiceOption(String strClass,
                                   String item)
Returns the current value of a given item in a given class

Specified by:
getMultipleChoiceOption in interface UserPreferencesManager

getMultipleChoiceDefaultOption

public int getMultipleChoiceDefaultOption(String strClass,
                                          String choice)
Returns the default value of a given item in a given class

Specified by:
getMultipleChoiceDefaultOption in interface UserPreferencesManager

setMultipleChoiceOption

public void setMultipleChoiceOption(String strClass,
                                    String choice,
                                    String value)
Sets the value of a given item in a given class, by its string description

Specified by:
setMultipleChoiceOption in interface UserPreferencesManager

setMultipleChoiceOption

public void setMultipleChoiceOption(String strClass,
                                    String choice,
                                    int value)
Sets the value of a given item in a given class, by its integer value

Specified by:
setMultipleChoiceOption in interface UserPreferencesManager

getClassDescription

public String getClassDescription()

getClassName

protected String getClassName()

getPreferencesSize

public int getPreferencesSize(String strClass)
returns the combined size of both types of items registered.

Specified by:
getPreferencesSize in interface UserPreferencesManager

readUserPreferences

public void readUserPreferences()


Copyright © 1997 - 2011 JMRI Community.
JMRI, DecoderPro, PanelPro, SoundPro, DispatcherPro and associated logos are our trademarks.

Additional information on copyright, trademarks and licenses is linked here.
Site hosted by: Get JMRI Model Railroad Interface at SourceForge.net. Fast, secure and Free Open Source software downloads