T-Plan Robot Enterprise 5.0.1
Build No. 5.0.1-20190308.1

com.tplan.robot.preferences
Class UserConfiguration

java.lang.Object
  extended by com.tplan.robot.preferences.AbstractUserConfiguration
      extended by com.tplan.robot.preferences.UserConfiguration
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.util.EventListener
Direct Known Subclasses:
PreferenceContainer

public class UserConfiguration
extends AbstractUserConfiguration
implements java.beans.PropertyChangeListener

A container for user preferences. Defines variables which affect the behavior of {


T-Plan Robot Enterprise, (C) 2009-2019 T-Plan Limited. All rights reserved.


Field Summary
protected  java.util.Map configuration
          A Map which will store user configuration in the memory.
protected  java.util.Map defaults
          A Map which will store default user configuration in the memory.
protected  java.util.Map<java.lang.String,java.lang.String> overrideTable
           
static java.lang.String WATCH_DOG_LIST_KEY
           
protected  com.tplan.robot.preferences.PreferenceWatchDog watchDog
           
 
Fields inherited from class com.tplan.robot.preferences.AbstractUserConfiguration
modified, numberFormat, numberParseLock
 
Constructor Summary
protected UserConfiguration()
          Constructor.
 
Method Summary
protected  java.lang.Object get(java.lang.Object key)
          Get a parameter.
static UserConfiguration getCopy()
          Get a shared instance of this configuration.
static UserConfiguration getDefaultConfiguration()
          Get a copy of the default configuration.
 java.lang.String getDefaultValue(java.lang.String key)
          Get default value for the given parameter
 java.awt.Color[] getDefaultValueAsArrayOfColors(java.lang.String key)
          Get default value of a parameter as an array of Color instances.
 java.awt.Color getDefaultValueAsColor(java.lang.String key)
          Get default value of a parameter as a Color instance.
 java.lang.Double getDefaultValueAsDouble(java.lang.String key)
          Get default value of a parameter as an Integer.
 java.util.List getDefaultValueAsListOfNumbers(java.lang.String key)
          Get default value of a parameter as a vector of numbers.
static UserConfiguration getInstance()
          Get a shared instance of this configuration.
 javax.swing.KeyStroke getKeyStroke(java.lang.String parameterName, boolean fixForMacIfNeeded)
          Get the value as a key stroke.
 java.util.Map<java.lang.String,java.lang.String> getOverrideTable()
           
 java.util.List<java.lang.String> getPreferenceNames()
           
 java.lang.Object getRawValue(java.lang.String key)
          Get the raw value stored in the internal map for the given key.
static void load(java.io.InputStream inStream)
          Load the configuration from an input stream.
static void loadDefaults(java.io.InputStream inStream)
          Load the default configuration from an input stream.
protected  java.util.List prefillList(int maxValue)
          Create a new vector and fill it with integers from 0 to argument value.
 void propertyChange(java.beans.PropertyChangeEvent evt)
           
protected  java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Set a parameter.
 void putRawValues(java.util.Map values)
           
 void remove(java.lang.String configKey)
           
static void resetToDefaults()
           
static void save(java.io.OutputStream outStream)
          Save the configuration into an output stream.
static void saveConfiguration()
           
 void setColors(java.lang.String parameterName, java.awt.Color[] colors)
          Save an array of colors to the configuration.
 void setOverrideTable(java.util.Map overrideTable)
           
 void startWatchDog()
           
 void updateListOfRecents(java.lang.String newItem, java.lang.String configKey, int sizeLimit)
           
 void updateListOfRecents(java.lang.String newItem, java.lang.String configKey, int sizeLimit, boolean caseSensitive)
          This method will try to load a vector of strings using the given key.
 
Methods inherited from class com.tplan.robot.preferences.AbstractUserConfiguration
addConfigurationListener, addConfigurationListener, colorArrayToString, colorToString, convertToDouble, convertToListOfNumbers, fireConfigurationChanged, getArrayOfBytes, getArrayOfInts, getBoolean, getBooleanStrict, getColor, getColors, getDouble, getDoubleStrict, getInteger, getIntegerStrict, getListOfNumbers, getListOfStrings, getParameter, getString, isModified, parseColor, parseColorArray, removeConfigurationListener, setBoolean, setDouble, setHTMLColor, setHTMLColorArray, setInteger, setListOfNumbers, setListOfObjects, setParameter, setString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configuration

protected java.util.Map configuration
A Map which will store user configuration in the memory.


defaults

protected java.util.Map defaults
A Map which will store default user configuration in the memory.


overrideTable

protected java.util.Map<java.lang.String,java.lang.String> overrideTable

watchDog

protected com.tplan.robot.preferences.PreferenceWatchDog watchDog

WATCH_DOG_LIST_KEY

public static final java.lang.String WATCH_DOG_LIST_KEY
See Also:
Constant Field Values
Constructor Detail

UserConfiguration

protected UserConfiguration()
Constructor. It is protected as the classes outside this package are supposed to share one instance of this configuration class.

Method Detail

startWatchDog

public void startWatchDog()

getInstance

public static UserConfiguration getInstance()
Get a shared instance of this configuration.

Returns:
a UserConfiguration instance.

getCopy

public static UserConfiguration getCopy()
Get a shared instance of this configuration.

Returns:
a UserConfiguration instance.

getDefaultConfiguration

public static UserConfiguration getDefaultConfiguration()
Get a copy of the default configuration.

Returns:
an copy of the default user configuration loaded from the internal configuration template.

resetToDefaults

public static void resetToDefaults()

load

public static void load(java.io.InputStream inStream)
                 throws java.io.IOException
Load the configuration from an input stream.

Parameters:
inStream - an input stream to load from.
Throws:
java.io.IOException - when in I/O error occurs, e.g. cannot read from file etc.

loadDefaults

public static void loadDefaults(java.io.InputStream inStream)
                         throws java.io.IOException
Load the default configuration from an input stream.

Parameters:
inStream - an input stream to load from.
Throws:
java.io.IOException - when in I/O error occurs, e.g. cannot read from file etc.

save

public static void save(java.io.OutputStream outStream)
                 throws java.io.IOException
Save the configuration into an output stream.

Parameters:
outStream - an output stream to save to.
Throws:
java.io.IOException - when in I/O error occurs, e.g. cannot write to a file etc.

saveConfiguration

public static void saveConfiguration()

put

protected java.lang.Object put(java.lang.Object key,
                               java.lang.Object value)
Set a parameter.

Specified by:
put in class AbstractUserConfiguration
Parameters:
key - the parameter name.
value - the value.
Returns:
the object

get

protected java.lang.Object get(java.lang.Object key)
Get a parameter.

Specified by:
get in class AbstractUserConfiguration
Parameters:
key - key to the parameter (parameter name)
Returns:
parameter value, null if not found

getDefaultValue

public java.lang.String getDefaultValue(java.lang.String key)
Get default value for the given parameter

Parameters:
key - parameter name
Returns:
default value or null when there's none

getDefaultValueAsDouble

public java.lang.Double getDefaultValueAsDouble(java.lang.String key)
Get default value of a parameter as an Integer.

Parameters:
key - parameter name
Returns:
default value or null when there's none

getDefaultValueAsListOfNumbers

public java.util.List getDefaultValueAsListOfNumbers(java.lang.String key)
Get default value of a parameter as a vector of numbers.

Parameters:
key - parameter name
Returns:
default value or null when there's none

getDefaultValueAsArrayOfColors

public java.awt.Color[] getDefaultValueAsArrayOfColors(java.lang.String key)
Get default value of a parameter as an array of Color instances.

Parameters:
key - parameter name
Returns:
default value or null when there's none

getDefaultValueAsColor

public java.awt.Color getDefaultValueAsColor(java.lang.String key)
Get default value of a parameter as a Color instance.

Parameters:
key - parameter name
Returns:
default value or null when there's none

prefillList

protected java.util.List prefillList(int maxValue)
Create a new vector and fill it with integers from 0 to argument value.

Parameters:
maxValue - maximum integer value to be added.
Returns:
a new vector containing integers from 0 to argument value.

setColors

public void setColors(java.lang.String parameterName,
                      java.awt.Color[] colors)
Save an array of colors to the configuration. Each color is converted to a vector of numbers where there are three integer numbers representing Red, Green and Blue portions as defined by the Color's RGB model. The vector of numbers is then saved using the setListOfNumbers() method which converts the vector of numbers into a String.

Parameters:
parameterName - parameter name.
colors - an array of Color instances.

updateListOfRecents

public void updateListOfRecents(java.lang.String newItem,
                                java.lang.String configKey,
                                int sizeLimit,
                                boolean caseSensitive)
This method will try to load a vector of strings using the given key. If the vector already contains the new item, it gets moved to the first position. Otherwise it is inserted into the first position.

If you need to keep the vector up to a certain size long, you may use the third argument to specify max vector size. A negative number disables this feature.

This method is used by dynamic menus that list e.g. recently open documents. Whenever a document is opened, it needs to be placed into the first position in the list. Such a list is usually of limited size, it e.g. lists just five most recently opened documents.

Parameters:
newItem - a new item. If it already exists in the vector, it will be just moved.
configKey - a key identifying the configuration vector.
sizeLimit - maximum size of the vector. If the vector exceeds this size, it wil be trimmed to the required size. Any negative number disables this feature.

updateListOfRecents

public void updateListOfRecents(java.lang.String newItem,
                                java.lang.String configKey,
                                int sizeLimit)

getOverrideTable

public java.util.Map<java.lang.String,java.lang.String> getOverrideTable()

setOverrideTable

public void setOverrideTable(java.util.Map overrideTable)

putRawValues

public void putRawValues(java.util.Map values)

remove

public void remove(java.lang.String configKey)

getPreferenceNames

public java.util.List<java.lang.String> getPreferenceNames()

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
Specified by:
propertyChange in interface java.beans.PropertyChangeListener

getRawValue

public java.lang.Object getRawValue(java.lang.String key)
Get the raw value stored in the internal map for the given key. As this class maintains all the values as String instances it always returns a string. Subclasses such as SimplePreferenceContainer may return something else.

Parameters:
key - a key.
Returns:
the raw unformatted value as it is stored in the internal map.
Since:
3.1.2/3.2

getKeyStroke

public javax.swing.KeyStroke getKeyStroke(java.lang.String parameterName,
                                          boolean fixForMacIfNeeded)
Get the value as a key stroke.

Parameters:
parameterName - the parameter name.
fixForMacIfNeeded - if the value is the default one and the local OS is Mac the method will fix the key stroke to meet the Mac guidelines (Ctrl is converted to Command, Alt to Ctrl).
Returns:
the key stroke.
Since:
4.1.4

T-Plan Robot Enterprise 5.0.1
Build No. 5.0.1-20190308.1