public class Config extends Properties implements PropertyChangeSource
Properties
, adding convenience methods for storing and
retrieving properties as strings, integers, booleans, and
Color
s. 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.
Properties
,
ConfigFile
,
ChangeEvent
,
PropertyChangeEvent
,
Serialized FormModifier and Type | Field and Description |
---|---|
private static String |
DEFAULT_DESCRIPTION |
protected String |
description
The description for this set of configuration parameters.
|
protected PropertyChangeSupport |
psupport
The support object for firing
|
protected ChangeSupport |
support
The support object for firing
ChangeEvent s when the object
changes. |
defaults
Constructor and Description |
---|
Config()
Construct a new
Config with a default description. |
Config(Properties properties,
String description)
Construct a new
Config object from a Properties
list. |
Config(String description)
Construct a new
Config object. |
Modifier and Type | Method and Description |
---|---|
void |
addChangeListener(ChangeListener listener)
Add a
ChangeListener to this object's list of listeners. |
void |
addPropertyChangeListener(PropertyChangeListener listener)
Add a
PropertyChangeListener 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.
|
Font |
getFont(String key)
Look up a
Font property. |
Font |
getFont(String key,
Font defaultValue)
Look up a
Font property. |
int |
getInt(String key)
Look up an integer property.
|
int |
getInt(String key,
int defaultValue)
Look up an integer property.
|
Object |
getObject(String key,
Object defaultValue)
Look up an arbitrary object 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. |
Font |
putFont(String key,
Font value)
Store a
Font property. |
int |
putInt(String key,
int value)
Store an integer property.
|
Object |
putObject(String key,
Object value)
Store an arbitrary object 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 |
removePropertyChangeListener(PropertyChangeListener listener)
Remove a
PropertyChangeListener from this object's list of
listeners. |
void |
setDescription(String description)
Set the description for this set of configuration parameters.
|
getProperty, getProperty, list, list, load, load, loadFromXML, propertyNames, save, setProperty, store, store, storeToXML, storeToXML, stringPropertyNames
clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keys, keySet, merge, putAll, putIfAbsent, rehash, remove, replace, replace, replaceAll, size, toString, values
private static final String DEFAULT_DESCRIPTION
protected String description
protected ChangeSupport support
ChangeEvent
s when the object
changes.protected PropertyChangeSupport psupport
public Config()
Config
with a default description.public Config(String description)
Config
object.description
- The description of the configuration parameters that
will be stored in this object (one line of text).public Config(Properties properties, String description)
Config
object from a Properties
list.public String getDescription()
setDescription(java.lang.String)
public void setDescription(String description)
description
- The new description, or null
if a default
description should be used.getDescription()
public String getString(String key)
String
property.key
- The name of the property.String
, or
null
if a property with the specified name does not exist.putString(java.lang.String, java.lang.String)
public String getString(String key, String defaultValue)
String
property.key
- The name of the property.defaultValue
- The default value to return.String
, or
defaultValue
if a property with the specified name does not
exist.putString(java.lang.String, java.lang.String)
public String putString(String key, String value)
String
property.key
- The name of the property.value
- The value of the property.null
if
there was no previous value.getString(java.lang.String)
public int getInt(String key)
key
- The name of the property.int
, or 0
if a property with the specified name does not exist.putInt(java.lang.String, int)
public int getInt(String key, int defaultValue)
key
- The name of the property.defaultValue
- The default value to return.String
, or
defaultValue
if a property with the specified name does not
exist.putInt(java.lang.String, int)
public int putInt(String key, int value)
key
- The name of the property.value
- The value of the property.getInt(java.lang.String)
public boolean getBoolean(String key)
key
- The name of the property.boolean
. Returns
false
if a property with the specified name does not exist.putBoolean(java.lang.String, boolean)
public boolean getBoolean(String key, boolean defaultValue)
key
- The name of the property.defaultValue
- The default value to return.boolean
, or
defaultValue
if a property with the specified name does not
exist.putBoolean(java.lang.String, boolean)
public boolean putBoolean(String key, boolean value)
key
- The name of the property.value
- The value of the property.false
if
there was no previous value.getBoolean(java.lang.String)
public Color getColor(String key)
Color
property.key
- The name of the property.Color
. Returns
null
if a property with the specified name does not exist,
or is not a properly formatted color specification.putColor(java.lang.String, java.awt.Color)
public Color getColor(String key, Color defaultValue)
Color
property.key
- The name of the property.defaultValue
- The default value to return.Color
, or
defaultValue
if a property with the specified name does not
exist.putColor(java.lang.String, java.awt.Color)
public Color putColor(String key, Color value)
Color
property.key
- The name of the property.value
- The value of the property.null
if
there was no previous value.getColor(java.lang.String)
public Font getFont(String key)
Font
property.key
- The name of the property.Font
. Returns
null
if a property with the specified name does not exist,
or is not a properly formatted font specification.putFont(java.lang.String, java.awt.Font)
public Font getFont(String key, Font defaultValue)
Font
property.key
- The name of the property.defaultValue
- The default value to return.Font
, or
defaultValue
if a property with the specified name does not
exist.putFont(java.lang.String, java.awt.Font)
public Font putFont(String key, Font value)
Font
property.key
- The name of the property.value
- The value of the property.null
if
there was no previous value.getFont(java.lang.String)
public Object putObject(String key, Object value)
key
- The name of the property.value
- The value of the property.null
if
there was no previous value.getObject(java.lang.String, java.lang.Object)
public Object getObject(String key, Object defaultValue)
key
- The name of the property.defaultValue
- The default value to return.defaultValue
if a
property with the specified name does not exist.putObject(java.lang.String, java.lang.Object)
public void clear()
public Enumeration list()
Enumeration
.public void addChangeListener(ChangeListener listener)
ChangeListener
to this object's list of listeners.listener
- The listener to add.public void removeChangeListener(ChangeListener listener)
ChangeListener
from this object's list of
listeners.listener
- The listener to remove.public void addPropertyChangeListener(PropertyChangeListener listener)
PropertyChangeListener
to this object's list of
listeners.addPropertyChangeListener
in interface PropertyChangeSource
listener
- The listener to add.public void removePropertyChangeListener(PropertyChangeListener listener)
PropertyChangeListener
from this object's list of
listeners.removePropertyChangeListener
in interface PropertyChangeSource
listener
- The listener to remove.WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses