Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 182 additions & 0 deletions test/jdk/javax/swing/text/BoxView/BaselineTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*
* Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/* @test
* @bug 4519537 4522866
* @summary Tests that text and components in paragraph views line up at their baselines.
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual BaselineTest
*/

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;

import javax.swing.text.ComponentView;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.Element;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledEditorKit;
import javax.swing.text.View;
import javax.swing.text.ViewFactory;

public class BaselineTest {

static final String INSTRUCTIONS = """
Test that components displayed in a JTextPane properly respect their vertical alignment.
There are two text panes, stacked vertically with similar content except the bottom components are taller.
The content consists of a leading and trailing text string, with pink coloured components between.
The text string content means the strings 'Default Size Text' and 'Large Size Text'.
Text content baseline is at the bottom of CAPITAL letters in the text.
Each pink component has a string displaying its alignment setting in the range 0.0 to 1.0
NB: The position of the strings "align = 0.0" etc is not important, it is the component position that matters.
0.0 means it should be aligned with its top at the text content baseline,
1.0 means it should be aligned with its bottom at the text content baseline.
A value in between will be a proportional alignment, eg 0.5 is centered on the text content baseline
If the content displays as described, the test PASSES.
""";

public static void main(String[] args) throws Exception {
PassFailJFrame.builder()
.title("BaselineTest Test Instructions")
.instructions(INSTRUCTIONS)
.columns(60)
.rows(12)
.testUI(BaselineTest::createUI)
.positionTestUIBottomRowCentered()
.build()
.awaitAndCheck();
}

public static JFrame createUI() {
JFrame frame = new JFrame("BaselineTest");
frame.setLayout(new GridLayout(2, 1));

JTextPane prefPane = new JTextPane();
initJTextPane(prefPane);
frame.add(new JScrollPane(prefPane));

JTextPane variablePane = new JTextPane();
variablePane.setEditorKit(new CustomEditorKit());
initJTextPane(variablePane);
frame.add(new JScrollPane(variablePane));
frame.setSize(800, 400);
return frame;
}

static void initJTextPane(JTextPane tp) {

try {
Document doc = tp.getDocument();

doc.insertString(0, " Default Size Text ", null);
tp.setCaretPosition(doc.getLength());
tp.insertComponent(new PaintLabel(0.0f));
tp.insertComponent(new PaintLabel(0.2f));
tp.insertComponent(new PaintLabel(0.5f));
tp.insertComponent(new PaintLabel(0.7f));
tp.insertComponent(new PaintLabel(1.0f));
SimpleAttributeSet set = new SimpleAttributeSet();
StyleConstants.setFontSize(set, 20);
tp.setCaretPosition(doc.getLength());
doc.insertString(doc.getLength(), " Large Size Text ", set);
} catch (BadLocationException ble) {
throw new RuntimeException(ble);
}
}

static class PaintLabel extends JLabel {

private int pref = 40;
private int min = pref - 30;
private int max = pref + 30;

public PaintLabel(float align) {

setAlignmentY(align);
String alignStr = String.valueOf(align);

setText("align = " + alignStr);
setOpaque(true);
setBackground(Color.PINK);
}

public Dimension getMinimumSize() {
return new Dimension(super.getMinimumSize().width, min);
}

public Dimension getPreferredSize() {
return new Dimension(super.getPreferredSize().width, pref);
}

public Dimension getMaximumSize() {
return new Dimension(super.getMaximumSize().width, max);
}

public void paintComponent(Graphics g) {
g.setColor(Color.PINK);
g.fillRect(0, 0, getWidth(), getHeight());
int y = (int)(getAlignmentY() * getHeight());
g.setColor(Color.BLACK);
g.drawLine(0, y, getWidth(), y);
g.drawString(getText(), 0, 10);
}
}

static class CustomComponentView extends ComponentView {

public CustomComponentView(Element elem) {
super(elem);
}

public int getResizeWeight(int axis) {
return 1;
}
}

static class CustomEditorKit extends StyledEditorKit implements ViewFactory {

public View create(Element elem) {
if (StyleConstants.ComponentElementName.equals(elem.getName())) {
return new CustomComponentView(elem);
} else {
return super.getViewFactory().create(elem);
}
}

public ViewFactory getViewFactory() {
return this;
}
}

}
93 changes: 93 additions & 0 deletions test/jdk/javax/swing/text/GlyphView/bug4188841.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/* @test
* @bug 4188841
* @summary Tests a JTextPane wrapping issue
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual bug4188841
*/

import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;

public class bug4188841 {

static final String INSTRUCTIONS = """
The text pane contains the phrase "the quick brown fox jumps over the lazy dog",
all the words are separated by tabs. When the test starts, the whole phrase should
appear on one line. If it is wrapped along two or more lines, the test FAILS.

Otherwise, place the text caret in the very end of the line (e.g. by clicking
in the line and hitting End). Press Enter twice. The text should appear as one
line at all times. If the text wraps when you press Enter, the test FAILS.
""";

static class NoWrapTextPane extends JTextPane {

public boolean getScrollableTracksViewportWidth() {
//should not allow text to be wrapped
return false;
}

public void setSize(Dimension d) {
// don't let the Textpane get sized smaller than its parent
if (d.width < getParent().getSize().width) {
super.setSize(getParent().getSize());
}
else {
super.setSize(d);
}
}
}

static JFrame createUI() {

JFrame frame = new JFrame("bug4188841");

NoWrapTextPane nwp = new NoWrapTextPane();
nwp.setText("the\tquick\tbrown\tfox\tjumps\tover\tthe\tlazy\tdog!");
nwp.setCaretPosition(nwp.getText().length());

JScrollPane scrollPane = new JScrollPane(nwp,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

frame.add(scrollPane);
frame.setSize(400, 300);
return frame;
}

public static void main(String args[]) throws Exception {
PassFailJFrame.builder()
.title("Test Instructions")
.instructions(INSTRUCTIONS)
.columns(60)
.testUI(bug4188841::createUI)
.build()
.awaitAndCheck();
}
}
90 changes: 90 additions & 0 deletions test/jdk/javax/swing/text/html/FormView/4473401/bug4473401.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/* @test
* @bug 4473401
* @summary Tests if FormSubmitEvent is submitted correctly.
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual bug4473401
*/

import java.io.File;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.html.FormSubmitEvent;
import javax.swing.text.html.HTMLEditorKit;

public class bug4473401 implements HyperlinkListener {

static final String INSTRUCTIONS = """
The test window displays an HTML frameset with a frame
on the left and another to the right.
Push the 'Submit Query' button in the left frame to perform testing.
The window should be updated to have only one frame with the
message 'If you see this page the test PASSED'.
If it appears, PASS the test, otherwise FAIL the test.
""";

static JEditorPane jep;
static JFrame createUI() {

JFrame frame = new JFrame("bug4473401");
jep = new JEditorPane();
jep.addHyperlinkListener(new bug4473401());
HTMLEditorKit kit = new HTMLEditorKit();
kit.setAutoFormSubmission(false);
jep.setEditorKit(kit);
jep.setEditable(false);

try {
File file = new File(System.getProperty("test.src", "."), "frameset.html");
System.out.println(file.toURI().toURL());
jep.setPage(file.toURL());
} catch (Exception e) {
throw new RuntimeException(e);
}

frame.add(jep);
frame.setSize(500, 500);
return frame;
}

public void hyperlinkUpdate(HyperlinkEvent e) {
if (e instanceof FormSubmitEvent) {
jep.setText("If you see this page the test<font color=green> PASSED</font></CENTER>");
}
}

public static void main(String args[]) throws Exception {
PassFailJFrame.builder()
.title("Test Instructions")
.instructions(INSTRUCTIONS)
.columns(40)
.testUI(bug4473401::createUI)
.build()
.awaitAndCheck();
}
}
9 changes: 9 additions & 0 deletions test/jdk/javax/swing/text/html/FormView/4473401/frame1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<body>
Push the <span style="color:blue">Submit query</span> button
<FORM ACTION="./frameresult.html" METHOD=post TARGET="main" >
<input type="text" name="Selection"><BR>
<INPUT type="submit">
</FORM>
</body>
</html>
4 changes: 4 additions & 0 deletions test/jdk/javax/swing/text/html/FormView/4473401/frame2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<HTML>
<BODY>
</BODY>
</HTML>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
If you see this page the test <font color=red>FAILED</font>.
</body>
</html>
Loading