public class TLcyPreferencesManager extends Object
Manager of preferences. Users of the API shouldn't create a TLcyPreferencesManager
themselves, instead the TLcyPreferencesManager
can be retrieved using ILcyLucyEnv.getPreferencesManager()
.
The preferences are divided in two categories: user preferences and system preferences. Both
are represented as ALcyProperties
and can be retrieved with getCurrentUserPreferences()
and getSystemPreferences()
respectively. User preferences
concern the user, and can be different per user of the system. System preferences are application
wide preferences, that should only differ per system. Changes in the preferences can be observed
by adding a PropertyChangeListener
to the ALcyProperties
instances.
Additionally, this manager offers ILcyPropertiesDecoder
decoders to addons so
they can decode their initial configuration. The default ILcyPropertiesDecoder
decodes the configuration files specified by the source name, but alternative implementations can
be set using the setUserPreferencesPropertiesDecoder(ILcyPropertiesDecoder)
and setSystemPreferencesPropertiesDecoder(ILcyPropertiesDecoder)
methods. These could for instance
retrieve the initial configuration from a database.
This class does not take care of making the preferences persistent so that they are available
the next time the application is started. This is done by the TLcyPersistentPreferencesAddOn
. If this addon is not loaded,
the preferences will not be persistent.
Modifier and Type | Field and Description |
---|---|
static String |
DATA_DIRECTORY_KEY
Property name for the data directory in the preference manager.
|
static String |
SCROLL_UP_ZOOM_OUT_KEY
Defines the zoom direction of the scroll wheel.
|
Constructor and Description |
---|
TLcyPreferencesManager()
Creates a new preferences manager.
|
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener aListener)
Deprecated.
Add the listener to #getCurrentUserPreferences instead.
|
void |
addPropertyChangeListener(String aPropertyName,
PropertyChangeListener aListener)
Deprecated.
Add the listener to #getCurrentUserPreferences instead.
|
TLcyStringProperties |
getCurrentUserPreferences()
Returns the user preferences of this
TLcyPreferencesManager . |
TLcyStringProperties |
getSystemPreferences()
Returns the system preferences of this
TLcyPreferencesManager . |
ILcyPropertiesDecoder |
getSystemPreferencesPropertiesDecoder()
Returns the
ILcyPropertiesDecoder that addons can use to decode their initial
system configuration. |
Properties |
getUserPreferences()
Deprecated.
Use #getCurrentUserPreferences instead.
|
ILcyPropertiesDecoder |
getUserPreferencesPropertiesDecoder()
Returns the
ILcyPropertiesDecoder that addons can use to decode their initial
user configuration. |
void |
removePropertyChangeListener(PropertyChangeListener aListener)
Deprecated.
Remove the listener to #getCurrentUserPreferences instead.
|
void |
removePropertyChangeListener(String aPropertyName,
PropertyChangeListener aListener)
Deprecated.
Remove the listener from #getCurrentUserPreferences instead.
|
void |
setSystemPreferencesPropertiesDecoder(ILcyPropertiesDecoder aSystemPreferencesPropertiesDecoder)
Sets the
ILcyPropertiesDecoder that addons should use to decode their initial
system configuration. |
void |
setUserPreferencesPropertiesDecoder(ILcyPropertiesDecoder aUserPreferencesPropertiesDecoder)
Sets the
ILcyPropertiesDecoder that addons should use to decode their initial
user configuration. |
public static final String DATA_DIRECTORY_KEY
java.lang.String
. This property is, for example, used in the Open
and Save dialogs to represent the current directory.public static final String SCROLL_UP_ZOOM_OUT_KEY
public TLcyPreferencesManager()
Creates a new preferences manager. Clients should not use this constructor but rather
retrieve a preferences manager from the Lucy backend. See ILcyLucyEnv.getPreferencesManager()
public ILcyPropertiesDecoder getSystemPreferencesPropertiesDecoder()
Returns the ILcyPropertiesDecoder
that addons can use to decode their initial
system configuration. The default ILcyPropertiesDecoder
interprets the given
source name as a file relative to the classpath or current working directory and expects the
file to contain properties in the java.util.Properties
format.
ILcyPropertiesDecoder
to decode initial system configuration. Never
null
.public void setSystemPreferencesPropertiesDecoder(ILcyPropertiesDecoder aSystemPreferencesPropertiesDecoder)
Sets the ILcyPropertiesDecoder
that addons should use to decode their initial
system configuration.
aSystemPreferencesPropertiesDecoder
- The ILcyPropertiesDecoder
that should be used to decode initial system
configuration. Must not be null
.getSystemPreferencesPropertiesDecoder()
public ILcyPropertiesDecoder getUserPreferencesPropertiesDecoder()
Returns the ILcyPropertiesDecoder
that addons can use to decode their initial
user configuration. The default ILcyPropertiesDecoder
adds '.userPrefs' before the
extension of the the given source name and interprets that result as a file relative to the
classpath or current working directory and expects the file to contain properties in the
java.util.Properties
format.
For instance, getUserPreferencesPropertiesDecoder().decode( "sourceName.cfg" )
will look for the sourceName.userPrefs.cfg
file relative to the classpath or
working directory.
ILcyPropertiesDecoder
to decode initial user configuration. Never
null
.public void setUserPreferencesPropertiesDecoder(ILcyPropertiesDecoder aUserPreferencesPropertiesDecoder)
Sets the ILcyPropertiesDecoder
that addons should use to decode their initial
user configuration.
aUserPreferencesPropertiesDecoder
- The ILcyPropertiesDecoder
that should be used to decode initial user
configuration. Must not be null
.getUserPreferencesPropertiesDecoder()
public TLcyStringProperties getSystemPreferences()
Returns the system preferences of this TLcyPreferencesManager
. The intention
is to have system wide preferences, so they should be identical for all users in a system, but
it is up to the addon that makes the preferences persistent to fulfill this task. Note that
changes to these system preferences currently aren't made persistent. This is a known
limitation of TLcyPersistentPreferencesAddOn
).
Preferences can be added to and retrieved from this TLcyStringProperties
object
by using the various put
and get
methods. Note that only
String
values are allowed to be stored; the simple types such as int, double, etc.
are automatically converted to String
s by TLcyStringProperties
. Note
that the keys should be unique (application wide) and it is therefore advised to use the
package name as a prefix for the names of the keys.
TLcyPreferencesManager
.public TLcyStringProperties getCurrentUserPreferences()
TLcyPreferencesManager
. The intention is to
have separate preferences for every user in a system, but it is up to the addon that makes the
preferences persistent (see TLcyPersistentPreferencesAddOn
)
to fulfill this task. Preferences can be added to and retrieved from this
TLcyStringProperties
object by using the various put
and
get
methods. Note that only String
values are allowed to be stored;
the simple types such as int, double, etc. are automatically converted to String
s
by TLcyStringProperties
. Note that the keys should be unique (application wide)
and it is therefore advised to use the package name as a prefix for the names of the keys.TLcyPreferencesManager
.@Deprecated public Properties getUserPreferences()
Returns the user preferences of this TLcyPreferencesManager
. The intention is
to have separate preferences for every user in a system, but it is up to the addon that makes
the preferences persistent (see TLcyPersistentPreferencesAddOn
)
to fulfill this task.
Properties
object by
using Properties.setProperty(String, String)
, they can be retrieved by using Properties.getProperty(String)
. Only String
objects can be used as 'key' and
'value'. Note that the keys should be unique and it is therefore advised to use the package
name as a prefix for the names of the keys.TLcyPreferencesManager
.@Deprecated public void addPropertyChangeListener(PropertyChangeListener aListener)
Adds a listener to listen for changes in all preferences. The source of the event is the
Properties
object that is involved in the change (e.g getUserPreferences()
). The property name is the key of the property that has changed, or
null if multiple properties have changed. If the property name is available (not null), the
old and new values will be available too.
aListener
- The listener to add.@Deprecated public void addPropertyChangeListener(String aPropertyName, PropertyChangeListener aListener)
Equivalent to addPropertyChangeListener(java.beans.PropertyChangeListener)
, but
only events with respect to the property with name aPropertyName are received by
aListener.
aPropertyName
- The property name to listen for changes.aListener
- The listener.@Deprecated public void removePropertyChangeListener(PropertyChangeListener aListener)
Removes the listener so that it no longer receives change events.
aListener
- The listener to remove.@Deprecated public void removePropertyChangeListener(String aPropertyName, PropertyChangeListener aListener)
Removes the listener so that it no longer receives change events for the given aPropertyName.
aPropertyName
- The property name to stop listening for.aListener
- The listener to remove.