Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / java / awt / print / Book.java
blob41f360beca0cb74d05e18b6f3e52f32229f0ff60
1 /* Book.java -- A mixed group of pages to print.
2 Copyright (C) 1999, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package java.awt.print;
41 import java.util.Vector;
43 /**
44 * This class allows documents to be created with different paper types,
45 * page formatters, and painters.
47 * @author Aaron M. Renn (arenn@urbanophile.com)
49 public class Book implements Pageable
51 /**
52 * Painter objects for the book.
54 Vector printables = new Vector();
56 /**
57 * Page formats for the book.
59 Vector page_formats = new Vector();
61 /**
62 * Initializes a new instance of <code>Book</code> that is empty.
64 public Book()
68 /**
69 * Returns the number of pages in this book.
71 * @return The number of pages in this book.
73 public int getNumberOfPages()
75 return printables.size();
78 /**
79 * This method returns the <code>PageFormat</code> object for the
80 * specified page.
82 * @param page_number The number of the page to get information for, where
83 * page numbers start at 0.
85 * @return The <code>PageFormat</code> object for the specified page.
87 * @exception IndexOutOfBoundsException If the page number is not valid.
89 public PageFormat getPageFormat(int page_number)
91 return (PageFormat) page_formats.elementAt(page_number);
94 /**
95 * This method returns the <code>Printable</code> object for the
96 * specified page.
98 * @param page_number The number of the page to get information for, where
99 * page numbers start at 0.
101 * @return The <code>Printable</code> object for the specified page.
103 * @exception IndexOutOfBoundsException If the page number is not valid.
105 public Printable getPrintable(int page_number)
107 return (Printable) printables.elementAt(page_number);
111 * This method appends a page to the end of the book.
113 * @param printable The <code>Printable</code> for this page.
114 * @param page_format The <code>PageFormat</code> for this page.
116 * @exception NullPointerException If either argument is <code>null</code>.
118 public void append(Printable printable, PageFormat page_format)
120 append(printable, page_format, 1);
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>.
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.
132 * @exception NullPointerException If any argument is <code>null</code>.
134 public void append(Printable printable, PageFormat page_format, int num_pages)
136 for (int i = 0; i < num_pages; i++)
138 printables.addElement(printable);
139 page_formats.addElement(page_format);
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.
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.
152 * @throws IndexOutOfBoundsException If the specified page does not exist.
154 public void setPage(int page_num, Printable printable, PageFormat page_format)
156 printables.setElementAt(printable, page_num);
157 page_formats.setElementAt(page_format, page_num);