jdk/test/java/awt/print/PrinterJob/PrinterDevice.java
author psadhukhan
Fri, 17 Jun 2016 16:52:38 +0530
changeset 39520 df99c6e834bc
parent 24143 064337def883
permissions -rw-r--r--
6966350: Empty pages when printing on Lexmark E352dn PS3 with "1200 IQ" setting Reviewed-by: prr, jdv
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
 *
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    26
 * @bug 4276227
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    27
 * @summary Checks that the PrinterGraphics is for a Printer GraphicsDevice.
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    28
 * Test doesn't run unless there's a printer on the system.
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    29
 * @author prr
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    30
 * @run main/othervm PrinterDevice
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    31
 */
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    32
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    33
import java.awt.*;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    34
import java.awt.geom.*;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    35
import java.awt.print.*;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    36
import java.io.*;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    37
import javax.print.attribute.*;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    38
import javax.print.attribute.standard.*;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    39
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    40
public class PrinterDevice implements Printable {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    41
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    42
    public static void main(String args[]) throws PrinterException {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    43
        System.setProperty("java.awt.headless", "true");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    44
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    45
        PrinterJob pj = PrinterJob.getPrinterJob();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    46
        if (pj.getPrintService() == null) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    47
            return; /* Need a printer to run this test */
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    48
        }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    49
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    50
        PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    51
        File f = new File("./out.prn");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    52
        f.deleteOnExit();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    53
        aset.add(new Destination(f.toURI()));
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    54
        aset.add(OrientationRequested.LANDSCAPE);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    55
        pj.setPrintable(new PrinterDevice());
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    56
        pj.print(aset);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    57
    }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    58
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    59
    public int print(Graphics g, PageFormat pf, int pageIndex) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    60
         if (pageIndex > 0 ) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    61
             return Printable.NO_SUCH_PAGE;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    62
         }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    63
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    64
         /* Make sure calls to get DeviceConfig, its transforms,
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    65
          * etc all work without exceptions and as expected */
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    66
         Graphics2D g2 = (Graphics2D)g;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    67
         GraphicsConfiguration gConfig = g2.getDeviceConfiguration();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    68
         AffineTransform dt = gConfig.getDefaultTransform();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    69
         AffineTransform nt = gConfig.getNormalizingTransform();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    70
         AffineTransform gt = g2.getTransform();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    71
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    72
         System.out.println("Graphics2D transform = " + gt);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    73
         System.out.println("Default transform = " + dt);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    74
         System.out.println("Normalizing transform = " + nt);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    75
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    76
         Rectangle bounds = gConfig.getBounds();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    77
         System.out.println("Bounds = " + bounds);
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    78
         if (!nt.isIdentity()) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    79
             throw new RuntimeException("Expected Identity transdform");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    80
         }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    81
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    82
         /* Make sure that device really is TYPE_PRINTER */
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    83
         GraphicsDevice gd = gConfig.getDevice();
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    84
         System.out.println("Printer Device ID = " + gd.getIDstring());
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    85
         if (!(gd.getType() == GraphicsDevice.TYPE_PRINTER)) {
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    86
             throw new RuntimeException("Expected printer device");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    87
         }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    88
         System.out.println(" *** ");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    89
         System.out.println("");
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    90
         return Printable.PAGE_EXISTS;
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    91
    }
064337def883 8038723: Openup some PrinterJob tests
prr
parents:
diff changeset
    92
}