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(new GUIMerlinFocus(), new ExtendedRobot()).runTask();
  41     }
  42 
  43     TaskProgrammaticTraversal(GUIMerlinFocus gui, ExtendedRobot robot) {
  44          super(gui, robot);
  45     }
  46 
  47     public void task() throws Exception {
  48         gui.testFrame2.setVisible(true);
  49         robot.waitForIdle(1000);
  50 
  51         Point button9Center = gui.button9.getLocationOnScreen();
  52         button9Center.translate(gui.button9.getWidth()/2, gui.button9.getHeight()/2);
  53         robot.glide(gui.button9.getLocationOnScreen(), button9Center);
  54         robot.waitForIdle(1000);
  55         robot.click();
  56 
  57         gui.manager2.focusNextComponent();
  58         robot.waitForIdle(1000);
  59 
  60         if (gui.focusGained2 != gui.choice8)
  61             throw new RuntimeException("KeyboardFocusManager.focusNextComponent() " +
  62                     "is not changing the focus owner.");
  63 
  64         gui.manager2.focusPreviousComponent();
  65         robot.waitForIdle(1000);
  66 
  67         if (gui.focusGained2 != gui.button9)
  68             throw new RuntimeException("KeyboardFocusManager.focusPreviousComponent() " +
  69                     "is not changing the focus owner.");
  70 
  71         gui.manager2.focusPreviousComponent(gui.checkbox8);
  72         robot.waitForIdle(1000);
  73 
  74         if (gui.focusGained2 != gui.textfield8)
  75             throw new RuntimeException("KeyboardFocusManager.focusPreviousComponent(component) " +
  76                     "is not changing the focus owner.");
  77 
  78         gui.manager2.focusNextComponent(gui.textfield8);
  79         robot.waitForIdle(1000);
  80 
  81         if (gui.focusGained2 != gui.checkbox8)
  82             throw new RuntimeException("KeyboardFocusManager.focusNextComponent(component) " +
  83                     "is not changing the focus owner.");
  84 
  85         gui.button8.transferFocus();
  86         robot.waitForIdle(1000);
  87 
  88         if (gui.focusGained2 != gui.list8)
  89             throw new RuntimeException("Component.transferFocus() is not changing " +
  90                     "the focus owner.");
  91 
  92         gui.list8.transferFocusBackward();
  93         robot.waitForIdle(1000);
  94 
  95         if (gui.focusGained2 != gui.button8)
  96             throw new RuntimeException("Component.transferFocusBackward() is not " +
  97                     "changing the focus owner.");
  98     }
  99 }