Class Preferences


  • public class Preferences
    extends java.lang.Object
    Uses Properties to manage user preferences as name/value pairs. All methods are static.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String APPLICATION_PREFERENCES_FILENAME
      The APPLICATION_PREFERENCES_FILENAME is the default name for the user preferences file.
      static java.lang.String LAST_EXPORT_DIRECTORY
      Preference name for the export directory that was last accessed.
      static java.lang.String LAST_IMPORT_DIRECTORY
      Preference name for the import directory that was last accessed for domain files.
      static java.lang.String LAST_NEW_PROJECT_DIRECTORY
      Preference name for directory last selected for creating a new project.
      static java.lang.String LAST_OPENED_ARCHIVE_DIRECTORY
      Preference name for the last opened archive directory.
      static java.lang.String LAST_TOOL_EXPORT_DIRECTORY
      Preference name for export directory that was last accessed for tools.
      static java.lang.String LAST_TOOL_IMPORT_DIRECTORY
      Preference name for import directory that was last accessed for tools.
      static java.lang.String PROJECT_DIRECTORY
      Preference name for the project directory.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void clear()
      Clears all properties in this Preferences object.
      static java.lang.String getFilename()
      Get the filename that will be used in the store() method.
      static java.lang.String[] getPluginPaths()
      Return the paths in the UserPluginPath property.
      static java.lang.String getProperty​(java.lang.String name)
      Get the property with the given name.
      static java.lang.String getProperty​(java.lang.String name, java.lang.String defaultValue)
      Get the property with the given name; if there is no property, return the defaultValue.
      static java.lang.String getProperty​(java.lang.String name, java.lang.String defaultValue, boolean useHistoricalValue)
      Get the property with the given name; if there is no property, return the defaultValue.
      static java.util.List<java.lang.String> getPropertyNames()
      Get an array of known property names.
      static java.lang.String removeProperty​(java.lang.String name)
      Removes the given preference from this preferences object.
      static void setFilename​(java.lang.String name)
      Set the filename so that when the store() method is called, the preferences are written to this file.
      static void setPluginPaths​(java.lang.String[] paths)
      Set the paths to be used as the UserPluginPath property.
      static void setProperty​(java.lang.String name, java.lang.String value)
      Set the property value.
      static boolean store()
      Store the preferences in a file for the current filename.
      • Methods inherited from class java.lang.Object

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

      • APPLICATION_PREFERENCES_FILENAME

        public static final java.lang.String APPLICATION_PREFERENCES_FILENAME
        The APPLICATION_PREFERENCES_FILENAME is the default name for the user preferences file.
        See Also:
        Preferences, Constant Field Values
      • LAST_OPENED_ARCHIVE_DIRECTORY

        public static final java.lang.String LAST_OPENED_ARCHIVE_DIRECTORY
        Preference name for the last opened archive directory.
        See Also:
        Constant Field Values
      • PROJECT_DIRECTORY

        public static final java.lang.String PROJECT_DIRECTORY
        Preference name for the project directory.
        See Also:
        Constant Field Values
      • LAST_TOOL_IMPORT_DIRECTORY

        public static final java.lang.String LAST_TOOL_IMPORT_DIRECTORY
        Preference name for import directory that was last accessed for tools.
        See Also:
        Constant Field Values
      • LAST_TOOL_EXPORT_DIRECTORY

        public static final java.lang.String LAST_TOOL_EXPORT_DIRECTORY
        Preference name for export directory that was last accessed for tools.
        See Also:
        Constant Field Values
      • LAST_NEW_PROJECT_DIRECTORY

        public static final java.lang.String LAST_NEW_PROJECT_DIRECTORY
        Preference name for directory last selected for creating a new project.
        See Also:
        Constant Field Values
      • LAST_IMPORT_DIRECTORY

        public static final java.lang.String LAST_IMPORT_DIRECTORY
        Preference name for the import directory that was last accessed for domain files.
        See Also:
        Constant Field Values
      • LAST_EXPORT_DIRECTORY

        public static final java.lang.String LAST_EXPORT_DIRECTORY
        Preference name for the export directory that was last accessed.
        See Also:
        Constant Field Values
    • Method Detail

      • clear

        public static void clear()
        Clears all properties in this Preferences object.

        Warning: Save any changes pending before calling this method, as this call will erase any changes not written do disk via store()

      • removeProperty

        public static java.lang.String removeProperty​(java.lang.String name)
        Removes the given preference from this preferences object.
        Parameters:
        name - the name of the preference key to remove.
        Returns:
        the value that was stored with the given key.
      • getProperty

        public static java.lang.String getProperty​(java.lang.String name)
        Get the property with the given name.

        Note: all getProperty(...) methods will first check System.getProperty(String) for a value first. This allows users to override preferences from the command-line.

        Parameters:
        name - the property name
        Returns:
        the current property value; null if not set
      • getProperty

        public static java.lang.String getProperty​(java.lang.String name,
                                                   java.lang.String defaultValue)
        Get the property with the given name; if there is no property, return the defaultValue.

        Note: all getProperty(...) methods will first check System.getProperty(String) for a value first. This allows users to override preferences from the command-line.

        Parameters:
        name - the property name
        defaultValue - the default value
        Returns:
        the property value; default value if not set
        See Also:
        getProperty(String, String, boolean)
      • getProperty

        public static java.lang.String getProperty​(java.lang.String name,
                                                   java.lang.String defaultValue,
                                                   boolean useHistoricalValue)
        Get the property with the given name; if there is no property, return the defaultValue.

        This version of getProperty will, when useHistoricalValue is true, look for the given preference value in the last used installation of the application.

        Note: all getProperty(...) methods will first check System.getProperty(String) for a value first. This allows users to override preferences from the command-line.

        Parameters:
        name - The name of the property for which to get a value
        defaultValue - The value to use if there is no value yet set for the given name
        useHistoricalValue - True signals to check the last used application installation for a value for the given name if that value has not yet been set.
        Returns:
        the property with the given name; if there is no property, return the defaultValue.
        See Also:
        getProperty(String), getProperty(String, String)
      • setProperty

        public static void setProperty​(java.lang.String name,
                                       java.lang.String value)
        Set the property value. If a null value is passed, then the property is removed from this collection of preferences.
        Parameters:
        name - property name
        value - value for property
      • getPropertyNames

        public static java.util.List<java.lang.String> getPropertyNames()
        Get an array of known property names.
        Returns:
        if there are no properties, return a zero-length array
      • getFilename

        public static java.lang.String getFilename()
        Get the filename that will be used in the store() method.
        Returns:
        the filename
      • setFilename

        public static void setFilename​(java.lang.String name)
        Set the filename so that when the store() method is called, the preferences are written to this file.
        Parameters:
        name - the filename
      • store

        public static boolean store()
        Store the preferences in a file for the current filename.
        Returns:
        true if the file was written
        Throws:
        java.lang.RuntimeException - if the preferences filename was not set
      • getPluginPaths

        public static java.lang.String[] getPluginPaths()
        Return the paths in the UserPluginPath property. Return zero length array if this property is not set.
        Returns:
        the paths
      • setPluginPaths

        public static void setPluginPaths​(java.lang.String[] paths)
        Set the paths to be used as the UserPluginPath property.
        Parameters:
        paths - the paths