|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.xnap.util.AbstractPreferences
public abstract class AbstractPreferences
This class provides a default implementation for a preferences framework. Methods are provided that can read and write native types, arrays and a few custom types.
Field Summary | |
---|---|
static java.lang.String |
ARRAY_SEPARATOR
|
protected boolean |
changedFlag
Determines if preferences need to be saved. |
protected static org.apache.log4j.Logger |
logger
|
protected java.lang.String |
namespace
The namespace is prefixed to each key. |
protected int |
oldVersion
Version of database when read. |
protected java.io.File |
prefsFile
Preferences database. |
protected java.beans.PropertyChangeSupport |
propertyChange
|
protected java.util.Properties |
props
Preferences. |
protected int |
version
Version of database format. |
Constructor Summary | |
---|---|
AbstractPreferences(java.lang.String filename,
int version,
java.lang.String namespace)
Constructs a PreferencesSupport object. |
Method Summary | |
---|---|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener l)
Adds a preferences listener. |
void |
addPropertyChangeListener(java.lang.String key,
java.beans.PropertyChangeListener l)
Adds a preferences listener for a specific key. |
static boolean |
areObjectsEqual(java.lang.Object[] obj1,
java.lang.Object[] obj2)
Determine if 2 arrays are equal, or both point to null. |
static boolean |
areObjectsEqual(java.lang.Object obj1,
java.lang.Object obj2)
Determine if 2 objects are equal, or both point to null. |
abstract void |
convert(int oldVersion)
Invoked by read() to converts preferences from
oldVersion to current version. |
void |
firePropertyChange(java.lang.String key,
java.lang.Object oldValue,
java.lang.Object newValue)
Fires PropertyChangeEvent without namespace. |
java.lang.String |
get(java.lang.String key)
|
java.lang.String[] |
getArray(java.lang.String key)
|
boolean |
getBoolean(java.lang.String key)
|
java.awt.Color |
getColor(java.lang.String key)
|
java.lang.String |
getFilename()
Returns the absolute path of the preferences file. |
java.awt.Font |
getFont(java.lang.String key)
Always returns a valid font. |
int |
getInt(java.lang.String key)
Reads an integer from the properties. |
int[] |
getIntArray(java.lang.String key)
|
javax.swing.KeyStroke |
getKeyStroke(java.lang.String key)
Reads a keystroke from the properties. |
long |
getLong(java.lang.String key)
|
int |
getOldVersion()
Returns the version of the preferences in the file at the point of the last read operation. |
protected java.lang.String |
getProperty(java.lang.String key,
java.lang.String defaultValue)
Returns a property. |
int |
getVersion()
Returns the current version of the preferences. |
void |
read()
Reads preferences from default preferences file. |
void |
read(java.io.File f)
Reads preferences from f . |
void |
removeProperty(java.lang.String key)
Ignores namespace. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener l)
Removes a preferences listener. |
void |
removePropertyChangeListener(java.lang.String key,
java.beans.PropertyChangeListener l)
|
void |
renameProperty(java.lang.String oldKey,
java.lang.String newKey)
Renames a property, used for conversion of property file formats. |
void |
set(java.lang.String key,
boolean newValue)
|
void |
set(java.lang.String key,
java.awt.Color newValue)
|
void |
set(java.lang.String key,
java.awt.Font newValue)
Saves a font. |
void |
set(java.lang.String key,
int newValue)
|
void |
set(java.lang.String key,
int[] newValue)
|
void |
set(java.lang.String key,
javax.swing.KeyStroke newValue)
|
void |
set(java.lang.String key,
long newValue)
|
void |
set(java.lang.String key,
java.lang.String newValue)
|
void |
set(java.lang.String key,
java.lang.String[] newValue)
|
void |
setDefault(java.lang.String key,
java.lang.String value)
Sets a default property. |
void |
setDefault(java.lang.String key,
java.lang.String value,
Validator validator)
Sets a default property. |
protected void |
setProperty(java.lang.String key,
java.lang.String newValue)
Sets a property. |
protected void |
setProperty(java.lang.String key,
java.lang.String newValue,
boolean validate)
Sets a property. |
static java.lang.String |
toString(java.awt.Font font)
|
static java.lang.String |
toString(javax.swing.KeyStroke keystroke)
|
boolean |
write()
Writes preferences to default preferences file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String ARRAY_SEPARATOR
protected static org.apache.log4j.Logger logger
protected transient java.beans.PropertyChangeSupport propertyChange
protected boolean changedFlag
protected java.io.File prefsFile
protected int version
protected int oldVersion
protected java.lang.String namespace
protected java.util.Properties props
Constructor Detail |
---|
public AbstractPreferences(java.lang.String filename, int version, java.lang.String namespace)
PreferencesSupport
object.
filename
- the filename of the preferences fileversion
- the current version of the preferences, this version
can be more recent than the version of the filenamespace
- the namespace, used as a prefix for all keysMethod Detail |
---|
public java.lang.String getFilename()
public void read(java.io.File f)
f
.
public void read()
public boolean write()
IOException
has occuredpublic int getOldVersion()
public int getVersion()
public abstract void convert(int oldVersion)
read()
to converts preferences from
oldVersion
to current version.
public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
public void addPropertyChangeListener(java.lang.String key, java.beans.PropertyChangeListener l)
public void firePropertyChange(java.lang.String key, java.lang.Object oldValue, java.lang.Object newValue)
public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
public void removePropertyChangeListener(java.lang.String key, java.beans.PropertyChangeListener l)
public java.lang.String get(java.lang.String key)
public java.lang.String[] getArray(java.lang.String key)
public boolean getBoolean(java.lang.String key)
public java.awt.Color getColor(java.lang.String key)
public java.awt.Font getFont(java.lang.String key)
public javax.swing.KeyStroke getKeyStroke(java.lang.String key)
public int getInt(java.lang.String key)
public int[] getIntArray(java.lang.String key)
public long getLong(java.lang.String key)
public void set(java.lang.String key, java.lang.String newValue)
public void set(java.lang.String key, java.lang.String[] newValue)
public void set(java.lang.String key, boolean newValue)
public void set(java.lang.String key, java.awt.Color newValue)
public void set(java.lang.String key, java.awt.Font newValue)
public void set(java.lang.String key, int newValue)
public void set(java.lang.String key, int[] newValue)
public void set(java.lang.String key, javax.swing.KeyStroke newValue)
public void set(java.lang.String key, long newValue)
public void setDefault(java.lang.String key, java.lang.String value, Validator validator)
If a key already exists, the corresponding value is validated
by validator
and will replaced by value
if the validation fails.
key
- the keyvalue
- the default valuevalidator
- a validator that is invoked each time a value is setpublic void setDefault(java.lang.String key, java.lang.String value)
key
- the keyvalue
- the default valuepublic void removeProperty(java.lang.String key)
public void renameProperty(java.lang.String oldKey, java.lang.String newKey)
protected java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
protected void setProperty(java.lang.String key, java.lang.String newValue, boolean validate)
newValue
is validated if
validate
is set to true and a validator has been
provided.
key
- the key to setnewValue
- the value to setvalidate
- if true, newValue
will be validated
java.lang.IllegalArgumentException
- if newValue
is not validprotected void setProperty(java.lang.String key, java.lang.String newValue)
newValue
is validated if a validator has
been provided.
key
- the key to setnewValue
- the value to setsetProperty(String, String, boolean)
public static boolean areObjectsEqual(java.lang.Object obj1, java.lang.Object obj2)
public static boolean areObjectsEqual(java.lang.Object[] obj1, java.lang.Object[] obj2)
public static java.lang.String toString(java.awt.Font font)
public static java.lang.String toString(javax.swing.KeyStroke keystroke)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |