test/jdk/javax/print/StreamPrintingOrientation.java
author herrick
Mon, 28 Oct 2019 11:21:43 -0400
branchJDK-8200758-branch
changeset 58818 a9316bb4c0e8
parent 47216 71c04702a3d5
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4595
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21596
diff changeset
     2
 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
4595
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
     4
 *
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
21596
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 5506
diff changeset
     7
 * published by the Free Software Foundation.
4595
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
     8
 *
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    13
 * accompanied this code).
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    14
 *
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4595
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4595
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4595
diff changeset
    21
 * questions.
4595
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    22
 */
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    23
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    24
/*
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    25
 * @test
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    26
 * @bug 4904236
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    27
 * @summary You would see a cross-platform print dialog being popped up. Check whether orientation is shown as LANDSCAPE. Click 'OK'. 'streamexample.ps' will be created in the same dir where this application was executed. Pass if the orientation in the ps file is landscape.
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    28
 * @run main/manual StreamPrintingOrientation
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    29
 */
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    30
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    31
import java.awt.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    32
import java.awt.print.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    33
import javax.print.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    34
import javax.print.attribute.standard.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    35
import javax.print.attribute.*;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    36
import java.io.FileOutputStream;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    37
import java.io.File;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    38
import java.util.Locale;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    39
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    40
class StreamPrintingOrientation implements Printable {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    41
        /**
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    42
         * Constructor
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    43
         */
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    44
         public StreamPrintingOrientation() {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    45
                super();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    46
        }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    47
        /**
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    48
         * Starts the application.
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    49
         */
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    50
        public static void main(java.lang.String[] args) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    51
                StreamPrintingOrientation pd = new StreamPrintingOrientation();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    52
                PrinterJob pj = PrinterJob.getPrinterJob();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    53
                HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    54
                PrintService service = null;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    55
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    56
                FileOutputStream fos = null;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    57
                File f = null, f1 = null;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    58
                String mType = "application/postscript";
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    59
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    60
                try {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    61
                        f = new File("streamexample.ps");
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    62
                        fos = new FileOutputStream(f);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    63
                        StreamPrintServiceFactory[] factories = PrinterJob.lookupStreamPrintServices(mType);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    64
                        if (factories.length > 0)
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    65
                                service = factories[0].getPrintService(fos);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    66
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    67
                        if (service != null) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    68
                                System.out.println("Stream Print Service "+service);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    69
                                pj.setPrintService(service);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    70
                        } else {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    71
                                throw new RuntimeException("No stream Print Service available.");
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    72
                        }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    73
                } catch (Exception e) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    74
                        e.printStackTrace();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    75
                }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    76
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    77
                pj.setPrintable(pd);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    78
                prSet.add(OrientationRequested.LANDSCAPE);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    79
                prSet.add(new Copies(3));
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    80
                prSet.add(new JobName("orientation test", null));
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    81
                System.out.println("open PrintDialog..");
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    82
                if (pj.printDialog(prSet)) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    83
                        try {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    84
                                System.out.println("\nValues in attr set passed to print method");
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    85
                                Attribute attr[] = prSet.toArray();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    86
                                for (int x = 0; x < attr.length; x ++) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    87
                                        System.out.println("Name "+attr[x].getName()+"  "+attr[x]);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    88
                                }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    89
                                System.out.println("About to print the data ...");
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    90
                                if (service != null) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    91
                                        System.out.println("TEST: calling Print");
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    92
                                        pj.print(prSet);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    93
                                        System.out.println("TEST: Printed");
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    94
                                }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    95
                        }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    96
                        catch (PrinterException pe) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    97
                                pe.printStackTrace();
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    98
                        }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
    99
                }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   100
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   101
        }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   102
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   103
        //printable interface
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   104
        public int print(Graphics g, PageFormat pf, int pi) throws PrinterException {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   105
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   106
                if (pi > 0) {
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   107
                        return Printable.NO_SUCH_PAGE;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   108
                }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   109
                // Simply draw two rectangles
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   110
                Graphics2D g2 = (Graphics2D)g;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   111
                g2.setColor(Color.black);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   112
                g2.translate(pf.getImageableX(), pf.getImageableY());
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   113
                System.out.println("StreamPrinting Test Width "+pf.getWidth()+" Height "+pf.getHeight());
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   114
                g2.drawRect(1,1,200,300);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   115
                g2.drawRect(1,1,25,25);
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   116
                return Printable.PAGE_EXISTS;
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   117
        }
84bc8a58537f 6915906: tests in closed/javax/print/ should not be calling System.exit()
jgodinez
parents:
diff changeset
   118
}