1 /*
2 * Copyright (c) 2017, 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 * @key headful
27 * @bug 8190192
28 * @requires os.family=="mac"
29 * @summary Double click on the title bar no longer repositions the window
30 * @run main DoubleClickTitleBarTest
31 */
32
33 import javax.swing.JFrame;
34 import javax.swing.SwingUtilities;
35 import java.awt.Robot;
36 import java.awt.Point;
37 import java.awt.event.InputEvent;
38 import java.awt.AWTException;
39 import java.awt.event.WindowAdapter;
40 import java.awt.event.WindowEvent;
41 import java.awt.event.WindowStateListener;
42
43 public class DoubleClickTitleBarTest {
44 private static Point position = null;
45 private static JFrame frame = null;
46 private static boolean windowMinimizedState = false, windowMaximizedState = false;
47 //offset from top left to some place on title bar
48 final private static int X_OFFSET = 100, Y_OFFSET = 7;
49
50 public static void main(String[] args) throws Exception {
51 try {
52 SwingUtilities.invokeAndWait(new Runnable() {
53 @Override
54 public void run() {
55 doTest();
56 }
57 });
58
59 Robot robot = new Robot();
60 robot.delay(500);
61
62 SwingUtilities.invokeAndWait(new Runnable() {
63 @Override
64 public void run() {
65 position = frame.getLocationOnScreen();
66 }
67 });
68
69 //offset from the top left
70 robot.mouseMove(position.x + X_OFFSET,
71 position.y + Y_OFFSET);
72
73 //do resize
74 robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
75 robot.mouseMove(frame.getLocationOnScreen().x + 200,
76 frame.getLocationOnScreen().y + 200);
77 robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
78 robot.delay(500);
79
80 SwingUtilities.invokeAndWait(new Runnable() {
81 @Override
82 public void run() {
83 position = frame.getLocationOnScreen();
84 }
85 });
86
87 //after resize, do offset from top left
88 robot.mouseMove(position.x + X_OFFSET,
89 position.y + Y_OFFSET);
90 robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
91 robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
92 robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
93 robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
94
95 //wait till maximizing the window
96 robot.delay(1000);
97
98 if(!(windowMinimizedState && windowMaximizedState)) {
99 throw new RuntimeException("Test failed:");
100 }
101 } finally {
102 if(frame != null) {
103 frame.dispose();
104 }
105 }
106 }
107
108 private static void doTest() {
109 frame = new JFrame();
110 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
111 frame.pack();
112
113 WindowStateListener listener = new WindowAdapter() {
114 public void windowStateChanged(WindowEvent evt) {
115 int oldState = evt.getOldState();
116 int newState = evt.getNewState();
117
118 if((oldState & JFrame.MAXIMIZED_BOTH) != 0 &&
119 (newState & JFrame.MAXIMIZED_BOTH) == 0) {
120 windowMinimizedState = true;
121 }
122 else if(windowMinimizedState &&
123 (oldState & JFrame.MAXIMIZED_BOTH) == 0 &&
124 (newState & JFrame.MAXIMIZED_BOTH) != 0) {
125 windowMaximizedState = true;
126 }
127 }
128 };
129
130 frame.addWindowStateListener(listener);
131 frame.setSize(200, 200);
132 frame.setLocation(100, 100);
133 frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
134 frame.setResizable(true);
135 frame.setVisible(true);
136 }
137 }
138