kiwi.util
Class Config

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--java.util.Properties
                    |
                    +--kiwi.util.Config
Direct Known Subclasses:
ConfigFile

public class Config
extends Properties

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.

Version:
1.1 (11/98)
Author:
Mark Lindner, PING Software Group
See Also:
Properties, ConfigFile, ChangeEvent, Serialized Form

Field Summary
protected  String description
          The description for this set of configuration parameters.
protected  ChangeSupport support
          The support object for firing ChangeEvents when the object changes.
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
Config()
          Construct a new Config with a default description.
Config(String description)
          Construct a new Config object.
 
Method Summary
 void addChangeListener(ChangeListener listener)
          Add a ChangeListener to this object's list of listeners.
 void clear()
          Remove all properties.
 boolean getBoolean(String key)
          Look up an boolean property.
 boolean getBoolean(String key, boolean defaultValue)
          Look up a boolean property.
 Color getColor(String key)
          Look up a Color property.
 Color getColor(String key, Color defaultValue)
          Look up a Color property.
 String getDescription()
          Get the description for this set of configuration parameters.
 int getInt(String key)
          Look up an integer property.
 int getInt(String key, int defaultValue)
          Look up an integer property.
 String getString(String key)
          Look up a String property.
 String getString(String key, String defaultValue)
          Look up a String property.
 Enumeration list()
          Get a list of properties.
 Object put(Object key, Object value)
          Store an arbitrary property.
 boolean putBoolean(String key, boolean value)
          Store a boolean property.
 Color putColor(String key, Color value)
          Store a Color property.
 int putInt(String key, int value)
          Store an integer property.
 String putString(String key, String value)
          Store a String property.
 Object remove(Object key)
          Remove a property.
 void removeChangeListener(ChangeListener listener)
          Remove a ChangeListener from this object's list of listeners.
 void setDescription(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

description

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

support

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

Config

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

Config

public Config(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).
Method Detail

getDescription

public String getDescription()
Get the description for this set of configuration parameters.
Returns:
The description.
See Also:
setDescription(java.lang.String)

setDescription

public void setDescription(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 String getString(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 String getString(String key,
                        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 String putString(String key,
                        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(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(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(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(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(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(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 Color getColor(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 Color getColor(String key,
                      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 Color putColor(String key,
                      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)

put

public Object put(Object key,
                  Object value)
Store an arbitrary property.
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.
Overrides:
put in class Hashtable

remove

public Object remove(Object key)
Remove a property. Removes the property for the given key.
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.
Overrides:
remove in class Hashtable
See Also:
clear()

clear

public void clear()
Remove all properties. Removes all properties from this object.
Overrides:
clear in class Hashtable

list

public Enumeration list()
Get a list of properties.
Returns:
A list of the property names as an Enumeration.

addChangeListener

public void addChangeListener(ChangeListener listener)
Add a ChangeListener to this object's list of listeners.
Parameters:
listener - The listener to add.

removeChangeListener

public void removeChangeListener(ChangeListener listener)
Remove a ChangeListener from this object's list of listeners.
Parameters:
listener - The listener to remove.