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