1/* 2 * Copyright (c) 2004, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26package sun.print; 27 28import java.awt.GraphicsConfiguration; 29import java.awt.GraphicsDevice; 30 31import java.awt.Rectangle; 32import java.awt.Transparency; 33import java.awt.geom.AffineTransform; 34import java.awt.image.BufferedImage; 35import java.awt.image.ColorModel; 36import java.awt.image.DirectColorModel; 37 38public class PrinterGraphicsConfig extends GraphicsConfiguration { 39 40 static ColorModel theModel; 41 42 GraphicsDevice gd; 43 int pageWidth, pageHeight; 44 AffineTransform deviceTransform; 45 46 public PrinterGraphicsConfig(String printerID, AffineTransform deviceTx, 47 int pageWid, int pageHgt) { 48 this.pageWidth = pageWid; 49 this.pageHeight = pageHgt; 50 this.deviceTransform = deviceTx; 51 this.gd = new PrinterGraphicsDevice(this, printerID); 52 } 53 54 /** 55 * Return the graphics device associated with this configuration. 56 */ 57 public GraphicsDevice getDevice() { 58 return gd; 59 } 60 61 /** 62 * Returns the color model associated with this configuration. 63 */ 64 public ColorModel getColorModel() { 65 if (theModel == null) { 66 BufferedImage bufImg = 67 new BufferedImage(1,1, BufferedImage.TYPE_3BYTE_BGR); 68 theModel = bufImg.getColorModel(); 69 } 70 71 return theModel; 72 } 73 74 /** 75 * Returns the color model associated with this configuration that 76 * supports the specified transparency. 77 */ 78 public ColorModel getColorModel(int transparency) { 79 switch (transparency) { 80 case Transparency.OPAQUE: 81 return getColorModel(); 82 case Transparency.BITMASK: 83 return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000); 84 case Transparency.TRANSLUCENT: 85 return ColorModel.getRGBdefault(); 86 default: 87 return null; 88 } 89 } 90 91 /** 92 * Returns the default Transform for this configuration. This 93 * Transform is typically the Identity transform for most normal 94 * screens. Device coordinates for screen and printer devices will 95 * have the origin in the upper left-hand corner of the target region of 96 * the device, with X coordinates 97 * increasing to the right and Y coordinates increasing downwards. 98 * For image buffers, this Transform will be the Identity transform. 99 */ 100 public AffineTransform getDefaultTransform() { 101 return new AffineTransform(deviceTransform); 102 } 103 104 /** 105 * 106 * Returns a Transform that can be composed with the default Transform 107 * of a Graphics2D so that 72 units in user space will equal 1 inch 108 * in device space. 109 * Given a Graphics2D, g, one can reset the transformation to create 110 * such a mapping by using the following pseudocode: 111 * <pre> 112 * GraphicsConfiguration gc = g.getGraphicsConfiguration(); 113 * 114 * g.setTransform(gc.getDefaultTransform()); 115 * g.transform(gc.getNormalizingTransform()); 116 * </pre> 117 * Note that sometimes this Transform will be identity (e.g. for 118 * printers or metafile output) and that this Transform is only 119 * as accurate as the information supplied by the underlying system. 120 * For image buffers, this Transform will be the Identity transform, 121 * since there is no valid distance measurement. 122 */ 123 public AffineTransform getNormalizingTransform() { 124 return new AffineTransform(); 125 } 126 127 public Rectangle getBounds() { 128 return new Rectangle(0, 0, pageWidth, pageHeight); 129 } 130} 131