jdk/test/java/awt/print/Dialog/MediaInPrintable.java
author vlivanov
Wed, 02 Mar 2016 15:42:03 +0300
changeset 36349 6cc8e6f596b2
parent 24143 064337def883
permissions -rw-r--r--
8151020: [TESTBUG] UnsafeGetStableArrayElement::testL_* fail intermittently Reviewed-by: zmajo, shade
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24143
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
     1
/*
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
     2
 * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
     4
 *
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
     8
 *
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    13
 * accompanied this code).
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    14
 *
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    18
 *
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    21
 * questions.
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    22
 */
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    23
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    24
/**
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    25
 * @test
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    26
 * @bug 4869575 6361766
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    27
 * @summary Setting orientation in the page format does not have any effect on the printout. To test 6361766, the application must exit.
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    28
 * @run main/manual MediaInPrintable
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    29
 */
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    30
import java.awt.*;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    31
import java.awt.print.*;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    32
import javax.print.attribute.HashPrintRequestAttributeSet;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    33
import javax.print.attribute.PrintRequestAttributeSet;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    34
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    35
public class MediaInPrintable implements Printable {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    36
        private static Font fnt = new Font("Helvetica",Font.PLAIN,24);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    37
        public static void main(String[] args) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    38
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    39
            System.out.println("arguments : native1 | native2\nExpected output :\n\tnative1 -  Landscape orientation.\n\tnative2 - Legal paper is selected.");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    40
            if (args.length == 0) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    41
                return;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    42
            }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    43
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    44
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    45
            // Get a PrinterJob
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    46
            PrinterJob job = PrinterJob.getPrinterJob();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    47
            PageFormat pf = new PageFormat();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    48
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    49
            if (args[0].equals("native1")) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    50
                pf.setOrientation(PageFormat.LANDSCAPE);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    51
                job.setPrintable(new MediaInPrintable(), pf);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    52
                if (job.printDialog()) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    53
                        // Print the job if the user didn't cancel printing
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    54
                        try {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    55
                                job.print();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    56
                        } catch (Exception e) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    57
                                e.printStackTrace();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    58
                        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    59
                }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    60
            } else if (args[0].equals("native2")) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    61
                Paper p = new Paper();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    62
                p.setSize(612.0, 1008.0);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    63
                p.setImageableArea(72.0, 72.0, 468.0, 864.0);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    64
                pf.setPaper(p);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    65
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    66
                job.setPrintable(new MediaInPrintable(), pf);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    67
                if (job.printDialog()) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    68
                        // Print the job if the user didn't cancel printing
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    69
                        try {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    70
                                job.print();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    71
                        } catch (Exception e) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    72
                                e.printStackTrace();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    73
                        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    74
                }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    75
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    76
            }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    77
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    78
                //System.exit(0);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    79
        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    80
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    81
        public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    82
        if (pageIndex > 0) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    83
                return Printable.NO_SUCH_PAGE;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    84
        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    85
        g.setFont(fnt);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    86
        g.setColor(Color.green);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    87
        g.drawString("Page " + (pageIndex+1), 100, 100);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    88
        return Printable.PAGE_EXISTS;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    89
        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    90
}