KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > SentEvent


1 /*
2  * @(#)SentEvent.java 1.6 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.awt;
9
10 import java.awt.AWTEvent JavaDoc;
11 import java.awt.ActiveEvent JavaDoc;
12 import sun.awt.AppContext;
13 import sun.awt.SunToolkit;
14
15 /**
16  * A wrapping tag for a nested AWTEvent which indicates that the event was
17  * sent from another AppContext. The destination AppContext should handle the
18  * event even if it is currently blocked waiting for a SequencedEvent or
19  * another SentEvent to be handled.
20  *
21  * @version 1.6, 12/19/03
22  * @author David Mendenhall
23  */

24 class SentEvent extends AWTEvent JavaDoc implements ActiveEvent JavaDoc {
25     static final int ID =
26     java.awt.event.FocusEvent.FOCUS_LAST + 2;
27
28     boolean dispatched;
29     private AWTEvent JavaDoc nested;
30     private AppContext toNotify;
31
32     SentEvent() {
33     this(null);
34     }
35     SentEvent(AWTEvent JavaDoc nested) {
36     this(nested, null);
37     }
38     SentEvent(AWTEvent JavaDoc nested, AppContext toNotify) {
39     super((nested != null)
40               ? nested.getSource()
41               : Toolkit.getDefaultToolkit(),
42           ID);
43     this.nested = nested;
44     this.toNotify = toNotify;
45     }
46
47     public void dispatch() {
48         try {
49             if (nested != null) {
50                 Toolkit.getEventQueue().dispatchEvent(nested);
51             }
52         } finally {
53             dispatched = true;
54             if (toNotify != null) {
55                 SunToolkit.postEvent(toNotify, new SentEvent JavaDoc());
56             }
57             synchronized (this) {
58                 notifyAll();
59             }
60         }
61     }
62     final void dispose() {
63         dispatched = true;
64         if (toNotify != null) {
65             SunToolkit.postEvent(toNotify, new SentEvent JavaDoc());
66         }
67         synchronized (this) {
68             notifyAll();
69         }
70     }
71 }
72
Popular Tags