java.lang.Object
qupath.fx.prefs.PreferenceManager
A utility class for managing preferences in a JavaFX application.
This class provides a number of methods for creating properties that are backed by a Preferences
object.
The properties can be reset to their default values by calling reset()
, and persistent properties can have
their values reloaded from the backing store by calling reload()
.
Note that save()
should be called to ensure that any changes to persistent properties are saved to the
backing store before the host application is closed.
-
Property Summary
TypePropertyDescriptionjavafx.beans.property.ReadOnlyObjectProperty<Preferences>
Get a read-only property containing thePreferences
object backing thisPreferenceManager
. -
Method Summary
Modifier and TypeMethodDescriptionstatic PreferenceManager
create
(Preferences preferences) Create preference manager using the provided preferences object as the backing store.static PreferenceManager
createForSystemPreferences
(String pathName) Create a preference manager using the provided path name to create a system preferences node.static PreferenceManager
createForUserPreferences
(String pathName) Create a preference manager using the provided path name to create a user preferences node.javafx.beans.property.BooleanProperty
createPersistentBooleanProperty
(String key, boolean defaultValue) Create a boolean property that is persisted to the backing store with the specified key.javafx.beans.property.DoubleProperty
createPersistentDoubleProperty
(String key, double defaultValue) Create a double property that is persisted to the backing store with the specified key.<T extends Enum>
javafx.beans.property.ObjectProperty<T>createPersistentEnumProperty
(String key, T defaultValue) Create an enum property that is persisted to the backing store with the specified key.<T extends Enum>
javafx.beans.property.ObjectProperty<T>createPersistentEnumProperty
(String key, T defaultValue, Class<T> enumType) Create an enum property that is persisted to the backing store with the specified key.javafx.beans.property.ObjectProperty<File>
createPersistentFileProperty
(String key, File defaultValue) Create a property storing aFile
object that is persisted to the backing store with the specified key.javafx.beans.property.FloatProperty
createPersistentFloatProperty
(String key, float defaultValue) Create a float property that is persisted to the backing store with the specified key.javafx.beans.property.IntegerProperty
createPersistentIntegerProperty
(String key, int defaultValue) Create an integer property that is persisted to the backing store with the specified key.javafx.beans.property.ObjectProperty<Locale>
createPersistentLocaleProperty
(String key, Locale defaultValue) Create a property storing aLocale
that is persisted to the backing store with the specified key.javafx.beans.property.LongProperty
createPersistentLongProperty
(String key, long defaultValue) Create a long property that is persisted to the backing store with the specified key.<T> javafx.beans.property.ObjectProperty<T>
createPersistentObjectProperty
(String key, T defaultValue, Function<T, String> serializer, Function<String, T> deserializer) Create an object property that is persisted to the backing store with the specified key.<T> javafx.beans.property.ObjectProperty<T>
createPersistentObjectProperty
(String key, T defaultValue, javafx.util.StringConverter<T> converter) Create an object property that is persisted to the backing store with the specified key and converter.javafx.beans.property.ObjectProperty<Path>
createPersistentPathProperty
(String key, Path defaultValue) Create a property storing aPath
object that is persisted to the backing store with the specified key.javafx.beans.property.StringProperty
createPersistentStringProperty
(String key, String defaultValue) Create a String property that is persisted to the backing store with the specified key.javafx.beans.property.ObjectProperty<URI>
createPersistentUriProperty
(String key, URI defaultValue) Create a property storing aURI
that is persisted to the backing store with the specified key.javafx.beans.property.BooleanProperty
createTransientBooleanProperty
(String key, boolean defaultValue) Create a boolean property that is not persisted to the backing store.javafx.beans.property.DoubleProperty
createTransientDoubleProperty
(String key, double defaultValue) Create a double property that is not persisted to the backing store.javafx.beans.property.FloatProperty
createTransientFloatProperty
(String key, float defaultValue) Create a float property that is not persisted to the backing store.javafx.beans.property.IntegerProperty
createTransientIntegerProperty
(String key, int defaultValue) Create an integer property that is not persisted to the backing store.javafx.beans.property.LongProperty
createTransientLongProperty
(String key, long defaultValue) Create a double property that is not persisted to the backing store.<T> javafx.beans.property.ObjectProperty<T>
createTransientObjectProperty
(String key, T defaultValue) Create an object property that is not persisted to the backing store.javafx.beans.property.StringProperty
createTransientStringProperty
(String key, String defaultValue) Create a String property that is not persisted to the backing store.Get thePreferences
object backing thisPreferenceManager
.javafx.beans.property.ReadOnlyObjectProperty<Preferences>
Get a read-only property containing thePreferences
object backing thisPreferenceManager
.void
reload()
Request that all properties associated with persistent preferences have their values reloaded from the backing store.void
reset()
Request that persistent and transient properties created from this manager have their values reset to their defaults.void
save()
Save the preferences to the backing store.toXml()
Dump the current preferences to an XML string.
-
Property Details
-
preferences
Get a read-only property containing thePreferences
object backing thisPreferenceManager
. This property can be used to observe changes to the backing preferences object, which occur if the preferences are reset.- See Also:
-
-
Method Details
-
create
Create preference manager using the provided preferences object as the backing store.- Parameters:
preferences
-- Returns:
- a new preference manager instance
-
createForUserPreferences
Create a preference manager using the provided path name to create a user preferences node.- Parameters:
pathName
-- Returns:
- a new preference manager instance
-
createForSystemPreferences
Create a preference manager using the provided path name to create a system preferences node.- Parameters:
pathName
-- Returns:
- a new preference manager instance
-
getPreferences
Get thePreferences
object backing thisPreferenceManager
.Note that the preferences object returned by this method must not be retained and reused, because it may be invalidated by a call to
* @returnreset()
. Rather, as far as possible other methods of this class should be used rather than accessing thePreferences
directly. -
preferencesProperty
Get a read-only property containing thePreferences
object backing thisPreferenceManager
. This property can be used to observe changes to the backing preferences object, which occur if the preferences are reset.- See Also:
-
reset
Request that persistent and transient properties created from this manager have their values reset to their defaults.- Throws:
BackingStoreException
-
reload
public void reload()Request that all properties associated with persistent preferences have their values reloaded from the backing store. -
save
Save the preferences to the backing store.- Throws:
BackingStoreException
-
toXml
Dump the current preferences to an XML string.- Returns:
- Throws:
BackingStoreException
IOException
-
createPersistentBooleanProperty
public javafx.beans.property.BooleanProperty createPersistentBooleanProperty(String key, boolean defaultValue) Create a boolean property that is persisted to the backing store with the specified key.- Parameters:
key
- key used to store the property value, and used for the property namedefaultValue
- default property value; used if the property is not found in the backing store, or ifreset()
is called.- Returns:
- the property
-
createTransientBooleanProperty
public javafx.beans.property.BooleanProperty createTransientBooleanProperty(String key, boolean defaultValue) Create a boolean property that is not persisted to the backing store. It can still be reset to its default value upon a call toreset()
.- Parameters:
key
- key used to store the property value, and used for the property namedefaultValue
- default property value- Returns:
- the property
-
createPersistentIntegerProperty
public javafx.beans.property.IntegerProperty createPersistentIntegerProperty(String key, int defaultValue) Create an integer property that is persisted to the backing store with the specified key.- Parameters:
key
- key used to store the property value, and used for the property namedefaultValue
- default property value; used if the property is not found in the backing store, or ifreset()
is called.- Returns:
- the property
-
createTransientIntegerProperty
public javafx.beans.property.IntegerProperty createTransientIntegerProperty(String key, int defaultValue) Create an integer property that is not persisted to the backing store. It can still be reset to its default value upon a call toreset()
.- Parameters:
key
- key used to store the property value, and used for the property namedefaultValue
- default property value- Returns:
- the property
-
createPersistentFloatProperty
public javafx.beans.property.FloatProperty createPersistentFloatProperty(String key, float defaultValue) Create a float property that is persisted to the backing store with the specified key.- Parameters:
key
- key used to store the property value, and used for the property namedefaultValue
- default property value; used if the property is not found in the backing store, or ifreset()
is called.- Returns:
- the property
-
createTransientFloatProperty
public javafx.beans.property.FloatProperty createTransientFloatProperty(String key, float defaultValue) Create a float property that is not persisted to the backing store. It can still be reset to its default value upon a call toreset()
.- Parameters:
key
- key used to store the property value, and used for the property namedefaultValue
- default property value- Returns:
- the property
-
createPersistentDoubleProperty
public javafx.beans.property.DoubleProperty createPersistentDoubleProperty(String key, double defaultValue) Create a double property that is persisted to the backing store with the specified key.- Parameters:
key
- key used to store the property value, and used for the property namedefaultValue
- default property value; used if the property is not found in the backing store, or ifreset()
is called.- Returns:
- the property
-
createTransientDoubleProperty
public javafx.beans.property.DoubleProperty createTransientDoubleProperty(String key, double defaultValue) Create a double property that is not persisted to the backing store. It can still be reset to its default value upon a call toreset()
.- Parameters:
key
- key used to store the property value, and used for the property namedefaultValue
- default property value- Returns:
- the property
-
createPersistentLongProperty
public javafx.beans.property.LongProperty createPersistentLongProperty(String key, long defaultValue) Create a long property that is persisted to the backing store with the specified key.- Parameters:
key
- key used to store the property value, and used for the property namedefaultValue
- default property value; used if the property is not found in the backing store, or ifreset()
is called.- Returns:
- the property
-
createTransientLongProperty
public javafx.beans.property.LongProperty createTransientLongProperty(String key, long defaultValue) Create a double property that is not persisted to the backing store. It can still be reset to its default value upon a call toreset()
.- Parameters:
key
- key used to store the property value, and used for the property namedefaultValue
- default property value- Returns:
- the property
-
createPersistentStringProperty
public javafx.beans.property.StringProperty createPersistentStringProperty(String key, String defaultValue) Create a String property that is persisted to the backing store with the specified key.- Parameters:
key
- key used to store the property value, and used for the property namedefaultValue
- default property value; used if the property is not found in the backing store, or ifreset()
is called.- Returns:
- the property
-
createTransientStringProperty
public javafx.beans.property.StringProperty createTransientStringProperty(String key, String defaultValue) Create a String property that is not persisted to the backing store. It can still be reset to its default value upon a call toreset()
.- Parameters:
key
- key used to store the property value, and used for the property namedefaultValue
- default property value- Returns:
- the property
-
createPersistentEnumProperty
public <T extends Enum> javafx.beans.property.ObjectProperty<T> createPersistentEnumProperty(String key, T defaultValue, Class<T> enumType) Create an enum property that is persisted to the backing store with the specified key.- Type Parameters:
T
- the enum type- Parameters:
key
- key used to store the property value, and used for the property namedefaultValue
- default property value; used if the property is not found in the backing store, or ifreset()
is called.enumType
- the enum type, required for conversion to/from a preference string- Returns:
- the property
-
createPersistentEnumProperty
public <T extends Enum> javafx.beans.property.ObjectProperty<T> createPersistentEnumProperty(String key, T defaultValue) Create an enum property that is persisted to the backing store with the specified key.- Type Parameters:
T
- the enum type- Parameters:
key
- key used to store the property value, and used for the property namedefaultValue
- default property value; used if the property is not found in the backing store, or ifreset()
is called. The enum type is inferred from the default value, which must not be null.- Returns:
- the property
-
createPersistentPathProperty
public javafx.beans.property.ObjectProperty<Path> createPersistentPathProperty(String key, Path defaultValue) Create a property storing aPath
object that is persisted to the backing store with the specified key.- Parameters:
key
- key used to store the property value, and used for the property namedefaultValue
- default property value; used if the property is not found in the backing store, or ifreset()
is called.- Returns:
- the property
-
createPersistentFileProperty
public javafx.beans.property.ObjectProperty<File> createPersistentFileProperty(String key, File defaultValue) Create a property storing aFile
object that is persisted to the backing store with the specified key.- Parameters:
key
- key used to store the property value, and used for the property namedefaultValue
- default property value; used if the property is not found in the backing store, or ifreset()
is called.- Returns:
- the property
-
createPersistentUriProperty
public javafx.beans.property.ObjectProperty<URI> createPersistentUriProperty(String key, URI defaultValue) Create a property storing aURI
that is persisted to the backing store with the specified key.- Parameters:
key
- key used to store the property value, and used for the property namedefaultValue
- default property value; used if the property is not found in the backing store, or ifreset()
is called.- Returns:
- the property
-
createPersistentLocaleProperty
public javafx.beans.property.ObjectProperty<Locale> createPersistentLocaleProperty(String key, Locale defaultValue) Create a property storing aLocale
that is persisted to the backing store with the specified key.- Parameters:
key
- key used to store the property value, and used for the property namedefaultValue
- default property value; used if the property is not found in the backing store, or ifreset()
is called.- Returns:
- the property
-
createPersistentObjectProperty
public <T> javafx.beans.property.ObjectProperty<T> createPersistentObjectProperty(String key, T defaultValue, javafx.util.StringConverter<T> converter) Create an object property that is persisted to the backing store with the specified key and converter.- Type Parameters:
T
- the property type- Parameters:
key
- key used to store the property value, and used for the property namedefaultValue
- default property value; used if the property is not found in the backing store, or ifreset()
is called.converter
- a string converter to assist with conversion to/from a preference string- Returns:
- the property
-
createPersistentObjectProperty
public <T> javafx.beans.property.ObjectProperty<T> createPersistentObjectProperty(String key, T defaultValue, Function<T, String> serializer, Function<String, T> deserializer) Create an object property that is persisted to the backing store with the specified key. This is an alternative method to call #createPersistentObjectProperty(String, Object, StringConverter) that uses a pair of functions for serialization and deserialization.- Type Parameters:
T
- the property type- Parameters:
key
- key used to store the property value, and used for the property namedefaultValue
- default property value; used if the property is not found in the backing store, or ifreset()
is called.serializer
- method to convert the default value to a stringdeserializer
- method to convert the string value to a property value- Returns:
- the property
-
createTransientObjectProperty
public <T> javafx.beans.property.ObjectProperty<T> createTransientObjectProperty(String key, T defaultValue) Create an object property that is not persisted to the backing store. It can still be reset to its default value upon a call toreset()
.- Type Parameters:
T
- the property type- Parameters:
key
- key used to store the property value, and used for the property namedefaultValue
- default property value- Returns:
- the property
-