src/share/classes/java/awt/EventDispatchThread.java

Print this page




 121 
 122     void pumpEventsForHierarchy(int id, Conditional cond, Component modalComponent) {
 123         pumpEventsForFilter(id, cond, new HierarchyEventFilter(modalComponent));
 124     }
 125 
 126     void pumpEventsForFilter(Conditional cond, EventFilter filter) {
 127         pumpEventsForFilter(ANY_EVENT, cond, filter);
 128     }
 129 
 130     void pumpEventsForFilter(int id, Conditional cond, EventFilter filter) {
 131         addEventFilter(filter);
 132         doDispatch = true;
 133         shutdown |= isInterrupted();
 134         while (doDispatch && !shutdown && cond.evaluate()) {
 135             pumpOneEventForFilters(id);
 136         }
 137         removeEventFilter(filter);
 138     }
 139 
 140     void addEventFilter(EventFilter filter) {

 141         eventLog.finest("adding the event filter: " + filter);

 142         synchronized (eventFilters) {
 143             if (!eventFilters.contains(filter)) {
 144                 if (filter instanceof ModalEventFilter) {
 145                     ModalEventFilter newFilter = (ModalEventFilter)filter;
 146                     int k = 0;
 147                     for (k = 0; k < eventFilters.size(); k++) {
 148                         EventFilter f = eventFilters.get(k);
 149                         if (f instanceof ModalEventFilter) {
 150                             ModalEventFilter cf = (ModalEventFilter)f;
 151                             if (cf.compareTo(newFilter) > 0) {
 152                                 break;
 153                             }
 154                         }
 155                     }
 156                     eventFilters.add(k, filter);
 157                 } else {
 158                     eventFilters.add(filter);
 159                 }
 160             }
 161         }
 162     }
 163 
 164     void removeEventFilter(EventFilter filter) {

 165         eventLog.finest("removing the event filter: " + filter);

 166         synchronized (eventFilters) {
 167             eventFilters.remove(filter);
 168         }
 169     }
 170 
 171     void pumpOneEventForFilters(int id) {
 172         AWTEvent event = null;
 173         boolean eventOK = false;
 174         try {
 175             EventQueue eq = null;
 176             EventQueueDelegate.Delegate delegate = null;
 177             do {
 178                 // EventQueue may change during the dispatching
 179                 eq = getEventQueue();
 180                 delegate = EventQueueDelegate.getDelegate();
 181 
 182                 if (delegate != null && id == ANY_EVENT) {
 183                     event = delegate.getNextEvent(eq);
 184                 } else {
 185                     event = (id == ANY_EVENT) ? eq.getNextEvent() : eq.getNextEvent(id);




 121 
 122     void pumpEventsForHierarchy(int id, Conditional cond, Component modalComponent) {
 123         pumpEventsForFilter(id, cond, new HierarchyEventFilter(modalComponent));
 124     }
 125 
 126     void pumpEventsForFilter(Conditional cond, EventFilter filter) {
 127         pumpEventsForFilter(ANY_EVENT, cond, filter);
 128     }
 129 
 130     void pumpEventsForFilter(int id, Conditional cond, EventFilter filter) {
 131         addEventFilter(filter);
 132         doDispatch = true;
 133         shutdown |= isInterrupted();
 134         while (doDispatch && !shutdown && cond.evaluate()) {
 135             pumpOneEventForFilters(id);
 136         }
 137         removeEventFilter(filter);
 138     }
 139 
 140     void addEventFilter(EventFilter filter) {
 141         if (eventLog.isLoggable(PlatformLogger.FINEST)) {
 142             eventLog.finest("adding the event filter: " + filter);
 143         }
 144         synchronized (eventFilters) {
 145             if (!eventFilters.contains(filter)) {
 146                 if (filter instanceof ModalEventFilter) {
 147                     ModalEventFilter newFilter = (ModalEventFilter)filter;
 148                     int k = 0;
 149                     for (k = 0; k < eventFilters.size(); k++) {
 150                         EventFilter f = eventFilters.get(k);
 151                         if (f instanceof ModalEventFilter) {
 152                             ModalEventFilter cf = (ModalEventFilter)f;
 153                             if (cf.compareTo(newFilter) > 0) {
 154                                 break;
 155                             }
 156                         }
 157                     }
 158                     eventFilters.add(k, filter);
 159                 } else {
 160                     eventFilters.add(filter);
 161                 }
 162             }
 163         }
 164     }
 165 
 166     void removeEventFilter(EventFilter filter) {
 167         if (eventLog.isLoggable(PlatformLogger.FINEST)) {
 168             eventLog.finest("removing the event filter: " + filter);
 169         }
 170         synchronized (eventFilters) {
 171             eventFilters.remove(filter);
 172         }
 173     }
 174 
 175     void pumpOneEventForFilters(int id) {
 176         AWTEvent event = null;
 177         boolean eventOK = false;
 178         try {
 179             EventQueue eq = null;
 180             EventQueueDelegate.Delegate delegate = null;
 181             do {
 182                 // EventQueue may change during the dispatching
 183                 eq = getEventQueue();
 184                 delegate = EventQueueDelegate.getDelegate();
 185 
 186                 if (delegate != null && id == ANY_EVENT) {
 187                     event = delegate.getNextEvent(eq);
 188                 } else {
 189                     event = (id == ANY_EVENT) ? eq.getNextEvent() : eq.getNextEvent(id);