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 import java.awt.event.WindowAdapter;
26 import java.awt.event.WindowEvent;
27 import java.awt.event.WindowFocusListener;
28 import java.awt.geom.Area;
29 import java.awt.geom.GeneralPath;
30 import java.awt.geom.Rectangle2D;
31 import java.util.HashMap;
32
33 /*
34 * @test
35 * @bug 8013450
36 * @summary Check if the window events (Focus and Activation) are triggered correctly
37 * when clicked on visible and clipped areas.
38 * @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
39 * @library ../../../../lib/testlibrary
40 * @build Common ExtendedRobot
41 * @run main FocusAWTTest
42 */
43
44 public class FocusAWTTest extends Common {
45
46 ExtendedRobot robot;
47 int dx;
48 int dy;
49 static final int x = 20;
50 static final int y = 400;
51
52 static volatile HashMap<String, Boolean> flags = new HashMap<String, Boolean>();
53 static {
54 flags.put("backgroundWindowActivated", false);
55 flags.put("backgroundWindowDeactivated", false);
56 flags.put("backgroundWindowGotFocus", false);
57 flags.put("backgroundWindowLostFocus", false);
132 window.setPreferredSize(new Dimension(200, 200));
133 window.setLocation(70 + dx, 450 + dy);
134 window.setLayout(new BorderLayout());
135
136 window.addWindowFocusListener(new WindowFocusListener() {
137 public void windowGainedFocus(WindowEvent e) { flags.put("foregroundWindowGotFocus", true); }
138 public void windowLostFocus(WindowEvent e) { flags.put("foregroundWindowLostFocus", true); }
139 });
140
141 window.addWindowListener(new WindowAdapter() {
142 public void windowActivated(WindowEvent e) { flags.put("foregroundWindowActivated", true); }
143 public void windowDeactivated(WindowEvent e) { flags.put("foregroundWindowDeactivated", true); }
144 });
145
146 applyShape();
147 window.pack();
148 window.setAlwaysOnTop(true);
149 window.setVisible(true);
150 }
151
152 public void doTest() throws Exception {
153 super.doTest();
154 final Point wls = new Point();
155 final Dimension size = new Dimension();
156 EventQueue.invokeAndWait(() -> {
157 window.requestFocus();
158 wls.setLocation(window.getLocationOnScreen());
159 window.getSize(size);
160 });
161
162 robot.waitForIdle();
163
164 check(wls.x + size.width - 5, wls.y + 5, wls.x + size.width / 3, wls.y + size.height / 3);
165 check(wls.x + size.width / 2, wls.y + size.height / 2, wls.x + size.width * 2 / 3, wls.y + size.height * 2 / 3);
166
167 EventQueue.invokeAndWait(() -> {
168 background.dispose();
169 window.dispose();
170 });
171
|
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 import java.awt.event.WindowAdapter;
26 import java.awt.event.WindowEvent;
27 import java.awt.event.WindowFocusListener;
28 import java.awt.geom.Area;
29 import java.awt.geom.GeneralPath;
30 import java.awt.geom.Rectangle2D;
31 import java.util.HashMap;
32
33 /*
34 * @test
35 * @bug 8013450
36 * @summary Check if the window events (Focus and Activation) are triggered correctly
37 * when clicked on visible and clipped areas.
38 *
39 * Test Description: Check if PERPIXEL_TRANSPARENT Translucency type is supported
40 * by the current platform. Proceed if it is supported. Apply different
41 * types of shapes on a Window. Make it appear with a known background.
42 * Check if mouse events which result in window-activated events are
43 * triggered only within the window's shape and not outside. Repeat this
44 * for Window, Dialog and Frame.
45 * Expected Result: If PERPIXEL_TRANSPARENT Translucency type is supported, window should
46 * gain focus and should trigger activated events only when it is clicked on the
47 * visible areas. Events should be delivered to the background window if clicked
48 * on the clipped areas.
49 *
50 * @author mrkam
51 * @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
52 * @library ../../../../lib/testlibrary
53 * @build Common ExtendedRobot
54 * @run main FocusAWTTest
55 */
56
57 public class FocusAWTTest extends Common {
58
59 ExtendedRobot robot;
60 int dx;
61 int dy;
62 static final int x = 20;
63 static final int y = 400;
64
65 static volatile HashMap<String, Boolean> flags = new HashMap<String, Boolean>();
66 static {
67 flags.put("backgroundWindowActivated", false);
68 flags.put("backgroundWindowDeactivated", false);
69 flags.put("backgroundWindowGotFocus", false);
70 flags.put("backgroundWindowLostFocus", false);
145 window.setPreferredSize(new Dimension(200, 200));
146 window.setLocation(70 + dx, 450 + dy);
147 window.setLayout(new BorderLayout());
148
149 window.addWindowFocusListener(new WindowFocusListener() {
150 public void windowGainedFocus(WindowEvent e) { flags.put("foregroundWindowGotFocus", true); }
151 public void windowLostFocus(WindowEvent e) { flags.put("foregroundWindowLostFocus", true); }
152 });
153
154 window.addWindowListener(new WindowAdapter() {
155 public void windowActivated(WindowEvent e) { flags.put("foregroundWindowActivated", true); }
156 public void windowDeactivated(WindowEvent e) { flags.put("foregroundWindowDeactivated", true); }
157 });
158
159 applyShape();
160 window.pack();
161 window.setAlwaysOnTop(true);
162 window.setVisible(true);
163 }
164
165 @Override
166 public void doTest() throws Exception {
167 super.doTest();
168 final Point wls = new Point();
169 final Dimension size = new Dimension();
170 EventQueue.invokeAndWait(() -> {
171 window.requestFocus();
172 wls.setLocation(window.getLocationOnScreen());
173 window.getSize(size);
174 });
175
176 robot.waitForIdle();
177
178 check(wls.x + size.width - 5, wls.y + 5, wls.x + size.width / 3, wls.y + size.height / 3);
179 check(wls.x + size.width / 2, wls.y + size.height / 2, wls.x + size.width * 2 / 3, wls.y + size.height * 2 / 3);
180
181 EventQueue.invokeAndWait(() -> {
182 background.dispose();
183 window.dispose();
184 });
185
|