author | hseigel |
Wed, 01 Mar 2017 08:00:02 -0500 | |
changeset 46194 | 5596e6f63072 |
parent 40128 | e635645d2a8a |
permissions | -rw-r--r-- |
37697
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
1 |
/* |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
4 |
* |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
8 |
* |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
13 |
* accompanied this code). |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
14 |
* |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
18 |
* |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
21 |
* questions. |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
22 |
*/ |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
23 |
|
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
24 |
|
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
25 |
import java.awt.AWTException; |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
26 |
import java.awt.BorderLayout; |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
27 |
import java.awt.Point; |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
28 |
import java.awt.Robot; |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
29 |
import java.awt.event.InputEvent; |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
30 |
import javax.swing.JButton; |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
31 |
import javax.swing.JFrame; |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
32 |
import javax.swing.SwingUtilities; |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
33 |
|
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
34 |
/* |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
35 |
* @test |
40128
e635645d2a8a
8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents:
37697
diff
changeset
|
36 |
* @key headful |
37697
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
37 |
* @bug 8049069 |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
38 |
* @summary Tests whether right mouse click releases a pressed JButton |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
39 |
*/ |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
40 |
|
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
41 |
public class PressedButtonRightClickTest { |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
42 |
|
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
43 |
private static Robot testRobot; |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
44 |
private static JFrame myFrame; |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
45 |
private static JButton myButton; |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
46 |
|
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
47 |
public static void main(String[] args) throws Throwable { |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
48 |
|
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
49 |
SwingUtilities.invokeAndWait(new Runnable() { |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
50 |
|
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
51 |
@Override |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
52 |
public void run() { |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
53 |
constructTestUI(); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
54 |
} |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
55 |
}); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
56 |
|
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
57 |
try { |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
58 |
testRobot = new Robot(); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
59 |
} catch (AWTException ex) { |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
60 |
throw new RuntimeException("Exception in Robot creation"); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
61 |
} |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
62 |
|
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
63 |
testRobot.waitForIdle(); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
64 |
|
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
65 |
// Method performing auto test operation |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
66 |
test(); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
67 |
|
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
68 |
disposeTestUI(); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
69 |
} |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
70 |
|
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
71 |
private static void test() { |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
72 |
Point loc = myFrame.getLocationOnScreen(); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
73 |
|
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
74 |
testRobot.mouseMove((loc.x + 100), (loc.y + 100)); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
75 |
|
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
76 |
// Press the left mouse button |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
77 |
testRobot.mousePress(InputEvent.BUTTON1_DOWN_MASK); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
78 |
myButton.setText("Left button pressed"); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
79 |
testRobot.delay(1000); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
80 |
|
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
81 |
// Press the right mouse button |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
82 |
testRobot.mousePress(InputEvent.BUTTON3_DOWN_MASK); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
83 |
myButton.setText("Left button pressed + Right button pressed"); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
84 |
testRobot.delay(1000); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
85 |
|
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
86 |
// Release the right mouse button |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
87 |
testRobot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
88 |
myButton.setText("Right button released"); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
89 |
testRobot.delay(1000); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
90 |
|
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
91 |
// Test whether the button is still pressed |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
92 |
if (myButton.getModel().isPressed() == false) { |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
93 |
disposeTestUI(); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
94 |
throw new RuntimeException("Test Failed!"); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
95 |
} |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
96 |
} |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
97 |
|
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
98 |
private static void disposeTestUI() { |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
99 |
myFrame.setVisible(false); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
100 |
myFrame.dispose(); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
101 |
} |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
102 |
|
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
103 |
public static void constructTestUI() { |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
104 |
myFrame = new JFrame(); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
105 |
myFrame.setLayout(new BorderLayout()); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
106 |
myButton = new JButton("Whatever"); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
107 |
myFrame.add(myButton, BorderLayout.CENTER); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
108 |
myFrame.setSize(400, 300); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
109 |
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
110 |
myFrame.setVisible(true); |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
111 |
} |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
112 |
} |
9bdfdb90249b
8049069: JButton incorrect behaviour on button release
aghaisas
parents:
diff
changeset
|
113 |