author | mhalder |
Wed, 16 Jan 2019 23:56:32 +0530 | |
changeset 53358 | 659b004b6a1b |
parent 51449 | cb672967bd9b |
permissions | -rw-r--r-- |
2 | 1 |
/* |
53358
659b004b6a1b
8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents:
51449
diff
changeset
|
2 |
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
@test |
|
39056
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
5506
diff
changeset
|
26 |
@key headful |
53358
659b004b6a1b
8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents:
51449
diff
changeset
|
27 |
@bug 4980161 7158623 8204860 8208125 8215280 |
2 | 28 |
@summary Setting focusable window state to false makes the maximized frame resizable |
49305
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
29 |
@compile UnfocusableMaximizedFrameResizablity.java |
2 | 30 |
@run main UnfocusableMaximizedFrameResizablity |
31 |
*/ |
|
32 |
||
49305
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
33 |
import java.awt.Toolkit; |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
34 |
import java.awt.Frame; |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
35 |
import java.awt.Rectangle; |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
36 |
import java.awt.AWTException; |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
37 |
import java.awt.event.InputEvent; |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
38 |
import java.awt.Robot; |
2 | 39 |
|
49305
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
40 |
public class UnfocusableMaximizedFrameResizablity { |
2 | 41 |
|
49305
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
42 |
private static Frame frame; |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
43 |
private static Robot robot; |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
44 |
private static boolean isProgInterruption = false; |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
45 |
private static Thread mainThread = null; |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
46 |
private static int sleepTime = 300000; |
2 | 47 |
|
51065
20a772d8ded0
8204860: The frame could be resized by dragging a corner of the frame with the mouse
mhalder
parents:
49305
diff
changeset
|
48 |
private static void createAndShowFrame() throws Exception { |
2 | 49 |
|
53358
659b004b6a1b
8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents:
51449
diff
changeset
|
50 |
//MAXIMIZED_BOTH frame is resizable on Mac OS by default. Nothing to test. |
659b004b6a1b
8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents:
51449
diff
changeset
|
51 |
if (System.getProperty("os.name").toLowerCase().startsWith("mac")) { |
659b004b6a1b
8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents:
51449
diff
changeset
|
52 |
cleanup(); |
659b004b6a1b
8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents:
51449
diff
changeset
|
53 |
return; |
659b004b6a1b
8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents:
51449
diff
changeset
|
54 |
} |
659b004b6a1b
8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents:
51449
diff
changeset
|
55 |
|
49305
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
56 |
//The MAXIMIZED_BOTH state is not supported by the toolkit. Nothing to test. |
2 | 57 |
if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) { |
53358
659b004b6a1b
8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents:
51449
diff
changeset
|
58 |
cleanup(); |
2 | 59 |
return; |
60 |
} |
|
61 |
||
51449
cb672967bd9b
8208125: Cannot input text into JOptionPane Text Input Dialog
mhalder
parents:
51065
diff
changeset
|
62 |
frame = new Frame("Unfocusable frame"); |
49305
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
63 |
frame.setMaximizedBounds(new Rectangle(0, 0, 300, 300)); |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
64 |
frame.setSize(200, 200); |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
65 |
frame.setVisible(true); |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
66 |
frame.setExtendedState(Frame.MAXIMIZED_BOTH); |
51449
cb672967bd9b
8208125: Cannot input text into JOptionPane Text Input Dialog
mhalder
parents:
51065
diff
changeset
|
67 |
frame.setFocusableWindowState(false); |
2 | 68 |
|
49305
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
69 |
try { |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
70 |
robot = new Robot(); |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
71 |
} catch (AWTException e) { |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
72 |
throw new RuntimeException("Robot creation failed"); |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
73 |
} |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
74 |
robot.delay(2000); |
2 | 75 |
|
76 |
// The initial bounds of the frame |
|
49305
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
77 |
final Rectangle bounds = frame.getBounds(); |
2 | 78 |
|
79 |
// Let's move the mouse pointer to the bottom-right coner of the frame (the "size-grip") |
|
80 |
robot.mouseMove(bounds.x + bounds.width - 2, bounds.y + bounds.height - 2); |
|
49305
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
81 |
robot.waitForIdle(); |
2 | 82 |
|
83 |
// ... and start resizing |
|
49305
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
84 |
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
85 |
robot.waitForIdle(); |
2 | 86 |
robot.mouseMove(bounds.x + bounds.width + 20, bounds.y + bounds.height + 15); |
49305
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
87 |
robot.waitForIdle(); |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
88 |
|
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
89 |
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
90 |
robot.waitForIdle(); |
2 | 91 |
|
92 |
// The bounds of the frame after the attempt of resizing is made |
|
49305
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
93 |
final Rectangle finalBounds = frame.getBounds(); |
2 | 94 |
|
95 |
if (!finalBounds.equals(bounds)) { |
|
49305
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
96 |
cleanup(); |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
97 |
throw new RuntimeException("The maximized unfocusable frame can be resized."); |
2 | 98 |
} |
51449
cb672967bd9b
8208125: Cannot input text into JOptionPane Text Input Dialog
mhalder
parents:
51065
diff
changeset
|
99 |
cleanup(); |
49305
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
100 |
} |
2 | 101 |
|
49305
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
102 |
private static void cleanup() { |
53358
659b004b6a1b
8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents:
51449
diff
changeset
|
103 |
if (frame != null) { |
659b004b6a1b
8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents:
51449
diff
changeset
|
104 |
frame.dispose(); |
659b004b6a1b
8215280: Double click on titlebar not working for Frame with extended state set to MAXIMIZED_BOTH
mhalder
parents:
51449
diff
changeset
|
105 |
} |
49305
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
106 |
isProgInterruption = true; |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
107 |
mainThread.interrupt(); |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
108 |
} |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
109 |
|
51065
20a772d8ded0
8204860: The frame could be resized by dragging a corner of the frame with the mouse
mhalder
parents:
49305
diff
changeset
|
110 |
public static void main(String args[]) throws Exception { |
2 | 111 |
|
49305
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
112 |
mainThread = Thread.currentThread(); |
2 | 113 |
|
49305
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
114 |
try { |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
115 |
createAndShowFrame(); |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
116 |
mainThread.sleep(sleepTime); |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
117 |
} catch (InterruptedException e) { |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
118 |
if (!isProgInterruption) { |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
119 |
throw e; |
2 | 120 |
} |
121 |
} |
|
122 |
||
49305
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
123 |
if (!isProgInterruption) { |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
124 |
throw new RuntimeException("Timed out after " + sleepTime / 1000 |
2f2b37908f91
7158623: Should an unfocusable maximized Frame be resizable
mhalder
parents:
47216
diff
changeset
|
125 |
+ " seconds"); |
2 | 126 |
} |
127 |
} |
|
128 |
} |
|
129 |