Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JOptionPane/6428694/bug6428694.java
38918 views
/*1* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23@test24@bug 642869425@summary Checks that double click closes JOptionPane's input dialog.26@library ../../../../lib/testlibrary27@build ExtendedRobot28@author Mikhail Lapshin29@run main bug642869430*/3132import javax.swing.JFrame;33import javax.swing.SwingUtilities;34import javax.swing.JOptionPane;35import java.awt.*;36import java.awt.event.InputEvent;3738public class bug6428694 {39private static JFrame frame;40private static boolean mainIsWaitingForDialogClosing;41private static ExtendedRobot robot;42private static volatile boolean testPassed;4344public static void main(String[] args) throws Exception {45robot = new ExtendedRobot();46try {47SwingUtilities.invokeLater(new Runnable() {48public void run() {49bug6428694.setupUI();50}51});52robot.waitForIdle();53test();54} finally {55stopEDT();56}5758if (testPassed) {59System.out.println("Test passed");60} else {61throw new RuntimeException("JOptionPane doesn't close input dialog " +62"by double click!");63}64}6566private static void setupUI() {67frame = new JFrame("bug6428694 test");68frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);69frame.setVisible(true);7071Object[] selectedItems = new Object[40];72for (int i = 0; i < 39; i++) {73selectedItems[i] = ("item: " + i);74}75JOptionPane.showInputDialog(frame,76"Double click on selected item then click cancel",77"Test Option Dialog", JOptionPane.WARNING_MESSAGE, null,78selectedItems, selectedItems[0]);7980// We are here if double click has closed the dialog81// or when the EDT is stopping82testPassed = mainIsWaitingForDialogClosing;83}8485private static void test() {8687mainIsWaitingForDialogClosing = true;8889// Perform double click on an item90int frameLeftX = frame.getLocationOnScreen().x;91int frameUpperY = frame.getLocationOnScreen().y;92robot.mouseMove(frameLeftX + 150, frameUpperY + 120);93robot.waitForIdle();94robot.delay(100);95robot.setAutoDelay(50);96robot.mousePress(InputEvent.BUTTON1_MASK);97robot.mouseRelease(InputEvent.BUTTON1_MASK);98robot.mousePress(InputEvent.BUTTON1_MASK);99robot.mouseRelease(InputEvent.BUTTON1_MASK);100101// Wait for the input dialog closing102robot.waitForIdle();103robot.delay(2000);104105mainIsWaitingForDialogClosing = false;106}107108private static void stopEDT() {109if (frame != null) {110frame.dispose();111}112}113}114115116