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 net.wotonomy.foundation.NSSelector;
22
23 /***
24 * A convenience observer for objects that do not or cannot
25 * subclass EODelayedObserver. EOObserverProxy will invoke
26 * an NSSelector on an object when it receives a subjectChanged
27 * message.
28 *
29 * @author michael@mpowers.net
30 * @author $Author: cgruber $
31 * @version $Revision: 893 $
32 */
33 public class EOObserverProxy
34 extends EODelayedObserver
35 {
36 protected Object target;
37 protected NSSelector selector;
38 protected int priority;
39
40 /***
41 * Constructs an EODelayedObserver that will invoke the specified selector
42 * on the specified object, and will run at the specified priority.
43 */
44 public EOObserverProxy (
45 Object anObject, NSSelector aSelector, int aPriority )
46 {
47 target = anObject;
48 selector = aSelector;
49 priority = aPriority;
50 }
51
52 /***
53 * Constructs an EODelayedObserver that will invoke the specified selector
54 * on the specified object, and will run at ObserverPriorityThird priority,
55 * which is the default.
56 */
57 public EOObserverProxy (
58 Object anObject, NSSelector aSelector )
59 {
60 this( anObject, aSelector, ObserverPriorityThird );
61 }
62
63 /***
64 * Returns the priority of this observer in the queue.
65 * This implementation returns the priority specified
66 * in the constructor.
67 */
68 public int priority ()
69 {
70 return priority;
71 }
72
73 /***
74 * Notifies observer that one or more objects that
75 * it is observing have changed. The observer should
76 * check all objects it is observing for changes.
77 */
78 public void subjectChanged ()
79 {
80 try
81 {
82 selector.invoke( target );
83 }
84 catch ( Exception exc )
85 {
86 System.out.println( "Error notifying observer: " );
87 exc.printStackTrace();
88 }
89 }
90
91 }
92
93
94
95
96
97
98
99
100
101
102
103
104