Skip to content

Commit 8c6b611

Browse files
author
Abhishek Kumar
committed
8353832: Opensource FontClass, Selection and Icon tests
Reviewed-by: jdv
1 parent cfbbcd7 commit 8c6b611

File tree

4 files changed

+350
-0
lines changed

4 files changed

+350
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (c) 2002, 2025, 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+
import java.awt.Color;
25+
import java.awt.Dimension;
26+
import java.awt.Graphics;
27+
import java.awt.Graphics2D;
28+
import java.awt.font.TextAttribute;
29+
import java.awt.font.TransformAttribute;
30+
import java.awt.geom.AffineTransform;
31+
import java.text.AttributedCharacterIterator;
32+
import java.text.AttributedString;
33+
34+
import javax.swing.JPanel;
35+
36+
/*
37+
* @test
38+
* @bug 4650042
39+
* @summary Draw text using a transform to simulate superscript, it should look like a superscript
40+
* @library /java/awt/regtesthelpers
41+
* @build PassFailJFrame
42+
* @run main/manual FontTransformAttributeTest
43+
*/
44+
45+
public class FontTransformAttributeTest extends JPanel {
46+
AttributedCharacterIterator iter;
47+
48+
public static void main(String[] args) throws Exception {
49+
final String INSTRUCTIONS = """
50+
This test should display a string ending with the superscripted number '11'.
51+
Pass the test if you see the superscript.""";
52+
53+
PassFailJFrame.builder()
54+
.title("FontTransformAttributeTest Instruction")
55+
.instructions(INSTRUCTIONS)
56+
.columns(35)
57+
.splitUI(FontTransformAttributeTest::new)
58+
.build()
59+
.awaitAndCheck();
60+
}
61+
62+
FontTransformAttributeTest() {
63+
AffineTransform superTransform = AffineTransform.getScaleInstance(0.65, 0.65);
64+
superTransform.translate(0, -7);
65+
TransformAttribute superAttribute = new TransformAttribute(superTransform);
66+
String s = "a big number 7 11";
67+
AttributedString as = new AttributedString(s);
68+
as.addAttribute(TextAttribute.TRANSFORM, superAttribute, 15, 17);
69+
iter = as.getIterator();
70+
setBackground(Color.WHITE);
71+
}
72+
73+
@Override
74+
public Dimension getPreferredSize() {
75+
return new Dimension(200, 100);
76+
}
77+
78+
@Override
79+
public void paint(Graphics g) {
80+
Graphics2D g2 = (Graphics2D) g;
81+
Dimension d = getSize();
82+
g2.drawString(iter, 20, d.height / 2 + 8);
83+
}
84+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) 1999, 2025, 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+
import java.awt.Dimension;
25+
import java.awt.Font;
26+
import java.awt.Graphics;
27+
28+
import javax.swing.JPanel;
29+
30+
/*
31+
* @test
32+
* @bug 4248579
33+
* @summary Make sure the underscore glyph appears in the different strings
34+
* @library /java/awt/regtesthelpers
35+
* @build PassFailJFrame
36+
* @run main/manual FontUnderscoreTest
37+
*/
38+
39+
public class FontUnderscoreTest extends JPanel {
40+
public static void main(String[] args) throws Exception {
41+
final String INSTRUCTIONS = """
42+
Make sure all 8 underscore characters appear in each
43+
of the 3 strings.
44+
45+
Press PASS if all 8 are there, else FAIL.""";
46+
47+
PassFailJFrame.builder()
48+
.title("FontUnderscoreTest Instruction")
49+
.instructions(INSTRUCTIONS)
50+
.columns(35)
51+
.splitUI(FontUnderscoreTest::new)
52+
.build()
53+
.awaitAndCheck();
54+
}
55+
56+
@Override
57+
public Dimension getPreferredSize() {
58+
return new Dimension(550, 230);
59+
}
60+
61+
@Override
62+
public void paint(Graphics g) {
63+
Font f = new Font(Font.SANS_SERIF, Font.PLAIN, 24);
64+
g.setFont(f);
65+
g.drawString ("8 underscore characters appear in each string", 5, 200);
66+
67+
g.drawString("J_A_V_A_2_j_a_v_a", 25, 50);
68+
69+
f = new Font(Font.SERIF, Font.PLAIN, 24);
70+
g.setFont(f);
71+
g.drawString("J_A_V_A_2_j_a_v_a", 25, 100);
72+
73+
f = new Font(Font.MONOSPACED, Font.PLAIN, 24);
74+
g.setFont(f);
75+
g.drawString("J_A_V_A_2_j_a_v_a", 25, 150);
76+
}
77+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 2000, 2025, 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+
import java.awt.event.ActionEvent;
25+
import java.awt.event.ActionListener;
26+
27+
import javax.swing.JButton;
28+
import javax.swing.JDialog;
29+
import javax.swing.JFrame;
30+
import javax.swing.JOptionPane;
31+
32+
/*
33+
* @test
34+
* @bug 4284610
35+
* @summary Tests that a child of the non-resizable dialog acquires valid icon.
36+
* @requires (os.family == "windows")
37+
* @library /java/awt/regtesthelpers
38+
* @build PassFailJFrame
39+
* @run main/manual ChildFrameIconTest
40+
*/
41+
42+
public class ChildFrameIconTest {
43+
public static void main(String[] args) throws Exception {
44+
final String INSTRUCTIONS = """
45+
Press "Show Dialog" button to open a dialog with this message:
46+
Do you see a coffee cup icon in the upper left corner ?
47+
48+
Look at the icon in the upper left corner of the message dialog.
49+
50+
Press Pass if you see default coffee cup icon else press Fail.""";
51+
52+
PassFailJFrame.builder()
53+
.title("ChildFrameIconTest Instruction")
54+
.instructions(INSTRUCTIONS)
55+
.columns(35)
56+
.testUI(ChildFrameIconTest::createUI)
57+
.build()
58+
.awaitAndCheck();
59+
}
60+
61+
private static JFrame createUI() {
62+
JFrame f = new JFrame("ChildFrameIconTest UI");
63+
JButton b = new JButton("Show Dialog");
64+
b.addActionListener(new ActionListener() {
65+
public void actionPerformed(ActionEvent e) {
66+
String msg = "Do you see a coffee cup icon in the upper left corner ?";
67+
JDialog dlg = new JDialog(f, "Non-resizable JDialog", false);
68+
dlg.setResizable(false);
69+
JOptionPane.showMessageDialog(dlg, msg);
70+
}
71+
});
72+
f.add(b);
73+
f.setSize(250, 100);
74+
return f;
75+
}
76+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright (c) 1999, 2025, 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+
import java.awt.Toolkit;
25+
import java.awt.datatransfer.Clipboard;
26+
import java.awt.datatransfer.DataFlavor;
27+
import java.awt.datatransfer.Transferable;
28+
import java.awt.event.ActionEvent;
29+
import java.awt.event.ActionListener;
30+
31+
import java.io.Serializable;
32+
33+
import javax.swing.JButton;
34+
import javax.swing.JFrame;
35+
import javax.swing.JOptionPane;
36+
37+
/*
38+
* @test
39+
* @bug 4139552
40+
* @summary Checks to see if 'isDataFlavorSupported' throws exception.
41+
* @library /java/awt/regtesthelpers
42+
* @build PassFailJFrame
43+
* @run main/manual TestClipboard
44+
*/
45+
46+
public class TestClipboard {
47+
48+
public static void main(String[] args) throws Exception {
49+
final String INSTRUCTIONS = """
50+
This test has two steps:
51+
52+
1. you need to place some text onto the system clipboard,
53+
for example,
54+
on Windows, you could highlight some text in notepad, and do a Ctrl-C
55+
or select menu Edit->Copy;
56+
57+
on Linux or Mac, you can do the same with any Terminal or Console or
58+
Text application.
59+
60+
2. After you copy to system clipboard, press "Click Me" button.
61+
62+
Test will fail if any exception is thrown.
63+
64+
Press Pass if you see "Test Passed" in log area.""";
65+
66+
PassFailJFrame.builder()
67+
.title("TestClipboard Instruction")
68+
.instructions(INSTRUCTIONS)
69+
.columns(45)
70+
.testUI(TestClipboard::createUI)
71+
.logArea(4)
72+
.build()
73+
.awaitAndCheck();
74+
}
75+
76+
private static JFrame createUI() {
77+
JFrame f = new JFrame("ChildFrameIconTest UI");
78+
JButton b = new JButton("Click Me");
79+
b.addActionListener(new ActionListener() {
80+
public void actionPerformed(ActionEvent e) {
81+
try {
82+
new MyTest();
83+
} catch (Exception ex) {
84+
throw new RuntimeException("Exception Thrown : " + ex);
85+
}
86+
}
87+
});
88+
f.add(b);
89+
f.setSize(200, 100);
90+
return f;
91+
}
92+
93+
static class MyFlavor extends Object implements Serializable {
94+
// Stub class needed in order to define the data flavor type
95+
}
96+
97+
static class MyTest {
98+
public MyTest() throws Exception {
99+
// Create an arbitrary dataflavor
100+
DataFlavor myFlavor = new DataFlavor(MyFlavor.class, "TestClipboard");
101+
// Get the system clipboard
102+
Clipboard theClipboard =
103+
Toolkit.getDefaultToolkit().getSystemClipboard();
104+
// Get the current contents of the clipboard
105+
Transferable theTransfer = theClipboard.getContents(this);
106+
107+
// See if the flavor is supported. This may result in a null
108+
// pointer exception.
109+
theTransfer.isDataFlavorSupported(myFlavor);
110+
PassFailJFrame.log("Test Passed");
111+
}
112+
}
113+
}

0 commit comments

Comments
 (0)