Skip to content

Commit 4803d8a

Browse files
committed
Remove page format - throw jtreg.SkippedException if the printer is not available - Enhancments
1 parent 58ca7af commit 4803d8a

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

test/jdk/java/awt/print/PrinterJob/PageRanges.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public static void main(String args[]) throws Exception {
5757

5858
PassFailJFrame passFailJFrame = PassFailJFrame.builder()
5959
.instructions(INSTRUCTIONS)
60-
.rows((int) INSTRUCTIONS.lines().count() + 2)
6160
.columns(45)
6261
.build();
6362

test/jdk/java/awt/print/PrinterJob/PolylinePrintingTest.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
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

@@ -36,34 +38,39 @@
3638
import java.awt.Graphics2D;
3739
import java.awt.geom.Path2D;
3840
import java.awt.print.PageFormat;
39-
import java.awt.print.Paper;
4041
import java.awt.print.Printable;
4142
import java.awt.print.PrinterException;
4243
import java.awt.print.PrinterJob;
44+
import jtreg.SkippedException;
4345

4446
public 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

Comments
 (0)