core.prefs
Class Prefs

java.lang.Object
  extended bycore.EventNotifier
      extended bycore.prefs.PrefsNotifier
          extended bycore.prefs.Prefs

public class Prefs
extends PrefsNotifier

Handle user and wide preferences. I choose to wrap this around java.util.Properties. User prefs are the user specific preferences file. Wide prefs is the prefs file for every user. User prefs has preference over wide prefs.

Author:
hoele

Field Summary
static java.lang.String COMRADE
          The string to prepend to user names so they don't conflict with special folders such as ipserver.
static java.lang.String MESSENGER_DIR_NAME
          The name of the directory to save files in user's home.
static java.lang.String PREFS_FILE_NAME
          The name of preference files.
 
Constructor Summary
Prefs()
          Creates a new prefs object for no particular user.
Prefs(IPServer ipServer, java.lang.String name)
          Creates a special preference location for an IPServer.
 
Method Summary
 java.io.File getMessengerDirectory()
          Returns the directory in the user's home that contains this apps files.
 boolean getPreference(java.lang.String key, boolean def)
          Returns the preference value associated with the given key, or def if the given key does not exist.
 int getPreference(java.lang.String key, int def)
          Returns the preference value associated with the given key, or def if the given key does not exist.
 java.lang.String getPreference(java.lang.String key, java.lang.String def)
          Returns the preference value associated with the given key, or def if the given key does not exist.
 java.io.File getUserDirectory()
          Returns the users directory.
 void save()
          Saves the user's prefs file and wide prefs file.
 void setNewUser(java.lang.String user)
          Set preferences to be the preferences for the given user.
 void setPreference(java.lang.String key, boolean value)
          Set the user preference with given key to the given value.
 void setPreference(java.lang.String key, int value)
          Set the user preference with given key to the given value.
 void setPreference(java.lang.String key, java.lang.String value)
          Set the user preference with given key to the given value.
 void setWidePreference(java.lang.String key, boolean value)
          Set the wide preference with given key to the given value.
 void setWidePreference(java.lang.String key, int value)
          Set the wide preference with given key to the given value.
 void setWidePreference(java.lang.String key, java.lang.String value)
          Set the wide preference with given key to the given value.
 
Methods inherited from class core.prefs.PrefsNotifier
firePrefChangedEvent
 
Methods inherited from class core.EventNotifier
addListener, removeListener
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MESSENGER_DIR_NAME

public static final java.lang.String MESSENGER_DIR_NAME
The name of the directory to save files in user's home. Will be hidden in unix.

See Also:
Constant Field Values

PREFS_FILE_NAME

public static final java.lang.String PREFS_FILE_NAME
The name of preference files.

See Also:
Constant Field Values

COMRADE

public static final java.lang.String COMRADE
The string to prepend to user names so they don't conflict with special folders such as ipserver.

See Also:
Constant Field Values
Constructor Detail

Prefs

public Prefs()
Creates a new prefs object for no particular user. Wide prefs is accessible.


Prefs

public Prefs(IPServer ipServer,
             java.lang.String name)
Creates a special preference location for an IPServer.

Parameters:
ipServer - The ipserver to load prefs for.
name - The name of the ipserver.
Method Detail

setNewUser

public void setNewUser(java.lang.String user)
Set preferences to be the preferences for the given user.

Parameters:
user - The user whose preferences will be loaded.

save

public void save()
Saves the user's prefs file and wide prefs file.


getUserDirectory

public java.io.File getUserDirectory()
Returns the users directory.

Returns:
The users directory.

setPreference

public void setPreference(java.lang.String key,
                          java.lang.String value)
Set the user preference with given key to the given value.

Parameters:
key - The key to access the preference.
value - The value to be associated with the given key.

setWidePreference

public void setWidePreference(java.lang.String key,
                              java.lang.String value)
Set the wide preference with given key to the given value.

Parameters:
key - The key to access the preference.
value - The value to be associated with the given key.

getPreference

public java.lang.String getPreference(java.lang.String key,
                                      java.lang.String def)
Returns the preference value associated with the given key, or def if the given key does not exist.

Parameters:
key - The key the preference wanted is associated with.
def - The default value to return if no value is found.
Returns:
The value associated with the given key, or def.

setPreference

public void setPreference(java.lang.String key,
                          int value)
Set the user preference with given key to the given value.

Parameters:
key - The key to access the preference.
value - The value to be associated with the given key.

setWidePreference

public void setWidePreference(java.lang.String key,
                              int value)
Set the wide preference with given key to the given value.

Parameters:
key - The key to access the preference.
value - The value to be associated with the given key.

getPreference

public int getPreference(java.lang.String key,
                         int def)
Returns the preference value associated with the given key, or def if the given key does not exist.

Parameters:
key - The key the preference wanted is associated with.
def - The default value to return if no value is found.
Returns:
The value associated with the given key, or def.

setPreference

public void setPreference(java.lang.String key,
                          boolean value)
Set the user preference with given key to the given value.

Parameters:
key - The key to access the preference.
value - The value to be associated with the given key.

setWidePreference

public void setWidePreference(java.lang.String key,
                              boolean value)
Set the wide preference with given key to the given value.

Parameters:
key - The key to access the preference.
value - The value to be associated with the given key.

getPreference

public boolean getPreference(java.lang.String key,
                             boolean def)
Returns the preference value associated with the given key, or def if the given key does not exist.

Parameters:
key - The key the preference wanted is associated with.
def - The default value to return if no value is found.
Returns:
The value associated with the given key, or def.

getMessengerDirectory

public java.io.File getMessengerDirectory()
Returns the directory in the user's home that contains this apps files.

Returns:
The messenger directory.