Skip to content
Snippets Groups Projects
Commit 6a3c646b authored by Goetz Lindenmaier's avatar Goetz Lindenmaier
Browse files

8325762: Use PassFailJFrame.Builder.splitUI() in PrintLatinCJKTest.java

Backport-of: 41242cbe5d01fc6e19859626dd08f6191e7486fb
parent 9000e17a
Branches
Tags
No related merge requests found
/* /*
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
* @run main/manual PrintLatinCJKTest * @run main/manual PrintLatinCJKTest
*/ */
import java.awt.BorderLayout;
import java.awt.Font; import java.awt.Font;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.print.PageFormat; import java.awt.print.PageFormat;
...@@ -39,51 +38,57 @@ import java.awt.print.Printable; ...@@ -39,51 +38,57 @@ import java.awt.print.Printable;
import java.awt.print.PrinterException; import java.awt.print.PrinterException;
import java.awt.print.PrinterJob; import java.awt.print.PrinterJob;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import javax.swing.JButton;
import javax.swing.JFrame;
import static javax.swing.SwingUtilities.invokeAndWait; import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
public class PrintLatinCJKTest implements Printable { public class PrintLatinCJKTest implements Printable {
private static PrintLatinCJKTest testInstance = new PrintLatinCJKTest(); private static final String TEXT = "\u4e00\u4e01\u4e02\u4e03\u4e04English";
private static JFrame frame;
private static final String info = """ private static final String INFO = """
You need a printer for this test. If you have none, let Press Print, send the output to the printer and examine it.
the test pass. If there is a printer, press Print, send The printout should have text looking like this:
the output to the printer, and examine it. It should have
text looking like this : \u4e00\u4e01\u4e02\u4e03\u4e04English """
+ TEXT + """
Press Pass if the text is printed correctly.
If Japanese and English text overlap, press Fail.
To test 8022536, if a remote printer is the system default, To test 8022536, if a remote printer is the system default,
it should show in the dialog as the selected printer. it should show in the dialog as the selected printer.
"""; """;
public static void showFrame() throws InterruptedException, InvocationTargetException { private static JComponent createTestUI() {
invokeAndWait( () -> {
frame = new JFrame("Test Frame");
JButton b = new JButton("Print"); JButton b = new JButton("Print");
b.addActionListener((ae) -> { b.addActionListener((ae) -> {
try { try {
PrinterJob job = PrinterJob.getPrinterJob(); PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(testInstance); job.setPrintable(new PrintLatinCJKTest());
if (job.printDialog()) { if (job.printDialog()) {
job.print(); job.print();
} }
} catch (PrinterException ex) { } catch (PrinterException ex) {
ex.printStackTrace(); ex.printStackTrace();
String msg = "PrinterException: " + ex.getMessage();
JOptionPane.showMessageDialog(b, msg, "Error occurred",
JOptionPane.ERROR_MESSAGE);
PassFailJFrame.forceFail(msg);
} }
}); });
frame.getContentPane().add(b, BorderLayout.SOUTH);
frame.pack();
// add the test frame to dispose Box main = Box.createHorizontalBox();
PassFailJFrame.addTestWindow(frame); main.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
main.add(Box.createHorizontalGlue());
// Arrange the test instruction frame and test frame side by side main.add(b);
PassFailJFrame.positionTestWindow(frame, main.add(Box.createHorizontalGlue());
PassFailJFrame.Position.HORIZONTAL); return main;
frame.setVisible(true);
});
} }
@Override @Override
...@@ -93,22 +98,24 @@ public class PrintLatinCJKTest implements Printable { ...@@ -93,22 +98,24 @@ public class PrintLatinCJKTest implements Printable {
return Printable.NO_SUCH_PAGE; return Printable.NO_SUCH_PAGE;
} }
g.translate((int) pf.getImageableX(), (int) pf.getImageableY()); g.translate((int) pf.getImageableX(), (int) pf.getImageableY());
g.setFont(new Font("Dialog", Font.PLAIN, 36)); g.setFont(new Font(Font.DIALOG, Font.PLAIN, 36));
g.drawString("\u4e00\u4e01\u4e02\u4e03\u4e04English", 20, 100); g.drawString(TEXT, 20, 100);
return Printable.PAGE_EXISTS; return Printable.PAGE_EXISTS;
} }
public static void main(String[] args) throws InterruptedException, InvocationTargetException { public static void main(String[] args) throws InterruptedException, InvocationTargetException {
PassFailJFrame passFailJFrame = new PassFailJFrame.Builder() if (PrinterJob.lookupPrintServices().length == 0) {
.title("Test Instructions Frame") throw new RuntimeException("Printer not configured or available.");
.instructions(info) }
PassFailJFrame.builder()
.title("Print Latin CJK Test")
.instructions(INFO)
.testTimeOut(10) .testTimeOut(10)
.rows(10) .rows(12)
.columns(45) .columns(30)
.build(); .splitUI(PrintLatinCJKTest::createTestUI)
showFrame(); .build()
passFailJFrame.awaitAndCheck(); .awaitAndCheck();
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment