1 /*
   2  * Copyright (c) 2000, 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 
  26 package sun.print;
  27 
  28 import java.awt.Graphics;
  29 import java.awt.PrintGraphics;
  30 import java.awt.PrintJob;
  31 
  32 /**
  33  * A subclass of Graphics that can be printed to. The
  34  * graphics calls are forwared to another Graphics instance
  35  * that does the actual rendering.
  36  */
  37 
  38 public class ProxyPrintGraphics extends ProxyGraphics
  39                                 implements PrintGraphics {
  40 
  41     private PrintJob printJob;
  42 
  43     public ProxyPrintGraphics(Graphics graphics, PrintJob thePrintJob) {
  44         super(graphics);
  45         printJob = thePrintJob;
  46     }
  47 
  48     /**
  49      * Returns the PrintJob object from which this PrintGraphics
  50      * object originated.
  51      */
  52     public PrintJob getPrintJob() {
  53         return printJob;
  54     }
  55 
  56    /**
  57      * Creates a new <code>Graphics</code> object that is
  58      * a copy of this <code>Graphics</code> object.
  59      * @return     a new graphics context that is a copy of
  60      *                       this graphics context.
  61      */
  62     public Graphics create() {
  63         return new ProxyPrintGraphics(getGraphics().create(), printJob);
  64     }
  65 
  66 
  67     /**
  68      * Creates a new <code>Graphics</code> object based on this
  69      * <code>Graphics</code> object, but with a new translation and
  70      * clip area.
  71      * Refer to
  72      * {@link sun.print.ProxyGraphics#create(int, int, int, int)}
  73      * for a complete description of this method.
  74      * <p>
  75      * @param      x   the <i>x</i> coordinate.
  76      * @param      y   the <i>y</i> coordinate.
  77      * @param      width   the width of the clipping rectangle.
  78      * @param      height   the height of the clipping rectangle.
  79      * @return     a new graphics context.
  80      * @see        java.awt.Graphics#translate
  81      * @see        java.awt.Graphics#clipRect
  82      */
  83     public Graphics create(int x, int y, int width, int height) {
  84         Graphics g = getGraphics().create(x, y, width, height);
  85         return new ProxyPrintGraphics(g, printJob);
  86     }
  87 
  88     public Graphics getGraphics() {
  89         return super.getGraphics();
  90     }
  91 
  92 
  93    /* Spec implies dispose() should flush the page, but the implementation
  94     * has in fact always done this on the getGraphics() call, thereby
  95     * ensuring that multiple pages are cannot be rendered simultaneously.
  96     * We will preserve that behaviour and there is consqeuently no need
  97     * to take any action in this dispose method.
  98     */
  99     public void dispose() {
 100      super.dispose();
 101     }
 102 
 103 }