Class UserPrefs

java.lang.Object
   |
   +----java.util.Dictionary
           |
           +----java.util.Hashtable
                   |
                   +----java.util.Properties
                           |
                           +----UserPrefs

public class UserPrefs
extends Properties
Simple, generic class to load up or save properties for an application. (eg user preferences) While reading in values, it will automatically convert from string format, to your choice of int or boolean, if desired. We assume that you want properties stored in a file named $HOME/.yourappname, where $HOME represents the users "home directory"


Constructor Index

 o UserPrefs(String)
We try to read in a preferences file, from the user's "HOME" directory.

Method Index

 o getBool(String)
look up property that is a boolean value
 o getBool(String, boolean)
 o getInt(String)
look up property that is an int value
 o getInt(String, int)
look up property that is an int value
 o getString(String)
Gets named resource, as a string value.
 o getString(String, String)
Gets named resource, as a string value.
 o getUserHome()
The java spec guarantees that a "home" directory be specified.
 o Save()
save user preferences to default file.
 o setPref(String, String)
way to directly set a preference.

Constructors

 o UserPrefs
 public UserPrefs(String appname)
We try to read in a preferences file, from the user's "HOME" directory. We base the name of the file, on the name of the application we are in. Use the getUserHome() call if you want to know what directory this is in.

Parameters:
appname - name of application calling this class

Methods

 o getUserHome
 public String getUserHome()
The java spec guarantees that a "home" directory be specified. We look it up for our own uses at initialization If you want to do other things in the user's home dir, this routine is an easy way to find out where it is. This returns string that will have trailing fileseparator, eg "/") so you can slap together a filename directly after it, and not worry about that sort of junk.

 o setPref
 public void setPref(String prefname,
                     String value)
way to directly set a preference. You'll have to do your own type conversion.

Parameters:
prefname - name of property
value - string value of property
 o getString
 public String getString(String name)
Gets named resource, as a string value. returns null if no such resource defined.

Parameters:
name - name of property
 o getString
 public String getString(String name,
                         String defstr)
Gets named resource, as a string value.

Parameters:
name - name of property
defval - default value to remember and return , if no existing property name found.
 o getInt
 public int getInt(String name)
look up property that is an int value

Parameters:
name - name of property
 o getInt
 public int getInt(String name,
                   int defval)
look up property that is an int value

Parameters:
name - name of property
defval - default value to remember and return , if no existing property name found.
 o getBool
 public boolean getBool(String name)
look up property that is a boolean value

Parameters:
name - name of property
defval - default value to remember and return , if no existing property name found.
 o getBool
 public boolean getBool(String name,
                        boolean defval)
Parameters:
name - name of property
defval - default value to remember and return , if no existing property name found.
 o Save
 public void Save() throws IOException
save user preferences to default file. Duh.