kiwi.util
Class Config

java.lang.Object
  extended byjava.util.Dictionary
      extended byjava.util.Hashtable
          extended byjava.util.Properties
              extended bykiwi.util.Config
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, PropertyChangeSource, java.io.Serializable

public class Config
extends java.util.Properties
implements PropertyChangeSource

Configuration object. This class extends Properties, adding convenience methods for storing and retrieving properties as strings, integers, booleans, and Colors. All values are stored internally as strings, so that persisting the object will produce a human-readable and -modifiable file.

Whenever the contents of the Config object change, a ChangeEvent is fired. Also, when a specific property in the object changes, a PropertyChangeEvent is fired.

Author:
Mark Lindner, PING Software Group
See Also:
Properties, kiwi.io.ConfigFile, ChangeEvent, PropertyChangeEvent, Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.Hashtable
 
Field Summary
private static java.lang.String DEFAULT_DESCRIPTION
           
protected  java.lang.String description
          The description for this set of configuration parameters.
protected  java.beans.PropertyChangeSupport psupport
          The support object for firing PropertyChangeEvents when a property changes.
protected  ChangeSupport support
          The support object for firing ChangeEvents when the object changes.
 
Fields inherited from class java.util.Properties
defaults
 
Fields inherited from class java.util.Hashtable
 
Constructor Summary
Config()
          Construct a new Config with a default description.
Config(java.util.Properties properties, java.lang.String description)
          Construct a new Config object from a Properties list.
Config(java.lang.String description)
          Construct a new Config object.
 
Method Summary
 void addChangeListener(javax.swing.event.ChangeListener listener)
          Add a ChangeListener to this object's list of listeners.
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Add a PropertyChangeListener to this object's list of listeners.
 void clear()
          Remove all properties.
 boolean getBoolean(java.lang.String key)
          Look up an boolean property.
 boolean getBoolean(java.lang.String key, boolean defaultValue)
          Look up a boolean property.
 java.awt.Color getColor(java.lang.String key)
          Look up a Color property.
 java.awt.Color getColor(java.lang.String key, java.awt.Color defaultValue)
          Look up a Color property.
 java.lang.String getDescription()
          Get the description for this set of configuration parameters.
 java.awt.Font getFont(java.lang.String key)
          Look up a Font property.
 java.awt.Font getFont(java.lang.String key, java.awt.Font defaultValue)
          Look up a Font property.
 int getInt(java.lang.String key)
          Look up an integer property.
 int getInt(java.lang.String key, int defaultValue)
          Look up an integer property.
 java.lang.String getString(java.lang.String key)
          Look up a String property.
 java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
          Look up a String property.
 java.util.Enumeration list()
          Get a list of properties.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Store an arbitrary property.
 boolean putBoolean(java.lang.String key, boolean value)
          Store a boolean property.
 java.awt.Color putColor(java.lang.String key, java.awt.Color value)
          Store a Color property.
 java.awt.Font putFont(java.lang.String key, java.awt.Font value)
          Store a Font property.
 int putInt(java.lang.String key, int value)
          Store an integer property.
 java.lang.String putString(java.lang.String key, java.lang.String value)
          Store a String property.
 java.lang.Object remove(java.lang.Object key)
          Remove a property.
 void removeChangeListener(javax.swing.event.ChangeListener listener)
          Remove a ChangeListener from this object's list of listeners.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Remove a PropertyChangeListener from this object's list of listeners.
 void setDescription(java.lang.String description)
          Set the description for this set of configuration parameters.
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, propertyNames, save, setProperty, store
 
Methods inherited from class java.util.Hashtable
clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, putAll, rehash, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_DESCRIPTION

private static final java.lang.String DEFAULT_DESCRIPTION
See Also:
Constant Field Values

description

protected java.lang.String description
The description for this set of configuration parameters.


support

protected ChangeSupport support
The support object for firing ChangeEvents when the object changes.


psupport

protected java.beans.PropertyChangeSupport psupport
The support object for firing PropertyChangeEvents when a property changes.

Constructor Detail

Config

public Config()
Construct a new Config with a default description.


Config

public Config(java.lang.String description)
Construct a new Config object.

Parameters:
description - The description of the configuration parameters that will be stored in this object (one line of text).

Config

public Config(java.util.Properties properties,
              java.lang.String description)
Construct a new Config object from a Properties list.

Method Detail

getDescription

public java.lang.String getDescription()
Get the description for this set of configuration parameters.

Returns:
The description.
See Also:
setDescription(java.lang.String)

setDescription

public void setDescription(java.lang.String description)
Set the description for this set of configuration parameters.

Parameters:
description - The new description, or null if a default description should be used.
See Also:
getDescription()

getString

public java.lang.String getString(java.lang.String key)
Look up a String property.

Parameters:
key - The name of the property.
Returns:
The property's value, as a String, or null if a property with the specified name does not exist.
See Also:
putString(java.lang.String, java.lang.String)

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String defaultValue)
Look up a String property.

Parameters:
key - The name of the property.
defaultValue - The default value to return.
Returns:
The property's value, as a String, or defaultValue if a property with the specified name does not exist.
See Also:
putString(java.lang.String, java.lang.String)

putString

public java.lang.String putString(java.lang.String key,
                                  java.lang.String value)
Store a String property.

Parameters:
key - The name of the property.
value - The value of the property.
Returns:
The old value associated with this key, or null if there was no previous value.
See Also:
getString(java.lang.String)

getInt

public int getInt(java.lang.String key)
Look up an integer property.

Parameters:
key - The name of the property.
Returns:
The property's value, as an int, or 0 if a property with the specified name does not exist.
See Also:
putInt(java.lang.String, int)

getInt

public int getInt(java.lang.String key,
                  int defaultValue)
Look up an integer property.

Parameters:
key - The name of the property.
defaultValue - The default value to return.
Returns:
The property's value, as an String, or defaultValue if a property with the specified name does not exist.
See Also:
putInt(java.lang.String, int)

putInt

public int putInt(java.lang.String key,
                  int value)
Store an integer property.

Parameters:
key - The name of the property.
value - The value of the property.
Returns:
The old value associated with this key, or 0 if there was no previous value.
See Also:
getInt(java.lang.String)

getBoolean

public boolean getBoolean(java.lang.String key)
Look up an boolean property.

Parameters:
key - The name of the property.
Returns:
The property's value, as a boolean. Returns false if a property with the specified name does not exist.
See Also:
putBoolean(java.lang.String, boolean)

getBoolean

public boolean getBoolean(java.lang.String key,
                          boolean defaultValue)
Look up a boolean property.

Parameters:
key - The name of the property.
defaultValue - The default value to return.
Returns:
The property's value, as a boolean, or defaultValue if a property with the specified name does not exist.
See Also:
putBoolean(java.lang.String, boolean)

putBoolean

public boolean putBoolean(java.lang.String key,
                          boolean value)
Store a boolean property.

Parameters:
key - The name of the property.
value - The value of the property.
Returns:
The old value associated with this key, or false if there was no previous value.
See Also:
getBoolean(java.lang.String)

getColor

public java.awt.Color getColor(java.lang.String key)
Look up a Color property.

Parameters:
key - The name of the property.
Returns:
The property's value, as a Color. Returns null if a property with the specified name does not exist, or is not a properly formatted color specification.
See Also:
putColor(java.lang.String, java.awt.Color)

getColor

public java.awt.Color getColor(java.lang.String key,
                               java.awt.Color defaultValue)
Look up a Color property.

Parameters:
key - The name of the property.
defaultValue - The default value to return.
Returns:
The property's value, as a Color, or defaultValue if a property with the specified name does not exist.
See Also:
putColor(java.lang.String, java.awt.Color)

putColor

public java.awt.Color putColor(java.lang.String key,
                               java.awt.Color value)
Store a Color property.

Parameters:
key - The name of the property.
value - The value of the property.
Returns:
The old value associated with this key, or null if there was no previous value.
See Also:
getColor(java.lang.String)

getFont

public java.awt.Font getFont(java.lang.String key)
Look up a Font property.

Parameters:
key - The name of the property.
Returns:
The property's value, as a Font. Returns null if a property with the specified name does not exist, or is not a properly formatted font specification.
See Also:
putFont(java.lang.String, java.awt.Font)

getFont

public java.awt.Font getFont(java.lang.String key,
                             java.awt.Font defaultValue)
Look up a Font property.

Parameters:
key - The name of the property.
defaultValue - The default value to return.
Returns:
The property's value, as a Font, or defaultValue if a property with the specified name does not exist.
See Also:
putFont(java.lang.String, java.awt.Font)

putFont

public java.awt.Font putFont(java.lang.String key,
                             java.awt.Font value)
Store a Font property.

Parameters:
key - The name of the property.
value - The value of the property.
Returns:
The old value associated with this key, or null if there was no previous value.
See Also:
getFont(java.lang.String)

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Store an arbitrary property.

Specified by:
put in interface java.util.Map
Parameters:
key - The object that identifies the property.
value - The value of the property.
Returns:
The old value associated with this key, or null if there was no previous value.

remove

public java.lang.Object remove(java.lang.Object key)
Remove a property. Removes the property for the given key.

Specified by:
remove in interface java.util.Map
Parameters:
key - The object that identifies the property.
Returns:
The value associated with this key, or null if there was no property with the given key in this object.
See Also:
clear()

clear

public void clear()
Remove all properties. Removes all properties from this object.

Specified by:
clear in interface java.util.Map

list

public java.util.Enumeration list()
Get a list of properties.

Returns:
A list of the property names as an Enumeration.

addChangeListener

public void addChangeListener(javax.swing.event.ChangeListener listener)
Add a ChangeListener to this object's list of listeners.

Parameters:
listener - The listener to add.

removeChangeListener

public void removeChangeListener(javax.swing.event.ChangeListener listener)
Remove a ChangeListener from this object's list of listeners.

Parameters:
listener - The listener to remove.

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a PropertyChangeListener to this object's list of listeners.

Specified by:
addPropertyChangeListener in interface PropertyChangeSource
Parameters:
listener - The listener to add.
Since:
Kiwi 1.3

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a PropertyChangeListener from this object's list of listeners.

Specified by:
removePropertyChangeListener in interface PropertyChangeSource
Parameters:
listener - The listener to remove.
Since:
Kiwi 1.3