/* Wotonomy: OpenStep design patterns for pure Java applications. Copyright (C) 2001 Intersect Software Corporation This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, see http://www.gnu.org */ package net.wotonomy.control; import net.wotonomy.foundation.NSSelector; /** * A convenience observer for objects that do not or cannot * subclass EODelayedObserver. EOObserverProxy will invoke * an NSSelector on an object when it receives a subjectChanged * message. * * @author michael@mpowers.net * @author $Author: cgruber $ * @version $Revision: 893 $ */ public class EOObserverProxy extends EODelayedObserver { protected Object target; protected NSSelector selector; protected int priority; /** * Constructs an EODelayedObserver that will invoke the specified selector * on the specified object, and will run at the specified priority. */ public EOObserverProxy ( Object anObject, NSSelector aSelector, int aPriority ) { target = anObject; selector = aSelector; priority = aPriority; } /** * Constructs an EODelayedObserver that will invoke the specified selector * on the specified object, and will run at ObserverPriorityThird priority, * which is the default. */ public EOObserverProxy ( Object anObject, NSSelector aSelector ) { this( anObject, aSelector, ObserverPriorityThird ); } /** * Returns the priority of this observer in the queue. * This implementation returns the priority specified * in the constructor. */ public int priority () { return priority; } /** * Notifies observer that one or more objects that * it is observing have changed. The observer should * check all objects it is observing for changes. */ public void subjectChanged () { try { selector.invoke( target ); } catch ( Exception exc ) { System.out.println( "Error notifying observer: " ); exc.printStackTrace(); } } } /* * $Log$ * Revision 1.1 2006/02/16 13:19:57 cgruber * Check in all sources in eclipse-friendly maven-enabled packages. * * Revision 1.1 2001/10/22 21:55:32 mpowers * This turns out to be a really useful class. * * */