0N/A/*
2362N/A * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A test
0N/A @bug 6252982
0N/A @summary PIT: Keyboard FocusTraversal not working when choice's drop-down is visible, on XToolkit
0N/A @author andrei.dmitriev : area=awt.choice
0N/A @run applet ChoiceKeyEventReaction.html
0N/A*/
0N/A
0N/Aimport java.applet.Applet;
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/Aimport test.java.awt.regtesthelpers.Util;
0N/A
0N/Apublic class ChoiceKeyEventReaction extends Applet
0N/A{
0N/A Robot robot;
0N/A Choice choice1 = new Choice();
0N/A Point pt;
0N/A TextField tf = new TextField("Hi");
0N/A
0N/A boolean keyTypedOnTextField = false;
0N/A boolean itemChanged = false;
0N/A String toolkit;
0N/A
0N/A public void init()
0N/A {
0N/A toolkit = Toolkit.getDefaultToolkit().getClass().getName();
0N/A System.out.println("Current toolkit is :" +toolkit);
0N/A for (int i = 1; i<20; i++){
0N/A choice1.add("item-0"+i);
0N/A }
0N/A tf.addKeyListener(new KeyAdapter(){
0N/A public void keyPressed(KeyEvent ke) {
0N/A keyTypedOnTextField = true;
0N/A System.out.println(ke);
0N/A }
0N/A });
0N/A
0N/A
0N/A choice1.addItemListener(new ItemListener() {
0N/A public void itemStateChanged(ItemEvent e) {
0N/A itemChanged = true;
0N/A System.out.println(e);
0N/A }
0N/A });
0N/A
0N/A choice1.setFocusable(false);
0N/A add(tf);
0N/A add(choice1);
0N/A setLayout (new FlowLayout());
0N/A }//End init()
0N/A
0N/A public void start ()
0N/A {
0N/A setSize (200,200);
0N/A setVisible(true);
0N/A validate();
0N/A try{
0N/A robot = new Robot();
0N/A Util.waitForIdle(robot);
0N/A moveFocusToTextField();
0N/A testKeyOnChoice(InputEvent.BUTTON1_MASK, KeyEvent.VK_UP);
0N/A } catch (Throwable e) {
0N/A throw new RuntimeException("Test failed. Exception thrown: "+e);
0N/A }
0N/A }// start()
0N/A
0N/A public void testKeyOnChoice(int button, int key){
0N/A pt = choice1.getLocationOnScreen();
0N/A robot.mouseMove(pt.x + choice1.getWidth()/2, pt.y + choice1.getHeight()/2);
0N/A Util.waitForIdle(robot);
0N/A robot.mousePress(button);
0N/A robot.delay(10);
0N/A robot.mouseRelease(button);
0N/A Util.waitForIdle(robot);
0N/A
0N/A robot.keyPress(key);
0N/A robot.keyRelease(key);
0N/A
0N/A Util.waitForIdle(robot);
0N/A
0N/A System.out.println("keyTypedOnTextField = "+keyTypedOnTextField +": itemChanged = " + itemChanged);
0N/A
0N/A if (itemChanged){
0N/A throw new RuntimeException("Test failed. ItemChanged event occur on Choice.");
0N/A }
0N/A
0N/A // We may just write
0N/A // if (toolkit.equals("sun.awt.windows.WToolkit") == keyTypedOnTextField) {fail;}
0N/A // but must report differently in these cases so put two separate if statements for simplicity.
0N/A if (toolkit.equals("sun.awt.windows.WToolkit") &&
0N/A !keyTypedOnTextField)
0N/A {
0N/A throw new RuntimeException("Test failed. (Win32) KeyEvent wasn't addressed to TextField. ");
0N/A }
0N/A
0N/A if (!toolkit.equals("sun.awt.windows.WToolkit") &&
0N/A keyTypedOnTextField)
0N/A {
0N/A throw new RuntimeException("Test failed. (XToolkit/MToolkit). KeyEvent was addressed to TextField.");
0N/A }
0N/A
0N/A System.out.println("Test passed. Unfocusable Choice doesn't react on keys.");
0N/A //close opened choice
0N/A robot.keyPress(KeyEvent.VK_ESCAPE);
0N/A robot.keyRelease(KeyEvent.VK_ESCAPE);
0N/A Util.waitForIdle(robot);
0N/A }
0N/A
0N/A public void moveFocusToTextField(){
0N/A pt = tf.getLocationOnScreen();
0N/A robot.mouseMove(pt.x + tf.getWidth()/2, pt.y + tf.getHeight()/2);
0N/A Util.waitForIdle(robot);
0N/A robot.mousePress(InputEvent.BUTTON1_MASK);
0N/A robot.delay(10);
0N/A robot.mouseRelease(InputEvent.BUTTON1_MASK);
0N/A Util.waitForIdle(robot);
0N/A }
0N/A}//:~