1 | /* Book.java -- A mixed group of pages to print.
|
---|
2 | Copyright (C) 1999 Free Software Foundation, Inc.
|
---|
3 |
|
---|
4 | This file is part of GNU Classpath.
|
---|
5 |
|
---|
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.
|
---|
10 |
|
---|
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.
|
---|
15 |
|
---|
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.
|
---|
20 |
|
---|
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.
|
---|
25 |
|
---|
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. */
|
---|
37 |
|
---|
38 |
|
---|
39 | package java.awt.print;
|
---|
40 |
|
---|
41 | import java.util.Vector;
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * This class allows documents to be created with different paper types,
|
---|
45 | * page formatters, and painters.
|
---|
46 | *
|
---|
47 | * @author Aaron M. Renn (arenn@urbanophile.com)
|
---|
48 | */
|
---|
49 | public class Book implements Pageable
|
---|
50 | {
|
---|
51 |
|
---|
52 | /*
|
---|
53 | * Instance Variables
|
---|
54 | */
|
---|
55 |
|
---|
56 | // Painter objects for the book
|
---|
57 | Vector printables = new Vector();
|
---|
58 |
|
---|
59 | // Page formats for the book
|
---|
60 | Vector page_formats = new Vector();
|
---|
61 |
|
---|
62 | /*************************************************************************/
|
---|
63 |
|
---|
64 | /*
|
---|
65 | * Constructors
|
---|
66 | */
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Initializes a new instance of <code>Book</code> that is empty.
|
---|
70 | */
|
---|
71 | public
|
---|
72 | Book()
|
---|
73 | {
|
---|
74 | ;
|
---|
75 | }
|
---|
76 |
|
---|
77 | /*************************************************************************/
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Returns the number of pages in this book.
|
---|
81 | *
|
---|
82 | * @return The number of pages in this book.
|
---|
83 | */
|
---|
84 | public int
|
---|
85 | getNumberOfPages()
|
---|
86 | {
|
---|
87 | return(printables.size());
|
---|
88 | }
|
---|
89 |
|
---|
90 | /*************************************************************************/
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * This method returns the <code>PageFormat</code> object for the
|
---|
94 | * specified page.
|
---|
95 | *
|
---|
96 | * @param page_numbers The number of the page to get information for, where
|
---|
97 | * page numbers start at 0.
|
---|
98 | *
|
---|
99 | * @return The <code>PageFormat</code> object for the specified page.
|
---|
100 | *
|
---|
101 | * @exception IndexOutOfBoundsException If the page number is not valid.
|
---|
102 | */
|
---|
103 | public PageFormat
|
---|
104 | getPageFormat(int page_number)
|
---|
105 | {
|
---|
106 | return((PageFormat)page_formats.elementAt(page_number));
|
---|
107 | }
|
---|
108 |
|
---|
109 | /*************************************************************************/
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * This method returns the <code>Printable</code> object for the
|
---|
113 | * specified page.
|
---|
114 | *
|
---|
115 | * @param page_numbers The number of the page to get information for, where
|
---|
116 | * page numbers start at 0.
|
---|
117 | *
|
---|
118 | * @return The <code>Printable</code> object for the specified page.
|
---|
119 | *
|
---|
120 | * @exception IndexOutOfBoundsException If the page number is not valid.
|
---|
121 | */
|
---|
122 | public Printable
|
---|
123 | getPrintable(int page_number)
|
---|
124 | {
|
---|
125 | return((Printable)printables.elementAt(page_number));
|
---|
126 | }
|
---|
127 |
|
---|
128 | /*************************************************************************/
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * This method appends a page to the end of the book.
|
---|
132 | *
|
---|
133 | * @param printable The <code>Printable</code> for this page.
|
---|
134 | * @param page_format The <code>PageFormat</code> for this page.
|
---|
135 | *
|
---|
136 | * @exception NullPointerException If either argument is <code>null</code>.
|
---|
137 | */
|
---|
138 | public void
|
---|
139 | append(Printable printable, PageFormat page_format)
|
---|
140 | {
|
---|
141 | append(printable, page_format, 1);
|
---|
142 | }
|
---|
143 |
|
---|
144 | /*************************************************************************/
|
---|
145 |
|
---|
146 | /**
|
---|
147 | * This method appends the specified number of pages to the end of the book.
|
---|
148 | * Each one will be associated with the specified <code>Printable</code>
|
---|
149 | * and <code>PageFormat</code>.
|
---|
150 | *
|
---|
151 | * @param printable The <code>Printable</code> for this page.
|
---|
152 | * @param page_format The <code>PageFormat</code> for this page.
|
---|
153 | * @param num_pages The number of pages to append.
|
---|
154 | *
|
---|
155 | * @exception NullPointerException If any argument is <code>null</code>.
|
---|
156 | */
|
---|
157 | public void
|
---|
158 | append(Printable painter, PageFormat page_format, int num_pages)
|
---|
159 | {
|
---|
160 | for (int i = 0; i < num_pages; i++)
|
---|
161 | {
|
---|
162 | printables.addElement(painter);
|
---|
163 | page_formats.addElement(page_format);
|
---|
164 | }
|
---|
165 | }
|
---|
166 |
|
---|
167 | /*************************************************************************/
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * This method changes the <code>Printable</code> and <code>PageFormat</code>
|
---|
171 | * for the specified page. The page must already exist or an exception
|
---|
172 | * will be thrown.
|
---|
173 | *
|
---|
174 | * @param page_num The page number to alter.
|
---|
175 | * @param printable The new <code>Printable</code> for the page.
|
---|
176 | * @param page_format The new <code>PageFormat</code> for the page.
|
---|
177 | *
|
---|
178 | * @param IndexOutOfBoundsException If the specified page does not exist.
|
---|
179 | */
|
---|
180 | public void
|
---|
181 | setPage(int page_num, Printable printable, PageFormat page_format)
|
---|
182 | {
|
---|
183 | printables.setElementAt(printable, page_num);
|
---|
184 | page_formats.setElementAt(page_format, page_num);
|
---|
185 | }
|
---|
186 |
|
---|
187 | } // class Book
|
---|
188 |
|
---|