byucc.jhdl.apps.util
Class Properties

java.lang.Object
  extended bybyucc.jhdl.apps.util.Properties

public class Properties
extends java.lang.Object

This class provides a central location for storing and retrieving global properties for CVT-related applications and components. The static methods of this class provide a simplified interface for creating and retrieving property values. Properties are identified by a string. Components should take care to make new property identifiers unique; the simplest way to do that would be to prepend the fully-qualified class name of the component that creates the property (e.g. byucc.jhdl.apps.Viewers.Schematic.SchematicCanvas:printing-fit-to-page). Various types of property values are supported: String, boolean, number (integer or double), multiple choice string.

This class is convenient for sharing property information between components. For example, the command line interpreter could be used to set properties that would then affect the way GUI components behave. For such cases of property sharing, it may be useful to have one class responsible for determining the name of the property and have that name stored in a public static final String field.

Author:
Anthony L. Slade

Field Summary
static java.lang.String CLI_GET
          The CLI command for getting property values
static java.lang.String CLI_SET
          The CLI command for setting properties
static int TYPE_BOOLEAN
          Used to indicate a property is a boolean type
static int TYPE_DOUBLE
          Used to indicate a property is a double type
static int TYPE_INTEGER
          Used to indicate a property is a integer type
static int TYPE_MULTIPLE_CHOICE
          Used to indicate a property is a multiple choice type
static int TYPE_STRING
          Used to indicate a property is a String type
static int TYPE_UNDEFINED
          Used to indicate a property type is undefined
 
Method Summary
static CLInterpreter getInterpreter()
           
static java.lang.String[] getMultipleChoiceOptions(java.lang.String property)
          Returns the possible choices for a multiple choice property.
static java.lang.String getProperty(java.lang.String identifier)
          Returns a string representation of the value of the property associated with the given identifier
static java.lang.String getProperty(java.lang.String identifier, java.lang.String defaultValue)
          Returns a string representation of the value of the property associated with the given identifier, if the property is not set, then the property is set to given defaultValue value and that value is returned
static boolean getPropertyBoolean(java.lang.String identifier)
          No matter what, this method attempts to parse the value of the property identified as if it is a boolean
static boolean getPropertyBoolean(java.lang.String identifier, boolean defaultValue)
          No matter what, this method attempts to parse the value of the property identified as if it is a boolean.
static boolean getPropertyBoolean(java.lang.String identifier, java.lang.String defaultValue)
          No matter what, this method attempts to parse the value of the property identified as if it is a boolean.
static double getPropertyDouble(java.lang.String identifier)
          No matter what, this method attempts to parse the value of the property identified as if it is a double.
static double getPropertyDouble(java.lang.String identifier, double defaultValue)
          No matter what, this method attempts to parse the value of the property identified as if it is a double.
static double getPropertyDouble(java.lang.String identifier, java.lang.String defaultValue)
          No matter what, this method attempts to parse the value of the property identified as if it is a double.
static int getPropertyInteger(java.lang.String identifier)
          No matter what, this method attempts to parse the value of the property identified as if it is an integer
static int getPropertyInteger(java.lang.String identifier, int defaultValue)
          No matter what, this method attempts to parse the value of the property identified as if it is an integer
static int getPropertyInteger(java.lang.String identifier, java.lang.String defaultValue)
          No matter what, this method attempts to parse the value of the property identified as if it is an integer
static java.lang.String getPropertyMultipleChoice(java.lang.String identifier)
          Returns the selected value of a multiple choice list property.
static java.lang.String getPropertyMultipleChoice(java.lang.String identifier, java.lang.String defaultValue)
          Returns the selected value of a multiple choice list property.
static java.lang.String getPropertyMultipleChoice(java.lang.String identifier, java.lang.String defaultValue, java.lang.String[] defaultOptions)
          Returns the selected value of a multiple choice list property.
static int getPropertyType(java.lang.String identifier)
          Returns the type of the property associated with the given identifier
static void printProperties(CLInterpreter interp)
          Displays the currently set properties on the output component of the given interpreter.
static boolean propertyExists(java.lang.String identifier)
           
static void setInterpreter(CLInterpreter theInterpreter)
          Use this method to set up the CLI commands for Properties
static void setProperty(java.lang.String identifier, java.lang.String value)
          Sets the property for the given identifier to the given value.
static void setPropertyBoolean(java.lang.String identifier, boolean value)
          Sets the property for the given identifier to the given value.
static void setPropertyBoolean(java.lang.String identifier, java.lang.String value)
          Sets the property for the given identifier to the given value.
static void setPropertyDouble(java.lang.String identifier, double value)
          Sets the property for the given identifier to the given value.
static void setPropertyDouble(java.lang.String identifier, java.lang.String value)
          Sets the property for the given identifier to the given value.
static void setPropertyInteger(java.lang.String identifier, int value)
          Sets the property for the given identifier to the given value.
static void setPropertyInteger(java.lang.String identifier, java.lang.String value)
          Sets the property for the given identifier to the given value.
static void setPropertyMultipleChoice(java.lang.String identifier, java.lang.String value)
          Sets the property for the given identifier to the given value.
static void setPropertyMultipleChoice(java.lang.String identifier, java.lang.String[] options)
          This method creates (or overwrites) a multiple choice property with the given options.
static void setPropertyMultipleChoice(java.lang.String identifier, java.lang.String[] options, java.lang.String value)
          This method creates (or overwrites) a multiple choice property with the given options.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_STRING

public static final int TYPE_STRING
Used to indicate a property is a String type

See Also:
Constant Field Values

TYPE_BOOLEAN

public static final int TYPE_BOOLEAN
Used to indicate a property is a boolean type

See Also:
Constant Field Values

TYPE_INTEGER

public static final int TYPE_INTEGER
Used to indicate a property is a integer type

See Also:
Constant Field Values

TYPE_DOUBLE

public static final int TYPE_DOUBLE
Used to indicate a property is a double type

See Also:
Constant Field Values

TYPE_MULTIPLE_CHOICE

public static final int TYPE_MULTIPLE_CHOICE
Used to indicate a property is a multiple choice type

See Also:
Constant Field Values

TYPE_UNDEFINED

public static final int TYPE_UNDEFINED
Used to indicate a property type is undefined

See Also:
Constant Field Values

CLI_SET

public static java.lang.String CLI_SET
The CLI command for setting properties


CLI_GET

public static java.lang.String CLI_GET
The CLI command for getting property values

Method Detail

propertyExists

public static boolean propertyExists(java.lang.String identifier)
Returns:
true if a property by the given name has been created, otherwise false.

getInterpreter

public static CLInterpreter getInterpreter()
Returns:
the CLInterpreter associated with the Properties CLI commands, or null if the CLI commands haven't been set.

getMultipleChoiceOptions

public static java.lang.String[] getMultipleChoiceOptions(java.lang.String property)
Returns the possible choices for a multiple choice property. If the property doesn't exist or if it is not a TYPE_MULTIPLE_CHOICE property, then the list will be empty.

Returns:
the list of possible choices for the multiple choice property indicated

getProperty

public static java.lang.String getProperty(java.lang.String identifier)
Returns a string representation of the value of the property associated with the given identifier

Parameters:
identifier - the name of the property
Returns:
the String representation of the property for the given identifier

getProperty

public static java.lang.String getProperty(java.lang.String identifier,
                                           java.lang.String defaultValue)
Returns a string representation of the value of the property associated with the given identifier, if the property is not set, then the property is set to given defaultValue value and that value is returned

Parameters:
identifier - the name of the property
defaultValue - the value to fall back on if the property hasn't been set yet
Returns:
the String representation of the property for the given identifier, or default if the property hasn't been set yet.

getPropertyBoolean

public static boolean getPropertyBoolean(java.lang.String identifier)
No matter what, this method attempts to parse the value of the property identified as if it is a boolean

Parameters:
identifier - the name of the property to look up
Returns:
true if the property is set to "true" "on" or "1"; otherwise returns false.

getPropertyBoolean

public static boolean getPropertyBoolean(java.lang.String identifier,
                                         boolean defaultValue)
No matter what, this method attempts to parse the value of the property identified as if it is a boolean. If the value hasn't been set yet, then it is set to the given defaultValue and that value is returned.

Parameters:
identifier - the name of the property to look up
defaultValue - value to fall back on if the property isn't set
Returns:
true if the property is set to "true" "on" or "1"; otherwise returns false.

getPropertyBoolean

public static boolean getPropertyBoolean(java.lang.String identifier,
                                         java.lang.String defaultValue)
No matter what, this method attempts to parse the value of the property identified as if it is a boolean. If the value hasn't been set yet, then it is set to the given defaultValue and that value is returned.

Parameters:
identifier - the name of the property to look up
defaultValue - value to fall back on if the property isn't set
Returns:
true if the property is set to "true" "on" or "1"; otherwise returns false.

getPropertyDouble

public static double getPropertyDouble(java.lang.String identifier)
No matter what, this method attempts to parse the value of the property identified as if it is a double.

Parameters:
identifier - the name of the property to look up
Returns:
The double representation of the given property or zero if the property hasn't been set.
Throws:
java.lang.NumberFormatException - if the value is not actually a double

getPropertyDouble

public static double getPropertyDouble(java.lang.String identifier,
                                       double defaultValue)
No matter what, this method attempts to parse the value of the property identified as if it is a double.

Parameters:
identifier - the name of the property to look up
defaultValue - the value to fall back on if the property isn't set.
Returns:
The double representation of the given property or defaultValue if the property hasn't been set.
Throws:
java.lang.NumberFormatException - if the current value is not actually a double.

getPropertyDouble

public static double getPropertyDouble(java.lang.String identifier,
                                       java.lang.String defaultValue)
No matter what, this method attempts to parse the value of the property identified as if it is a double.

Parameters:
identifier - the name of the property to look up
defaultValue - the value to fall back on if the property isn't set.
Returns:
The double representation of the given property or defaultValue if the property hasn't been set.
Throws:
java.lang.NumberFormatException - if the current value is not actually a double.

getPropertyInteger

public static int getPropertyInteger(java.lang.String identifier)
No matter what, this method attempts to parse the value of the property identified as if it is an integer

Parameters:
identifier - the name of the property to look up
Returns:
The integer representation of the given property or zero if the property has not been set.
Throws:
java.lang.NumberFormatException - if the value is not actually an integer

getPropertyInteger

public static int getPropertyInteger(java.lang.String identifier,
                                     int defaultValue)
No matter what, this method attempts to parse the value of the property identified as if it is an integer

Parameters:
identifier - the name of the property to look up.
defaultValue - value to fall back on if the property isn't set.
Returns:
The integer representation of the given property or defaultValue if the property has not been set.
Throws:
java.lang.NumberFormatException - if the current value is not actually an integer.

getPropertyInteger

public static int getPropertyInteger(java.lang.String identifier,
                                     java.lang.String defaultValue)
No matter what, this method attempts to parse the value of the property identified as if it is an integer

Parameters:
identifier - the name of the property to look up.
defaultValue - value to fall back on if the property isn't set.
Returns:
The integer representation of the given property or defaultValue if the property has not been set.
Throws:
java.lang.NumberFormatException - if the current value is not actually an integer.

getPropertyMultipleChoice

public static java.lang.String getPropertyMultipleChoice(java.lang.String identifier)
Returns the selected value of a multiple choice list property.

Parameters:
identifier - the name of the property to look up.
Returns:
the selected value of the list, or null if none is selected or the property has not been set.

getPropertyMultipleChoice

public static java.lang.String getPropertyMultipleChoice(java.lang.String identifier,
                                                         java.lang.String defaultValue)
Returns the selected value of a multiple choice list property.

Parameters:
identifier - the name of the property to look up.
defaultValue - the value to fall back on if and only if the property hasn't been set yet. The property will be set to defaultValue if that is the case, and defaultValue will be the only available option listed in the property.
Returns:
the selected value of the list, or null if none is selected or defaultValue if the property isn't set.

getPropertyMultipleChoice

public static java.lang.String getPropertyMultipleChoice(java.lang.String identifier,
                                                         java.lang.String defaultValue,
                                                         java.lang.String[] defaultOptions)
Returns the selected value of a multiple choice list property.

Parameters:
identifier - the name of the property to look up.
defaultValue - the value to fall back on if and only if the property hasn't been set yet. The property selection will be set to defaultValue if that is the case.
defaultOptions - if, and only if, the property hasn't been set yet, then these options will be the set of options for the property.
Returns:
the selected value of the list, or null if none is selected or defaultValue if the property isn't set.

getPropertyType

public static int getPropertyType(java.lang.String identifier)
Returns the type of the property associated with the given identifier

Parameters:
identifier - the name of the property
Returns:
the type of the property

printProperties

public static void printProperties(CLInterpreter interp)
Displays the currently set properties on the output component of the given interpreter.

Parameters:
interp - the interpreter that will print the properties

setInterpreter

public static void setInterpreter(CLInterpreter theInterpreter)
Use this method to set up the CLI commands for Properties


setProperty

public static void setProperty(java.lang.String identifier,
                               java.lang.String value)
Sets the property for the given identifier to the given value. Assumes the type will be TYPE_STRING, unless the property is already a multiple choice property, in which case the selection is set to the given value and the value is added to the end of the list of options if it is not already included.

Parameters:
identifier - the name of the property to set
value - the value to set the property to

setPropertyBoolean

public static void setPropertyBoolean(java.lang.String identifier,
                                      boolean value)
Sets the property for the given identifier to the given value. The type will be set to TYPE_BOOLEAN.

Parameters:
identifier - the name of the property to set
value - the value to set the property to

setPropertyBoolean

public static void setPropertyBoolean(java.lang.String identifier,
                                      java.lang.String value)
Sets the property for the given identifier to the given value. The type will be set to TYPE_BOOLEAN.

Parameters:
identifier - the name of the property to set
value - the value to set the property to. In order for it to be correctly interpreted as TRUE, it should be one of "true", "on", or "1".

setPropertyDouble

public static void setPropertyDouble(java.lang.String identifier,
                                     double value)
Sets the property for the given identifier to the given value. The type will be set to TYPE_DOUBLE.

Parameters:
identifier - the name of the property to set
value - the value to set the property to

setPropertyDouble

public static void setPropertyDouble(java.lang.String identifier,
                                     java.lang.String value)
Sets the property for the given identifier to the given value. The type will be set to TYPE_DOUBLE.

Parameters:
identifier - the name of the property to set
value - the value to set the property to
Throws:
java.lang.NumberFormatException - if the value is not a valid double string

setPropertyInteger

public static void setPropertyInteger(java.lang.String identifier,
                                      int value)
Sets the property for the given identifier to the given value. The type will be set to TYPE_INTEGER.

Parameters:
identifier - the name of the property to set.
value - the value to set the property to

setPropertyInteger

public static void setPropertyInteger(java.lang.String identifier,
                                      java.lang.String value)
Sets the property for the given identifier to the given value. The type will be set to TYPE_INTEGER.

Parameters:
identifier - the name of the property to set.
value - the value to set the property to; can be prefixed with 0x, 0d, 0o, or 0b for hexadecimal, decimal, octal, or binary numbers respectively.
Throws:
java.lang.NumberFormatException - if the value is not a valid integer string

setPropertyMultipleChoice

public static void setPropertyMultipleChoice(java.lang.String identifier,
                                             java.lang.String value)
Sets the property for the given identifier to the given value. The property should already be a TYPE_MULTIPLE_CHOICE property for this method to always work as expected.

The selection is set to the given value. If that value is not already in the list of options, it is added to the end of the list.

Parameters:
identifier - the name of the property to set
value - the value to set the property to

setPropertyMultipleChoice

public static void setPropertyMultipleChoice(java.lang.String identifier,
                                             java.lang.String[] options)
This method creates (or overwrites) a multiple choice property with the given options. The current selection is set to null

Parameters:
identifier - the name of the new (or overwritten) property
options - the possible options for the property

setPropertyMultipleChoice

public static void setPropertyMultipleChoice(java.lang.String identifier,
                                             java.lang.String[] options,
                                             java.lang.String value)
This method creates (or overwrites) a multiple choice property with the given options. The current selection is set to the given value.

Parameters:
identifier - the name of the new (or overwritten) property
options - the possible options for the property. It is up to the user to determine the order and uniqueness of the entries. Note that LIST_DELIMETER ('@') is not allowed to appear in the options.
value - the current selection for the property. NOTE: no effort is made to ensure that the given value is one of the options listed in the given array of String; therefore, this may be a way of setting the multiple choice property to a value that is not a default choice.


Copyright ? 2006 Brigham Young University, Configurable Computing Laboratory. All Rights Reserved.