author | duke |
Wed, 05 Jul 2017 19:21:47 +0200 | |
changeset 21538 | a2533d997389 |
parent 13988 | 218c91f4bb7b |
child 28071 | 3acb75b8df45 |
permissions | -rw-r--r-- |
13988
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
1 |
/* |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
2 |
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
4 |
* |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
8 |
* |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
13 |
* accompanied this code). |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
14 |
* |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
18 |
* |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
21 |
* questions. |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
22 |
*/ |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
23 |
|
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
24 |
/* |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
25 |
* Portions Copyright (c) 2012 IBM Corporation |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
26 |
*/ |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
27 |
|
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
28 |
/* |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
29 |
* @test |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
30 |
* @bug 7194184 |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
31 |
* @summary Tests JColorChooser Swatch keyboard accessibility. |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
32 |
* @author Sean Chou |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
33 |
* @library ../regtesthelpers |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
34 |
* @build Util |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
35 |
* @run main Test7194184 |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
36 |
*/ |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
37 |
|
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
38 |
import java.awt.Component; |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
39 |
import java.awt.AWTException; |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
40 |
import java.awt.Color; |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
41 |
import java.awt.Robot; |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
42 |
import java.awt.Toolkit; |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
43 |
import java.awt.event.KeyEvent; |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
44 |
|
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
45 |
import javax.swing.JColorChooser; |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
46 |
import javax.swing.JFrame; |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
47 |
import javax.swing.SwingUtilities; |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
48 |
|
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
49 |
import java.util.concurrent.Callable; |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
50 |
import sun.awt.SunToolkit; |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
51 |
|
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
52 |
public class Test7194184 implements Runnable { |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
53 |
private static JFrame frame; |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
54 |
private static JColorChooser colorChooser; |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
55 |
private static Color selectedColor; |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
56 |
|
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
57 |
public static void main(String[] args) throws Exception { |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
58 |
testKeyBoardAccess(); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
59 |
} |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
60 |
|
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
61 |
private static void testKeyBoardAccess() throws Exception { |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
62 |
Robot robot = new Robot(); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
63 |
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
64 |
|
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
65 |
SwingUtilities.invokeLater(new Test7194184()); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
66 |
toolkit.realSync(); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
67 |
|
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
68 |
SwingUtilities.invokeLater(new Runnable() { |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
69 |
@Override |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
70 |
public void run() { |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
71 |
selectedColor = colorChooser.getColor(); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
72 |
|
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
73 |
Component recentSwatchPanel = Util.findSubComponent(colorChooser, "RecentSwatchPanel"); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
74 |
if (recentSwatchPanel == null) { |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
75 |
throw new RuntimeException("RecentSwatchPanel not found"); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
76 |
} |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
77 |
recentSwatchPanel.requestFocusInWindow(); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
78 |
} |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
79 |
}); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
80 |
|
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
81 |
toolkit.realSync(); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
82 |
|
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
83 |
// Tab to move the focus to MainSwatch |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
84 |
Util.hitKeys(robot, KeyEvent.VK_SHIFT, KeyEvent.VK_TAB); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
85 |
|
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
86 |
// Select the color on right |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
87 |
Util.hitKeys(robot, KeyEvent.VK_RIGHT); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
88 |
Util.hitKeys(robot, KeyEvent.VK_RIGHT); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
89 |
Util.hitKeys(robot, KeyEvent.VK_SPACE); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
90 |
toolkit.realSync(); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
91 |
|
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
92 |
SwingUtilities.invokeAndWait(new Runnable() { |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
93 |
@Override |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
94 |
public void run() { |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
95 |
frame.dispose(); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
96 |
if (selectedColor == colorChooser.getColor()) { |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
97 |
throw new RuntimeException("JColorChooser misses keyboard accessibility"); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
98 |
} |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
99 |
} |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
100 |
}); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
101 |
} |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
102 |
|
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
103 |
public void run() { |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
104 |
String title = getClass().getName(); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
105 |
frame = new JFrame(title); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
106 |
colorChooser = new JColorChooser(); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
107 |
|
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
108 |
frame.add(colorChooser); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
109 |
frame.pack(); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
110 |
frame.setVisible(true); |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
111 |
} |
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
112 |
|
218c91f4bb7b
7194184: JColorChooser swatch cannot accessed from keyboard
zhouyx
parents:
diff
changeset
|
113 |
} |