Skip to content

Commit d6003fe

Browse files
author
Ichiroh Takiguchi
committed
8139173: [macosx] JInternalFrame shadow is not properly drawn
Reviewed-by: mdoerr Backport-of: f7814c120bf84d7e9b459f81a6ce19b44fa122ec
1 parent 8533ba4 commit d6003fe

File tree

2 files changed

+145
-4
lines changed

2 files changed

+145
-4
lines changed

src/java.desktop/macosx/classes/com/apple/laf/AquaInternalFrameBorder.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -378,9 +378,7 @@ public void drawWindowTitle(final Graphics g, final JInternalFrame frame, final
378378
final int x = inX;
379379
final int y = inY;
380380
final int w = inW;
381-
int h = inH;
382-
383-
h = metrics.titleBarHeight + inH;
381+
final int h = inH;
384382

385383
// paint the background
386384
titleBarPainter.state.set(frame.isSelected() ? State.ACTIVE : State.INACTIVE);
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*
2+
* Copyright (c) 2022, 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 8139173
28+
* @requires (os.family == "mac")
29+
* @summary Verify JInternalFrame's border
30+
* @run main JInternalFrameBorderTest
31+
*/
32+
33+
import java.awt.BorderLayout;
34+
import java.awt.Color;
35+
import java.awt.Graphics;
36+
import java.awt.Insets;
37+
import java.awt.Point;
38+
import java.awt.Rectangle;
39+
import java.awt.Robot;
40+
import javax.swing.JDesktopPane;
41+
import javax.swing.JFrame;
42+
import javax.swing.JInternalFrame;
43+
import javax.swing.SwingUtilities;
44+
import javax.swing.UIManager;
45+
46+
public class JInternalFrameBorderTest {
47+
48+
private static JFrame frame;
49+
private static JDesktopPane desktopPane;
50+
private static JInternalFrame internalFrame;
51+
private static final int LIMIT = 100;
52+
private static Robot robot;
53+
private static Point pos;
54+
private static Rectangle rect;
55+
private static Insets insets;
56+
57+
public static void main(String[] args) throws Exception {
58+
robot = new Robot();
59+
createUI();
60+
robot.waitForIdle();
61+
robot.delay(1000);
62+
63+
SwingUtilities.invokeAndWait(() -> {
64+
pos = internalFrame.getLocationOnScreen();
65+
rect = internalFrame.getBounds();
66+
insets = internalFrame.getInsets();
67+
});
68+
robot.waitForIdle();
69+
70+
// bottom
71+
int x = pos.x + rect.x + rect.width/2;
72+
int y = pos.y + rect.y + rect.height - insets.bottom + 1;
73+
Color colorBottom = robot.getPixelColor(x, y);
74+
75+
// left
76+
x = pos.x + rect.x + insets.left - 1;
77+
y = pos.y + rect.y + rect.height/2;
78+
Color colorLeft = robot.getPixelColor(x, y);
79+
80+
// right
81+
x = pos.x + rect.x + rect.width - insets.left + 1;
82+
y = pos.y + rect.y + rect.height/2;
83+
Color colorRight = robot.getPixelColor(x, y);
84+
85+
robot.waitForIdle();
86+
cleanUp();
87+
88+
int diff = getDiff(colorLeft, colorBottom);
89+
if (diff > LIMIT) {
90+
throw new RuntimeException("Unexpected border bottom=" +
91+
colorBottom + " left=" + colorLeft);
92+
}
93+
diff = getDiff(colorRight, colorBottom);
94+
if (diff > LIMIT) {
95+
throw new RuntimeException("Unexpected border bottom=" +
96+
colorBottom + " right=" + colorRight);
97+
}
98+
}
99+
100+
private static void createUI() throws Exception {
101+
SwingUtilities.invokeAndWait(() -> {
102+
try {
103+
UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel");
104+
} catch (Exception e) {
105+
throw new RuntimeException("Cannot initialize Aqua L&F");
106+
}
107+
desktopPane = new JDesktopPane() {
108+
@Override
109+
protected void paintComponent(Graphics g) {
110+
super.paintComponent(g);
111+
g.setColor(Color.BLUE);
112+
g.fillRect(0, 0, getWidth(), getHeight());
113+
}
114+
};
115+
internalFrame = new JInternalFrame();
116+
frame = new JFrame();
117+
internalFrame.setSize(500, 200);
118+
internalFrame.setVisible(true);
119+
desktopPane.add(internalFrame);
120+
121+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
122+
frame.getContentPane().setLayout(new BorderLayout());
123+
frame.getContentPane().add(desktopPane, "Center");
124+
frame.setSize(500, 500);
125+
frame.setLocationRelativeTo(null);
126+
frame.setVisible(true);
127+
frame.toFront();
128+
});
129+
}
130+
131+
private static int getDiff(Color c1, Color c2) {
132+
int r = Math.abs(c1.getRed() - c2.getRed());
133+
int g = Math.abs(c1.getGreen() - c2.getGreen());
134+
int b = Math.abs(c1.getBlue() - c2.getBlue());
135+
return r + g + b;
136+
}
137+
138+
private static void cleanUp() throws Exception {
139+
SwingUtilities.invokeAndWait(() -> {
140+
frame.dispose();
141+
});
142+
}
143+
}

0 commit comments

Comments
 (0)