Path: blob/master/test/jdk/java/awt/Mouse/TitleBarDoubleClick/TitleBarDoubleClick.java
41153 views
/*1* Copyright (c) 2002, 2018, 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*/2223/*24@test25@key headful26@bug 466441527@summary Test that double clicking the titlebar does not send RELEASE/CLICKED28@library ../../regtesthelpers29@build Util30@run main TitleBarDoubleClick31*/3233import java.awt.*;34import java.awt.event.*;35import test.java.awt.regtesthelpers.Util;3637public class TitleBarDoubleClick implements MouseListener,38WindowListener39{40//Declare things used in the test, like buttons and labels here41private final static Rectangle BOUNDS = new Rectangle(300, 300, 300, 300);42private final static int TITLE_BAR_OFFSET = 10;4344Frame frame;45Robot robot;4647public static void main(final String[] args) {48TitleBarDoubleClick app = new TitleBarDoubleClick();49app.start();50}5152public void start ()53{54robot = Util.createRobot();55robot.setAutoDelay(100);56robot.mouseMove(BOUNDS.x + (BOUNDS.width / 2),57BOUNDS.y + (BOUNDS.height/ 2));5859frame = new Frame("TitleBarDoubleClick");60frame.setBounds(BOUNDS);61frame.addMouseListener(this);62frame.addWindowListener(this);63frame.setVisible(true);64}// start()6566// Move the mouse into the title bar and double click to maximize the67// Frame68static boolean hasRun = false;6970private void doTest() {71if (hasRun) return;72hasRun = true;7374System.out.println("doing test");75robot.mouseMove(BOUNDS.x + (BOUNDS.width / 2),76BOUNDS.y + TITLE_BAR_OFFSET);77robot.delay(50);78// Util.waitForIdle(robot) seem always hangs here.79// Need to use it instead robot.delay() when the bug become fixed.80System.out.println("1st press: currentTimeMillis: " + System.currentTimeMillis());81robot.mousePress(InputEvent.BUTTON1_MASK);82robot.delay(50);83System.out.println("1st release: currentTimeMillis: " + System.currentTimeMillis());84robot.mouseRelease(InputEvent.BUTTON1_MASK);85robot.delay(50);86System.out.println("2nd press: currentTimeMillis: " + System.currentTimeMillis());87robot.mousePress(InputEvent.BUTTON1_MASK);88robot.delay(50);89System.out.println("2nd release: currentTimeMillis: " + System.currentTimeMillis());90robot.mouseRelease(InputEvent.BUTTON1_MASK);91System.out.println("done: currentTimeMillis: " + System.currentTimeMillis());92}9394private void fail() {95throw new AWTError("Test failed");96}9798public void mouseEntered(MouseEvent e) {}99public void mouseExited(MouseEvent e) {}100public void mousePressed(MouseEvent e) {fail();}101public void mouseReleased(MouseEvent e) {fail();}102public void mouseClicked(MouseEvent e) {fail();}103104public void windowActivated(WindowEvent e) {doTest();}105public void windowClosed(WindowEvent e) {}106public void windowClosing(WindowEvent e) {}107public void windowDeactivated(WindowEvent e) {}108public void windowDeiconified(WindowEvent e) {}109public void windowIconified(WindowEvent e) {}110public void windowOpened(WindowEvent e) {}111112}// class TitleBarDoubleClick113114115