2727 * @key printer
2828 * @summary Test printing of wide poly lines.
2929 * @library /java/awt/regtesthelpers
30+ * @library /test/lib
3031 * @build PassFailJFrame
32+ * @build jtreg.SkippedException
3133 * @run main/manual PolylinePrintingTest
3234 */
3335
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 {
4547 private static final String INSTRUCTIONS = """
46- You must have a printer available to perform this test.
47- Click OK in the print dialog and collect the printed page.
48+ Press OK in the print dialog and collect the printed page.
4849 Passing test : Output should show two identical chevrons.
4950 Failing test : The line joins will appear different.
5051 """ ;
5152
5253 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+
5359 PassFailJFrame passFailJFrame = PassFailJFrame .builder ()
5460 .instructions (INSTRUCTIONS )
55- .rows ((int ) INSTRUCTIONS .lines ().count () + 2 )
5661 .columns (45 )
5762 .build ();
5863
59- new PolylinePrintingTest ();
64+ job .setPrintable (new PolylinePrintingTest ());
65+ if (job .printDialog ()) {
66+ job .print ();
67+ }
6068
6169 passFailJFrame .awaitAndCheck ();
6270 }
6371
6472 public int print (Graphics graphics , PageFormat pageFormat ,
6573 int pageIndex ) throws PrinterException {
66-
6774 if (pageIndex > 0 ) {
6875 return NO_SUCH_PAGE ;
6976 }
@@ -84,7 +91,6 @@ public int print(Graphics graphics, PageFormat pageFormat,
8491
8592 private void drawPolylineGOOD (Graphics2D g2d ,
8693 int [] x2Points , int [] y2Points ) {
87-
8894 Path2D polyline =
8995 new Path2D .Float (Path2D .WIND_EVEN_ODD , x2Points .length );
9096
@@ -101,16 +107,4 @@ private void drawPolylineBAD(Graphics2D g, int[] xp, int[] yp) {
101107 g .translate (0 , offset );
102108 g .drawPolyline (xp , yp , xp .length );
103109 }
104-
105- public PolylinePrintingTest () throws PrinterException {
106- PrinterJob job = PrinterJob .getPrinterJob ();
107- PageFormat pf = job .defaultPage ();
108- Paper p = pf .getPaper ();
109- p .setImageableArea (0 ,0 ,p .getWidth (), p .getHeight ());
110- pf .setPaper (p );
111- job .setPrintable (this , pf );
112- if (job .printDialog ()) {
113- job .print ();
114- }
115- }
116110}
0 commit comments