11/*
2- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2121 * questions.
2222 */
2323
24- /**
24+ /*
2525 * @test
26- * @bug 800535 8022536
26+ * @bug 8008535 8022536
27+ * @library ../../regtesthelpers
28+ * @build PassFailJFrame
2729 * @summary JDK7 Printing: CJK and Latin Text in string overlap
28- * @run main/manual=yesno PrintLatinCJKTest
30+ * @run main/manual PrintLatinCJKTest
2931 */
3032
33+ import java .awt .BorderLayout ;
3134import java .awt .Font ;
3235import java .awt .Graphics ;
33- import java .awt .event .ActionEvent ;
34- import java .awt .event .ActionListener ;
3536import java .awt .print .PageFormat ;
36- import java .awt .print .Pageable ;
3737import java .awt .print .Printable ;
3838import java .awt .print .PrinterException ;
3939import java .awt .print .PrinterJob ;
40+ import java .lang .reflect .InvocationTargetException ;
4041import javax .swing .JButton ;
4142import javax .swing .JFrame ;
42- import javax .swing .JTextArea ;
4343
44- import javax .swing .SwingUtilities ;
44+ import static javax .swing .SwingUtilities .invokeAndWait ;
45+
46+ public class PrintLatinCJKTest implements Printable {
47+
48+ private static PrintLatinCJKTest testInstance = new PrintLatinCJKTest ();
49+ private static JFrame frame ;
50+ private static final String info = """
51+ You need a printer for this test. If you have none, let
52+ the test pass. If there is a printer, press Print, send
53+ the output to the printer, and examine it. It should have
54+ text looking like this : \u4e00 \u4e01 \u4e02 \u4e03 \u4e04 English
4555
46- public class PrintLatinCJKTest implements Printable , ActionListener {
56+ To test 8022536, if a remote printer is the system default,
57+ it should show in the dialog as the selected printer.
58+ """ ;
4759
48- static PrintLatinCJKTest testInstance = new PrintLatinCJKTest ();
49- private PageFormat pf ;
60+ public static void showFrame () throws InterruptedException , InvocationTargetException {
61+ invokeAndWait ( () -> {
62+ frame = new JFrame ("Test Frame" );
63+ JButton b = new JButton ("Print" );
64+ b .addActionListener ((ae ) -> {
65+ try {
66+ PrinterJob job = PrinterJob .getPrinterJob ();
67+ job .setPrintable (testInstance );
68+ if (job .printDialog ()) {
69+ job .print ();
70+ }
71+ } catch (PrinterException ex ) {
72+ ex .printStackTrace ();
73+ }
74+ });
75+ frame .getContentPane ().add (b , BorderLayout .SOUTH );
76+ frame .pack ();
77+ frame .setLocationRelativeTo (null );
78+ frame .setVisible (true );
5079
51- static String info =
52- "To test 8022536, if a remote printer is the system default," +
53- "it should show in the dialog as the selected printer.\n " +
54- "You need a printer for this test. If you have none, let " +
55- "the test pass. If there is a printer, press Print, send " +
56- "the output to the printer, and examine it. It should have " +
57- "text looking like this : \u4e00 \u4e01 \u4e02 \u4e03 \u4e04 English." ;
80+ // add the test frame to dispose
81+ PassFailJFrame .addTestFrame (frame );
5882
59- public static void showFrame () {
60- JFrame f = new JFrame ();
61- JTextArea jta = new JTextArea (info , 4 , 30 );
62- jta .setLineWrap (true );
63- jta .setWrapStyleWord (true );
64- f .add ("Center" , jta );
65- JButton b = new JButton ("Print" );
66- b .addActionListener (testInstance );
67- f .add ("South" , b );
68- f .pack ();
69- f .setVisible (true );
83+ // Arrange the test instruction frame and test frame side by side
84+ PassFailJFrame .positionTestFrame (frame ,
85+ PassFailJFrame .Position .HORIZONTAL );
86+ });
7087 }
7188
89+ @ Override
7290 public int print (Graphics g , PageFormat pf , int pageIndex )
7391 throws PrinterException {
74-
7592 if (pageIndex > 0 ) {
7693 return Printable .NO_SUCH_PAGE ;
7794 }
@@ -81,24 +98,12 @@ public int print(Graphics g, PageFormat pf, int pageIndex)
8198 return Printable .PAGE_EXISTS ;
8299 }
83100
84- public void actionPerformed (ActionEvent e ) {
85- try {
86- PrinterJob job = PrinterJob .getPrinterJob ();
87- job .setPrintable (testInstance );
88- if (job .printDialog ()) {
89- job .print ();
90- }
91- } catch (PrinterException ex ) {
92- ex .printStackTrace ();
93- }
94- }
95-
96- public static void main (String [] args ) {
97- SwingUtilities .invokeLater (new Runnable () {
98- @ Override
99- public void run () {
100- showFrame ();
101- }
102- });
101+ public static void main (String [] args ) throws InterruptedException , InvocationTargetException {
102+ PassFailJFrame passFailJFrame = new PassFailJFrame ("Test Instruction" +
103+ "Frame" , info , 10 , 40 , 5 );
104+ showFrame ();
105+ passFailJFrame .awaitAndCheck ();
103106 }
104107}
108+
109+
0 commit comments