author | goetz |
Tue, 14 Jun 2016 10:44:59 +0200 | |
changeset 39056 | d99e63b6d962 |
parent 35657 | 5ee7a31d7923 |
permissions | -rw-r--r-- |
35657
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
1 |
/* |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
4 |
* |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
8 |
* |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
13 |
* accompanied this code). |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
14 |
* |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
18 |
* |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
21 |
* questions. |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
22 |
*/ |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
23 |
|
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
24 |
import java.awt.Component; |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
25 |
import java.awt.EventQueue; |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
26 |
import java.awt.MouseInfo; |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
27 |
import java.awt.Rectangle; |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
28 |
import java.awt.Robot; |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
29 |
import java.awt.event.InputEvent; |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
30 |
import java.awt.event.KeyAdapter; |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
31 |
import java.awt.event.KeyEvent; |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
32 |
|
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
33 |
import javax.swing.JFrame; |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
34 |
import javax.swing.JTextField; |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
35 |
|
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
36 |
/** |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
37 |
* @test |
39056
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
35657
diff
changeset
|
38 |
* @key headful |
35657
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
39 |
* @bug 8143054 |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
40 |
*/ |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
41 |
public final class MouseModifiersInKeyEvent { |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
42 |
|
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
43 |
private static int modifiersEX = 0; |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
44 |
private static int modifiers = 0; |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
45 |
private static JFrame f; |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
46 |
private static Rectangle bounds; |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
47 |
|
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
48 |
public static void main(final String[] args) throws Exception { |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
49 |
for (int i = 1; i <= MouseInfo.getNumberOfButtons(); ++i) { |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
50 |
test(InputEvent.getMaskForButton(i)); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
51 |
} |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
52 |
} |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
53 |
|
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
54 |
private static void test(final int mask) throws Exception { |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
55 |
final Robot r = new Robot(); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
56 |
r.setAutoDelay(100); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
57 |
r.setAutoWaitForIdle(true); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
58 |
|
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
59 |
EventQueue.invokeAndWait(MouseModifiersInKeyEvent::createAndShowGUI); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
60 |
r.waitForIdle(); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
61 |
EventQueue.invokeAndWait(() -> bounds = f.getBounds()); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
62 |
|
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
63 |
r.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
64 |
r.mousePress(mask); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
65 |
r.keyPress(KeyEvent.VK_A); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
66 |
r.keyRelease(KeyEvent.VK_A); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
67 |
|
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
68 |
EventQueue.invokeAndWait(() -> f.dispose()); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
69 |
|
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
70 |
r.mouseRelease(mask); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
71 |
|
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
72 |
// all extended modifiers should work |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
73 |
if (modifiersEX != mask) { |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
74 |
System.err.println("Expected modifiersEX: " + mask); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
75 |
System.err.println("Actual modifiersEX: " + modifiersEX); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
76 |
throw new RuntimeException(); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
77 |
} |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
78 |
// old modifiers work only for button1 |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
79 |
if (modifiersEX == InputEvent.BUTTON1_DOWN_MASK) { |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
80 |
if (modifiers != InputEvent.BUTTON1_MASK) { |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
81 |
System.err.println("Expected modifiers: " + InputEvent.BUTTON1_MASK); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
82 |
System.err.println("Actual modifiers: " + modifiers); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
83 |
throw new RuntimeException(); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
84 |
} |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
85 |
} |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
86 |
modifiersEX = 0; |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
87 |
modifiers = 0; |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
88 |
} |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
89 |
|
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
90 |
private static void createAndShowGUI() { |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
91 |
f = new JFrame(); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
92 |
|
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
93 |
final Component component = new JTextField(); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
94 |
component.addKeyListener(new MyKeyListener()); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
95 |
|
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
96 |
f.add(component); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
97 |
f.setSize(300, 300); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
98 |
f.setLocationRelativeTo(null); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
99 |
f.setAlwaysOnTop(true); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
100 |
f.setVisible(true); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
101 |
} |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
102 |
|
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
103 |
static final class MyKeyListener extends KeyAdapter { |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
104 |
|
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
105 |
public void keyPressed(final KeyEvent e) { |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
106 |
modifiersEX = e.getModifiersEx(); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
107 |
modifiers = e.getModifiers(); |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
108 |
} |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
109 |
} |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
110 |
} |
5ee7a31d7923
8143054: [macosx] KeyEvent modifiers do not contain information about mouse buttons
serb
parents:
diff
changeset
|
111 |