| Classes in this File | Line Coverage | Branch Coverage | Complexity | |||||||
| EODelayedObserver |
|
| 1.0;1 |
| 1 | /* |
|
| 2 | Wotonomy: OpenStep design patterns for pure Java applications. |
|
| 3 | Copyright (C) 2000 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 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 | 0 | public EODelayedObserver () |
| 60 | 0 | { |
| 61 | 0 | } |
| 62 | ||
| 63 | /** |
|
| 64 | * Removes this observer from the observer queue |
|
| 65 | * for a currently pending notification. |
|
| 66 | */ |
|
| 67 | public void discardPendingNotification () |
|
| 68 | { |
|
| 69 | 0 | observerQueue().dequeueObserver( this ); |
| 70 | 0 | } |
| 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 | 0 | 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 | 0 | 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 | // interface EOObserving |
|
| 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 | 0 | observerQueue().enqueueObserver( this ); |
| 110 | 0 | } |
| 111 | ||
| 112 | // interface Observer |
|
| 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 | 0 | objectWillChange( anObject ); |
| 126 | 0 | } |
| 127 | ||
| 128 | } |
|
| 129 | ||
| 130 | /* |
|
| 131 | * $Log$ |
|
| 132 | * Revision 1.2 2006/02/16 16:47:14 cgruber |
|
| 133 | * Move some classes in to "internal" packages and re-work imports, etc. |
|
| 134 | * |
|
| 135 | * Also use UnsupportedOperationExceptions where appropriate, instead of WotonomyExceptions. |
|
| 136 | * |
|
| 137 | * Revision 1.1 2006/02/16 13:19:57 cgruber |
|
| 138 | * Check in all sources in eclipse-friendly maven-enabled packages. |
|
| 139 | * |
|
| 140 | * Revision 1.2 2001/10/26 18:38:10 mpowers |
|
| 141 | * Reordered priorities. |
|
| 142 | * |
|
| 143 | * Revision 1.1.1.1 2000/12/21 15:46:38 mpowers |
|
| 144 | * Contributing wotonomy. |
|
| 145 | * |
|
| 146 | * Revision 1.3 2000/12/20 16:25:35 michael |
|
| 147 | * Added log to all files. |
|
| 148 | * |
|
| 149 | * |
|
| 150 | */ |
|
| 151 | ||
| 152 |