Class PrefHelper
java.lang.Object
ca.phon.util.PrefHelper
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:
- 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. - User preferences
getUserPreferences() - Finally, the default is returned if the key is not found.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringGet the value of the specifiedStringpreference.static BooleangetBoolean(String key, Boolean def) Get the value of the specifiedBooleanpreference.static byte[]getByteArray(String key, byte[] def) Get the value of the specifiedpreference.invalid reference
byte[]static ColorRetrieve a color preference.static DoubleGet the value of the specifiedDoublepreference.static <T extends Enum<?>>
TGet the value of the specified enum preference.static FloatGet the value of the specifiedFloatpreference.static FontFonts preferences can be stored usingStrings orarrays.invalid reference
bytestatic ObjectgetFormattedObject(String key, Format format, Object def) static IntegerGet the value of the specifiedIntegerpreference.static LongGet the value of the specifiedLongpreference.static <T extends Serializable>
TgetSerializedObject(String key, Class<T> type, T def) static StringReturns the location of the application data folder for the current platform.static Stringstatic StringThe location of the user 'Documents' folder with 'Phon' appended.static PreferencesReturns the root user preferences node.static boolean
-
Field Details
-
PREF_ROOT
-
-
Constructor Details
-
PrefHelper
public PrefHelper()
-
-
Method Details
-
getUserDataFolder
Returns the location of the application data folder for the current platform.- Returns:
- application support folder location
-
getUserDocumentsFolder
-
getUserDocumentsPhonFolder
The location of the user 'Documents' folder with 'Phon' appended. -
getUserPreferences
Returns the root user preferences node.- Returns:
- a
Preferencesinstance
-
get
-
getInt
Get the value of the specifiedIntegerpreference. If found usingSystem.getProperty(String, String), the value is decoded usingInteger.decode(String).- Parameters:
key-def-- Returns:
- the value of the specified
key, ordefaultif not found in the preferences chain.
-
getBoolean
Get the value of the specifiedBooleanpreference. If found usingSystem.getProperty(String, String), the value is decoded usingBoolean.parseBoolean(String).- Parameters:
key-def-- Returns:
- the value of the specified
key, ordefaultif not found in the preferences chain.
-
getFloat
Get the value of the specifiedFloatpreference. If found usingSystem.getProperty(String, String), the value is decoded usingFloat.parseFloat(String).- Parameters:
key-def-- Returns:
- the value of the specified
key, ordefaultif not found in the preferences chain.
-
getDouble
Get the value of the specifiedDoublepreference. If found usingSystem.getProperty(String, String), the value is decoded usingFloat.parseFloat(String).- Parameters:
key-def-- Returns:
- the value of the specified
key, ordefaultif not found in the preferences chain.
-
getLong
Get the value of the specifiedLongpreference. If found usingSystem.getProperty(String, String), the value is decoded usingLong.parseLong(String).- Parameters:
key-def-- Returns:
- the value of the specified
key, ordefaultif not found in the preferences chain.
-
getEnum
-
getByteArray
Get the value of the specifiedpreference. Unlike other properties,invalid reference
byte[]preferences cannot be overridden from the command line. The byte array contains ainvalid reference
byte[]Stringin base64 encoding.- Parameters:
key-def-- Returns:
- the value of the specified
key, ordefaultif not found in the preferences chain.
-
getColor
Retrieve a color preference. Colors are decoded using
Color.decode(String).- Parameters:
key-def-- Returns:
- the color value for the given
keyordefif not found.
-
getFont
Fonts preferences can be stored using
Strings orarrays. If stored as a string, the font is decoded usinginvalid reference
byteFont.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, ordefaultif not found in the preferences chain.
-
getSerializedObject
- Parameters:
key-type-def-- Returns:
-
getFormattedObject
-
isDebugMode
public static boolean isDebugMode()
-