Skip to content

Commit 617503a

Browse files
author
duke
committed
Backport 788e6e154824317cf92884510c2ee116bc64f510
1 parent a0ed69d commit 617503a

File tree

4 files changed

+262
-0
lines changed

4 files changed

+262
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright (c) 2001, 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 4290656
27+
* @summary Tests if custom AbstractButton implementation fails with Metal L&F
28+
* @key headful
29+
*/
30+
31+
import java.awt.BorderLayout;
32+
import java.awt.Graphics;
33+
import java.awt.Robot;
34+
import javax.swing.AbstractButton;
35+
import javax.swing.DefaultButtonModel;
36+
import javax.swing.JFrame;
37+
import javax.swing.SwingUtilities;
38+
import javax.swing.UIManager;
39+
import javax.swing.plaf.ButtonUI;
40+
41+
public class bug4290656 {
42+
static JFrame f;
43+
44+
public static void main(String[] args) throws Exception {
45+
try {
46+
SwingUtilities.invokeAndWait(() -> {
47+
f = new JFrame("bug4290656");
48+
try {
49+
UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel());
50+
} catch (Exception e) {
51+
throw new RuntimeException("Failed to set metal L&F.");
52+
}
53+
54+
MyCustomButton button = new MyCustomButton();
55+
MyCustomToggleButton toggleButton = new MyCustomToggleButton();
56+
f.getContentPane().add(button, BorderLayout.NORTH);
57+
f.getContentPane().add(toggleButton, BorderLayout.SOUTH);
58+
59+
f.setLocationRelativeTo(null);
60+
f.setVisible(true);
61+
});
62+
63+
Robot r = new Robot();
64+
r.waitForIdle();
65+
r.delay(1000);
66+
} finally {
67+
SwingUtilities.invokeAndWait(() -> {
68+
if (f != null) {
69+
f.dispose();
70+
}
71+
});
72+
}
73+
}
74+
}
75+
76+
class MyCustomButton extends AbstractButton {
77+
private static final String uiClassID = "ButtonUI";
78+
79+
public MyCustomButton() {
80+
setModel(new DefaultButtonModel());
81+
init(null, null);
82+
}
83+
84+
public void updateUI() {
85+
setUI((ButtonUI) UIManager.getUI(this));
86+
}
87+
88+
public String getUIClassID() {
89+
return uiClassID;
90+
}
91+
92+
protected void paintBorder(Graphics g) {
93+
super.paintBorder(g);
94+
}
95+
}
96+
97+
class MyCustomToggleButton extends AbstractButton {
98+
private static final String uiClassID = "ToggleButtonUI";
99+
100+
public MyCustomToggleButton() {
101+
setModel(new DefaultButtonModel());
102+
init(null, null);
103+
}
104+
105+
public void updateUI() {
106+
setUI((ButtonUI) UIManager.getUI(this));
107+
}
108+
109+
public String getUIClassID() {
110+
return uiClassID;
111+
}
112+
113+
protected void paintBorder(Graphics g) {
114+
super.paintBorder(g);
115+
}
116+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 1999, 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 4236213
27+
* @summary Regression test isJavaLAFLockedCorrectly.java Failing with JDK-1.2.2-R
28+
*/
29+
30+
import javax.swing.LookAndFeel;
31+
32+
public class isJavaLAFLockedCorrectly {
33+
public static void main(String[] args) {
34+
System.out.println(" === isJavaLAFLockedCorrectly === ");
35+
36+
LookAndFeel newJLF;
37+
try {
38+
// try to make a version of the JLF
39+
Class jlfClass = Class.forName("javax.swing.plaf.metal.MetalLookAndFeel");
40+
newJLF = (LookAndFeel) (jlfClass.newInstance());
41+
} catch (Exception e) {
42+
// if any of these things didn't work, throw an exception
43+
throw new RuntimeException("JLF not correctly (un)locked " +
44+
"- Class files probably missing");
45+
}
46+
47+
// see if the JLF is supported here
48+
// it sure better be as it's supposed to be supported everywhere
49+
if (newJLF.isSupportedLookAndFeel() == true) {
50+
System.out.println("\t JLF correctly locked");
51+
} else {
52+
throw new RuntimeException("JLF not correctly (un)locked");
53+
}
54+
}
55+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 1999, 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+
*/
27+
28+
import javax.swing.LookAndFeel;
29+
30+
public class isMultiLAFLockedCorrectly {
31+
public static void main(String[] args) {
32+
System.out.println(" === isMultiLAFLockedCorrectly === ");
33+
34+
LookAndFeel newMulti;
35+
try {
36+
// try to make a version of the Multi L&F
37+
Class multiClass = Class.forName("javax.swing.plaf.multi.MultiLookAndFeel");
38+
newMulti = (LookAndFeel) (multiClass.newInstance());
39+
} catch (Exception e) {
40+
// if any of these things didn't work, throw an exception
41+
throw new RuntimeException("Multi L&F not correctly locked " +
42+
"- Class files probably missing");
43+
}
44+
45+
// see if the Multi L&F is supported here
46+
// it sure better be as it's supposed to be supported everywhere
47+
if (newMulti.isSupportedLookAndFeel() == true) {
48+
System.out.println("\t Multi L&F correctly locked");
49+
} else {
50+
throw new RuntimeException("Multi L&F not correctly locked");
51+
}
52+
}
53+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 1999, 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 4221007
27+
* @summary Tests whether MetalInternalFrameTitlePane is public
28+
*/
29+
30+
import javax.swing.JInternalFrame;
31+
import javax.swing.plaf.metal.MetalInternalFrameTitlePane;
32+
33+
public class bug4221007 {
34+
public static void main(String[] args) {
35+
MetalInternalFrameTitlePane mitftp =
36+
new MetalInternalFrameTitlePane(new JInternalFrame());
37+
}
38+
}

0 commit comments

Comments
 (0)