org.esa.beam.util
Class PropertyMap

java.lang.Object
  extended by org.esa.beam.util.PropertyMap

public class PropertyMap
extends Object

The PropertyMap class can be used instead of the standard JDK java.util.Properties class.PropertyMap provides a generally more useful interface by adding a couple type conversion methods for a set of most frequently used data types, such as Boolean, Integer, Double, Color and Font.

Additionally the class provides property change support.

Version:
$Revision$ $Date$
Author:
Norman Fomferra

Constructor Summary
PropertyMap()
          Constructs a new and empty property map.
PropertyMap(Properties properties)
          Constructs a property map which uses the given Properties as a key/value container.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener listener)
           
 void addPropertyChangeListener(String key, PropertyChangeListener listener)
           
protected  void firePropertyChange(String key, Object oldValue, Object newValue)
           
 Properties getProperties()
          Returns the Properties instance in which this property map stores its key/value pairs.
 boolean getPropertyBool(String key)
          Gets a value of type boolean.
 boolean getPropertyBool(String key, boolean defaultValue)
          Gets a value of type boolean.
 Boolean getPropertyBool(String key, Boolean defaultValue)
          Gets a value of type Boolean.
 Color getPropertyColor(String key)
          Gets a value of type Color.
 Color getPropertyColor(String key, Color defaultValue)
          Gets a value of type Color.
 double getPropertyDouble(String key)
          Gets a value of type double.
 double getPropertyDouble(String key, double defaultValue)
          Gets a value of type double.
 Double getPropertyDouble(String key, Double defaultValue)
          Gets a value of type Double.
 Font getPropertyFont(String key)
          Gets a value of type Font.
 Font getPropertyFont(String key, Font defaultValue)
          Gets a value of type Font.
 int getPropertyInt(String key)
          Gets a value of type int.
 int getPropertyInt(String key, int defaultValue)
          Gets a value of type int.
 Integer getPropertyInt(String key, Integer defaultValue)
          Gets a value of type Integer.
 Enumeration getPropertyKeys()
          Returns an enumeration of the property keys in this map.
 String getPropertyString(String key)
          Gets a value of type String.
 String getPropertyString(String key, String defaultValue)
          Gets a value of type String.
 void load(File file)
          Loads key/value pairs from a text file into this property map.
 void removePropertyChangeListener(PropertyChangeListener listener)
           
 void removePropertyChangeListener(String key, PropertyChangeListener listener)
           
 void setPropertyBool(String key, boolean value)
          Sets a value of type boolean.
 void setPropertyBool(String key, Boolean newValue)
          Sets a value of type Boolean.
 void setPropertyColor(String key, Color newValue)
          Sets a value of type Color.
 void setPropertyDouble(String key, double newValue)
          Sets a value of type double.
 void setPropertyDouble(String key, Double newValue)
          Sets a value of type Double.
 void setPropertyFont(String key, Font newValue)
          Sets a font of type Font.
 void setPropertyInt(String key, int newValue)
          Sets a value of type int.
 void setPropertyInt(String key, Integer newValue)
          Sets a value of type Integer.
 void setPropertyString(String key, String newValue)
          Sets a value of type String.
 void store(File file, String header)
          Stores the key/value pairs of this property map into a text file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyMap

public PropertyMap()
Constructs a new and empty property map.


PropertyMap

public PropertyMap(Properties properties)
Constructs a property map which uses the given Properties as a key/value container.

Method Detail

load

public void load(File file)
          throws IOException
Loads key/value pairs from a text file into this property map.

Parameters:
file - the text file
Throws:
IOException - if an I/O error occurs

store

public void store(File file,
                  String header)
           throws IOException
Stores the key/value pairs of this property map into a text file.

Parameters:
file - the text file
header - an optional file header
Throws:
IOException - if an I/O error occurs

getProperties

public Properties getProperties()
Returns the Properties instance in which this property map stores its key/value pairs.


getPropertyKeys

public Enumeration getPropertyKeys()
Returns an enumeration of the property keys in this map.


getPropertyBool

public boolean getPropertyBool(String key)
Gets a value of type boolean.

Parameters:
key - the key
Returns:
the value for the given key, or false if the key is not contained in this property set.

getPropertyBool

public boolean getPropertyBool(String key,
                               boolean defaultValue)
Gets a value of type boolean.

Parameters:
key - the key
defaultValue - the default value that is returned if the key was not found in this property set.
Returns:
the value for the given key, or defaultValue if the key is not contained in this property set.

getPropertyBool

public Boolean getPropertyBool(String key,
                               Boolean defaultValue)
Gets a value of type Boolean.

Parameters:
key - the key
defaultValue - the default value that is returned if the key was not found in this property set.
Returns:
the value for the given key, or defaultValue if the key is not contained in this property set.

setPropertyBool

public void setPropertyBool(String key,
                            boolean value)
Sets a value of type boolean.

Parameters:
key - the key
value - the value
Throws:
IllegalArgumentException

setPropertyBool

public void setPropertyBool(String key,
                            Boolean newValue)
Sets a value of type Boolean.

Parameters:
key - the key
newValue - the new value
Throws:
IllegalArgumentException

getPropertyInt

public int getPropertyInt(String key)
Gets a value of type int.

Parameters:
key - the key
Returns:
the value for the given key, or 0 (zero) if the key is not contained in this property set.

getPropertyInt

public int getPropertyInt(String key,
                          int defaultValue)
Gets a value of type int.

Parameters:
key - the key
defaultValue - the default value that is returned if the key was not found in this property set.
Returns:
the value for the given key, or defaultValue if the key is not contained in this property set.

getPropertyInt

public Integer getPropertyInt(String key,
                              Integer defaultValue)
Gets a value of type Integer.

Parameters:
key - the key
defaultValue - the default value that is returned if the key was not found in this property set.
Returns:
the value for the given key, or defaultValue if the key is not contained in this property set.

setPropertyInt

public void setPropertyInt(String key,
                           int newValue)
Sets a value of type int.

Parameters:
key - the key
newValue - the new value
Throws:
IllegalArgumentException

setPropertyInt

public void setPropertyInt(String key,
                           Integer newValue)
Sets a value of type Integer.

Parameters:
key - the key
newValue - the value
Throws:
IllegalArgumentException

getPropertyDouble

public double getPropertyDouble(String key)
Gets a value of type double.

Parameters:
key - the key
Returns:
the value for the given key, or 0.0 (zero) if the key is not contained in this property set.

getPropertyDouble

public double getPropertyDouble(String key,
                                double defaultValue)
Gets a value of type double.

Parameters:
key - the key
defaultValue - the default value that is returned if the key was not found in this property set.
Returns:
the value for the given key, or defaultValue if the key is not contained in this property set.

getPropertyDouble

public Double getPropertyDouble(String key,
                                Double defaultValue)
Gets a value of type Double.

Parameters:
key - the key
defaultValue - the default value that is returned if the key was not found in this property set.
Returns:
the value for the given key, or defaultValue if the key is not contained in this property set.

setPropertyDouble

public void setPropertyDouble(String key,
                              double newValue)
Sets a value of type double.

Parameters:
key - the key
newValue - the new value
Throws:
IllegalArgumentException

setPropertyDouble

public void setPropertyDouble(String key,
                              Double newValue)
Sets a value of type Double.

Parameters:
key - the key
newValue - the value
Throws:
IllegalArgumentException

getPropertyString

public String getPropertyString(String key)
Gets a value of type String.

Parameters:
key - the key
Returns:
the value for the given key, or "" (empty string) if the key is not contained in this property set, never null.

getPropertyString

public String getPropertyString(String key,
                                String defaultValue)
Gets a value of type String.

Parameters:
key - the key
defaultValue - the default value that is returned if the key was not found in this property set.
Returns:
the value for the given key, or defaultValue if the key is not contained in this property set.

setPropertyString

public void setPropertyString(String key,
                              String newValue)
Sets a value of type String.

Parameters:
key - the key
newValue - the new value
Throws:
IllegalArgumentException

getPropertyColor

public Color getPropertyColor(String key)
Gets a value of type Color.

Parameters:
key - the key
Returns:
the value for the given key, or Color.black if the key is not contained in this property set, never null.

getPropertyColor

public Color getPropertyColor(String key,
                              Color defaultValue)
Gets a value of type Color.

Parameters:
key - the key
defaultValue - the default value that is returned if the key was not found in this property set.
Returns:
the value for the given key, or defaultValue if the key is not contained in this property set.

setPropertyColor

public void setPropertyColor(String key,
                             Color newValue)
Sets a value of type Color.

Parameters:
key - the key
newValue - the value
Throws:
IllegalArgumentException

getPropertyFont

public Font getPropertyFont(String key)
Gets a value of type Font. The method actually looks for three keys in order to construct the font instance:
  • <key>.name for the font's name
  • <key>.style for the font's style (an integer value)
  • <key>.name for the font's size in points (an integer value)
  • Parameters:
    key - the key
    Returns:
    the value for the given key, or a plain, 12-point "SandSerif" font if the key is not contained in this property set, never null.

    getPropertyFont

    public Font getPropertyFont(String key,
                                Font defaultValue)
    Gets a value of type Font. The method actually looks for three keys in order to construct the font instance:
  • <key>.name for the font's name
  • <key>.style for the font's style (an integer value)
  • <key>.name for the font's size in points (an integer value)
  • Parameters:
    key - the key
    defaultValue - the default value that is returned if the key was not found in this property set.
    Returns:
    the value for the given key, or defaultValue if the key is not contained in this property set.

    setPropertyFont

    public void setPropertyFont(String key,
                                Font newValue)
    Sets a font of type Font. The method actually puts three keys in this property set in order to store the font's properties:
  • <key>.name for the font's name
  • <key>.style for the font's style (an integer font)
  • <key>.name for the font's size in points (an integer font)
  • Parameters:
    key - the key
    newValue - the font
    Throws:
    IllegalArgumentException

    addPropertyChangeListener

    public void addPropertyChangeListener(PropertyChangeListener listener)

    addPropertyChangeListener

    public void addPropertyChangeListener(String key,
                                          PropertyChangeListener listener)

    removePropertyChangeListener

    public void removePropertyChangeListener(PropertyChangeListener listener)

    removePropertyChangeListener

    public void removePropertyChangeListener(String key,
                                             PropertyChangeListener listener)

    firePropertyChange

    protected void firePropertyChange(String key,
                                      Object oldValue,
                                      Object newValue)


    Copyright © 2002-2013 Brockmann Consult GmbH. All Rights Reserved.