4387N/A/*
4387N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4387N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4387N/A *
4387N/A * This code is free software; you can redistribute it and/or modify it
4387N/A * under the terms of the GNU General Public License version 2 only, as
4387N/A * published by the Free Software Foundation.
4387N/A *
4387N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4387N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4387N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4387N/A * version 2 for more details (a copy is included in the LICENSE file that
4387N/A * accompanied this code).
4387N/A *
4387N/A * You should have received a copy of the GNU General Public License version
4387N/A * 2 along with this work; if not, write to the Free Software Foundation,
4387N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4387N/A *
4387N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4387N/A * or visit www.oracle.com if you need additional information or have any
4387N/A * questions.
4387N/A */
4387N/A
4387N/A/*
4387N/A @test
4387N/A @bug 7050935
4387N/A @summary closed/java/awt/Choice/WheelEventsConsumed/WheelEventsConsumed.html fails on win32
4387N/A @author Oleg Pekhovskiy: area=awt-choice
4387N/A @run main ChoiceMouseWheelTest
4387N/A*/
4387N/A
4387N/Aimport java.awt.*;
4387N/Aimport java.awt.event.*;
4387N/A
4387N/Apublic class ChoiceMouseWheelTest extends Frame {
4387N/A
4387N/A private boolean itemChanged = false;
4387N/A private boolean wheelMoved = false;
4387N/A private boolean frameExited = false;
4387N/A
4387N/A public static void main(String[] args) {
4387N/A new ChoiceMouseWheelTest();
4387N/A }
4387N/A
4387N/A ChoiceMouseWheelTest() {
4387N/A super("ChoiceMouseWheelTest");
4387N/A setLayout(new FlowLayout());
4387N/A
4387N/A Choice choice = new Choice();
4387N/A
4387N/A addWindowListener(new WindowAdapter() {
4387N/A @Override
4387N/A public void windowClosing(WindowEvent e) {
4387N/A System.exit(0);
4387N/A }
4387N/A });
4387N/A
4387N/A for(Integer i = 0; i < 50; i++) {
4387N/A choice.add(i.toString());
4387N/A }
4387N/A
4387N/A choice.addItemListener(new ItemListener() {
4387N/A public void itemStateChanged(ItemEvent e) {
4387N/A itemChanged = true;
4387N/A }
4387N/A });
4387N/A choice.addMouseWheelListener(new MouseWheelListener() {
4387N/A public void mouseWheelMoved(MouseWheelEvent e) {
4387N/A wheelMoved = true;
4387N/A }
4387N/A });
4387N/A
4387N/A addMouseListener(new MouseAdapter() {
4387N/A @Override
4387N/A public void mouseExited(MouseEvent e) {
4387N/A frameExited = true;
4387N/A }
4387N/A });
4387N/A
4387N/A add(choice);
4387N/A setSize(200, 300);
4387N/A setVisible(true);
4387N/A toFront();
4387N/A
4387N/A try {
4387N/A Robot robot = new Robot();
4387N/A robot.setAutoDelay(100);
4387N/A robot.waitForIdle();
4387N/A
4387N/A Point pt = choice.getLocationOnScreen();
4387N/A Dimension size = choice.getSize();
4387N/A int x = pt.x + size.width / 3;
4387N/A robot.mouseMove(x, pt.y + size.height / 2);
4387N/A
4387N/A // Test mouse wheel over the choice
4387N/A String name = Toolkit.getDefaultToolkit().getClass().getName();
4779N/A
4779N/A // mouse wheel doesn't work for the choice on X11 and Mac, so skip it
4779N/A if(!name.equals("sun.awt.X11.XToolkit")
4779N/A && !name.equals("sun.lwawt.macosx.LWCToolkit")) {
4387N/A robot.mouseWheel(1);
4387N/A robot.waitForIdle();
4387N/A
4387N/A if(!wheelMoved || !itemChanged) {
4387N/A throw new RuntimeException("Mouse Wheel over the choice failed!");
4387N/A }
4387N/A }
4387N/A
4387N/A // Test mouse wheel over the drop-down list
4387N/A robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
4387N/A robot.waitForIdle();
4387N/A robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
4387N/A robot.waitForIdle();
4387N/A
4387N/A int y = getLocationOnScreen().y + getSize().height;
4387N/A while(!frameExited && y >= 0) { // move to the bottom of drop-down list
4387N/A robot.mouseMove(x, --y);
4387N/A robot.waitForIdle();
4387N/A }
4387N/A
4387N/A if(x < 0) {
4387N/A throw new RuntimeException("Could not enter drop-down list!");
4387N/A }
4387N/A
4387N/A y -= choice.getHeight() / 2;
4387N/A robot.mouseMove(x, y); // move to the last visible item in the drop-down list
4387N/A robot.waitForIdle();
4387N/A
4387N/A robot.mouseWheel(choice.getItemCount()); // wheel to the last item
4387N/A robot.waitForIdle();
4387N/A
4387N/A // click the last item
4387N/A itemChanged = false;
4387N/A robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
4387N/A robot.waitForIdle();
4387N/A robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
4387N/A robot.waitForIdle();
4387N/A
4387N/A if(!itemChanged || choice.getSelectedIndex() != choice.getItemCount() - 1) {
4387N/A throw new RuntimeException("Mouse Wheel scroll position error!");
4387N/A }
4387N/A
4387N/A System.exit(0);
4387N/A
4387N/A } catch (AWTException e) {
4387N/A throw new RuntimeException("AWTException occurred - problem creating robot!");
4387N/A }
4387N/A }
4387N/A}
4387N/A