1 /*
2 * Copyright (c) 2007, 2015, 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 import java.awt.event.InputEvent;
26 import java.awt.event.KeyEvent;
27 import java.awt.event.MouseAdapter;
28 import java.awt.event.MouseEvent;
29 import java.awt.image.BufferedImage;
30
31
32 /*
33 * @test
34 * @summary Check if MouseEvent has the proper modifiers when
35 * TrayIcon is clicked pressing the modifier keys
36 * @author Dmitriy Ermashov (dmitriy.ermashov@oracle.com)
37 * @library /java/awt/patchlib
38 * @library ../../../../lib/testlibrary ../
39 * @build java.desktop/java.awt.Helper
40 * @build ExtendedRobot SystemTrayIconHelper
41 * @run main TrayIconEventModifiersTest
42 */
43
44 public class TrayIconEventModifiersTest {
45
46 Image image;
47
48 TrayIcon icon;
49 ExtendedRobot robot;
50
51 Object mouseLock = new Object();
52
53 String caption = "Sample Icon";
54 boolean mousePressed = false;
55 boolean mouseReleased = false;
56 boolean mouseClicked = false;
196 tray.add(icon);
197 } catch (Exception e) {
198 throw new RuntimeException(e);
199 }
200 }
201
202 void doTest() throws Exception {
203
204 Point iconPosition = SystemTrayIconHelper.getTrayIconLocation(icon);
205 if (iconPosition == null)
206 throw new RuntimeException("Unable to find the icon location!");
207
208 robot.mouseMove(iconPosition.x, iconPosition.y);
209 robot.waitForIdle();
210
211 for (int i = 0; i < buttonTypes.length; i++) {
212 for (int j = 0; j < keyTypes.length; j++) {
213 mousePressed = false;
214
215 robot.keyPress(keyTypes[j]);
216 robot.mousePress(buttonTypes[i]);
217
218 if (! mousePressed) {
219 synchronized (mouseLock) {
220 try {
221 mouseLock.wait(3000);
222 } catch (Exception e) {
223 }
224 }
225 }
226 if (! mousePressed) {
227 if (! SystemTrayIconHelper.skip(buttonTypes[i]))
228 throw new RuntimeException("FAIL: mousePressed not triggered when " +
229 keyNames[j] + " + " + buttonNames[i] + " pressed");
230 } else {
231 int onMask = buttonMasks[i] | keyMasks[j];
232 if ((modifiers & onMask) != onMask) {
233 throw new RuntimeException("FAIL: getModifiersEx did not return " +
234 "the correct value when " + keyNames[j] + " + " +
235 buttonNames[i] + " pressed");
|
1 /*
2 * Copyright (c) 2007, 2016, 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.EventQueue;
25 import java.awt.Image;
26 import java.awt.Point;
27 import java.awt.SystemTray;
28 import java.awt.TrayIcon;
29 import java.awt.event.InputEvent;
30 import java.awt.event.KeyEvent;
31 import java.awt.event.MouseAdapter;
32 import java.awt.event.MouseEvent;
33 import java.awt.image.BufferedImage;
34
35
36 /*
37 * @test
38 * @bug 8161473
39 * @key headful
40 * @summary Check if MouseEvent has the proper modifiers when
41 * TrayIcon is clicked pressing the modifier keys
42 * @library /java/awt/patchlib
43 * @library ../../../../lib/testlibrary ../
44 * @build java.desktop/java.awt.Helper
45 * @build ExtendedRobot SystemTrayIconHelper
46 * @run main TrayIconEventModifiersTest
47 */
48
49 public class TrayIconEventModifiersTest {
50
51 Image image;
52
53 TrayIcon icon;
54 ExtendedRobot robot;
55
56 Object mouseLock = new Object();
57
58 String caption = "Sample Icon";
59 boolean mousePressed = false;
60 boolean mouseReleased = false;
61 boolean mouseClicked = false;
201 tray.add(icon);
202 } catch (Exception e) {
203 throw new RuntimeException(e);
204 }
205 }
206
207 void doTest() throws Exception {
208
209 Point iconPosition = SystemTrayIconHelper.getTrayIconLocation(icon);
210 if (iconPosition == null)
211 throw new RuntimeException("Unable to find the icon location!");
212
213 robot.mouseMove(iconPosition.x, iconPosition.y);
214 robot.waitForIdle();
215
216 for (int i = 0; i < buttonTypes.length; i++) {
217 for (int j = 0; j < keyTypes.length; j++) {
218 mousePressed = false;
219
220 robot.keyPress(keyTypes[j]);
221 robot.waitForIdle();
222 robot.mousePress(buttonTypes[i]);
223
224 if (! mousePressed) {
225 synchronized (mouseLock) {
226 try {
227 mouseLock.wait(3000);
228 } catch (Exception e) {
229 }
230 }
231 }
232 if (! mousePressed) {
233 if (! SystemTrayIconHelper.skip(buttonTypes[i]))
234 throw new RuntimeException("FAIL: mousePressed not triggered when " +
235 keyNames[j] + " + " + buttonNames[i] + " pressed");
236 } else {
237 int onMask = buttonMasks[i] | keyMasks[j];
238 if ((modifiers & onMask) != onMask) {
239 throw new RuntimeException("FAIL: getModifiersEx did not return " +
240 "the correct value when " + keyNames[j] + " + " +
241 buttonNames[i] + " pressed");
|