001/* Book.java -- A mixed group of pages to print.
002   Copyright (C) 1999, 2004  Free Software Foundation, Inc.
003
004This file is part of GNU Classpath.
005
006GNU Classpath is free software; you can redistribute it and/or modify
007it under the terms of the GNU General Public License as published by
008the Free Software Foundation; either version 2, or (at your option)
009any later version.
010
011GNU Classpath is distributed in the hope that it will be useful, but
012WITHOUT ANY WARRANTY; without even the implied warranty of
013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014General Public License for more details.
015
016You should have received a copy of the GNU General Public License
017along with GNU Classpath; see the file COPYING.  If not, write to the
018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
01902110-1301 USA.
020
021Linking this library statically or dynamically with other modules is
022making a combined work based on this library.  Thus, the terms and
023conditions of the GNU General Public License cover the whole
024combination.
025
026As a special exception, the copyright holders of this library give you
027permission to link this library with independent modules to produce an
028executable, regardless of the license terms of these independent
029modules, and to copy and distribute the resulting executable under
030terms of your choice, provided that you also meet, for each linked
031independent module, the terms and conditions of the license of that
032module.  An independent module is a module which is not derived from
033or based on this library.  If you modify this library, you may extend
034this exception to your version of the library, but you are not
035obligated to do so.  If you do not wish to do so, delete this
036exception statement from your version. */
037
038
039package java.awt.print;
040
041import java.util.Vector;
042
043/**
044 * This class allows documents to be created with different paper types,
045 * page formatters, and painters.
046 *
047 * @author Aaron M. Renn (arenn@urbanophile.com)
048 */
049public class Book implements Pageable
050{
051  /**
052   * Painter objects for the book.
053   */
054  Vector printables = new Vector();
055
056  /**
057   * Page formats for the book.
058   */
059  Vector page_formats = new Vector();
060
061  /**
062   * Initializes a new instance of <code>Book</code> that is empty.
063   */
064  public Book()
065  {
066  }
067
068  /**
069   * Returns the number of pages in this book.
070   *
071   * @return The number of pages in this book.
072   */
073  public int getNumberOfPages()
074  {
075    return printables.size();
076  }
077
078  /**
079   * This method returns the <code>PageFormat</code> object for the
080   * specified page.
081   *
082   * @param page_number The number of the page to get information for, where
083   * page numbers start at 0.
084   *
085   * @return The <code>PageFormat</code> object for the specified page.
086   *
087   * @exception IndexOutOfBoundsException If the page number is not valid.
088   */
089  public PageFormat getPageFormat(int page_number)
090  {
091    return (PageFormat) page_formats.elementAt(page_number);
092  }
093
094  /**
095   * This method returns the <code>Printable</code> object for the
096   * specified page.
097   *
098   * @param page_number The number of the page to get information for, where
099   * page numbers start at 0.
100   *
101   * @return The <code>Printable</code> object for the specified page.
102   *
103   * @exception IndexOutOfBoundsException If the page number is not valid.
104   */
105  public Printable getPrintable(int page_number)
106  {
107    return (Printable) printables.elementAt(page_number);
108  }
109
110  /**
111   * This method appends a page to the end of the book.
112   *
113   * @param printable The <code>Printable</code> for this page.
114   * @param page_format The <code>PageFormat</code> for this page.
115   *
116   * @exception NullPointerException If either argument is <code>null</code>.
117   */
118  public void append(Printable printable, PageFormat page_format)
119  {
120    append(printable, page_format, 1);
121  }
122
123  /**
124   * This method appends the specified number of pages to the end of the book.
125   * Each one will be associated with the specified <code>Printable</code>
126   * and <code>PageFormat</code>.
127   *
128   * @param printable The <code>Printable</code> for this page.
129   * @param page_format The <code>PageFormat</code> for this page.
130   * @param num_pages The number of pages to append.
131   *
132   * @exception NullPointerException If any argument is <code>null</code>.
133   */
134  public void append(Printable printable, PageFormat page_format, int num_pages)
135  {
136    for (int i = 0; i < num_pages; i++)
137      {
138        printables.addElement(printable);
139        page_formats.addElement(page_format);
140      }
141  }
142
143  /**
144   * This method changes the <code>Printable</code> and <code>PageFormat</code>
145   * for the specified page.  The page must already exist or an exception
146   * will be thrown.
147   *
148   * @param page_num The page number to alter.
149   * @param printable The new <code>Printable</code> for the page.
150   * @param page_format The new <code>PageFormat</code> for the page.
151   *
152   * @throws IndexOutOfBoundsException If the specified page does not exist.
153   */
154  public void setPage(int page_num, Printable printable, PageFormat page_format)
155  {
156    printables.setElementAt(printable, page_num);
157    page_formats.setElementAt(page_format, page_num);
158  }
159}