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 import java.awt.event.KeyEvent;
  26 
  27 /*
  28  * @test
  29  * @summary Change the focus between components and check whether the
  30  *          FocusEvents has been triggered properly and check whether the
  31  *          information about the Opposite Component can be obtained.
  32  * @author Aruna Samji
  33  * @library ../../../lib/testlibrary
  34  * @build ExtendedRobot
  35  * @run main TaskOppositeComponent
  36  */
  37 
  38 public class TaskOppositeComponent extends Task<GUIMerlinFocus> {
  39 
  40     public static void main (String[] args) throws Exception {
  41         new TaskOppositeComponent(new GUIMerlinFocus(), new ExtendedRobot()).runTask();
  42     }
  43 
  44     TaskOppositeComponent(GUIMerlinFocus gui, ExtendedRobot robot) {
  45          super(gui, robot);
  46     }
  47 
  48     public void task() throws Exception {
  49         gui.frame4.setVisible(true);
  50 
  51         // Transfer the focus from Button to List & check whether the
  52         // getOppositeComponent is returning the component which lost
  53         // the focus.
  54         Point button2Origin = gui.button2.getLocationOnScreen();
  55         Point button2Center = gui.button2.getLocationOnScreen();
  56         button2Center.translate(gui.button2.getWidth()/2, gui.button2.getHeight()/2);
  57         robot.glide(button2Origin, button2Center);
  58         robot.waitForIdle(1000);
  59         robot.click();
  60 
  61         robot.type(KeyEvent.VK_TAB);
  62 
  63         if (gui.focusLostComp!=gui.button2)
  64             throw new RuntimeException("didn't get the information about " +
  65                     "opposite Component which lose the focus.\n");
  66 
  67         // Transfer the focus from List to LwButton & check whether the
  68         // getOppositeComponent is returning the component which gain
  69         // the focus.
  70         robot.type(KeyEvent.VK_TAB);
  71 
  72         if (gui.focusGainedComp!=gui.list2)
  73             throw new RuntimeException("didn't get the information about " +
  74                     "opposite Component which gain the focus");
  75     }
  76 }