Path: blob/master/test/jdk/javax/swing/JOptionPane/6428694/bug6428694.java
41155 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* @key headful25* @bug 642869426* @summary Checks that double click closes JOptionPane's input dialog.27* @library /lib/client28* @build ExtendedRobot29* @author Mikhail Lapshin30* @run main bug642869431*/3233import javax.swing.JFrame;34import javax.swing.SwingUtilities;35import javax.swing.JOptionPane;36import java.awt.*;37import java.awt.event.InputEvent;3839public class bug6428694 {40private static JFrame frame;41private static boolean mainIsWaitingForDialogClosing;42private static ExtendedRobot robot;43private static volatile boolean testPassed;4445public static void main(String[] args) throws Exception {46robot = new ExtendedRobot();47try {48SwingUtilities.invokeLater(new Runnable() {49public void run() {50bug6428694.setupUI();51}52});53robot.waitForIdle();54test();55} finally {56stopEDT();57}5859if (testPassed) {60System.out.println("Test passed");61} else {62throw new RuntimeException("JOptionPane doesn't close input dialog " +63"by double click!");64}65}6667private static void setupUI() {68frame = new JFrame("bug6428694 test");69frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);70frame.setVisible(true);7172Object[] selectedItems = new Object[40];73for (int i = 0; i < 39; i++) {74selectedItems[i] = ("item: " + i);75}76JOptionPane.showInputDialog(frame,77"Double click on selected item then click cancel",78"Test Option Dialog", JOptionPane.WARNING_MESSAGE, null,79selectedItems, selectedItems[0]);8081// We are here if double click has closed the dialog82// or when the EDT is stopping83testPassed = mainIsWaitingForDialogClosing;84}8586private static void test() {8788mainIsWaitingForDialogClosing = true;8990// Perform double click on an item91int frameLeftX = frame.getLocationOnScreen().x;92int frameUpperY = frame.getLocationOnScreen().y;93robot.mouseMove(frameLeftX + 150, frameUpperY + 120);94robot.waitForIdle();95robot.delay(100);96robot.setAutoDelay(50);97robot.mousePress(InputEvent.BUTTON1_MASK);98robot.mouseRelease(InputEvent.BUTTON1_MASK);99robot.mousePress(InputEvent.BUTTON1_MASK);100robot.mouseRelease(InputEvent.BUTTON1_MASK);101102// Wait for the input dialog closing103robot.waitForIdle();104robot.delay(2000);105106mainIsWaitingForDialogClosing = false;107}108109private static void stopEDT() {110if (frame != null) {111frame.dispose();112}113}114}115116117