11/*
2- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2007, 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+ import java .awt .Color ;
25+ import java .awt .Graphics ;
26+ import java .awt .Graphics2D ;
27+ import java .awt .image .BufferedImage ;
28+ import java .awt .print .PageFormat ;
29+ import java .awt .print .Printable ;
30+ import java .awt .print .PrinterException ;
31+ import java .awt .print .PrinterJob ;
32+ import java .lang .reflect .InvocationTargetException ;
33+
34+ /*
2535 * @test
2636 * @bug 6581756
37+ * @library ../../../regtesthelpers
38+ * @build PassFailJFrame
2739 * @summary Test printing of images which need to have src area clipped
28- * @run main/manual=yesno PrintARGBImage
40+ * @run main/manual PrintARGBImage
2941 */
3042
31- import java .awt .*;
32- import java .awt .image .*;
33- import java .awt .print .*;
34-
3543public class PrintARGBImage implements Printable {
3644
37- static String [] text = {
38- "This is a manual test which needs a printer installed" ,
39- "If you have no printer installed you CANNOT use this test" ,
40- "It runs automatically and sends one page to the default printer" ,
41- "It passes if the text shows through the rectangular image" ,
42- };
45+ public static void main (String [] args ) throws InterruptedException ,
46+ InvocationTargetException {
47+ if (PrinterJob .lookupPrintServices ().length > 0 ) {
4348
44- public static void main ( String [] args ) {
45-
46- for (int i =0 ;i <text .length ;i ++) {
47- System .out .println (text [i ]);
48- }
49+ String instruction = """
50+ This is a manual test which needs a printer installed.
51+ If you have no printer installed the test passes automatically.
52+ The test runs automatically and sends one page to the default printer.
53+ The test passes if the text shows through the rectangular image.
54+ """ ;
4955
50- try {
51- PrinterJob pj = PrinterJob .getPrinterJob ();
52- pj .setPrintable (new PrintARGBImage ());
53- pj .print ();
56+ PassFailJFrame passFailJFrame = new PassFailJFrame (instruction , 10 );
57+ try {
58+ PrinterJob pj = PrinterJob .getPrinterJob ();
59+ pj .setPrintable (new PrintARGBImage ());
60+ pj .print ();
5461 } catch (Exception ex ) {
62+ ex .printStackTrace ();
63+ throw new RuntimeException ("Exception whilst printing." );
64+ }
65+
66+ passFailJFrame .awaitAndCheck ();
67+
68+ } else {
69+ System .out .println ("Printer not configured or available."
70+ + " Test cannot continue." );
71+ PassFailJFrame .forcePass ();
5572 }
5673 }
5774
5875 public int print (Graphics g , PageFormat pf , int pageIndex )
59- throws PrinterException {
76+ throws PrinterException {
6077
6178 if (pageIndex != 0 ) {
6279 return NO_SUCH_PAGE ;
@@ -77,3 +94,5 @@ public int print(Graphics g, PageFormat pf, int pageIndex)
7794 return PAGE_EXISTS ;
7895 }
7996}
97+
98+
0 commit comments