Class DynamicPrefChangeManager
- java.lang.Object
-
- de.sciss.app.DynamicPrefChangeManager
-
- All Implemented Interfaces:
DynamicListening,LaterInvocationManager.Listener,PreferenceNodeSync,java.util.EventListener,java.util.prefs.PreferenceChangeListener
public class DynamicPrefChangeManager extends java.lang.Object implements DynamicListening, java.util.prefs.PreferenceChangeListener, PreferenceNodeSync, LaterInvocationManager.Listener
A utility class for a mechanism common to many GUI objects : they listen to certain preferences and need to act upon changes. However to improve performance, the listening is paused when the components are hidden and resumed when they are shown or added to ancestor GUI components.This class tracks a set of preferences specified by key strings. It implements the DynamicListening interface and thus can be used in a DynamicAncestorAdapter. When the listening is resumes, this class checks for changes that might have occured to the tracked preferences. All relevant PreferenceChangeEvents are forwarded to the LaterInvocationManager.Listener provided in the constructor call.
Another important issue is to avoid deadlocks that can be easily caused in the java.util.prefs.Preferences context because it provides no means to find out who changed the preferences. Therefore if a component both changes a preferences and tracks (listens to) changes of the same preference, it can produce and infinite loop. Besides, if another component changes to prefs but the old value equals the new value, unneccessary overhead might be created. To avoid this, this class checks to see if a preference value really changed - if not, that PreferenceChangeEvent is NOT forwarded to the LIM-Listener.
-
-
Constructor Summary
Constructors Constructor Description DynamicPrefChangeManager(java.util.prefs.Preferences prefs, java.lang.String[] keys, java.util.prefs.PreferenceChangeListener client)DynamicPrefChangeManager(java.util.prefs.Preferences prefs, java.lang.String[] keys, java.util.prefs.PreferenceChangeListener client, boolean initialDelivery)Constructs a newDynamicPrefChangeManager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddeliverChanges()voidlaterInvocation(java.lang.Object o)Called later in the event thread, this passes the object given to the queue methodvoidpreferenceChange(java.util.prefs.PreferenceChangeEvent e)voidsetPreferences(java.util.prefs.Preferences prefs)Enables Preferences synchronization.voidstartListening()will be called when the component becomes visiblevoidstopListening()will be called when the component is hidden
-
-
-
Constructor Detail
-
DynamicPrefChangeManager
public DynamicPrefChangeManager(java.util.prefs.Preferences prefs, java.lang.String[] keys, java.util.prefs.PreferenceChangeListener client)
-
DynamicPrefChangeManager
public DynamicPrefChangeManager(java.util.prefs.Preferences prefs, java.lang.String[] keys, java.util.prefs.PreferenceChangeListener client, boolean initialDelivery)Constructs a newDynamicPrefChangeManager.- Parameters:
prefs- the Preference object to track. Note that the constructor does not register a PreferenceChangeListener, this is done when the DynamicListening.startListening() is involved. Therefore if you plan to not attach the DynamicPrefChangeManager to a DynamicAncestor- or -ComponentListener, you'll have to call startListening() manually.keys- the keys in the specified prefs which we shall track. Initially all values are considered null and nothing is broadcast. However, if startListening() is called, all values are checked, therefore all preference values which are not null will be initially forwarded to the LIM-Listener.client- usually the calling instance. laterInvocation() is called whenever the dynamic listening is active and preference changes occur which really alter the preference values. The object passed to laterInvocation is a PreferenceChangeEvent.
-
-
Method Detail
-
setPreferences
public void setPreferences(java.util.prefs.Preferences prefs)
Description copied from interface:PreferenceNodeSyncEnables Preferences synchronization. This method is not thread safe and must be called from the event thread. When a preference change is received, the GUI is updated and dispatches an event to registered listeners. Likewise, if the user adjusts the GUI value, the preference will be updated. The same is true, if you call one of the value changing methods.- Specified by:
setPreferencesin interfacePreferenceNodeSync- Parameters:
prefs- the preferences node in which the values are stored, or null to disable prefs sync.
-
deliverChanges
public void deliverChanges()
-
startListening
public void startListening()
Description copied from interface:DynamicListeningwill be called when the component becomes visible- Specified by:
startListeningin interfaceDynamicListening
-
stopListening
public void stopListening()
Description copied from interface:DynamicListeningwill be called when the component is hidden- Specified by:
stopListeningin interfaceDynamicListening
-
laterInvocation
public void laterInvocation(java.lang.Object o)
Description copied from interface:LaterInvocationManager.ListenerCalled later in the event thread, this passes the object given to the queue method- Specified by:
laterInvocationin interfaceLaterInvocationManager.Listener- Parameters:
o- object as passed toqueue
-
preferenceChange
public void preferenceChange(java.util.prefs.PreferenceChangeEvent e)
- Specified by:
preferenceChangein interfacejava.util.prefs.PreferenceChangeListener
-
-