1/*
2 * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.awt;
27
28import sun.awt.AppContext;
29import sun.awt.SunToolkit;
30
31/**
32 * A wrapping tag for a nested AWTEvent which indicates that the event was
33 * sent from another AppContext. The destination AppContext should handle the
34 * event even if it is currently blocked waiting for a SequencedEvent or
35 * another SentEvent to be handled.
36 *
37 * @author David Mendenhall
38 */
39class SentEvent extends AWTEvent implements ActiveEvent {
40    /*
41     * serialVersionUID
42     */
43    private static final long serialVersionUID = -383615247028828931L;
44
45    static final int ID =
46        java.awt.event.FocusEvent.FOCUS_LAST + 2;
47
48    boolean dispatched;
49    private AWTEvent nested;
50    private AppContext toNotify;
51
52    SentEvent() {
53        this(null);
54    }
55    SentEvent(AWTEvent nested) {
56        this(nested, null);
57    }
58    SentEvent(AWTEvent nested, AppContext toNotify) {
59        super((nested != null)
60                  ? nested.getSource()
61                  : Toolkit.getDefaultToolkit(),
62              ID);
63        this.nested = nested;
64        this.toNotify = toNotify;
65    }
66
67    public void dispatch() {
68        try {
69            if (nested != null) {
70                Toolkit.getEventQueue().dispatchEvent(nested);
71            }
72        } finally {
73            dispatched = true;
74            if (toNotify != null) {
75                SunToolkit.postEvent(toNotify, new SentEvent());
76            }
77            synchronized (this) {
78                notifyAll();
79            }
80        }
81    }
82    final void dispose() {
83        dispatched = true;
84        if (toNotify != null) {
85            SunToolkit.postEvent(toNotify, new SentEvent());
86        }
87        synchronized (this) {
88            notifyAll();
89        }
90    }
91}
92