01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Pavel Dolgov
19: * @version $Revision$
20: */package java.awt;
21:
22: import java.awt.event.ActionEvent;
23:
24: /**
25: * Thread for dispatching events in non-system EventQueue
26: */
27: final class EventQueueThread extends Thread {
28:
29: private static final class StopThreadEvent extends ActionEvent {
30: StopThreadEvent(Thread thread) {
31: super (thread, ACTION_PERFORMED, "stopThread"); //$NON-NLS-1$
32: }
33: }
34:
35: private final EventQueueCore core;
36:
37: EventQueueThread(EventQueueCore core) {
38: super ("AWT-EventQueueThread"); //$NON-NLS-1$
39: this .core = core;
40: setDaemon(false);
41: }
42:
43: @Override
44: public void run() {
45: while (!core.isEmpty(1000)) {
46: try {
47: AWTEvent e = core.getActiveEventQueue().getNextEvent();
48: if ((e instanceof StopThreadEvent)
49: && e.getSource() == this ) {
50: return;
51: }
52: core.dispatchEvent(e);
53: } catch (InterruptedException e) {
54: // do nothing
55: } catch (Exception e) {
56: e.printStackTrace();
57: }
58: }
59: }
60:
61: void postStopEvent() {
62: core.postEvent(new StopThreadEvent(this));
63: }
64: }
|