11/* 
2-  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 
2+  * Copyright (c) 2014, 2025,  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+ /* 
25+  * @test 
2526 * @bug 8041902 
2627 * @key printer 
2728 * @summary Test printing of wide poly lines. 
28-  * @run main/manual=yesno PolylinePrintingTest 
29+  * @library /java/awt/regtesthelpers 
30+  * @library /test/lib 
31+  * @build PassFailJFrame 
32+  * @build jtreg.SkippedException 
33+  * @run main/manual PolylinePrintingTest 
2934 */ 
3035
31- import  java .awt .Dialog ;
32- import  java .awt .Frame ;
33- import  java .awt .TextArea ;
3436import  java .awt .BasicStroke ;
3537import  java .awt .Graphics ;
3638import  java .awt .Graphics2D ;
3739import  java .awt .geom .Path2D ;
3840import  java .awt .print .PageFormat ;
39- import  java .awt .print .Paper ;
4041import  java .awt .print .Printable ;
4142import  java .awt .print .PrinterException ;
4243import  java .awt .print .PrinterJob ;
44+ import  jtreg .SkippedException ;
4345
4446public  class  PolylinePrintingTest  implements  Printable  {
47+     private  static  final  String  INSTRUCTIONS  = """ 
48+               Press OK in the print dialog and collect the printed page. 
49+               Passing test : Output should show two identical chevrons. 
50+               Failing test : The line joins will appear different. 
51+               """ ;
52+ 
53+     public  static  void  main (String [] args ) throws  Exception  {
54+         PrinterJob  job  = PrinterJob .getPrinterJob ();
55+         if  (job .getPrintService () == null ) {
56+             throw  new  SkippedException ("Printer not configured or available." );
57+         }
58+ 
59+         PassFailJFrame  passFailJFrame  = PassFailJFrame .builder ()
60+                 .instructions (INSTRUCTIONS )
61+                 .columns (45 )
62+                 .build ();
63+ 
64+         job .setPrintable (new  PolylinePrintingTest ());
65+         if  (job .printDialog ()) {
66+             job .print ();
67+         }
68+ 
69+         passFailJFrame .awaitAndCheck ();
70+     }
4571
4672    public  int  print (Graphics  graphics , PageFormat  pageFormat ,
4773                     int  pageIndex ) throws  PrinterException  {
48- 
4974        if  (pageIndex  > 0 ) {
5075            return  NO_SUCH_PAGE ;
5176        }
@@ -66,7 +91,6 @@ public int print(Graphics graphics, PageFormat pageFormat,
6691
6792    private  void  drawPolylineGOOD (Graphics2D  g2d ,
6893                                  int [] x2Points , int [] y2Points ) {
69- 
7094        Path2D  polyline  =
7195            new  Path2D .Float (Path2D .WIND_EVEN_ODD , x2Points .length );
7296
@@ -83,141 +107,4 @@ private void drawPolylineBAD(Graphics2D g, int[] xp, int[] yp) {
83107        g .translate (0 , offset );
84108        g .drawPolyline (xp , yp , xp .length );
85109    }
86- 
87-     public  PolylinePrintingTest () throws  PrinterException  {
88-         PrinterJob  job  = PrinterJob .getPrinterJob ();
89-         PageFormat  pf  = job .defaultPage ();
90-         Paper  p  = pf .getPaper ();
91-         p .setImageableArea (0 ,0 ,p .getWidth (), p .getHeight ());
92-         pf .setPaper (p );
93-         job .setPrintable (this , pf );
94-         if  (job .printDialog ()) {
95-             job .print ();
96-         }
97-     }
98- 
99-     public  static  void  main (String [] args ) throws  PrinterException  {
100-         String [] instructions  = {
101-              "You must have a printer available to perform this test." ,
102-              "OK the print dialog, and collect the printed page." ,
103-              "Passing test : Output should show two identical chevrons." ,
104-              "Failing test : The line joins will appear different." 
105-            };
106-         Sysout .createDialog ();
107-         Sysout .printInstructions (instructions );
108-         new  PolylinePrintingTest ();
109-     }
110110}
111- 
112- class  Sysout  {
113-    private  static  TestDialog  dialog ;
114- 
115-    public  static  void  createDialogWithInstructions ( String [] instructions  )
116-     {
117-       dialog  = new  TestDialog ( new  Frame (), "Instructions"  );
118-       dialog .printInstructions ( instructions  );
119-       dialog .show ();
120-       println ( "Any messages for the tester will display here."  );
121-     }
122- 
123-    public  static  void  createDialog ( )
124-     {
125-       dialog  = new  TestDialog ( new  Frame (), "Instructions"  );
126-       String [] defInstr  = { "Instructions will appear here. " , ""  } ;
127-       dialog .printInstructions ( defInstr  );
128-       dialog .show ();
129-       println ( "Any messages for the tester will display here."  );
130-     }
131- 
132- 
133-    public  static  void  printInstructions ( String [] instructions  )
134-     {
135-       dialog .printInstructions ( instructions  );
136-     }
137- 
138- 
139-    public  static  void  println ( String  messageIn  )
140-     {
141-       dialog .displayMessage ( messageIn  );
142-     }
143- 
144- }// Sysout  class 
145- 
146- /** 
147-   This is part of the standard test machinery.  It provides a place for the 
148-    test instructions to be displayed, and a place for interactive messages 
149-    to the user to be displayed. 
150-   To have the test instructions displayed, see Sysout. 
151-   To have a message to the user be displayed, see Sysout. 
152-   Do not call anything in this dialog directly. 
153-   */ 
154- class  TestDialog  extends  Dialog  {
155-   TextArea  instructionsText ;
156-    TextArea  messageText ;
157-    int  maxStringLength  = 80 ;
158- 
159-    //DO NOT call this directly, go through Sysout 
160-    public  TestDialog ( Frame  frame , String  name  )
161-     {
162-       super ( frame , name  );
163-       int  scrollBoth  = TextArea .SCROLLBARS_BOTH ;
164-       instructionsText  = new  TextArea ( "" , 15 , maxStringLength , scrollBoth  );
165-       add ( "North" , instructionsText  );
166- 
167-       messageText  = new  TextArea ( "" , 5 , maxStringLength , scrollBoth  );
168-       add ("Center" , messageText );
169- 
170-       pack ();
171- 
172-       show ();
173-     }// TestDialog() 
174- 
175-    //DO NOT call this directly, go through Sysout 
176-    public  void  printInstructions ( String [] instructions  )
177-     {
178-       //Clear out any current instructions 
179-       instructionsText .setText ( ""  );
180- 
181-       //Go down array of instruction strings 
182- 
183-       String  printStr , remainingStr ;
184-       for ( int  i =0 ; i  < instructions .length ; i ++ )
185-        {
186-          //chop up each into pieces maxSringLength long 
187-          remainingStr  = instructions [ i  ];
188-          while ( remainingStr .length () > 0  )
189-           {
190-             //if longer than max then chop off first max chars to print 
191-             if ( remainingStr .length () >= maxStringLength  )
192-              {
193-                //Try to chop on a word boundary 
194-                int  posOfSpace  = remainingStr .
195-                   lastIndexOf ( ' ' , maxStringLength  - 1  );
196-                if ( posOfSpace  <= 0  ) posOfSpace  = maxStringLength  - 1 ;
197- 
198-                printStr  = remainingStr .substring ( 0 , posOfSpace  + 1  );
199-                remainingStr  = remainingStr .substring ( posOfSpace  + 1  );
200-              }
201-             //else just print 
202-             else 
203-              {
204-                printStr  = remainingStr ;
205-                remainingStr  = "" ;
206-              }
207- 
208-             instructionsText .append ( printStr  + "\n "  );
209- 
210-           }// while 
211- 
212-        }// for 
213- 
214-     }//printInstructions() 
215- 
216-    //DO NOT call this directly, go through Sysout 
217-    public  void  displayMessage ( String  messageIn  )
218-     {
219-       messageText .append ( messageIn  + "\n "  );
220-     }
221- 
222- }// TestDialog  class 
223- 
0 commit comments