01: package gnu.kawa.models;
02:
03: /** Abstract class for Viewable objects, with notification/listener support. */
04:
05: public abstract class Model implements Viewable {
06: transient WeakListener listeners;
07:
08: /*
09: public abstract Object getProperty (Object key);
10:
11: public abstract void setProperty (Object key, Object value);
12: */
13:
14: public void addListener(ModelListener listener) {
15: listeners = new WeakListener(listener, listeners);
16: }
17:
18: public void addListener(WeakListener listener) {
19: listener.next = listeners;
20: listeners = listener;
21: }
22:
23: public void notifyListeners(String key) {
24: WeakListener prev = null;
25: WeakListener wlistener = listeners;
26: while (wlistener != null) {
27: Object listener = wlistener.get();
28: WeakListener next = wlistener.next;
29: if (listener == null) {
30: if (prev != null)
31: prev.next = next;
32: } else {
33: prev = wlistener;
34: wlistener.update(listener, this, key);
35: }
36: wlistener = next;
37: }
38: }
39: }
|