|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.sfac.setting.SettingsImpl
public class SettingsImpl
Default implementation of the Settings interface.
This class provides a 'Settings' service storing the settings in a java Property file.
The property are typed. The first time a property is accessed, it's type is set (the type is determined by the method called to
access the property like getRectangleProperty). Subsequent access to this property must use the same type. This is
done to improve efficiency because the propery can be stored with the proper type in the settings (wich avoids constant type
conversions).
This class uses TypeHelper objects to manage each type of propery. Each helper knows how to convert a data type from
and to string (as only string can be saved in properties). The helper class instance is also used to identify a data type.
For file properties, the base path used is the directory where the property file lies. This allow to move (or copy) the application easily without having to update all the file propeties with ne paths.
| Field Summary | |
|---|---|
static TypeHelper<Boolean> |
BOOLEAN_HELPER
Helper for identifying and managing Boolean properties. |
static TypeHelper<Color> |
COLOR_HELPER
Helper for identifying and managing Dimension properties. |
static TypeHelper<Dimension> |
DIMENSION_HELPER
Helper for identifying and managing Dimension properties. |
static TypeHelper<Double> |
DOUBLE_HELPER
Helper for identifying and managing Double properties. |
static TypeHelper<int[]> |
INT_ARRAY_HELPER
Helper for identifying and managing int array properties. |
static TypeHelper<Integer> |
INTEGER_HELPER
Helper for identifying and managing Integer properties. |
static TypeHelper<String> |
PASSWORD_HELPER
Helper for identifying and managing String properties. |
static TypeHelper<Rectangle> |
RECTANGLE_HELPER
Helper for identifying and managing Rectangle properties. |
static TypeHelper<String[]> |
STRING_ARRAY_HELPER
Helper for identifying and managing String properties. |
static TypeHelper<String> |
STRING_HELPER
Helper for identifying and managing String properties. |
| Constructor Summary | |
|---|---|
SettingsImpl(File propertyFile,
String descr)
Construct a new settings implementation bound to a given property file. |
|
| Method Summary | ||
|---|---|---|
void |
addPropertyChangeListener(String settingKey,
PropertyChangeListener listener)
Add a PropertyChangeListener for a specific setting. |
|
boolean |
containsProperty(String key)
Check if there is a property value defined for the given key. |
|
boolean |
getBooleanProperty(String key,
boolean defaultValue)
Get a boolean property value. |
|
Boolean |
getBooleanProperty(String key,
Boolean defaultValue)
Get a Boolean property value. |
|
Color |
getColorProperty(String key,
Color defaultValue)
Get a Color property value. |
|
String |
getDescription()
Get the settings description (the one saved at the top of the properties file). |
|
Dimension |
getDimensionProperty(String key,
Dimension defaultValue)
Get a Dimension property value. |
|
double |
getDoubleProperty(String key,
double defaultValue)
Get a double property value. |
|
|
getEnumProperty(String key,
T defaultValue)
Get a enumerated property value. |
|
FilePathUtils |
getFilePathUtils()
Get the FilePathUtils used to manage the file/directory settings. |
|
String |
getFileProperty(String key,
String defaultValue)
Get a absolute File or Directory property value. |
|
String |
getFileProperty(String key,
String defaultValue,
boolean absolute)
Get a File or Directory property value. |
|
int[] |
getIntArrayProperty(String key,
int[] defaultValue)
Get a int array property value. |
|
Integer |
getIntegerProperty(String key,
Integer defaultValue)
Get a Integer property value. |
|
int |
getIntProperty(String key,
int defaultValue)
Get a int property value. |
|
Iterator<String> |
getKeys()
Return an iterator for all the defined keys. |
|
String |
getPasswordProperty(String key,
String defaultValue)
Get a String property value to be used as a password. |
|
|
getProperty(String key,
TypeHelper<T> helper,
T defaultValue)
Get a property of type defined by the helper. |
|
String |
getPropertyAsInternalString(String key)
Get a property as stored internally by the map (as string). |
|
String |
getPropertyFilePath()
Get the path to the property file used to store the settings. |
|
Rectangle |
getRectangleProperty(String key,
Rectangle defaultValue)
Get a Rectangle property value. |
|
String[] |
getStringArrayProperty(String key,
String[] defaultValue)
Get a String array property value. |
|
String |
getStringProperty(String key,
String defaultValue)
Get a String property value. |
|
void |
load()
Load all the settings from the property file (if the file exists). |
|
void |
removeProperty(String key)
Remove the property. |
|
void |
removePropertyChangeListener(String settingKey,
PropertyChangeListener listener)
Remove a PropertyChangeListener for a specific setting. |
|
void |
save()
Save all the settings to the property file (if the file don't exists, it is created). |
|
void |
saveAs(File fil)
Save all the settings to a new property file. |
|
void |
setBooleanProperty(String key,
boolean value)
Set a new value for a boolean property. |
|
void |
setBooleanProperty(String key,
Boolean value)
Set a new value for a Boolean property. |
|
void |
setColorProperty(String key,
Color value)
Set a new value for a Color property. |
|
void |
setDescription(String newDescr)
Set the settings description (the one saved at the top of the properties file). |
|
void |
setDimensionProperty(String key,
Dimension value)
Set a new value for a Dimension property. |
|
void |
setDoubleProperty(String key,
double value)
Set a new value for a double property. |
|
|
setEnumProperty(String key,
T value)
Set a new value for a enumerated property. |
|
void |
setFileProperty(String key,
String value)
Set a new value for a File or Directory property. |
|
void |
setIntArrayProperty(String key,
int[] value)
Set a new value for a int array property. |
|
void |
setIntegerProperty(String key,
Integer value)
Set a new value for a Integer property. |
|
void |
setIntProperty(String key,
int value)
Set a new value for a int property. |
|
void |
setPasswordProperty(String key,
String value)
Set a new value for a String property. |
|
|
setProperty(String key,
TypeHelper<T> helper,
T value)
Set a property of type defined by the helper. |
|
void |
setPropertyAsInternalString(String key,
String value)
Set a property value using its internal string representation. |
|
void |
setPropertyFile(File fil)
Set a new property file to store the settings. |
|
void |
setRectangleProperty(String key,
Rectangle value)
Set a new value for a Rectangle property. |
|
void |
setStringArrayProperty(String key,
String[] value)
Set a new value for a String array property. |
|
void |
setStringProperty(String key,
String value)
Set a new value for a String property. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final TypeHelper<String> STRING_HELPER
public static final TypeHelper<String> PASSWORD_HELPER
public static final TypeHelper<String[]> STRING_ARRAY_HELPER
public static final TypeHelper<Integer> INTEGER_HELPER
public static final TypeHelper<Boolean> BOOLEAN_HELPER
public static final TypeHelper<Double> DOUBLE_HELPER
public static final TypeHelper<int[]> INT_ARRAY_HELPER
public static final TypeHelper<Rectangle> RECTANGLE_HELPER
public static final TypeHelper<Dimension> DIMENSION_HELPER
public static final TypeHelper<Color> COLOR_HELPER
| Constructor Detail |
|---|
public SettingsImpl(File propertyFile,
String descr)
propertyFile - File where the properties are stored.descr - Description of properties written as header in properties file.| Method Detail |
|---|
public String getPropertyFilePath()
Settings
getPropertyFilePath in interface Settingspublic String getDescription()
public void setDescription(String newDescr)
newDescr - the new settings description.public FilePathUtils getFilePathUtils()
FilePathUtils used to manage the file/directory settings. FilePathUtils is set to use the same base directory as this class.
getFilePathUtils in interface SettingsFilePathUtils used to manage the file/directory settings.
public void load()
throws IOException
load in interface SettingsIOException - If something prevents the settings to be loaded.
public void save()
throws IOException
save in interface SettingsIOException - If something prevents the settings to be saved.public void setPropertyFile(File fil)
setPropertyFile in interface Settingsfil - The new properties file.
public void saveAs(File fil)
throws IOException
saveAs in interface Settingsfil - The new properties file.
IOException - If something prevents the settings to be saved.public boolean containsProperty(String key)
containsProperty in interface Settingskey - Key for the value.
public Iterator<String> getKeys()
Settings
getKeys in interface Settingspublic void removeProperty(String key)
Settings
removeProperty in interface Settingskey - Key of the property to remove.public String getPropertyAsInternalString(String key)
Settings
getPropertyAsInternalString in interface Settingskey - Key for the property value.
public void setPropertyAsInternalString(String key,
String value)
Settings
setPropertyAsInternalString in interface Settingskey - Key for the property value.value - The new value of the property to associate to the given key.
public <T> T getProperty(String key,
TypeHelper<T> helper,
T defaultValue)
SettingsTypeHelper classes). For properties using a pre-defined type you should use the type-specific
method.
Note that if you create a new data type the same type helper INSTANCE should be used in all set and get for this type.
getProperty in interface Settingskey - Key for the property value.helper - Helper identifying the value type and knowing how to convert between string and the requested type. If the helper
is null, a string value is returned.
public <T> void setProperty(String key,
TypeHelper<T> helper,
T value)
SettingsTypeHelper classes). For properties using a pre-defined type you should use the type-specific
method. Note that if you create a new data type the same type helper INSTANCE should be used in all set and get for this type.
setProperty in interface Settingskey - Key for the property value.helper - Helper identifying the value type and knowing how to convert between string and the requested type. If the given
helper is null, the property will be stored as string (with basic toString conversion in the backing
properties map). When the given helper is null, no propertyChange event is generated.value - The new value of the property to associate to the given key.
public String getStringProperty(String key,
String defaultValue)
Settings
getStringProperty in interface Settingskey - Key for the value.defaultValue - Default value to be returned if no value is found for the key.
public void setStringProperty(String key,
String value)
Settings
setStringProperty in interface Settingskey - Key for the value.value - New value to be associated with the key.
public String getPasswordProperty(String key,
String defaultValue)
Settings
getPasswordProperty in interface Settingskey - Key for the value.defaultValue - Default value to be returned if no value is found for the key.
public void setPasswordProperty(String key,
String value)
Settings
setPasswordProperty in interface Settingskey - Key for the value.value - New value to be associated with the key.
public String[] getStringArrayProperty(String key,
String[] defaultValue)
Settings
getStringArrayProperty in interface Settingskey - Key for the value.defaultValue - Default value to be returned if no value is found for the key.
public void setStringArrayProperty(String key,
String[] value)
Settings
setStringArrayProperty in interface Settingskey - Key for the value.value - New value to be associated with the key.
public int getIntProperty(String key,
int defaultValue)
Settings
getIntProperty in interface Settingskey - Key for the value.defaultValue - Default value to be returned if no value is found for the key.
public void setIntProperty(String key,
int value)
Settings
setIntProperty in interface Settingskey - Key for the value.value - New value to be associated with the key.
public Integer getIntegerProperty(String key,
Integer defaultValue)
Settings
getIntegerProperty in interface Settingskey - Key for the value.defaultValue - Default value to be returned if no value is found for the key.
public void setIntegerProperty(String key,
Integer value)
Settings
setIntegerProperty in interface Settingskey - Key for the value.value - New value to be associated with the key.
public double getDoubleProperty(String key,
double defaultValue)
Settings
getDoubleProperty in interface Settingskey - Key for the value.defaultValue - Default value to be returned if no value is found for the key.
public void setDoubleProperty(String key,
double value)
Settings
setDoubleProperty in interface Settingskey - Key for the value.value - New value to be associated with the key.
public boolean getBooleanProperty(String key,
boolean defaultValue)
Settings
getBooleanProperty in interface Settingskey - Key for the value.defaultValue - Default value to be returned if no value is found for the key.
public void setBooleanProperty(String key,
boolean value)
Settings
setBooleanProperty in interface Settingskey - Key for the value.value - New value to be associated with the key.
public Boolean getBooleanProperty(String key,
Boolean defaultValue)
Settings
getBooleanProperty in interface Settingskey - Key for the value.defaultValue - Default value to be returned if no value is found for the key.
public void setBooleanProperty(String key,
Boolean value)
Settings
setBooleanProperty in interface Settingskey - Key for the value.value - New value to be associated with the key.
public int[] getIntArrayProperty(String key,
int[] defaultValue)
Settings
getIntArrayProperty in interface Settingskey - Key for the value.defaultValue - Default value to be returned if no value is found for the key.
public void setIntArrayProperty(String key,
int[] value)
Settings
setIntArrayProperty in interface Settingskey - Key for the value.value - New value to be associated with the key.
public Rectangle getRectangleProperty(String key,
Rectangle defaultValue)
Settings
getRectangleProperty in interface Settingskey - Key for the value.defaultValue - Default value to be returned if no value is found for the key.
public void setRectangleProperty(String key,
Rectangle value)
Settings
setRectangleProperty in interface Settingskey - Key for the value.value - New value to be associated with the key.
public Dimension getDimensionProperty(String key,
Dimension defaultValue)
Settings
getDimensionProperty in interface Settingskey - Key for the value.defaultValue - Default value to be returned if no value is found for the key.
public void setDimensionProperty(String key,
Dimension value)
Settings
setDimensionProperty in interface Settingskey - Key for the value.value - New value to be associated with the key.
public Color getColorProperty(String key,
Color defaultValue)
Settings
getColorProperty in interface Settingskey - Key for the value.defaultValue - Default value to be returned if no value is found for the key.
public void setColorProperty(String key,
Color value)
Settings
setColorProperty in interface Settingskey - Key for the value.value - New value to be associated with the key.
public <T extends Enum<T>> T getEnumProperty(String key,
T defaultValue)
Settings
getEnumProperty in interface Settingskey - Key for the value.defaultValue - Default value to be returned if no value is found for the key.
public <T extends Enum<T>> void setEnumProperty(String key,
T value)
Settings
setEnumProperty in interface Settingskey - Key for the value.value - New value to be associated with the key.
public String getFileProperty(String key,
String defaultValue)
Settings
getFileProperty in interface Settingskey - Key for the value.defaultValue - Default value to be returned if no value is found for the key. (if used, the default value will be processed to
ensure it's absolute)
public String getFileProperty(String key,
String defaultValue,
boolean absolute)
Settings
getFileProperty in interface Settingskey - Key for the value.defaultValue - Default value to be returned if no value is found for the key. (if used, the default value will be processed to
ensure it's relative or absolute as requested)absolute - tells if the returned file should be absolute or relative to the settings base directory.
public void setFileProperty(String key,
String value)
throws InvalidPathException
Settings
setFileProperty in interface Settingskey - Key for the value.value - New value to be associated with the key.
InvalidPathException - if the file set is invalid.
public void addPropertyChangeListener(String settingKey,
PropertyChangeListener listener)
addPropertyChangeListener in interface SettingssettingKey - The key of the setting to listen on.listener - The PropertyChangeListener to be added
public void removePropertyChangeListener(String settingKey,
PropertyChangeListener listener)
removePropertyChangeListener in interface SettingssettingKey - The key of the setting that was listened on.listener - The PropertyChangeListener to be removed
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||