1/* 2 * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* 25 test 26 @bug 4664415 27 @summary REGRESSION: double click jframe titlebar generating mouse events in panel 28 @author Andrei Dmitriev: area=awt.mouse 29 @run applet TitleBarDoubleClick.html 30*/ 31import java.applet.Applet; 32import java.awt.*; 33import java.awt.event.*; 34import test.java.awt.regtesthelpers.Util; 35 36public class TitleBarDoubleClick extends Applet implements MouseListener, 37 WindowListener 38{ 39 //Declare things used in the test, like buttons and labels here 40 private final static Rectangle BOUNDS = new Rectangle(300, 300, 300, 300); 41 private final static int TITLE_BAR_OFFSET = 10; 42 43 Frame frame; 44 Robot robot; 45 46 public void init() 47 { 48 this.setLayout (new BorderLayout ()); 49 50 }//End init() 51 52 public void start () 53 { 54 //Get things going. Request focus, set size, et cetera 55 setSize (200,200); 56 setVisible(true); 57 validate(); 58 59 //What would normally go into main() will probably go here. 60 //Use System.out.println for diagnostic messages that you want 61 //to read after the test is done. 62 //Use Sysout.println for messages you want the tester to read. 63 64 robot = Util.createRobot(); 65 robot.setAutoDelay(100); 66 robot.mouseMove(BOUNDS.x + (BOUNDS.width / 2), 67 BOUNDS.y + (BOUNDS.height/ 2)); 68 69 frame = new Frame("TitleBarDoubleClick"); 70 frame.setBounds(BOUNDS); 71 frame.addMouseListener(this); 72 frame.addWindowListener(this); 73 frame.setVisible(true); 74 }// start() 75 76 // Move the mouse into the title bar and double click to maximize the 77 // Frame 78 static boolean hasRun = false; 79 80 private void doTest() { 81 if (hasRun) return; 82 hasRun = true; 83 84 System.out.println("doing test"); 85 robot.mouseMove(BOUNDS.x + (BOUNDS.width / 2), 86 BOUNDS.y + TITLE_BAR_OFFSET); 87 robot.delay(50); 88 // Util.waitForIdle(robot) seem always hangs here. 89 // Need to use it instead robot.delay() when the bug become fixed. 90 System.out.println("1st press: currentTimeMillis: " + System.currentTimeMillis()); 91 robot.mousePress(InputEvent.BUTTON1_MASK); 92 robot.delay(50); 93 System.out.println("1st release: currentTimeMillis: " + System.currentTimeMillis()); 94 robot.mouseRelease(InputEvent.BUTTON1_MASK); 95 robot.delay(50); 96 System.out.println("2nd press: currentTimeMillis: " + System.currentTimeMillis()); 97 robot.mousePress(InputEvent.BUTTON1_MASK); 98 robot.delay(50); 99 System.out.println("2nd release: currentTimeMillis: " + System.currentTimeMillis()); 100 robot.mouseRelease(InputEvent.BUTTON1_MASK); 101 System.out.println("done: currentTimeMillis: " + System.currentTimeMillis()); 102 } 103 104 private void fail() { 105 throw new AWTError("Test failed"); 106 } 107 108 public void mouseEntered(MouseEvent e) {} 109 public void mouseExited(MouseEvent e) {} 110 public void mousePressed(MouseEvent e) {fail();} 111 public void mouseReleased(MouseEvent e) {fail();} 112 public void mouseClicked(MouseEvent e) {fail();} 113 114 public void windowActivated(WindowEvent e) {doTest();} 115 public void windowClosed(WindowEvent e) {} 116 public void windowClosing(WindowEvent e) {} 117 public void windowDeactivated(WindowEvent e) {} 118 public void windowDeiconified(WindowEvent e) {} 119 public void windowIconified(WindowEvent e) {} 120 public void windowOpened(WindowEvent e) {} 121 122}// class TitleBarDoubleClick 123