1
1
/*
2
- * Copyright (c) 2003, 2018 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2003, 2021 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
26
26
@key headful
27
27
@bug 4799136
28
28
@summary Tests that type-ahead for dialog works and doesn't block program
29
- @library ../../regtesthelpers
30
- @modules java.desktop/sun.awt
31
- @build Util
32
29
@run main TestDialogTypeAhead
33
30
*/
34
31
35
- import java .awt .*;
36
- import java .awt .event .*;
32
+
33
+ import java .awt .AWTEvent ;
34
+ import java .awt .Button ;
35
+ import java .awt .Component ;
36
+ import java .awt .DefaultKeyboardFocusManager ;
37
+ import java .awt .Dialog ;
38
+ import java .awt .Dimension ;
39
+ import java .awt .EventQueue ;
40
+ import java .awt .Frame ;
41
+ import java .awt .KeyboardFocusManager ;
42
+ import java .awt .Point ;
43
+ import java .awt .Robot ;
44
+ import java .awt .Toolkit ;
45
+ import java .awt .event .AWTEventListener ;
46
+ import java .awt .event .ActionEvent ;
47
+ import java .awt .event .ActionListener ;
48
+ import java .awt .event .FocusAdapter ;
49
+ import java .awt .event .FocusEvent ;
50
+ import java .awt .event .KeyAdapter ;
51
+ import java .awt .event .KeyEvent ;
37
52
import java .lang .reflect .InvocationTargetException ;
38
53
39
54
public class TestDialogTypeAhead {
@@ -49,8 +64,17 @@ public class TestDialogTypeAhead {
49
64
50
65
public static void main (final String [] args ) {
51
66
TestDialogTypeAhead app = new TestDialogTypeAhead ();
52
- app .init ();
53
- app .start ();
67
+ try {
68
+ app .init ();
69
+ app .start ();
70
+ } finally {
71
+ if (d != null ) {
72
+ d .dispose ();
73
+ }
74
+ if (f != null ) {
75
+ f .dispose ();
76
+ }
77
+ }
54
78
}
55
79
56
80
public void init ()
@@ -73,13 +97,12 @@ public void eventDispatched(AWTEvent e) {
73
97
ok .addKeyListener (new KeyAdapter () {
74
98
public void keyPressed (KeyEvent e ) {
75
99
System .err .println ("OK pressed" );
76
- d .dispose ();
77
- f .dispose ();
78
100
// Typed-ahead key events should only be accepted if
79
101
// they arrive after FOCUS_GAINED
80
102
if (gotFocus ) {
81
103
pressSema .raise ();
82
104
}
105
+
83
106
}
84
107
});
85
108
ok .addFocusListener (new FocusAdapter () {
@@ -112,6 +135,7 @@ public void start ()
112
135
{
113
136
try {
114
137
robot = new Robot ();
138
+ robot .setAutoDelay (100 );
115
139
} catch (Exception e ) {
116
140
throw new RuntimeException ("Can't create robot:" + e );
117
141
}
@@ -128,6 +152,7 @@ public void start ()
128
152
129
153
robot .keyPress (KeyEvent .VK_SPACE );
130
154
robot .keyRelease (KeyEvent .VK_SPACE );
155
+
131
156
try {
132
157
robotSema .doWait (1000 );
133
158
} catch (InterruptedException ie ) {
@@ -149,13 +174,13 @@ public void start ()
149
174
if (!pressSema .getState ()) {
150
175
throw new RuntimeException ("Type-ahead doesn't work" );
151
176
}
152
-
153
177
}// start()
154
178
155
- private void moveMouseOver (Container c ) {
179
+ private void moveMouseOver (Component c ) {
156
180
Point p = c .getLocationOnScreen ();
157
181
Dimension d = c .getSize ();
158
- robot .mouseMove (p .x + (int )(d .getWidth ()/2 ), p .y + (int )(d .getHeight ()/2 ));
182
+ robot .mouseMove (p .x + (int )(d .getWidth ()/2 ),
183
+ p .y + (int )(d .getHeight ()/2 ));
159
184
}
160
185
private void waitForIdle () {
161
186
try {
@@ -209,7 +234,10 @@ public void focusGained(FocusEvent fe) {
209
234
}
210
235
comp .removeFocusListener (fa );
211
236
if (!comp .isFocusOwner ()) {
212
- throw new RuntimeException ("Can't make " + comp + " focused, current owner is " + KeyboardFocusManager .getCurrentKeyboardFocusManager ().getFocusOwner ());
237
+ throw new RuntimeException ("Can't make " + comp + " focused,"
238
+ + "current owner is "
239
+ + KeyboardFocusManager
240
+ .getCurrentKeyboardFocusManager ().getFocusOwner ());
213
241
}
214
242
}
215
243
@@ -257,4 +285,3 @@ protected synchronized void enqueueKeyEvents(long after,
257
285
}
258
286
}
259
287
}// class TestDialogTypeAhead
260
-
0 commit comments