scphEditor
Class CloneableObservable

java.lang.Object
  extended by java.util.Observable
      extended by scphEditor.CloneableObservable
Direct Known Subclasses:
OperandVector

public class CloneableObservable
extends java.util.Observable

This class re-implements java.util.Observable so it can be cloned safely. But there can be two meanings for cloning an observable:

You can choose which one you want when you call the constructor. (The default is the first meaning: empty list.) In addition, you can change your mind any time in the program flow with the cloneObserverList() method.

This class does not implement java.lang.Cloneable! Reason: you might not want to support cloning in some of your subclasses. But this class provides a correctly-written protected clone() method, so your subclasses and the subclasses of your subclasses can rely on it. In other words, this class does not open up access until you want to, and provides proper support when you do open up access.

This class subclasses Observable, so that Observer objects cannot tell the difference. But all Observable methods accessing the observer list are overriden and re-implemented from scratch. Only the change methods are retained.

See Also:
cloneObserverList(boolean), Observable

Constructor Summary
CloneableObservable()
          Default constructor.
CloneableObservable(boolean cloneObserverList)
          Constructor specifying the copy policy for the observer list.
 
Method Summary
 void addObserver(java.util.Observer o)
          Adds an observer.
protected  java.lang.Object clone()
          Clones this object.
 boolean cloneObserverList()
          Gives the observer-list cloning policy.
 boolean cloneObserverList(boolean newPolicy)
          Changes the observer-list cloning policy.
 int countObservers()
          Gives the number of observers of this object.
 void deleteObserver(java.util.Observer o)
          Deletes an observer.
 void deleteObservers()
          Clears the observer list.
 void notifyObservers()
          If this object is marked as changed (hasChanged() returns true), mark itself as unchanged (with clearChanged()), and then notify all of its observers.
 void notifyObservers(java.lang.Object arg)
          If this object is marked as changed (hasChanged() returns true), mark itself as unchanged (with clearChanged()), and then notify all of its observers.
 
Methods inherited from class java.util.Observable
clearChanged, hasChanged, setChanged
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CloneableObservable

public CloneableObservable()
Default constructor.


CloneableObservable

public CloneableObservable(boolean cloneObserverList)
Constructor specifying the copy policy for the observer list.

Parameters:
cloneObserverList - true if you want a clone to duplicate the observer list of the original; false if you want the observer list of a clone to be empty.
Method Detail

clone

protected java.lang.Object clone()
Clones this object.

Overrides:
clone in class java.lang.Object

cloneObserverList

public boolean cloneObserverList()
Gives the observer-list cloning policy.


cloneObserverList

public boolean cloneObserverList(boolean newPolicy)
Changes the observer-list cloning policy.

Parameters:
newPolicy - true if you want a clone to duplicate the observer list of the original; false if you want the observer list of a clone to be empty.
Returns:
the old policy. (Same semantics as the parameter.)

addObserver

public void addObserver(java.util.Observer o)
Adds an observer. No duplication check!

Overrides:
addObserver in class java.util.Observable
Parameters:
o - the observer.

deleteObserver

public void deleteObserver(java.util.Observer o)
Deletes an observer.

Overrides:
deleteObserver in class java.util.Observable
Parameters:
o - the observer.

deleteObservers

public void deleteObservers()
Clears the observer list.

Overrides:
deleteObservers in class java.util.Observable

notifyObservers

public void notifyObservers()
If this object is marked as changed (hasChanged() returns true), mark itself as unchanged (with clearChanged()), and then notify all of its observers. Observers are notified by calling their update() methods with two parameters: this object, and null.

Overrides:
notifyObservers in class java.util.Observable
See Also:
Observable.hasChanged(), Observable.clearChanged(), Observer.update(java.util.Observable, java.lang.Object)

notifyObservers

public void notifyObservers(java.lang.Object arg)
If this object is marked as changed (hasChanged() returns true), mark itself as unchanged (with clearChanged()), and then notify all of its observers. Observers are notified by calling their update() methods with two parameters: this object, and the parameter arg.

Overrides:
notifyObservers in class java.util.Observable
Parameters:
arg - the second parameter to be passed to update() methods of observers.
See Also:
Observable.hasChanged(), Observable.clearChanged(), Observer.update(java.util.Observable, java.lang.Object)

countObservers

public int countObservers()
Gives the number of observers of this object.

Overrides:
countObservers in class java.util.Observable