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 Call the method KeyboardFocusManager. clearGlobalFocusOwner() 29 * and check whether the global focus owner has got cleared 30 * @author Aruna Samji 31 * @library ../../../lib/testlibrary 32 * @build ExtendedRobot 33 * @run main TaskGlobalFocusOwner 34 */ 35 36 public class TaskGlobalFocusOwner extends Task<GUIMerlinFocus> { 37 38 public static void main (String[] args) throws Exception { 39 new TaskGlobalFocusOwner(new GUIMerlinFocus(), new ExtendedRobot()).runTask(); 40 } 41 42 TaskGlobalFocusOwner(GUIMerlinFocus gui, ExtendedRobot robot) { 43 super(gui, robot); 44 } 45 46 public void task() throws Exception { 47 gui.testframe4.setVisible(true); 48 robot.waitForIdle(1000); 49 50 gui.tempfocus = true; 51 52 Point textfield15Center = gui.textfield15.getLocationOnScreen(); 53 textfield15Center.translate(gui.textfield15.getWidth()/2, gui.textfield15.getHeight()/2); 54 robot.glide(gui.textfield15.getLocationOnScreen(), textfield15Center); 55 robot.click(); 56 robot.waitForIdle(1000); 57 58 //Clear the GlobalFocusOwner, textfield should receive the permanent focus lost 59 //and any key events should not be generated. 60 gui.setBooleans(); 61 62 gui.de.clearGlobalFocusOwner(); 63 robot.waitForIdle(1000); 64 65 if (gui.tempfocus == true) 66 throw new RuntimeException("The focus lost is temporary when " + 67 "globalFocusOwner is cleared."); 68 69 robot.type('A'); 70 robot.waitForIdle(1000); 71 72 if (gui.keypressed15) 73 throw new RuntimeException("The keyevent is triggered when " + 74 "globalfocusowner is cleared" ); 75 76 //Get the focus again and check for the key events 77 gui.setBooleans(); 78 robot.click(); 79 robot.waitForIdle(1000); 80 81 if (! gui.focusgain) 82 throw new RuntimeException("The textfield did not get focus."); 83 84 robot.type('A'); 85 robot.waitForIdle(1000); 86 87 if (! gui.keypressed15) 88 throw new RuntimeException("The keyevent is not triggered."); 89 } 90 }