1 /*
   2  * Copyright (c) 1998, 2000, 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.print.Pageable;
  29 import java.awt.print.PageFormat;
  30 import java.awt.print.Printable;
  31 
  32 /**
  33  * A Book with an unknown number of pages where each
  34  * page has the same format and painter. This class
  35  * is used by PrinterJob to print Pageable jobs.
  36  */
  37 
  38 class OpenBook implements Pageable {
  39 
  40  /* Class Constants */
  41 
  42  /* Class Variables */
  43 
  44  /* Instance Variables */
  45 
  46     /**
  47      * The format of all of the pages.
  48      */
  49     private PageFormat mFormat;
  50 
  51     /**
  52      * The object that will render all of the pages.
  53      */
  54     private Printable mPainter;
  55 
  56  /* Instance Methods */
  57 
  58     /**
  59      * Create a  Pageable with an unknown number of pages
  60      * where every page shares the same format and
  61      * Printable.
  62      */
  63     OpenBook(PageFormat format, Printable painter) {
  64         mFormat = format;
  65         mPainter = painter;
  66     }
  67 
  68     /**
  69      * This object does not know the number of pages.
  70      */
  71     public int getNumberOfPages(){
  72         return UNKNOWN_NUMBER_OF_PAGES;
  73     }
  74 
  75     /**
  76      * Return the PageFormat of the page specified by 'pageIndex'.
  77      * @param int The zero based index of the page whose
  78      *            PageFormat is being requested.
  79      * @return The PageFormat describing the size and orientation
  80      */
  81     public PageFormat getPageFormat(int pageIndex) {
  82         return mFormat;
  83     }
  84 
  85     /**
  86      * Return the Printable instance responsible for rendering
  87      * the page specified by 'pageIndex'.
  88      * @param int The zero based index of the page whose
  89      *            Printable is being requested.
  90      * @return The Printable that will draw the page.
  91      */
  92     public Printable getPrintable(int pageIndex)
  93         throws IndexOutOfBoundsException
  94     {
  95         return mPainter;
  96     }
  97 }