1 /* 2 * Copyright (c) 2004, 2014, 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 import java.awt.*; 25 26 /* 27 * @test 28 * @summary Try to traverse through all the Focusable Components 29 * programmatically and check whether the focus has been traversed 30 * or not 31 * @author Aruna Samji 32 * @library ../../../lib/testlibrary 33 * @build ExtendedRobot 34 * @run main TaskProgrammaticTraversal 35 */ 36 37 public class TaskProgrammaticTraversal extends Task<GUIMerlinFocus> { 38 39 public static void main (String[] args) throws Exception { 40 new TaskProgrammaticTraversal(GUIMerlinFocus.class, new ExtendedRobot()).runTask(); 41 } 42 43 TaskProgrammaticTraversal(Class guiClass, ExtendedRobot robot) throws Exception { 44 super(guiClass, robot); 45 } 46 47 public void task() throws Exception { 48 EventQueue.invokeAndWait(() -> 49 gui.testFrame2.setVisible(true) 50 ); 51 robot.waitForIdle(1000); 52 53 Point button9Center = gui.button9.getLocationOnScreen(); 54 button9Center.translate(gui.button9.getWidth()/2, gui.button9.getHeight()/2); 55 robot.glide(gui.button9.getLocationOnScreen(), button9Center); 56 robot.waitForIdle(1000); 57 robot.click(); 58 59 EventQueue.invokeAndWait(gui.manager2::focusNextComponent); 60 robot.waitForIdle(1000); 61 62 if (gui.focusGained2 != gui.choice8) 63 throw new RuntimeException("KeyboardFocusManager.focusNextComponent() " + 64 "is not changing the focus owner."); 65 66 EventQueue.invokeAndWait(gui.manager2::focusPreviousComponent); 67 robot.waitForIdle(1000); 68 69 if (gui.focusGained2 != gui.button9) 70 throw new RuntimeException("KeyboardFocusManager.focusPreviousComponent() " + 71 "is not changing the focus owner."); 72 73 EventQueue.invokeAndWait(() -> 74 gui.manager2.focusPreviousComponent(gui.checkbox8) 75 ); 76 robot.waitForIdle(1000); 77 78 if (gui.focusGained2 != gui.textfield8) 79 throw new RuntimeException("KeyboardFocusManager.focusPreviousComponent(component) " + 80 "is not changing the focus owner."); 81 82 EventQueue.invokeAndWait(() -> 83 gui.manager2.focusNextComponent(gui.textfield8) 84 ); 85 robot.waitForIdle(1000); 86 87 if (gui.focusGained2 != gui.checkbox8) 88 throw new RuntimeException("KeyboardFocusManager.focusNextComponent(component) " + 89 "is not changing the focus owner."); 90 91 EventQueue.invokeAndWait(gui.button8::transferFocus); 92 robot.waitForIdle(1000); 93 94 if (gui.focusGained2 != gui.list8) 95 throw new RuntimeException("Component.transferFocus() is not changing " + 96 "the focus owner."); 97 98 EventQueue.invokeAndWait(gui.list8::transferFocusBackward); 99 robot.waitForIdle(1000); 100 101 if (gui.focusGained2 != gui.button8) 102 throw new RuntimeException("Component.transferFocusBackward() is not " + 103 "changing the focus owner."); 104 } 105 }