Skip to content

Commit f87aa30

Browse files
author
Andrew Lu
committed
8328238: Convert few closed manual applet tests to main
Backport-of: 68170ae22233462e8925c75c4737be7f0ba9353d
1 parent 123b973 commit f87aa30

File tree

4 files changed

+395
-0
lines changed

4 files changed

+395
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (c) 2001, 2024, 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 4419914
27+
* @summary Tests that tab movement is correct in RTL component orientation.
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4419914
31+
*/
32+
33+
import java.awt.BorderLayout;
34+
import java.awt.ComponentOrientation;
35+
import javax.swing.JButton;
36+
import javax.swing.JFrame;
37+
import java.util.Locale;
38+
39+
public class bug4419914 {
40+
private static final String INSTRUCTIONS = """
41+
1. You will see a frame with five buttons.
42+
2. Confirm that each button is placed as follows:
43+
NORTH
44+
END CENTER START
45+
SOUTH
46+
3. Press the "NORTH" button and confirm the button is focused.
47+
4. Press TAB repeatedly and confirm that the TAB focus moves from right to left.
48+
(NORTH - START - CENTER - END - SOUTH - NORTH - START - CENTER - ...)
49+
50+
If there's anything different from the above items, click Fail else click Pass.""";
51+
52+
public static void main(String[] args) throws Exception {
53+
PassFailJFrame.builder()
54+
.title("Tab movement Instructions")
55+
.instructions(INSTRUCTIONS)
56+
.rows(12)
57+
.columns(42)
58+
.testUI(bug4419914::createTestUI)
59+
.build()
60+
.awaitAndCheck();
61+
}
62+
63+
private static JFrame createTestUI() {
64+
JFrame frame = new JFrame("bug4419914");
65+
frame.setFocusCycleRoot(true);
66+
frame.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
67+
frame.setLocale(Locale.ENGLISH);
68+
69+
frame.enableInputMethods(false);
70+
frame.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
71+
frame.setLocale(Locale.ENGLISH);
72+
frame.setLayout(new BorderLayout());
73+
frame.add(new JButton("SOUTH"), BorderLayout.SOUTH);
74+
frame.add(new JButton("CENTER"), BorderLayout.CENTER);
75+
frame.add(new JButton("END"), BorderLayout.LINE_END);
76+
frame.add(new JButton("START"), BorderLayout.LINE_START);
77+
frame.add(new JButton("NORTH"), BorderLayout.NORTH);
78+
frame.setSize(300, 150);
79+
return frame;
80+
}
81+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright (c) 1999, 2024, 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 4210250
27+
* @summary Tests that PlainView repaints the necessary lines of text.
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual PaintTest
31+
*/
32+
33+
import java.awt.Container;
34+
import java.awt.Dimension;
35+
import java.awt.FlowLayout;
36+
import java.awt.Rectangle;
37+
import java.awt.event.ActionEvent;
38+
import java.awt.event.ActionListener;
39+
import javax.swing.JButton;
40+
import javax.swing.JFrame;
41+
import javax.swing.JScrollPane;
42+
import javax.swing.JTextArea;
43+
import javax.swing.SwingUtilities;
44+
45+
public class PaintTest {
46+
47+
private static final String INSTRUCTIONS = """
48+
Click the paint button.
49+
If half of the second line is erased,
50+
that is you can only see the bottom half of the second line
51+
with the top half painted over in white, click fail, else click pass.""";
52+
53+
54+
public static void main(String[] args) throws Exception {
55+
PassFailJFrame.builder()
56+
.title("PlainView Repaint Instructions")
57+
.instructions(INSTRUCTIONS)
58+
.rows(7)
59+
.columns(35)
60+
.testUI(PaintTest::createTestUI)
61+
.build()
62+
.awaitAndCheck();
63+
}
64+
65+
private static JFrame createTestUI() {
66+
JFrame frame = new JFrame("PaintTest");
67+
68+
new PaintTest().create(frame.getContentPane());
69+
frame.pack();
70+
return frame;
71+
}
72+
73+
74+
void create(Container parent) {
75+
parent.setLayout(new FlowLayout());
76+
77+
final JTextArea ta = new JTextArea
78+
("A sample textarea\nwith a couple of lines\nof text") {
79+
public Dimension getPreferredSize() {
80+
Dimension size = super.getPreferredSize();
81+
if (getFont() != null) {
82+
size.height += getFontMetrics(getFont())
83+
.getHeight() / 2;
84+
}
85+
return size;
86+
}
87+
};
88+
JButton button = new JButton("paint");
89+
90+
button.addActionListener(new ActionListener() {
91+
public void actionPerformed(ActionEvent ae) {
92+
SwingUtilities.invokeLater(new Runnable() {
93+
public void run() {
94+
Rectangle taBounds = ta.getBounds();
95+
int fontHeight =
96+
ta.getFontMetrics(ta.getFont()).getHeight();
97+
98+
taBounds.height = fontHeight + fontHeight / 2;
99+
ta.repaint(taBounds);
100+
}
101+
});
102+
}
103+
});
104+
105+
parent.add(new JScrollPane(ta));
106+
parent.add(button);
107+
}
108+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright (c) 1999, 2024, 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 4148489
27+
* @summary Text gets deleted with negative values for setFirstLineIndent.
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4148489
31+
*/
32+
33+
import java.awt.BorderLayout;
34+
import javax.swing.JFrame;
35+
import javax.swing.JPanel;
36+
import javax.swing.JScrollPane;
37+
import javax.swing.JTextPane;
38+
import javax.swing.UIManager;
39+
import javax.swing.text.BadLocationException;
40+
import javax.swing.text.DefaultStyledDocument;
41+
import javax.swing.text.JTextComponent;
42+
import javax.swing.text.StyleConstants;
43+
import javax.swing.text.StyleContext;
44+
import javax.swing.text.Style;
45+
46+
public class bug4148489 {
47+
48+
static StyleContext sc;
49+
static DefaultStyledDocument doc;
50+
51+
private static final String INSTRUCTIONS = """
52+
Put the cursor at the beginning of the first text line and move the
53+
cursor to the right using arrow key.
54+
If the text is not corrupted then click Pass
55+
If the text disappear while cursor moves click Fail.""";
56+
57+
public static void main(String[] args) throws Exception {
58+
PassFailJFrame.builder()
59+
.title("Text traversal Instructions")
60+
.instructions(INSTRUCTIONS)
61+
.rows(5)
62+
.columns(35)
63+
.testUI(bug4148489::createTestUI)
64+
.build()
65+
.awaitAndCheck();
66+
}
67+
68+
private static JFrame createTestUI() {
69+
try {
70+
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
71+
} catch (Exception e) {
72+
System.err.println("Error loading L&F: " + e);
73+
}
74+
JPanel testPanel = new JPanel();
75+
testPanel.setLayout(new BorderLayout());
76+
sc = new StyleContext();
77+
doc = new DefaultStyledDocument(sc);
78+
79+
setParagraph();
80+
JTextComponent editor = new JTextPane(doc);
81+
JScrollPane scroller = new JScrollPane();
82+
scroller.getViewport().add(editor);
83+
JPanel panel = new JPanel();
84+
panel.setLayout(new BorderLayout());
85+
panel.add("Center", scroller);
86+
testPanel.add("Center", panel);
87+
JFrame frame = new JFrame("Styled Document");
88+
frame.add(testPanel);
89+
frame.pack();
90+
return frame;
91+
}
92+
93+
static void setParagraph() {
94+
Style sty = sc.addStyle("normal", sc.getStyle(StyleContext.DEFAULT_STYLE));
95+
//here sets the negative value for setFirstLineIndent
96+
StyleConstants.setFirstLineIndent(sty, -50);
97+
StyleConstants.setLeftIndent(sty, 50);
98+
String data = "Here I wrote some text for test. You can ignore this text because of it's a senseless text.";
99+
try {
100+
Style s = null;
101+
doc.insertString(doc.getLength(), data, s);
102+
Style ls = sc.getStyle("normal");
103+
doc.setLogicalStyle(doc.getLength() - 1, ls);
104+
doc.insertString(doc.getLength(), "\n", null);
105+
} catch (BadLocationException e) {
106+
throw new RuntimeException("BadLocationException occures while calls insertString()...", e);
107+
}
108+
}
109+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) 2003, 2024, 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 4803145
27+
* @summary Tests if bullets for HTML <ul> are on the correct side for Arabic and Hebrew in JEditorPane
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4803145
31+
*/
32+
33+
import java.awt.BorderLayout;
34+
import java.awt.ComponentOrientation;
35+
import java.awt.event.ActionEvent;
36+
import java.awt.event.ActionListener;
37+
import javax.swing.JButton;
38+
import javax.swing.JEditorPane;
39+
import javax.swing.JFrame;
40+
import javax.swing.text.html.HTMLEditorKit;
41+
42+
public class bug4803145 {
43+
44+
private static final String INSTRUCTIONS = """
45+
A JEditorPane with some html list in Hebrew appears.
46+
The bullets should be on the left side of the list items.
47+
Press the "switch text orientation" button.
48+
After the text relayouts:
49+
50+
- If the bullets are to the right of the list items then test PASSED.
51+
52+
- If the bullets remained on the left side then test FAILED.""";
53+
54+
public static void main(String[] args) throws Exception {
55+
PassFailJFrame.builder()
56+
.title("JEditorPane Instructions")
57+
.instructions(INSTRUCTIONS)
58+
.rows(10)
59+
.columns(30)
60+
.testUI(bug4803145::createTestUI)
61+
.build()
62+
.awaitAndCheck();
63+
}
64+
65+
private static JFrame createTestUI() {
66+
67+
String text =
68+
"<ul>" +
69+
"<li>&#1502;&#1489;&#1493;&#1488;" +
70+
"<li>&#1488;&#1495;&#1505;&#1493;&#1503;" +
71+
"<li>(new code) &#1492;&#1511;&#1493;&#1491; &#1492;&#1497;&#1513;&#1503; (Old Code)" +
72+
"</ul>";
73+
74+
JFrame f = new JFrame("bug4803145");
75+
JEditorPane jep = new JEditorPane();
76+
jep.setEditorKit(new HTMLEditorKit());
77+
jep.setEditable(false);
78+
79+
jep.setText(text);
80+
81+
f.setSize(500, 500);
82+
f.add(jep);
83+
84+
JButton switchButton = new JButton("switch text orientation");
85+
switchButton.addActionListener(new ActionListener() {
86+
public void actionPerformed(ActionEvent e) {
87+
boolean isLeftToRight = jep.getComponentOrientation().isLeftToRight();
88+
jep.setComponentOrientation(isLeftToRight ? ComponentOrientation.RIGHT_TO_LEFT :
89+
ComponentOrientation.LEFT_TO_RIGHT);
90+
}
91+
});
92+
f.add(switchButton, BorderLayout.SOUTH);
93+
f.pack();
94+
return f;
95+
}
96+
97+
}

0 commit comments

Comments
 (0)