Class Preferences


  • public class Preferences
    extends java.lang.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.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  Preferences.Observer
      An observer interface for use by those that wishing to monitor changes to user preferences.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Preferences access()
      Access the single Preferences object.
      void addObserver​(java.lang.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.
      void addObserver​(java.lang.String prefix, Preferences.Observer o)
      Add an observer to be notified of changes to all preferences whose name begins with a given prefix.
      java.lang.String getPreference​(java.lang.String name)
      Get a named preference value.
      java.lang.String getPreference​(java.lang.String name, java.lang.String defaultValue)
      Get a named preference value, using a default if the named preference is not found.
      static java.io.File getPrefsDir()  
      void removeObserver​(java.lang.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.
      void removeObserver​(java.lang.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.
      void save()
      Save the current set of user preferences.
      void setPreference​(java.lang.String name, java.lang.String newValue)
      Set the value of a named preference.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • access

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

        public static java.io.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 java.lang.String getPreference​(java.lang.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:
        setPreference(java.lang.String, java.lang.String)
      • getPreference

        public java.lang.String getPreference​(java.lang.String name,
                                              java.lang.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(java.lang.String, java.lang.String)
      • setPreference

        public void setPreference​(java.lang.String name,
                                  java.lang.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:
        getPreference(java.lang.String)
      • addObserver

        public void addObserver​(java.lang.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(java.lang.String, com.sun.javatest.tool.Preferences.Observer)
      • removeObserver

        public void removeObserver​(java.lang.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:
        addObserver(java.lang.String, com.sun.javatest.tool.Preferences.Observer)
      • removeObserver

        public void removeObserver​(java.lang.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:
        addObserver(java.lang.String, com.sun.javatest.tool.Preferences.Observer)