|
1 /* |
|
2 * Copyright (c) 2007, 2014, 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. |
|
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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 import java.awt.*; |
|
25 |
|
26 // FDW: Frame -> Dialog -> Window |
|
27 public class FocusTransferFDWTest { |
|
28 |
|
29 class CustomFrame extends TestFrame { |
|
30 |
|
31 @Override |
|
32 public void doOpenAction() { |
|
33 if (dialog != null) { |
|
34 dialog.setVisible(true); |
|
35 } |
|
36 } |
|
37 } |
|
38 |
|
39 class CustomWindow extends TestWindow { |
|
40 |
|
41 public CustomWindow(Dialog d) { |
|
42 super(d); |
|
43 } |
|
44 |
|
45 @Override |
|
46 public void doCloseAction() { |
|
47 this.dispose(); |
|
48 } |
|
49 } |
|
50 |
|
51 class CustomDialog extends TestDialog { |
|
52 |
|
53 public CustomDialog(Frame f) { |
|
54 super(f); |
|
55 } |
|
56 |
|
57 @Override |
|
58 public void doOpenAction() { |
|
59 if (window != null) { |
|
60 window.setVisible(true); |
|
61 } |
|
62 } |
|
63 |
|
64 @Override |
|
65 public void doCloseAction() { |
|
66 this.dispose(); |
|
67 } |
|
68 } |
|
69 |
|
70 private TestDialog dialog; |
|
71 private TestFrame frame; |
|
72 private TestWindow window; |
|
73 |
|
74 private static final int delay = 1000; |
|
75 |
|
76 private final ExtendedRobot robot; |
|
77 |
|
78 private final Dialog.ModalityType modalityType; |
|
79 |
|
80 FocusTransferFDWTest(Dialog.ModalityType modType) throws Exception { |
|
81 |
|
82 modalityType = modType; |
|
83 |
|
84 robot = new ExtendedRobot(); |
|
85 EventQueue.invokeLater(this::createGUI); |
|
86 } |
|
87 |
|
88 private void createGUI() { |
|
89 |
|
90 frame = new CustomFrame(); |
|
91 frame.setLocation(50, 50); |
|
92 dialog = new CustomDialog((Frame) null); |
|
93 if (modalityType != null) { |
|
94 dialog.setModalityType(modalityType); |
|
95 } |
|
96 dialog.setLocation(250, 50); |
|
97 window = new CustomWindow(dialog); |
|
98 window.setLocation(450, 50); |
|
99 frame.setVisible(true); |
|
100 } |
|
101 |
|
102 private void closeAll() { |
|
103 if (dialog != null) { dialog.dispose(); } |
|
104 if ( frame != null) { frame.dispose(); } |
|
105 if (window != null) { window.dispose(); } |
|
106 } |
|
107 |
|
108 public void doTest() throws Exception { |
|
109 |
|
110 robot.waitForIdle(delay); |
|
111 |
|
112 try { |
|
113 |
|
114 frame.checkCloseButtonFocusGained(true); |
|
115 |
|
116 frame.clickOpenButton(robot); |
|
117 robot.waitForIdle(delay); |
|
118 |
|
119 dialog.checkCloseButtonFocusGained(true); |
|
120 |
|
121 frame.checkOpenButtonFocusLost(true); |
|
122 |
|
123 dialog.clickOpenButton(robot); |
|
124 robot.waitForIdle(delay); |
|
125 |
|
126 window.checkCloseButtonFocusGained(true); |
|
127 dialog.checkOpenButtonFocusLost(true); |
|
128 |
|
129 dialog.openGained.reset(); |
|
130 window.clickCloseButton(robot); |
|
131 |
|
132 dialog.checkOpenButtonFocusGained(true); |
|
133 |
|
134 frame.openGained.reset(); |
|
135 dialog.clickCloseButton(robot); |
|
136 |
|
137 frame.checkOpenButtonFocusGained(true); |
|
138 |
|
139 } catch (Exception e) { |
|
140 |
|
141 // make screenshot before exit |
|
142 Rectangle rect = new Rectangle(0, 0, 650, 250); |
|
143 java.awt.image.BufferedImage img = robot.createScreenCapture(rect); |
|
144 javax.imageio.ImageIO.write(img, "jpg", new java.io.File("NOK.jpg")); |
|
145 |
|
146 throw e; |
|
147 } |
|
148 |
|
149 robot.waitForIdle(delay); |
|
150 EventQueue.invokeAndWait(this::closeAll); |
|
151 } |
|
152 } |