1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.wotonomy.control;
20
21 import java.util.Observable;
22 import java.util.Observer;
23
24 /***
25 * This is an abstract class for receiving coalesced
26 * notifications of changes from objects.
27 * This class also implements Observer for greater
28 * compatibility.
29 * The point of EODelayedObservers is that when
30 * they receive a willChange message, they
31 * queue themselves with a EODelayedObserverQueue
32 * so they can receive a single subjectChanged()
33 * after all changes from an observed object take
34 * place.
35 *
36 * @author michael@mpowers.net
37 * @author $Author: cgruber $
38 * @version $Revision: 894 $
39 */
40 public abstract class EODelayedObserver
41 implements EOObserving, Observer
42 {
43 /***
44 * Notified immediately.
45 */
46 public static final int ObserverPriorityImmediate = 0;
47 public static final int ObserverPriorityFirst = 1;
48 public static final int ObserverPrioritySecond = 2;
49 public static final int ObserverPriorityThird = 3;
50 public static final int ObserverPriorityFourth = 4;
51 public static final int ObserverPriorityFifth = 5;
52 public static final int ObserverPrioritySixth = 6;
53 public static final int ObserverPriorityLater = 7;
54 public static final int ObserverNumberOfPriorities = 8;
55
56 /***
57 * Default constructor.
58 */
59 public EODelayedObserver ()
60 {
61 }
62
63 /***
64 * Removes this observer from the observer queue
65 * for a currently pending notification.
66 */
67 public void discardPendingNotification ()
68 {
69 observerQueue().dequeueObserver( this );
70 }
71
72 /***
73 * Returns the observer queue to which this observer
74 * belongs. This implementation returns the default
75 * EODelayedObserverQueue.
76 * Override to use a different one.
77 */
78 public EODelayedObserverQueue observerQueue ()
79 {
80 return EODelayedObserverQueue.defaultObserverQueue();
81 }
82
83 /***
84 * Returns the priority of this observer in the queue.
85 * This implementation returns ObserverPriorityThird.
86 * Override to be notified before other observers.
87 */
88 public int priority ()
89 {
90 return ObserverPriorityThird;
91 }
92
93 /***
94 * Notifies observer that one or more objects that
95 * it is observing have changed. The observer should
96 * check all objects it is observing for changes.
97 */
98 public abstract void subjectChanged ();
99
100
101
102 /***
103 * Called when the specified object is about to change.
104 * This implementation puts this observer on a
105 * notification queue.
106 */
107 public void objectWillChange ( Object anObject )
108 {
109 observerQueue().enqueueObserver( this );
110 }
111
112
113
114 /***
115 * Called when the specified object has changed,
116 * with the specified argument.
117 * This method is included for interacting with
118 * the java.lang.Observer pattern.
119 * This implementation simply objectWillChange(anObject)
120 * so that the observer still gets a single subjectChanged
121 * call in response to multiple changes.
122 */
123 public void update ( Observable anObject, Object aValue )
124 {
125 objectWillChange( anObject );
126 }
127
128 }
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152