jas.util
Class UserProperties

java.lang.Object
  extended by java.util.Dictionary
      extended by java.util.Hashtable
          extended by java.util.Properties
              extended by jas.util.UserProperties
All Implemented Interfaces:
Serializable, Cloneable, Map

public class UserProperties
extends Properties

This class is used to store user prorerties. There is one instance for the application. The UserProperties object used is available from the Application object using a getUserProperties() method.

Author:
Tony Johnson, Jonas Gifford
See Also:
Application, Application.getUserProperties(), Serialized Form

Field Summary
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
  UserProperties()
          The Application object will create an instance for the application and save it just before the application closes.
protected UserProperties(Properties def)
           
 
Method Summary
 boolean getBoolean(String key, boolean def)
           
 Color getColor(String key, Color def)
           
 float getFloat(String key, float def)
           
 int getInteger(String key)
           
 int getInteger(String key, int def)
           
 Rectangle getRectangle(String key, Rectangle def)
           
 String getString(String key, String def)
           
 String[] getStringArray(String key, String[] def)
           
static UserProperties getUserProperties()
           
 void save()
          Saves the properties.
 void setBoolean(String key, boolean value)
           
 void setColor(String key, Color c)
           
 void setFloat(String key, float f)
           
 void setInteger(String key, int i)
           
 void setRectangle(String key, Rectangle rect)
           
 void setString(String key, String s)
           
 void setStringArray(String key, String[] sa)
           
static String[] updateStringArray(String[] oldArray, String newString)
          This is a utility method for updating a string array of recently used items.
static String[] updateStringArray(String[] oldArray, String newString, int nStored)
          This is a utility method for updating a string array of recently used items.
 String[] updateStringArray(String[] oldArray, String newString, String lengthKey)
          This is a utility method for updating a string array of recently used items.
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, load, loadFromXML, propertyNames, save, setProperty, store, store, storeToXML, storeToXML, stringPropertyNames
 
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
 

Constructor Detail

UserProperties

public UserProperties()
The Application object will create an instance for the application and save it just before the application closes. Therefore, you should not have to use the constructor yourself. The UserProperties object used is available from the Application object using a getUserProperties() method.

See Also:
Application, Application.getUserProperties()

UserProperties

protected UserProperties(Properties def)
Method Detail

getRectangle

public Rectangle getRectangle(String key,
                              Rectangle def)
Parameters:
key - the key used to store this property
def - a default in case the property cannot be retrieved

setRectangle

public void setRectangle(String key,
                         Rectangle rect)
Parameters:
key - the key used to store this property
rect - the value to store

getColor

public Color getColor(String key,
                      Color def)
Parameters:
key - the key used to store this property
def - a default in case the property cannot be retrieved

setColor

public void setColor(String key,
                     Color c)
Parameters:
key - the key used to store this property
c - the value to store

getStringArray

public String[] getStringArray(String key,
                               String[] def)
Parameters:
key - the key used to store this property
def - a default in case the property cannot be retrieved

setStringArray

public void setStringArray(String key,
                           String[] sa)
Parameters:
key - the key used to store this property
sa - the value to store

getString

public String getString(String key,
                        String def)
Parameters:
key - the key used to store this property
def - a default in case the property cannot be retrieved

setString

public void setString(String key,
                      String s)
Parameters:
key - the key used to store this property
s - the value to store

getBoolean

public boolean getBoolean(String key,
                          boolean def)
Parameters:
key - the key used to store this property
def - a default in case the property cannot be retrieved

setBoolean

public void setBoolean(String key,
                       boolean value)
Parameters:
key - the key used to store this property
value - the value to store

getInteger

public int getInteger(String key)
               throws NumberFormatException
Parameters:
key - the key used to store this property
Throws:
NumberFormatException - if the property retrieved cannot be converted to int

getInteger

public int getInteger(String key,
                      int def)
Parameters:
key - the key used to store this property
def - a default in case the property cannot be retrieved

setFloat

public void setFloat(String key,
                     float f)
Parameters:
key - the key used to store this property
f - the value to store

getFloat

public float getFloat(String key,
                      float def)
Parameters:
key - the key used to store this property
def - a default in case the property cannot be retrieved

setInteger

public void setInteger(String key,
                       int i)
Parameters:
key - the key used to store this property
i - the value to store

save

public void save()
          throws IOException
Saves the properties. The application does this for you just before closing, so you don't have to call this method.

Throws:
IOException

updateStringArray

public static String[] updateStringArray(String[] oldArray,
                                         String newString)
This is a utility method for updating a string array of recently used items. Supply it with an old array and a new item. If the new item was already in the old array, then it is simply moved to the beginning. If it was not in the old array then it is placed at the front and the other items are shuffled back. The method will return an array with a maximum size of 4.

Parameters:
oldArray - the array to update (may safely be null)
newString - the new item to include
Returns:
the updated array

updateStringArray

public String[] updateStringArray(String[] oldArray,
                                  String newString,
                                  String lengthKey)
This is a utility method for updating a string array of recently used items. Supply it with an old array and a new item. If the new item was already in the old array, then it is simply moved to the beginning. If it was not in the old array then it is placed at the front and the other items are shuffled back. The method will return an array with a maximum size defined by the integer stored by the given key, or 4 if such an integer cannot be found.

Parameters:
oldArray - the array to update (may safely be null)
newString - the new item to include
lengthKey - the key used to find the maximum length of the resulting array
Returns:
the updated array

updateStringArray

public static String[] updateStringArray(String[] oldArray,
                                         String newString,
                                         int nStored)
This is a utility method for updating a string array of recently used items. Supply it with an old array and a new item. If the new item was already in the old array, then it is simply moved to the beginning. If it was not in the old array then it is placed at the front and the other items are shuffled back. The method will return an array of a maximum size given by the nStored parameter.

Parameters:
oldArray - the array to update (may safely be null)
newString - the new item to include
nStored - the maximum size of the updated array
Returns:
the updated array

getUserProperties

public static UserProperties getUserProperties()


Copyright © 2000-2009 FreeHEP. All Rights Reserved.