org.bs.mdi
Class Preferences

java.lang.Object
  extended byorg.bs.mdi.Preferences

public class Preferences
extends Object

Manages application-specific per-user preferences and settings.


Field Summary
protected static String newline
           
 
Constructor Summary
Preferences()
          Creates a new Preferences object.
 
Method Summary
 boolean getBoolean(String key, boolean def)
          Returns the boolean value specified by the given key from the preferences file.
 double getDouble(String key, double def)
          Returns the double value specified by the given key from the preferences file.
 int getInt(String key, int def)
          Returns the int value specified by the given key from the preferences file.
 long getLong(String key, long def)
          Returns the long value specified by the given key from the preferences file.
 Point getPoint(String key)
          Returns the point specified by the given key from the preferences file.
 Rectangle getRectangle(String key)
          Returns the rectangle specified by the given key from the preferences file.
 String getString(String key)
          Returns the string specified by the given key from the preferences file.
 void load()
          Loads the preferences from disk.
protected  String pointToString(Point p)
           
protected  String rectangleToString(Rectangle rect)
           
 void reload()
          Reloads the preferences from disk
 void save()
          Saves the preferences to disk.
 void setDouble(String key, double value)
          Writes the specified key-value pair into the preferences file.
 void setInt(String key, int value)
          Writes the specified key-value pair into the preferences file.
 void setLong(String key, long value)
          Writes the specified key-value pair into the preferences file.
 void setPoint(String key, Point value)
          Writes the specified key-value pair into the preferences file.
 void setRectangle(String key, Rectangle value)
          Writes the specified key-value pair into the preferences file.
 void setString(String key, String value)
          Writes the specified key-value pair into the preferences file.
protected  Boolean stringToBoolean(String s)
           
protected  Point stringToPoint(String s)
           
protected  Rectangle stringToRectangle(String s)
           
protected  Object toObject(String s)
           
protected  String toString(Object o)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

newline

protected static String newline
Constructor Detail

Preferences

public Preferences()
Creates a new Preferences object. Uses the application's name (see Application.getName()) as filename to store and retrieve user settings. The preferences file is usually created in the user's home directory and prefixed with a dot character to make it invisible on UNIX machines.

Method Detail

save

public void save()
Saves the preferences to disk.


load

public void load()
Loads the preferences from disk.


reload

public void reload()
Reloads the preferences from disk


getString

public String getString(String key)
Returns the string specified by the given key from the preferences file.

Parameters:
key - the key
Returns:
the string or null in case of error

getInt

public int getInt(String key,
                  int def)
Returns the int value specified by the given key from the preferences file.

Parameters:
key - the key
def - the default value which will be returned in case of error
Returns:
the int value

getLong

public long getLong(String key,
                    long def)
Returns the long value specified by the given key from the preferences file.

Parameters:
key - the key
def - the default value which will be returned in case of error
Returns:
the long value

getDouble

public double getDouble(String key,
                        double def)
Returns the double value specified by the given key from the preferences file.

Parameters:
key - the key
def - the default value which will be returned in case of error
Returns:
the double value

getPoint

public Point getPoint(String key)
Returns the point specified by the given key from the preferences file.

Parameters:
key - the key
Returns:
the point, or null in case of error

getRectangle

public Rectangle getRectangle(String key)
Returns the rectangle specified by the given key from the preferences file.

Parameters:
key - the key
Returns:
the rectangle, or null in case of error

getBoolean

public boolean getBoolean(String key,
                          boolean def)
Returns the boolean value specified by the given key from the preferences file.

Parameters:
key - the key
def - the default value which will be returned in case of error
Returns:
the boolean value

setString

public void setString(String key,
                      String value)
Writes the specified key-value pair into the preferences file.

Parameters:
key - the key
value - the value

setInt

public void setInt(String key,
                   int value)
Writes the specified key-value pair into the preferences file.

Parameters:
key - the key
value - the value

setLong

public void setLong(String key,
                    long value)
Writes the specified key-value pair into the preferences file.

Parameters:
key - the key
value - the value

setDouble

public void setDouble(String key,
                      double value)
Writes the specified key-value pair into the preferences file.

Parameters:
key - the key
value - the value

setPoint

public void setPoint(String key,
                     Point value)
Writes the specified key-value pair into the preferences file.

Parameters:
key - the key
value - the value

setRectangle

public void setRectangle(String key,
                         Rectangle value)
Writes the specified key-value pair into the preferences file.

Parameters:
key - the key
value - the value

pointToString

protected String pointToString(Point p)

rectangleToString

protected String rectangleToString(Rectangle rect)

stringToPoint

protected Point stringToPoint(String s)

stringToRectangle

protected Rectangle stringToRectangle(String s)

stringToBoolean

protected Boolean stringToBoolean(String s)

toString

protected String toString(Object o)

toObject

protected Object toObject(String s)