Package ca.phon.util
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()
- System preferences
invalid @link
#getSystemPreferences()
- Finally, the provide default is returned if the key is not found.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
Get the value of the specifiedString
preference.static Boolean
getBoolean
(String key, Boolean def) Get the value of the specifiedBoolean
preference.static byte[]
getByteArray
(String key, byte[] def) Get the value of the specifiedinvalid @link
byte[]
static Color
Retrieve a color preference.static Double
Get the value of the specifiedDouble
preference.static <T extends Enum<?>>
TGet the value of the specified enum preference.static Float
Get the value of the specifiedFloat
preference.static Font
Fonts preferences can be stored usingString
s orinvalid @link
byte
static Object
getFormattedObject
(String key, Format format, Object def) static Integer
Get the value of the specifiedInteger
preference.static Long
Get the value of the specifiedLong
preference.static <T extends Serializable>
TgetSerializedObject
(String key, Class<T> type, T def) static String
Returns the location of the application data folder for the current platform.static String
static String
The location of the user 'Documents' folder with 'Phon' appended.static Preferences
Returns the root user preferences node.
-
Field Details
-
PREF_ROOT
Application prefs root node- See Also:
-
-
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
Preferences
instance
-
get
Get the value of the specifiedString
preference.- Parameters:
key
-def
-- Returns:
- the value of the specified
key
, ordefault
if not found in the preferences chain.
-
getInt
Get the value of the specifiedInteger
preference. If found usingSystem.getProperty(String, String)
, the value is decoded usingInteger.decode(String)
.- Parameters:
key
-def
-- Returns:
- the value of the specified
key
, ordefault
if not found in the preferences chain.
-
getBoolean
Get the value of the specifiedBoolean
preference. If found usingSystem.getProperty(String, String)
, the value is decoded usingBoolean.parseBoolean(String)
.- Parameters:
key
-def
-- Returns:
- the value of the specified
key
, ordefault
if not found in the preferences chain.
-
getFloat
Get the value of the specifiedFloat
preference. If found usingSystem.getProperty(String, String)
, the value is decoded usingFloat.parseFloat(String)
.- Parameters:
key
-def
-- Returns:
- the value of the specified
key
, ordefault
if not found in the preferences chain.
-
getDouble
Get the value of the specifiedDouble
preference. If found usingSystem.getProperty(String, String)
, the value is decoded usinginvalid @link
Float#parseDouble(String)
- Parameters:
key
-def
-- Returns:
- the value of the specified
key
, ordefault
if not found in the preferences chain.
-
getLong
Get the value of the specifiedLong
preference. If found usingSystem.getProperty(String, String)
, the value is decoded usingLong.parseLong(String)
.- Parameters:
key
-def
-- Returns:
- the value of the specified
key
, ordefault
if not found in the preferences chain.
-
getEnum
Get the value of the specified enum preference.- Parameters:
enumClazz
-key
-def
-- Returns:
- the value of the specified
key
-
getByteArray
Get the value of the specifiedinvalid @link
byte[]
invalid @link
byte[]
String
in base64 encoding.- Parameters:
key
-def
-- Returns:
- the value of the specified
key
, ordefault
if 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
key
ordef
if not found.
-
getFont
Fonts preferences can be stored using
String
s orinvalid @link
byte
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
, ordefault
if not found in the preferences chain.
-
getSerializedObject
- Parameters:
key
-type
-def
-- Returns:
-
getFormattedObject
-