Class Preferences

java.lang.Object
com.sun.javatest.tool.Preferences

public class Preferences extends Object
A class which provides a collection of user preferences, and a GUI interface to edit them. Preferences are represented as named string values. For now, the data is stored in a standard Java properties file in the user's home directory; eventually, it will be converted to use the J2SE support for user preferences.
  • Method Details

    • access

      public static Preferences access()
      Access the single Preferences object.
      Returns:
      the single Preferences object
    • getPrefsDir

      public static File getPrefsDir()
    • save

      public void save()
      Save the current set of user preferences. For now, the data is stored in a standard Java properties file in the user's home directory; eventually, it will be converted to use the J2SE support for user preferences.
    • getPreference

      public String getPreference(String name)
      Get a named preference value.
      Parameters:
      name - the name of the desired preference
      Returns:
      the value of the named preference, or null if no such preference found
      See Also:
    • getPreference

      public String getPreference(String name, String defaultValue)
      Get a named preference value, using a default if the named preference is not found.
      Parameters:
      name - the name of the desired preference
      defaultValue - the default value to be returned if no such preference is found
      Returns:
      the value of the named preference, or the default value if no such preference found
      See Also:
    • setPreference

      public void setPreference(String name, String newValue)
      Set the value of a named preference. Any interested observers will be notified.
      Parameters:
      name - the name of the preference to be set
      newValue - the new value for the preference
      See Also:
    • addObserver

      public void addObserver(String prefix, Preferences.Observer o)
      Add an observer to be notified of changes to all preferences whose name begins with a given prefix. This allows an observer to monitor a single preference or a group of preferences.
      Parameters:
      prefix - the prefix to determine which preferences will be observed
      o - the observer to be added
      See Also:
    • addObserver

      public void addObserver(String[] prefixes, Preferences.Observer o)
      Add an observer to be notified of changes to all preferences whose name begins with any of a set of given prefixes. This allows an observer to monitor a single preference or a group of preferences.
      Parameters:
      prefixes - the prefix to determine which preferences will be observed
      o - the observer to be added
      See Also:
    • removeObserver

      public void removeObserver(String prefix, Preferences.Observer o)
      Remove an observer which was previously registered to be notified of changes to all preferences whose name begins with a given prefix. The prefix must exactly match the prefix with which it was previously registered.
      Parameters:
      prefix - the prefix to identify which instance of the observer to be removed
      o - the observer to be removed
      See Also:
    • removeObserver

      public void removeObserver(String[] prefixes, Preferences.Observer o)
      Remove an observer which was previously registered to be notified of changes to all preferences whose name begins with any of a set of prefixed. Each prefix must exactly match one with which the observer was previously registered.
      Parameters:
      prefixes - the prefix to identify which instances of the observer to be removed
      o - the observer to be removed
      See Also: