Skip to content

Commit a41b885

Browse files
author
duke
committed
Backport acf591e856ce4b43303b1578bd64a8c9ab0063ea
1 parent ae8db19 commit a41b885

File tree

3 files changed

+172
-34
lines changed

3 files changed

+172
-34
lines changed

src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsIconFactory.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2023, 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
@@ -28,7 +28,6 @@
2828
import java.awt.BasicStroke;
2929
import java.awt.Color;
3030
import java.awt.Component;
31-
import java.awt.Dimension;
3231
import java.awt.Graphics;
3332
import java.awt.Graphics2D;
3433
import java.awt.RenderingHints;
@@ -175,7 +174,7 @@ public static Icon createFrameResizeIcon() {
175174

176175
@SuppressWarnings("serial") // Same-version serialization only
177176
private static class FrameButtonIcon implements Icon, Serializable {
178-
private Part part;
177+
private final Part part;
179178

180179
private FrameButtonIcon(Part part) {
181180
this.part = part;
@@ -286,18 +285,10 @@ public int getIconWidth() {
286285
int width;
287286
if (XPStyle.getXP() != null) {
288287
// Fix for XP bug where sometimes these sizes aren't updated properly
289-
// Assume for now that height is correct and derive width using the
290-
// ratio from the uxtheme part
291-
width = UIManager.getInt("InternalFrame.titleButtonHeight") -2;
292-
Dimension d = XPStyle.getPartSize(Part.WP_CLOSEBUTTON, State.NORMAL);
293-
if (d != null && d.width != 0 && d.height != 0) {
294-
width = (int) ((float) width * d.width / d.height);
295-
}
288+
// Assume for now that height is correct and derive width from height
289+
width = UIManager.getInt("InternalFrame.titleButtonHeight") + 10;
296290
} else {
297-
width = UIManager.getInt("InternalFrame.titleButtonWidth") -2;
298-
}
299-
if (XPStyle.getXP() != null) {
300-
width -= 2;
291+
width = UIManager.getInt("InternalFrame.titleButtonHeight") - 2;
301292
}
302293
return width;
303294
}

src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsInternalFrameTitlePane.java

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2023, 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
@@ -25,20 +25,46 @@
2525

2626
package com.sun.java.swing.plaf.windows;
2727

28-
import sun.swing.SwingUtilities2;
29-
30-
import javax.swing.*;
31-
import javax.swing.border.*;
32-
import javax.swing.UIManager;
33-
import javax.swing.plaf.*;
34-
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
35-
import java.awt.*;
36-
import java.awt.event.*;
28+
import java.awt.Color;
29+
import java.awt.Component;
30+
import java.awt.Container;
31+
import java.awt.Dimension;
32+
import java.awt.Font;
33+
import java.awt.FontMetrics;
34+
import java.awt.GradientPaint;
35+
import java.awt.Graphics;
36+
import java.awt.Graphics2D;
37+
import java.awt.Insets;
38+
import java.awt.LayoutManager;
39+
import java.awt.Paint;
40+
import java.awt.Point;
41+
import java.awt.Rectangle;
42+
import java.awt.event.MouseAdapter;
43+
import java.awt.event.MouseEvent;
3744
import java.beans.PropertyChangeEvent;
3845
import java.beans.PropertyChangeListener;
3946
import java.beans.PropertyVetoException;
4047

41-
import static com.sun.java.swing.plaf.windows.TMSchema.*;
48+
import javax.swing.BorderFactory;
49+
import javax.swing.Icon;
50+
import javax.swing.JComponent;
51+
import javax.swing.JInternalFrame;
52+
import javax.swing.JLabel;
53+
import javax.swing.JMenuItem;
54+
import javax.swing.JPopupMenu;
55+
import javax.swing.JSeparator;
56+
import javax.swing.LookAndFeel;
57+
import javax.swing.UIDefaults;
58+
import javax.swing.UIManager;
59+
import javax.swing.border.Border;
60+
import javax.swing.plaf.UIResource;
61+
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
62+
63+
import sun.swing.SwingUtilities2;
64+
65+
import static com.sun.java.swing.plaf.windows.TMSchema.Part;
66+
import static com.sun.java.swing.plaf.windows.TMSchema.Prop;
67+
import static com.sun.java.swing.plaf.windows.TMSchema.State;
4268
import static com.sun.java.swing.plaf.windows.XPStyle.Skin;
4369

4470
@SuppressWarnings("serial") // Superclass is not serializable across versions
@@ -68,7 +94,6 @@ protected void installDefaults() {
6894
super.installDefaults();
6995

7096
titlePaneHeight = UIManager.getInt("InternalFrame.titlePaneHeight");
71-
buttonWidth = UIManager.getInt("InternalFrame.titleButtonWidth") - 4;
7297
buttonHeight = UIManager.getInt("InternalFrame.titleButtonHeight") - 4;
7398

7499
Object obj = UIManager.get("InternalFrame.titleButtonToolTipsOn");
@@ -77,15 +102,10 @@ protected void installDefaults() {
77102

78103
if (XPStyle.getXP() != null) {
79104
// Fix for XP bug where sometimes these sizes aren't updated properly
80-
// Assume for now that height is correct and derive width using the
81-
// ratio from the uxtheme part
82-
buttonWidth = buttonHeight;
83-
Dimension d = XPStyle.getPartSize(Part.WP_CLOSEBUTTON, State.NORMAL);
84-
if (d != null && d.width != 0 && d.height != 0) {
85-
buttonWidth = (int) ((float) buttonWidth * d.width / d.height);
86-
}
105+
// Assume for now that height is correct and derive width from height
106+
buttonWidth = buttonHeight + 14;
87107
} else {
88-
buttonWidth += 2;
108+
buttonWidth = buttonHeight + 2;
89109
Color activeBorderColor =
90110
UIManager.getColor("InternalFrame.activeBorderColor");
91111
setBorder(BorderFactory.createLineBorder(activeBorderColor, 1));
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Copyright (c) 2023, 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 8140527
27+
* @key headful
28+
* @requires (os.family == "windows")
29+
* @summary InternalFrame has incorrect title button width
30+
* @run main InternalFrameTitleButtonTest
31+
*/
32+
33+
import java.awt.Component;
34+
import java.awt.Robot;
35+
36+
import javax.swing.Icon;
37+
import javax.swing.JButton;
38+
import javax.swing.JComponent;
39+
import javax.swing.JDesktopPane;
40+
import javax.swing.JFrame;
41+
import javax.swing.JInternalFrame;
42+
import javax.swing.SwingUtilities;
43+
import javax.swing.UIManager;
44+
import javax.swing.plaf.basic.BasicInternalFrameUI;
45+
46+
public class InternalFrameTitleButtonTest {
47+
48+
private static JFrame frame;
49+
private static JInternalFrame iframe;
50+
51+
public static void main(String[] args) throws Exception {
52+
String osName = System.getProperty("os.name");
53+
if (!osName.toLowerCase().contains("win")) {
54+
System.out.println("The test is applicable only for Windows.");
55+
return;
56+
}
57+
58+
UIManager.setLookAndFeel(
59+
"com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
60+
try {
61+
test(2);
62+
} finally {
63+
SwingUtilities.invokeAndWait(() -> {
64+
if (frame != null) {
65+
frame.dispose();
66+
}
67+
});
68+
}
69+
70+
UIManager.setLookAndFeel(
71+
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
72+
try {
73+
test(14);
74+
} finally {
75+
SwingUtilities.invokeAndWait(() -> {
76+
if (frame != null) {
77+
frame.dispose();
78+
}
79+
});
80+
}
81+
82+
System.out.println("ok");
83+
}
84+
85+
private static void test(final int widthAdd) throws Exception {
86+
SwingUtilities.invokeAndWait(() -> {
87+
frame = new JFrame();
88+
89+
JDesktopPane pane = new JDesktopPane();
90+
frame.setContentPane(pane);
91+
frame.setSize(400, 400);
92+
frame.setVisible(true);
93+
94+
iframe = new JInternalFrame("Mail Reader", true,
95+
true, true, true);
96+
iframe.setSize(200, 200);
97+
pane.add(iframe);
98+
iframe.setVisible(true);
99+
});
100+
101+
Robot robot = new Robot();
102+
robot.waitForIdle();
103+
robot.delay(1000);
104+
105+
SwingUtilities.invokeAndWait(() -> {
106+
JComponent title = ((BasicInternalFrameUI) iframe.getUI()).getNorthPane();
107+
for (int i = 0; i < title.getComponentCount(); i++) {
108+
Component c = title.getComponent(i);
109+
if (c instanceof JButton button
110+
&& !testButtonSize(button, widthAdd)) {
111+
throw new RuntimeException("Wrong title icon size");
112+
}
113+
}
114+
});
115+
}
116+
117+
private static boolean testButtonSize(final JButton button,
118+
final int widthAdd) {
119+
int height = UIManager.getInt("InternalFrame.titleButtonHeight") - 4;
120+
Icon icon = button.getIcon();
121+
return height == button.getHeight()
122+
&& (height + widthAdd) == button.getWidth()
123+
&& height == icon.getIconHeight()
124+
&& (height + widthAdd) == icon.getIconWidth();
125+
}
126+
}
127+

0 commit comments

Comments
 (0)