org.jscience.util
Class AbstractChangeable

java.lang.Object
  extended by org.jscience.util.AbstractChangeable
All Implemented Interfaces:
Changeable

public abstract class AbstractChangeable
extends java.lang.Object
implements Changeable

Useful base-class for objects implementing Changeable


Constructor Summary
AbstractChangeable()
           
 
Method Summary
 void addChangeListener(ChangeListener cl)
          DOCUMENT ME!
 void addChangeListener(ChangeListener cl, ChangeType ct)
          DOCUMENT ME!
protected  ChangeSupport generateChangeSupport()
          Called the first time a ChangeSupport object is needed.
protected  ChangeSupport getChangeSupport(ChangeType ct)
          Called to retrieve the ChangeSupport for this object.
protected  boolean hasListeners()
          Deprecated. use hasListeners(ChangeType) if at all possible
protected  boolean hasListeners(ChangeType ct)
          Discover if we have listeners registered for a particular change type.
 boolean isUnchanging(ChangeType ct)
          DOCUMENT ME!
 void removeChangeListener(ChangeListener cl)
          DOCUMENT ME!
 void removeChangeListener(ChangeListener cl, ChangeType ct)
          DOCUMENT ME!
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractChangeable

public AbstractChangeable()
Method Detail

hasListeners

protected boolean hasListeners()
Deprecated. use hasListeners(ChangeType) if at all possible

Discover if we have any listeners registered.

Returns:
true if there is at least one listener

hasListeners

protected boolean hasListeners(ChangeType ct)
Discover if we have listeners registered for a particular change type.

Parameters:
ct - the ChangeType we are interested in
Returns:
true if there is at least one listener

generateChangeSupport

protected ChangeSupport generateChangeSupport()
Called the first time a ChangeSupport object is needed. Override this if you want to set the Unchanging set on the ChangeSupport, or if you want to install listeners on other objects when the change system is initialized.

Since:
1.3

getChangeSupport

protected ChangeSupport getChangeSupport(ChangeType ct)
Called to retrieve the ChangeSupport for this object.

Your implementation of this method should have the following structure:

 ChangeSupport cs = super.getChangeSupport(ct);
 

if(someForwarder == null && ct.isMatching(SomeInterface.SomeChangeType)) { someForwarder = new ChangeForwarder(...

this.stateVariable.addChangeListener(someForwarder, VariableInterface.AChange); }

return cs;

It is usual for the forwarding listeners (someForwarder in this example) to be transient and lazily instantiated. Be sure to register & unregister the forwarder in the code that does the ChangeEvent handling in setter methods.


addChangeListener

public final void addChangeListener(ChangeListener cl)
DOCUMENT ME!

Specified by:
addChangeListener in interface Changeable
Parameters:
cl - DOCUMENT ME!

addChangeListener

public final void addChangeListener(ChangeListener cl,
                                    ChangeType ct)
DOCUMENT ME!

Specified by:
addChangeListener in interface Changeable
Parameters:
cl - DOCUMENT ME!
ct - DOCUMENT ME!

removeChangeListener

public final void removeChangeListener(ChangeListener cl)
DOCUMENT ME!

Specified by:
removeChangeListener in interface Changeable
Parameters:
cl - DOCUMENT ME!

removeChangeListener

public final void removeChangeListener(ChangeListener cl,
                                       ChangeType ct)
DOCUMENT ME!

Specified by:
removeChangeListener in interface Changeable
Parameters:
cl - DOCUMENT ME!
ct - DOCUMENT ME!

isUnchanging

public final boolean isUnchanging(ChangeType ct)
DOCUMENT ME!

Specified by:
isUnchanging in interface Changeable
Parameters:
ct - DOCUMENT ME!
Returns:
DOCUMENT ME!