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