4365
|
1 |
/*
|
|
2 |
* Copyright 2009 Sun Microsystems, Inc. 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.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
@test
|
|
26 |
@bug 4913324
|
|
27 |
@author Oleg Sukhodolsky: area=eventqueue
|
|
28 |
@run main/timeout=30 PushPopTest
|
|
29 |
*/
|
|
30 |
|
|
31 |
import java.awt.*;
|
|
32 |
import java.awt.event.*;
|
|
33 |
import java.util.EmptyStackException;
|
|
34 |
import sun.awt.SunToolkit;
|
|
35 |
|
|
36 |
public class PushPopTest {
|
|
37 |
|
|
38 |
public static Frame frame;
|
|
39 |
public static void main(String[] args) {
|
|
40 |
frame = new Frame("");
|
|
41 |
frame.pack();
|
|
42 |
|
|
43 |
Runnable dummy = new Runnable() {
|
|
44 |
public void run() {
|
|
45 |
System.err.println("Dummy is here.");
|
|
46 |
}
|
|
47 |
};
|
|
48 |
EventQueue seq = Toolkit.getDefaultToolkit().getSystemEventQueue();
|
|
49 |
MyEventQueue1 eq1 = new MyEventQueue1();
|
|
50 |
MyEventQueue2 eq2 = new MyEventQueue2();
|
|
51 |
EventQueue.invokeLater(dummy);
|
|
52 |
|
|
53 |
seq.push(eq1);
|
|
54 |
EventQueue.invokeLater(dummy);
|
|
55 |
|
|
56 |
eq1.push(eq2);
|
|
57 |
EventQueue.invokeLater(dummy);
|
|
58 |
Runnable runnable = new Runnable() {
|
|
59 |
public void run() {
|
|
60 |
System.err.println("Dummy from SunToolkit");
|
|
61 |
}
|
|
62 |
};
|
|
63 |
InvocationEvent ie = new InvocationEvent(eq2, runnable, null, false);
|
|
64 |
System.err.println(ie);
|
|
65 |
SunToolkit.postEvent(SunToolkit.targetToAppContext(frame), ie);
|
|
66 |
eq1.pop();
|
|
67 |
frame.dispose();
|
|
68 |
}
|
|
69 |
}
|
|
70 |
|
|
71 |
class MyEventQueue1 extends EventQueue {
|
|
72 |
|
|
73 |
public void pop() throws EmptyStackException {
|
|
74 |
super.pop();
|
|
75 |
}
|
|
76 |
}
|
|
77 |
|
|
78 |
class MyEventQueue2 extends EventQueue {
|
|
79 |
|
|
80 |
protected void pop() throws EmptyStackException {
|
|
81 |
System.err.println("pop2()");
|
|
82 |
Thread.dumpStack();
|
|
83 |
try {
|
|
84 |
EventQueue.invokeAndWait(new Runnable() {
|
|
85 |
public void run() {
|
|
86 |
Runnable runnable = new Runnable() {
|
|
87 |
public void run() {
|
|
88 |
System.err.println("Dummy from here");
|
|
89 |
}
|
|
90 |
};
|
|
91 |
InvocationEvent ie = new InvocationEvent(MyEventQueue2.this, runnable, null, false);
|
|
92 |
SunToolkit.postEvent(SunToolkit.targetToAppContext(PushPopTest.frame), ie);
|
|
93 |
postEvent(ie);
|
|
94 |
}
|
|
95 |
});
|
|
96 |
} catch (InterruptedException ie) {
|
|
97 |
ie.printStackTrace();
|
|
98 |
} catch (java.lang.reflect.InvocationTargetException ie) {
|
|
99 |
ie.printStackTrace();
|
|
100 |
}
|
|
101 |
super.pop();
|
|
102 |
}
|
|
103 |
}
|