Module qupath.fx

Class PreferenceManager

java.lang.Object
qupath.fx.prefs.PreferenceManager

public class PreferenceManager extends Object
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 Details

    • preferences

      public javafx.beans.property.ReadOnlyObjectProperty<Preferences> preferencesProperty
      Get a read-only property containing the Preferences object backing this PreferenceManager. 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

      public static PreferenceManager create(Preferences preferences)
      Create preference manager using the provided preferences object as the backing store.
      Parameters:
      preferences -
      Returns:
      a new preference manager instance
    • createForUserPreferences

      public static PreferenceManager createForUserPreferences(String pathName)
      Create a preference manager using the provided path name to create a user preferences node.
      Parameters:
      pathName -
      Returns:
      a new preference manager instance
    • createForSystemPreferences

      public static PreferenceManager createForSystemPreferences(String pathName)
      Create a preference manager using the provided path name to create a system preferences node.
      Parameters:
      pathName -
      Returns:
      a new preference manager instance
    • getPreferences

      public Preferences getPreferences()
      Get the Preferences object backing this PreferenceManager.

      Note that the preferences object returned by this method must not be retained and reused, because it may be invalidated by a call to reset(). Rather, as far as possible other methods of this class should be used rather than accessing the Preferences directly.

      * @return
    • preferencesProperty

      public javafx.beans.property.ReadOnlyObjectProperty<Preferences> preferencesProperty()
      Get a read-only property containing the Preferences object backing this PreferenceManager. This property can be used to observe changes to the backing preferences object, which occur if the preferences are reset.
      See Also:
    • reset

      public void reset() throws BackingStoreException
      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

      public void save() throws BackingStoreException
      Save the preferences to the backing store.
      Throws:
      BackingStoreException
    • toXml

      public String toXml() throws IOException, BackingStoreException
      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 name
      defaultValue - default property value; used if the property is not found in the backing store, or if reset() 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 to reset().
      Parameters:
      key - key used to store the property value, and used for the property name
      defaultValue - 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 name
      defaultValue - default property value; used if the property is not found in the backing store, or if reset() 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 to reset().
      Parameters:
      key - key used to store the property value, and used for the property name
      defaultValue - 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 name
      defaultValue - default property value; used if the property is not found in the backing store, or if reset() 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 to reset().
      Parameters:
      key - key used to store the property value, and used for the property name
      defaultValue - 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 name
      defaultValue - default property value; used if the property is not found in the backing store, or if reset() 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 to reset().
      Parameters:
      key - key used to store the property value, and used for the property name
      defaultValue - 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 name
      defaultValue - default property value; used if the property is not found in the backing store, or if reset() 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 to reset().
      Parameters:
      key - key used to store the property value, and used for the property name
      defaultValue - 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 name
      defaultValue - default property value; used if the property is not found in the backing store, or if reset() 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 to reset().
      Parameters:
      key - key used to store the property value, and used for the property name
      defaultValue - 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 name
      defaultValue - default property value; used if the property is not found in the backing store, or if reset() 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 name
      defaultValue - default property value; used if the property is not found in the backing store, or if reset() 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 a Path 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 name
      defaultValue - default property value; used if the property is not found in the backing store, or if reset() is called.
      Returns:
      the property
    • createPersistentFileProperty

      public javafx.beans.property.ObjectProperty<File> createPersistentFileProperty(String key, File defaultValue)
      Create a property storing a File 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 name
      defaultValue - default property value; used if the property is not found in the backing store, or if reset() is called.
      Returns:
      the property
    • createPersistentUriProperty

      public javafx.beans.property.ObjectProperty<URI> createPersistentUriProperty(String key, URI defaultValue)
      Create a property storing a URI 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 name
      defaultValue - default property value; used if the property is not found in the backing store, or if reset() is called.
      Returns:
      the property
    • createPersistentLocaleProperty

      public javafx.beans.property.ObjectProperty<Locale> createPersistentLocaleProperty(String key, Locale defaultValue)
      Create a property storing a Locale 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 name
      defaultValue - default property value; used if the property is not found in the backing store, or if reset() 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 name
      defaultValue - default property value; used if the property is not found in the backing store, or if reset() 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 name
      defaultValue - default property value; used if the property is not found in the backing store, or if reset() is called.
      serializer - method to convert the default value to a string
      deserializer - 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 to reset().
      Type Parameters:
      T - the property type
      Parameters:
      key - key used to store the property value, and used for the property name
      defaultValue - default property value
      Returns:
      the property