jdk/test/java/awt/print/Dialog/PrintDlgPageable.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 4869502 4869539
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    27
 * @summary Confirm that ToPage is populated for argument =2. Range is disabled for argument = 0.
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    28
 * @run main/manual PrintDlgPageable
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 java.util.Locale;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    33
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    34
import javax.print.*;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    35
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    36
class PrintDlgPageable implements Printable {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    37
    public static int arg;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    38
        /**
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    39
         * Constructor
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    40
         */
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    41
         public PrintDlgPageable() {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    42
                super();
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
         * Starts the application.
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    46
         */
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    47
        public static void main(java.lang.String[] args) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    48
            if (args.length < 1) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    49
                System.out.println("usage: java PrintDlgPageable { 0 | 2}");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    50
                return;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    51
            }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    52
            arg = Integer.parseInt(args[0]);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    53
                PrintDlgPageable pd = new PrintDlgPageable();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    54
                PrinterJob pj = PrinterJob.getPrinterJob();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    55
                PageableHandler handler = new PageableHandler();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    56
                pj.setPageable(handler);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    57
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    58
                System.out.println("open PrintDialog..");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    59
                if (pj.printDialog()) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    60
                        try {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    61
                                System.out.println("About to print the data ...");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    62
                                pj.print();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    63
                                System.out.println("Printed");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    64
                        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    65
                        catch (PrinterException pe) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    66
                                pe.printStackTrace();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    67
                        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    68
                }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    69
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    70
        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    71
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    72
        //printable interface
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    73
        public int print(Graphics g, PageFormat pf, int pi) throws
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    74
PrinterException {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    75
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    76
                /*if (pi > 0) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    77
                        System.out.println("pi is greater than 0");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    78
                        return Printable.NO_SUCH_PAGE;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    79
                }*/
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    80
                // Simply draw two rectangles
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    81
                Graphics2D g2 = (Graphics2D)g;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    82
                g2.setColor(Color.black);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    83
                g2.translate(pf.getImageableX(), pf.getImageableY());
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    84
                g2.drawRect(1,1,200,300);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    85
                g2.drawRect(1,1,25,25);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    86
                System.out.println("print method called "+pi + " Orientation "+pf.getOrientation());
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    87
                return Printable.PAGE_EXISTS;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    88
        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    89
}
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    90
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    91
class PageableHandler implements Pageable {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    92
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    93
        PageFormat pf = new PageFormat();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    94
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    95
        public int getNumberOfPages() {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    96
                return PrintDlgPageable.arg;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    97
                //return 0;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    98
        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    99
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   100
        public Printable getPrintable(int pageIndex) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   101
                return new PrintDlgPageable();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   102
        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   103
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   104
        public PageFormat getPageFormat(int pageIndex) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   105
                System.out.println("getPageFormat called "+pageIndex);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   106
                if (pageIndex == 0) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   107
                        pf.setOrientation(PageFormat.PORTRAIT);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   108
                        System.out.println("Orientation returned from Pageable "+findOrientation(pf.getOrientation()));
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   109
                        return pf;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   110
                } else {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   111
                        pf.setOrientation(PageFormat.LANDSCAPE);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   112
                        System.out.println("Orientation returned from Pageable "+findOrientation(pf.getOrientation()));
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   113
                        return pf;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   114
                }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   115
        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   116
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   117
        public String findOrientation(int orient) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   118
                if (orient == PageFormat.LANDSCAPE) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   119
                        return "LANDSCAPE";
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   120
                }else if (orient == PageFormat.PORTRAIT) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   121
                        return "PORTRAIT";
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   122
                } else if (orient == PageFormat.REVERSE_LANDSCAPE) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   123
                        return "REVERSE LANDSCAPE";
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   124
                } else {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   125
                        return null;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   126
                }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   127
        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
   128
}