View Javadoc

1   /*
2   Wotonomy: OpenStep design patterns for pure Java applications.
3   Copyright (C) 2001 Intersect Software Corporation
4   
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9   
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  Lesser General Public License for more details.
14  
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, see http://www.gnu.org
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   * $Log$
95   * Revision 1.1  2006/02/16 13:19:57  cgruber
96   * Check in all sources in eclipse-friendly maven-enabled packages.
97   *
98   * Revision 1.1  2001/10/22 21:55:32  mpowers
99   * This turns out to be a really useful class.
100  *
101  *
102  */
103     
104