org.brains2b.swingext.conf
Class UserPreference

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<java.lang.Object,java.lang.Object>
          extended by java.util.Properties
              extended by org.brains2b.swingext.conf.UserPreference
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Object,java.lang.Object>

public class UserPreference
extends java.util.Properties

Abstract class extending Properties to use for user preferences in an application.

Version:
0.21.2 [23-09-2004]
Author:
dennis@brains2b.nl
See Also:
Properties, Serialized Form

Field Summary
static java.lang.String DEFAULTPATH
          Constant defining the default path "user.home"/.java/conf as a String
 
Fields inherited from class java.util.Properties
defaults
 
Constructor Summary
UserPreference(java.io.File file)
          Constructor for UserProperties.
UserPreference(java.lang.String filename)
          Constructor for UserProperties.
 
Method Summary
 java.lang.String getFilename()
          gets the filename with its path that is used to store the properties
protected  boolean isDirty()
          Checks to see if the properties have changed.
 void load()
          loads the properties from the defined file.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          add or modify a property to these UserProperties.
 void setDefault(java.lang.String key, java.lang.String defaultValue)
          sets a property as default This means that if a value already exists it is not overwritten and isDirty will stay false
protected  void setDirty(boolean dirty)
          Mark these properties as having been changed.
protected  void setFile(java.io.File f)
           
 java.lang.Object setProperty(java.lang.String key, java.lang.String value)
          
 void store()
           
 
Methods inherited from class java.util.Properties
getProperty, getProperty, list, list, load, loadFromXML, propertyNames, save, store, storeToXML, storeToXML
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULTPATH

public static final java.lang.String DEFAULTPATH
Constant defining the default path "user.home"/.java/conf as a String

Constructor Detail

UserPreference

public UserPreference(java.lang.String filename)
Constructor for UserProperties.

Parameters:
filename - String, the filename or relative filepath,including filename to DEFAULTPATH.

The file does not have to exist. Be aware that if you define a relative path this path will be created if properties need to be saved and path does not exist already. Be aware that you need OS access rights to the location you specified for the properties to be saved.

If you want to define the complete path yourself please use UserProperties(File)


UserPreference

public UserPreference(java.io.File file)
Constructor for UserProperties.

Parameters:
file - File, file object to a properties location.

The file does not have to exist. Be aware that if you define a path this path will be created if properties need to be saved and path does not exist already. Be aware that you need OS access rights to the location you specified for the properties to be saved.

Method Detail

load

public void load()
loads the properties from the defined file.


store

public void store()

setProperty

public java.lang.Object setProperty(java.lang.String key,
                                    java.lang.String value)

Overrides:
setProperty in class java.util.Properties

setDefault

public void setDefault(java.lang.String key,
                       java.lang.String defaultValue)
sets a property as default

This means that if a value already exists it is not overwritten and isDirty will stay false

Parameters:
key - String, the key for this property
defaultValue - String, the defaultValue to set

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
add or modify a property to these UserProperties.

prefered is using setProperty instead of this function. Overwritten to track changes.

Specified by:
put in interface java.util.Map<java.lang.Object,java.lang.Object>
Overrides:
put in class java.util.Hashtable<java.lang.Object,java.lang.Object>

isDirty

protected boolean isDirty()
Checks to see if the properties have changed.

Returns:
Returns a boolean

setDirty

protected void setDirty(boolean dirty)
Mark these properties as having been changed.

Parameters:
dirty - The dirty to set

setFile

protected void setFile(java.io.File f)

getFilename

public java.lang.String getFilename()
gets the filename with its path that is used to store the properties

Returns:
String representation of the complete filepath for the properties