mae.util
Class PropertyManager

java.lang.Object
  extended byjava.util.Dictionary
      extended byjava.util.Hashtable
          extended byjava.util.Properties
              extended bymae.util.PropertyManager
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class PropertyManager
extends java.util.Properties

Loads and saves Properties, with support for Color, Font, Bounds.

    Three levels are allowed:
  1. A file in the directory where the VM is started (depends on the IDE) ie, new File(".")
    When this file is empty, level two is used
  2. A read/only file (resource) in the directory where this class is located (this could be in a jar file)
  3. Defaults coded in the program
We try to find properties in this order on construction.
When saved, currnt values of properties are written to the first file above.

See Also:
Serialized Form

Field Summary
static java.lang.String EXT
          Default extension used in all property files
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
PropertyManager(java.lang.String p)
          Returns an instance, using file p.EXT in the directory where VM is started with no defaults.
PropertyManager(java.lang.String p, java.lang.Class caller)
          Returns an instance, using file p.EXT in the directory where VM is started, with defaults together with caller class.
PropertyManager(java.lang.String f, java.lang.String p, java.lang.Class caller)
          Returns an instance, using file f/p.EXT in the home directory of the user.
 
Method Summary
 java.awt.Rectangle getBounds(java.lang.String d, int w, int h)
          Returns a Rectangle property with name d, default width & height
 java.awt.Color getColor(java.lang.String d, java.awt.Color def)
          Returns a Color property with name d, default def
 java.awt.Font getFont(java.lang.String d, java.awt.Font def)
          Returns a Font property with name d, default def
 int getInteger(java.lang.String d, int def)
          Returns an integer property with name d, default def
 void list()
          Lists first level Properties object on System output
 void save(java.lang.String desc)
          Saves first level Properties object, with one-line comment desc
 void setBounds(java.lang.String d, java.awt.Rectangle r)
          Sets a Rectangle property with name d, value r
 void setColor(java.lang.String d, java.awt.Color c)
          Sets a Color property with name d, value c
 void setFont(java.lang.String d, java.awt.Font f)
          Sets a Font property with name d, value f
static boolean setIcon(javax.swing.JFrame f, java.lang.String s)
          Sets Icon for f, using image with name s
 void store(java.io.OutputStream os, java.lang.String head)
          Stores first level Properties object, overrides store()
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, propertyNames, save, setProperty
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EXT

public static final java.lang.String EXT
Default extension used in all property files

See Also:
Constant Field Values
Constructor Detail

PropertyManager

public PropertyManager(java.lang.String p)
Returns an instance, using file p.EXT in the directory where VM is started with no defaults.


PropertyManager

public PropertyManager(java.lang.String p,
                       java.lang.Class caller)
Returns an instance, using file p.EXT in the directory where VM is started, with defaults together with caller class.


PropertyManager

public PropertyManager(java.lang.String f,
                       java.lang.String p,
                       java.lang.Class caller)
Returns an instance, using file f/p.EXT in the home directory of the user.

Caller class is needed to locate resource file.

Method Detail

store

public void store(java.io.OutputStream os,
                  java.lang.String head)
           throws java.io.IOException
Stores first level Properties object, overrides store()

Throws:
java.io.IOException

save

public void save(java.lang.String desc)
Saves first level Properties object, with one-line comment desc


list

public void list()
Lists first level Properties object on System output


getInteger

public int getInteger(java.lang.String d,
                      int def)
Returns an integer property with name d, default def


setColor

public void setColor(java.lang.String d,
                     java.awt.Color c)
Sets a Color property with name d, value c


getColor

public java.awt.Color getColor(java.lang.String d,
                               java.awt.Color def)
Returns a Color property with name d, default def


setBounds

public void setBounds(java.lang.String d,
                      java.awt.Rectangle r)
Sets a Rectangle property with name d, value r


getBounds

public java.awt.Rectangle getBounds(java.lang.String d,
                                    int w,
                                    int h)
Returns a Rectangle property with name d, default width & height


setFont

public void setFont(java.lang.String d,
                    java.awt.Font f)
Sets a Font property with name d, value f


getFont

public java.awt.Font getFont(java.lang.String d,
                             java.awt.Font def)
Returns a Font property with name d, default def


setIcon

public static boolean setIcon(javax.swing.JFrame f,
                              java.lang.String s)
Sets Icon for f, using image with name s