Package ca.phon.util

Class PrefHelper

java.lang.Object
ca.phon.util.PrefHelper

public class PrefHelper extends Object

Helper class for managing several user preferences. Also contains methods for accessing the Preferences object for various roots.

The get...(key, default) methods available will search for the given key in the following order:

  1. System properties System.getProperty(String, String) (for all types of preferences except byte arrays). These can be specified on the command line using the
    -D<key>=<value>
    command line option.
  2. User preferences getUserPreferences()
  3. System preferences
    invalid @link
    #getSystemPreferences()
  4. Finally, the provide default is returned if the key is not found.
  • Field Details

  • Constructor Details

    • PrefHelper

      public PrefHelper()
  • Method Details

    • getUserDataFolder

      public static String getUserDataFolder()
      Returns the location of the application data folder for the current platform.
      Returns:
      application support folder location
    • getUserDocumentsFolder

      public static String getUserDocumentsFolder()
    • getUserDocumentsPhonFolder

      public static String getUserDocumentsPhonFolder()
      The location of the user 'Documents' folder with 'Phon' appended.
    • getUserPreferences

      public static Preferences getUserPreferences()
      Returns the root user preferences node.
      Returns:
      a Preferences instance
    • get

      public static String get(String key, String def)
      Get the value of the specified String preference.
      Parameters:
      key -
      def -
      Returns:
      the value of the specified key, or default if not found in the preferences chain.
    • getInt

      public static Integer getInt(String key, Integer def)
      Get the value of the specified Integer preference. If found using System.getProperty(String, String), the value is decoded using Integer.decode(String).
      Parameters:
      key -
      def -
      Returns:
      the value of the specified key, or default if not found in the preferences chain.
    • getBoolean

      public static Boolean getBoolean(String key, Boolean def)
      Get the value of the specified Boolean preference. If found using System.getProperty(String, String), the value is decoded using Boolean.parseBoolean(String).
      Parameters:
      key -
      def -
      Returns:
      the value of the specified key, or default if not found in the preferences chain.
    • getFloat

      public static Float getFloat(String key, Float def)
      Get the value of the specified Float preference. If found using System.getProperty(String, String), the value is decoded using Float.parseFloat(String).
      Parameters:
      key -
      def -
      Returns:
      the value of the specified key, or default if not found in the preferences chain.
    • getDouble

      public static Double getDouble(String key, Double def)
      Get the value of the specified Double preference. If found using System.getProperty(String, String), the value is decoded using
      invalid @link
      Float#parseDouble(String)
      .
      Parameters:
      key -
      def -
      Returns:
      the value of the specified key, or default if not found in the preferences chain.
    • getLong

      public static Long getLong(String key, Long def)
      Get the value of the specified Long preference. If found using System.getProperty(String, String), the value is decoded using Long.parseLong(String).
      Parameters:
      key -
      def -
      Returns:
      the value of the specified key, or default if not found in the preferences chain.
    • getEnum

      public static <T extends Enum<?>> T getEnum(Class<T> enumClazz, String key, T def)
      Get the value of the specified enum preference.
      Parameters:
      enumClazz -
      key -
      def -
      Returns:
      the value of the specified key
    • getByteArray

      public static byte[] getByteArray(String key, byte[] def)
      Get the value of the specified
      invalid @link
      byte[]
      preference. Unlike other properties,
      invalid @link
      byte[]
      preferences cannot be overridden from the command line. The byte array contains a String in base64 encoding.
      Parameters:
      key -
      def -
      Returns:
      the value of the specified key, or default if not found in the preferences chain.
    • getColor

      public static Color getColor(String key, Color def)

      Retrieve a color preference. Colors are decoded using Color.decode(String).

      Parameters:
      key -
      def -
      Returns:
      the color value for the given key or def if not found.
    • getFont

      public static Font getFont(String key, Font def)

      Fonts preferences can be stored using Strings or

      invalid @link
      byte
      arrays. If stored as a string, the font is decoded using Font.decode(String). If stored as a byte array, the font is loaded using the byte[] array as an binary input stream.

      Note: It is not recommended to store fonts in byte arrays!

      Parameters:
      key -
      def -
      Returns:
      the value of the specified key, or default if not found in the preferences chain.
    • getSerializedObject

      public static <T extends Serializable> T getSerializedObject(String key, Class<T> type, T def)
      Parameters:
      key -
      type -
      def -
      Returns:
    • getFormattedObject

      public static Object getFormattedObject(String key, Format format, Object def)