1 /* 2 * Copyright (c) 2012, 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 /* 25 * Portions Copyright (c) 2012 IBM Corporation 26 */ 27 28 /* 29 * @test 30 * @key headful 31 * @bug 7194184 32 * @summary Tests JColorChooser Swatch keyboard accessibility. 33 * @author Sean Chou 34 * @library ../regtesthelpers 35 * @build Util 36 * @run main Test7194184 37 */ 38 39 import java.awt.Component; 40 import java.awt.AWTException; 41 import java.awt.Color; 42 import java.awt.Robot; 43 import java.awt.event.KeyEvent; 44 45 import javax.swing.JColorChooser; 46 import javax.swing.JFrame; 47 import javax.swing.SwingUtilities; 48 49 import java.util.concurrent.Callable; 50 51 public class Test7194184 implements Runnable { 52 private static JFrame frame; 53 private static JColorChooser colorChooser; 54 private static Color selectedColor; 55 56 public static void main(String[] args) throws Exception { 57 testKeyBoardAccess(); 58 } 59 60 private static void testKeyBoardAccess() throws Exception { 61 Robot robot = new Robot(); 62 63 SwingUtilities.invokeLater(new Test7194184()); 64 robot.waitForIdle(); 65 66 SwingUtilities.invokeLater(new Runnable() { 67 @Override 68 public void run() { 69 selectedColor = colorChooser.getColor(); 70 71 Component recentSwatchPanel = Util.findSubComponent(colorChooser, "RecentSwatchPanel"); 72 if (recentSwatchPanel == null) { 73 throw new RuntimeException("RecentSwatchPanel not found"); 74 } 75 recentSwatchPanel.requestFocusInWindow(); 76 } 77 }); 78 79 robot.waitForIdle(); 80 81 // Tab to move the focus to MainSwatch 82 Util.hitKeys(robot, KeyEvent.VK_SHIFT, KeyEvent.VK_TAB); 83 84 // Select the color on right 85 Util.hitKeys(robot, KeyEvent.VK_RIGHT); 86 Util.hitKeys(robot, KeyEvent.VK_RIGHT); 87 Util.hitKeys(robot, KeyEvent.VK_SPACE); 88 robot.waitForIdle(); 89 90 SwingUtilities.invokeAndWait(new Runnable() { 91 @Override 92 public void run() { 93 frame.dispose(); 94 if (selectedColor == colorChooser.getColor()) { 95 throw new RuntimeException("JColorChooser misses keyboard accessibility"); 96 } 97 } 98 }); 99 } 100 101 public void run() { 102 String title = getClass().getName(); 103 frame = new JFrame(title); 104 colorChooser = new JColorChooser(); 105 106 frame.add(colorChooser); 107 frame.pack(); 108 frame.setVisible(true); 109 } 110 111 }