public interface Configuration2 extends Configuration
Configuration
class to handle properties in a generic way. The only methods you have to
implement are:
getPropertiesTypes()
setPropertyValue(java.lang.String, java.lang.Object)
getPropertyValue(java.lang.String)
public class MyConfiguration implements Configuration2 { public static final String MY_INT_PROPERTY = "MyIntProperty"; private static final SortedMap<String, Class<?>> properties = new TreeMap<>(); static { properties.put(MY_INT_PROPERTY, Integer.Type); } private int intPropValue = 0; public SortedMap<String, Class<?>> getPropertiesTypes() { return properties; } public void setPropertyValue(String key, Object value) { if (key.equals(MY_INT_PROPERTY) && value instanceof Integer) { intPropValue = (Integer)value; } } public Object getPropertyValue(String key) { if (key.equals(MY_INT_PROPERTY)) { return intPropValue; } else { return null; } }
Plugin.getPluginConfiguration()
Modifier and Type | Method and Description |
---|---|
default void |
getConfiguration(java.util.prefs.Preferences pref,
java.io.File dir)
Called when the Preferences key-value entries must be updated with the configuration.
|
default java.lang.Object |
getPrefValue(java.util.prefs.Preferences pref,
java.lang.String key,
java.lang.Object defValue,
java.io.File dir)
Return the Preferences value for a property.
|
java.util.SortedMap<java.lang.String,java.lang.Class<?>> |
getPropertiesTypes()
Return a sorted Map with the properties keys and their type.
|
java.lang.Object |
getPropertyValue(java.lang.String key)
Return the value for a property.
|
default boolean |
getPropertyValueAsBoolean(java.lang.String key,
boolean defaultValue)
Return the value for a property as a boolean.
|
default char |
getPropertyValueAsChar(java.lang.String key,
char defaultValue)
Return the value for a property as a char.
|
default java.io.File |
getPropertyValueAsFile(java.lang.String key,
java.io.File defaultValue)
Return the value for a property as a File.
|
default float |
getPropertyValueAsFloat(java.lang.String key,
float defaultValue)
Return the value for a property as a float.
|
default int |
getPropertyValueAsInt(java.lang.String key,
int defaultValue)
Return the value for a property as an int.
|
default long |
getPropertyValueAsLong(java.lang.String key,
long defaultValue)
Return the value for a property as a long.
|
default java.lang.String |
getPropertyValueAsString(java.lang.String key,
java.lang.String defaultValue)
Return the value for a property as a String.
|
default java.net.URL |
getPropertyValueAsURL(java.lang.String key,
java.net.URL defaultValue)
Return the value for a property as a URL.
|
default boolean |
isShowingWarnings()
Return true if warnings should be presented.
|
default void |
putConfiguration(java.util.prefs.Preferences pref,
java.io.File dir)
Called when the configuration must be filled with key-value entries stored in a Preferences.
|
default void |
putPrefValue(java.util.prefs.Preferences pref,
java.lang.String key,
java.lang.Object o,
java.io.File dir)
Put the Preferences value for a property.
|
void |
setPropertyValue(java.lang.String key,
java.lang.Object value)
Set the value for a property.
|
default void |
warning(java.lang.String message)
Emit a warning.
|
setupApplicationDesc
java.util.SortedMap<java.lang.String,java.lang.Class<?>> getPropertiesTypes()
Character
or Character.TYPE
Integer
or Integer.TYPE
Float
or Float.TYPE
Long
or Long.TYPE
Boolean
String
File
and URL
void setPropertyValue(java.lang.String key, java.lang.Object value)
key
- the property keyvalue
- the property valuejava.lang.Object getPropertyValue(java.lang.String key)
key
- the property keydefault boolean isShowingWarnings()
default void warning(java.lang.String message)
err
streamif isShowingWarnings()
returns
true.message
- the messagedefault char getPropertyValueAsChar(java.lang.String key, char defaultValue)
key
- the property keydefaultValue
- the default valuedefault int getPropertyValueAsInt(java.lang.String key, int defaultValue)
key
- the property keydefaultValue
- the default valuedefault float getPropertyValueAsFloat(java.lang.String key, float defaultValue)
key
- the property keydefaultValue
- the default valuedefault long getPropertyValueAsLong(java.lang.String key, long defaultValue)
key
- the property keydefaultValue
- the default valuedefault boolean getPropertyValueAsBoolean(java.lang.String key, boolean defaultValue)
key
- the property keydefaultValue
- the default valuedefault java.io.File getPropertyValueAsFile(java.lang.String key, java.io.File defaultValue)
key
- the property keydefaultValue
- the default valuedefault java.net.URL getPropertyValueAsURL(java.lang.String key, java.net.URL defaultValue)
key
- the property keydefaultValue
- the default valuedefault java.lang.String getPropertyValueAsString(java.lang.String key, java.lang.String defaultValue)
key
- the property keydefaultValue
- the default valuedefault void putPrefValue(java.util.prefs.Preferences pref, java.lang.String key, java.lang.Object o, java.io.File dir)
pref
- the Preferenceskey
- the property keyo
- the property valuedir
- the directory to use as a current directory to store File preferences. This parameter can
be used for the configuration to define the File preference path relative to the directory, but a
Configuration might also not take this parameter into account at alldefault java.lang.Object getPrefValue(java.util.prefs.Preferences pref, java.lang.String key, java.lang.Object defValue, java.io.File dir)
pref
- the Preferenceskey
- the property keydefValue
- the property default valuedir
- the directory to use as a current directory to store File preferences. This parameter can
be used for the configuration to define the File preference path relative to the directory, but a
Configuration might also not take this parameter into account at alldefault void putConfiguration(java.util.prefs.Preferences pref, java.io.File dir)
Integer
or Integer.TYPE
Float
or Float.TYPE
Long
or Long.TYPE
Boolean
String
File
and URL
putPrefValue(java.util.prefs.Preferences, java.lang.String, java.lang.Object, java.io.File)
will be used.putConfiguration
in interface Configuration
pref
- the Preferencesdir
- the directory to use as a current directory to store File preferences. This parameter can
be used for the configuration to define the File preference path relative to the directory, but a
Configuration might also not take this parameter into account at alldefault void getConfiguration(java.util.prefs.Preferences pref, java.io.File dir)
Character
or Character.TYPE
Integer
or Integer.TYPE
Float
or Float.TYPE
Long
or Long.TYPE
Boolean
String
File
and URL
getPrefValue(java.util.prefs.Preferences, java.lang.String, java.lang.Object, java.io.File)
will be used.getConfiguration
in interface Configuration
pref
- the Preferencesdir
- the directory to use as a current directory to store File preferences. This parameter can
be used for the configuration to define the File preference path relative to the directory, but a
Configuration might also not take this parameter into account at all