laser.alphabet.event
Class AlphabetChangeManager<L extends LabelInterface>

java.lang.Object
  extended by laser.alphabet.event.AlphabetChangeManager<L>
All Implemented Interfaces:
java.io.Serializable

public class AlphabetChangeManager<L extends LabelInterface>
extends java.lang.Object
implements java.io.Serializable

The AlphabetChangeManager class provides the ability for an alphabet to be observed by registered listeners and notifies any registered listeners whenever a change occurs.

NOTES:

REFERENCE: See "Design Patterns: Elements of Reusable Object-Oriented Software" by Gamma et al.

Author:
Heather M. Conboy (laser-software@cs.umass.edu), Paula A. Wing
See Also:
Serialized Form

Constructor Summary
AlphabetChangeManager(AlphabetInterface<L> alphabet)
          Creates a new AlphabetChangeManager.
 
Method Summary
 void activateEventDeferral()
          Activates event deferral.
 boolean addAlphabetChangeListener(AlphabetChangeListener<L> listener)
          Registers the given AlphabetChangeListener as being interested in any changes to the alphabet.
 void deactivateEventDeferral()
          Deactivates event deferral.
 void fireAlphabetChangeEvent(AlphabetChangeEvent<L> event)
          Fires an existing AlphabetChangeEvent to any registered listeners.
 void fireAlphabetChangeEvent(java.lang.String aspect, AlphabetChangeAction action, java.lang.Object value)
          Creates a new AlphabetChangeEvent and fires it to any registered listeners.
 AlphabetInterface<L> getSource()
          Gets the alphabet that is having its changes managed.
 boolean removeAlphabetChangeListener(AlphabetChangeListener<L> listener)
          Unregisters the given AlphabetChangeListener as being interested in any changes to the alphabet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AlphabetChangeManager

public AlphabetChangeManager(AlphabetInterface<L> alphabet)
Creates a new AlphabetChangeManager.

PRECONDITION: The alphabet must be non-null.

Parameters:
alphabet - The alphabet whose changes are to be managed.
Method Detail

getSource

public AlphabetInterface<L> getSource()
Gets the alphabet that is having its changes managed.

NOTE: It will be the source of any events.

Returns:
The managed alphabet

addAlphabetChangeListener

public boolean addAlphabetChangeListener(AlphabetChangeListener<L> listener)
Registers the given AlphabetChangeListener as being interested in any changes to the alphabet. The same listener may be added multiple times, and will receive multiple notifications

PRECONDITION: The listener must be non-null.

Parameters:
listener - The listener to be registered
Returns:
true if the listener was added to this Alphabet

removeAlphabetChangeListener

public boolean removeAlphabetChangeListener(AlphabetChangeListener<L> listener)
Unregisters the given AlphabetChangeListener as being interested in any changes to the alphabet. If there are multiple registrations, only one registration will be removed.

PRECONDITION: The listener must be non-null.

Parameters:
listener - The listener to be unregistered
Returns:
true if the listener was removed from this Alphabet

fireAlphabetChangeEvent

public void fireAlphabetChangeEvent(AlphabetChangeEvent<L> event)
Fires an existing AlphabetChangeEvent to any registered listeners. PRECONDITIONS:

Parameters:
event - The AlphabetChangeEvent of interest

fireAlphabetChangeEvent

public void fireAlphabetChangeEvent(java.lang.String aspect,
                                    AlphabetChangeAction action,
                                    java.lang.Object value)
Creates a new AlphabetChangeEvent and fires it to any registered listeners. PRECONDITIONS:

Parameters:
aspect - The aspect of the alphabet that has changed
action - The action that represents how it changed
value - The value that represents what changed

activateEventDeferral

public void activateEventDeferral()
Activates event deferral.

NOTE: This means that the events will be queued until the corresponding number of deactivates has occured.


deactivateEventDeferral

public void deactivateEventDeferral()
Deactivates event deferral.