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.Toolkit; 44 import java.awt.event.KeyEvent; 45 46 import javax.swing.JColorChooser; 47 import javax.swing.JFrame; 48 import javax.swing.SwingUtilities; 49 50 import java.util.concurrent.Callable; 51 import sun.awt.SunToolkit; 52 53 public class Test7194184 implements Runnable { 54 private static JFrame frame; 55 private static JColorChooser colorChooser; 56 private static Color selectedColor; 57 58 public static void main(String[] args) throws Exception { 59 testKeyBoardAccess(); 60 } 61 62 private static void testKeyBoardAccess() throws Exception { 63 Robot robot = new Robot(); 64 SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); 65 66 SwingUtilities.invokeLater(new Test7194184()); 67 toolkit.realSync(); 68 69 SwingUtilities.invokeLater(new Runnable() { 70 @Override 71 public void run() { 72 selectedColor = colorChooser.getColor(); 73 74 Component recentSwatchPanel = Util.findSubComponent(colorChooser, "RecentSwatchPanel"); 75 if (recentSwatchPanel == null) { 76 throw new RuntimeException("RecentSwatchPanel not found"); 77 } 78 recentSwatchPanel.requestFocusInWindow(); 79 } 80 }); 81 82 toolkit.realSync(); 83 84 // Tab to move the focus to MainSwatch 85 Util.hitKeys(robot, KeyEvent.VK_SHIFT, KeyEvent.VK_TAB); 86 87 // Select the color on right 88 Util.hitKeys(robot, KeyEvent.VK_RIGHT); 89 Util.hitKeys(robot, KeyEvent.VK_RIGHT); 90 Util.hitKeys(robot, KeyEvent.VK_SPACE); 91 toolkit.realSync(); 92 93 SwingUtilities.invokeAndWait(new Runnable() { 94 @Override 95 public void run() { 96 frame.dispose(); 97 if (selectedColor == colorChooser.getColor()) { 98 throw new RuntimeException("JColorChooser misses keyboard accessibility"); 99 } 100 } 101 }); 102 } 103 104 public void run() { 105 String title = getClass().getName(); 106 frame = new JFrame(title); 107 colorChooser = new JColorChooser(); 108 109 frame.add(colorChooser); 110 frame.pack(); 111 frame.setVisible(true); 112 } 113 114 }