public class Preferences extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Preferences.AbstractSetting<T>
Base abstract class of all settings, holding the setting value.
|
static interface |
Preferences.ColorKey |
private static class |
Preferences.DefaultPreferenceChangeEvent<T> |
static class |
Preferences.ListListSetting
|
static class |
Preferences.ListSetting
|
static class |
Preferences.MapListSetting
|
static interface |
Preferences.pref |
static interface |
Preferences.PreferenceChangedListener |
static interface |
Preferences.PreferenceChangeEvent<T> |
static interface |
Preferences.Setting<T>
Interface for a preference value
|
private class |
Preferences.SettingToXml |
static interface |
Preferences.SettingVisitor |
static class |
Preferences.StringSetting
Setting containing a
String value. |
static interface |
Preferences.writeExplicitly |
Constructor and Description |
---|
Preferences() |
Modifier and Type | Method and Description |
---|---|
void |
addPreferenceChangeListener(Preferences.PreferenceChangedListener listener) |
static <T> T |
deserializeStruct(Map<String,String> hash,
Class<T> klass) |
static boolean |
equalArray(Collection<Collection<String>> a,
Collection<List<String>> b) |
static boolean |
equalCollection(Collection<String> a,
Collection<String> b) |
static boolean |
equalListOfStructs(Collection<Map<String,String>> a,
Collection<Map<String,String>> b) |
private static boolean |
equalMap(Map<String,String> a,
Map<String,String> b) |
protected <T> void |
firePreferenceChanged(String key,
Preferences.Setting<T> oldValue,
Preferences.Setting<T> newValue) |
void |
fromXML(Reader in) |
String |
get(String key)
Get settings value for a certain key.
|
String |
get(String key,
String def)
Get settings value for a certain key and provide default a value.
|
Map<String,String> |
getAllColors() |
Map<String,Preferences.Setting> |
getAllDefaults() |
Collection<String> |
getAllPossiblePreferenceDirs() |
Map<String,String> |
getAllPrefix(String prefix) |
List<String> |
getAllPrefixCollectionKeys(String prefix) |
Map<String,Preferences.Setting> |
getAllSettings() |
Collection<Collection<String>> |
getArray(String key) |
Collection<Collection<String>> |
getArray(String key,
Collection<Collection<String>> def)
Used to read a 2-dimensional array of strings from the preference file.
|
boolean |
getBoolean(String key) |
boolean |
getBoolean(String key,
boolean def) |
boolean |
getBoolean(String key,
String specName,
boolean def) |
File |
getCacheDirectory()
Get the directory where cached content of any kind should be stored.
|
Collection<String> |
getCollection(String key)
Get a list of values for a certain key
|
Collection<String> |
getCollection(String key,
Collection<String> def)
Get a list of values for a certain key
|
Color |
getColor(Preferences.ColorKey key) |
Color |
getColor(String colName,
Color def)
Convenience method for accessing colour preferences.
|
Color |
getColor(String colName,
String specName,
Color def)
Convenience method for accessing colour preferences.
|
String |
getColorName(String o) |
Color |
getDefaultColor(String colKey) |
Map<String,String> |
getDefaults() |
double |
getDouble(String key,
double def) |
int |
getInteger(String key,
int def) |
int |
getInteger(String key,
String specName,
int def) |
<T> List<T> |
getListOfStructs(String key,
Class<T> klass)
Get a list of hashes which are represented by a struct-like class.
|
Collection<Map<String,String>> |
getListOfStructs(String key,
Collection<Map<String,String>> def) |
<T> List<T> |
getListOfStructs(String key,
Collection<T> def,
Class<T> klass)
same as above, but returns def if nothing was found
|
long |
getLong(String key,
long def) |
File |
getPluginsDirectory()
Returns the user plugin directory
|
Collection<String> |
getPluginSites()
Replies the collection of plugin site URLs from where plugin lists can be downloaded
|
File |
getPreferenceFile()
Returns the user preferences file
|
String |
getPreferencesDir()
Returns the location of the user defined preferences directory
|
File |
getPreferencesDirFile()
Returns the user defined preferences directory
|
Color |
getUIColor(String colName) |
void |
init(boolean reset) |
static boolean |
isEqual(Preferences.Setting<?> a,
Preferences.Setting<?> b) |
private void |
jumpToEnd() |
void |
load() |
void |
parse() |
protected List<String> |
parseInnerList() |
protected Map<String,String> |
parseMap() |
void |
parseRoot() |
protected void |
parseToplevelList() |
boolean |
put(String key,
boolean value) |
boolean |
put(String key,
String value)
Set a value for a certain setting.
|
boolean |
putArray(String key,
Collection<Collection<String>> value) |
private void |
putArrayDefault(String key,
List<List<String>> val) |
boolean |
putCollection(String key,
Collection<String> value) |
boolean |
putCollectionBounded(String key,
int maxsize,
Collection<String> val)
Saves at most
maxsize items of collection val . |
private void |
putCollectionDefault(String key,
List<String> val) |
boolean |
putColor(String colKey,
Color val) |
void |
putDefault(String key,
String def) |
boolean |
putDouble(String key,
Double value) |
boolean |
putInteger(String key,
Integer value) |
boolean |
putListOfStructs(String key,
Collection<Map<String,String>> value) |
<T> boolean |
putListOfStructs(String key,
Collection<T> val,
Class<T> klass)
Save a list of hashes represented by a struct-like class.
|
private void |
putListOfStructsDefault(String key,
List<Map<String,String>> val) |
boolean |
putLong(String key,
Long value) |
boolean |
putSetting(String key,
Preferences.Setting value) |
void |
removeFromCollection(String key,
String value) |
void |
removeObsolete()
Removes obsolete preference settings.
|
void |
removePreferenceChangeListener(Preferences.PreferenceChangedListener listener) |
void |
resetToDefault() |
void |
save()
Called after every put.
|
private <T> Collection<Map<String,String>> |
serializeListOfStructs(Collection<T> l,
Class<T> klass) |
static <T> Map<String,String> |
serializeStruct(T struct,
Class<T> klass) |
private void |
setCorrectPermissions(File file) |
void |
setPluginSites(Collection<String> sites)
Sets the collection of plugin site URLs.
|
protected void |
throwException(String msg) |
String |
toXML(boolean nopass) |
void |
updateSystemProperties()
Updates system properties with the current values in the preferences.
|
private void |
updateSystemProperty(String key,
String value) |
void |
validateXML(Reader in) |
private File preferencesDirFile
getPreferencesDirFile()
private File cacheDirFile
protected final SortedMap<String,String> properties
protected final SortedMap<String,String> colornames
protected final SortedMap<String,List<String>> collectionProperties
protected final SortedMap<String,List<String>> collectionDefaults
protected final SortedMap<String,List<Map<String,String>>> listOfStructsProperties
protected final SortedMap<String,List<Map<String,String>>> listOfStructsDefaults
private final CopyOnWriteArrayList<Preferences.PreferenceChangedListener> listeners
private static final String[] DEFAULT_PLUGIN_SITE
protected XMLStreamReader parser
public Preferences()
public void addPreferenceChangeListener(Preferences.PreferenceChangedListener listener)
public void removePreferenceChangeListener(Preferences.PreferenceChangedListener listener)
protected <T> void firePreferenceChanged(String key, Preferences.Setting<T> oldValue, Preferences.Setting<T> newValue)
public String getPreferencesDir()
public File getPreferencesDirFile()
public File getPreferenceFile()
public File getPluginsDirectory()
public File getCacheDirectory()
public Collection<String> getAllPossiblePreferenceDirs()
public String get(String key)
key
- the identifier for the settingpublic String get(String key, String def)
key
- the identifier for the settingdef
- the default value. For each call of get() with a given key, the
default value must be the same.public Map<String,String> getAllPrefix(String prefix)
public List<String> getAllPrefixCollectionKeys(String prefix)
public Map<String,String> getAllColors()
public Map<String,String> getDefaults()
public void putDefault(String key, String def)
public boolean getBoolean(String key)
public boolean getBoolean(String key, boolean def)
public boolean getBoolean(String key, String specName, boolean def)
public boolean put(String key, String value)
key
- the unique identifier for the settingvalue
- the value of the setting. Can be null or "" which both removes
the key-value entry.public boolean putInteger(String key, Integer value)
public void save() throws IOException
IOException
private void setCorrectPermissions(File file)
public void init(boolean reset)
public final void resetToDefault()
public Color getColor(String colName, Color def)
colName
- name of the colourdef
- default valuepublic Color getUIColor(String colName)
public String getColorName(String o)
public Color getColor(Preferences.ColorKey key)
public Color getColor(String colName, String specName, Color def)
colName
- name of the colourspecName
- name of the special colour settingsdef
- default valuepublic Color getDefaultColor(String colKey)
public int getInteger(String key, int def)
public int getInteger(String key, String specName, int def)
public Collection<String> getCollection(String key, Collection<String> def)
key
- the identifier for the settingdef
- the default value.public Collection<String> getCollection(String key)
key
- the identifier for the settingpublic void removeFromCollection(String key, String value)
public boolean putCollection(String key, Collection<String> value)
public static boolean equalCollection(Collection<String> a, Collection<String> b)
public boolean putCollectionBounded(String key, int maxsize, Collection<String> val)
maxsize
items of collection val
.private void putCollectionDefault(String key, List<String> val)
public Collection<Collection<String>> getArray(String key, Collection<Collection<String>> def)
public Collection<Collection<String>> getArray(String key)
public boolean putArray(String key, Collection<Collection<String>> value)
public static boolean equalArray(Collection<Collection<String>> a, Collection<List<String>> b)
private void putArrayDefault(String key, List<List<String>> val)
public Collection<Map<String,String>> getListOfStructs(String key, Collection<Map<String,String>> def)
public boolean putListOfStructs(String key, Collection<Map<String,String>> value)
public static boolean equalListOfStructs(Collection<Map<String,String>> a, Collection<Map<String,String>> b)
private void putListOfStructsDefault(String key, List<Map<String,String>> val)
public <T> List<T> getListOfStructs(String key, Class<T> klass)
key
- main preference keyklass
- The struct classpublic <T> List<T> getListOfStructs(String key, Collection<T> def, Class<T> klass)
public <T> boolean putListOfStructs(String key, Collection<T> val, Class<T> klass)
key
- main preference keyval
- the list that is supposed to be savedklass
- The struct classprivate <T> Collection<Map<String,String>> serializeListOfStructs(Collection<T> l, Class<T> klass)
public static <T> Map<String,String> serializeStruct(T struct, Class<T> klass)
public static <T> T deserializeStruct(Map<String,String> hash, Class<T> klass)
public boolean putSetting(String key, Preferences.Setting value)
public Map<String,Preferences.Setting> getAllSettings()
public Map<String,Preferences.Setting> getAllDefaults()
public void updateSystemProperties()
private void updateSystemProperty(String key, String value)
public Collection<String> getPluginSites()
public void setPluginSites(Collection<String> sites)
sites
- the site URLspublic void validateXML(Reader in) throws Exception
Exception
public void fromXML(Reader in) throws XMLStreamException
XMLStreamException
public void parse() throws XMLStreamException
XMLStreamException
public void parseRoot() throws XMLStreamException
XMLStreamException
private void jumpToEnd() throws XMLStreamException
XMLStreamException
protected void parseToplevelList() throws XMLStreamException
XMLStreamException
protected List<String> parseInnerList() throws XMLStreamException
XMLStreamException
protected Map<String,String> parseMap() throws XMLStreamException
XMLStreamException
protected void throwException(String msg)
public void removeObsolete()
public static boolean isEqual(Preferences.Setting<?> a, Preferences.Setting<?> b)