/* * Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ import java.awt.*; import java.awt.event.KeyEvent; /* * @test * @summary Change the focus between components and check whether the * FocusEvents has been triggered properly and check whether the * information about the Opposite Component can be obtained. * @author Aruna Samji * @library ../../../lib/testlibrary * @build ExtendedRobot * @run main TaskOppositeComponent */ public class TaskOppositeComponent extends Task { public static void main (String[] args) throws Exception { new TaskOppositeComponent(GUIMerlinFocus.class, new ExtendedRobot()).runTask(); } TaskOppositeComponent(Class guiClass, ExtendedRobot robot) throws Exception { super(guiClass, robot); } public void task() throws Exception { EventQueue.invokeAndWait(() -> gui.frame4.setVisible(true) ); robot.waitForIdle(1000); // Transfer the focus from Button to List & check whether the // getOppositeComponent is returning the component which lost // the focus. Point button2Origin = gui.button2.getLocationOnScreen(); Point button2Center = gui.button2.getLocationOnScreen(); button2Center.translate(gui.button2.getWidth()/2, gui.button2.getHeight()/2); robot.glide(button2Origin, button2Center); robot.waitForIdle(1000); robot.click(); robot.type(KeyEvent.VK_TAB); if (gui.focusLostComp != gui.button2) throw new RuntimeException("didn't get the information about " + "opposite Component which lose the focus.\n"); // Transfer the focus from List to LwButton & check whether the // getOppositeComponent is returning the component which gain // the focus. robot.type(KeyEvent.VK_TAB); if (gui.focusGainedComp!=gui.list2) throw new RuntimeException("didn't get the information about " + "opposite Component which gain the focus"); } }