1 /*
2 * Copyright (c) 1997, 2013, 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
30 /**
31 * The <code>Book</code> class provides a representation of a document in
32 * which pages may have different page formats and page painters. This
33 * class uses the {@link Pageable} interface to interact with a
34 * {@link PrinterJob}.
35 * @see Pageable
36 * @see PrinterJob
37 */
38
39 public class Book implements Pageable {
40
41 /* Class Constants */
42
43 /* Class Variables */
44
45 /* Instance Variables */
46
47 /**
48 * The set of pages that make up the Book.
49 */
50 private Vector mPages;
51
52 /* Instance Methods */
53
54 /**
55 * Creates a new, empty <code>Book</code>.
56 */
57 public Book() {
58 mPages = new Vector();
59 }
60
61 /**
62 * Returns the number of pages in this <code>Book</code>.
63 * @return the number of pages this <code>Book</code> contains.
64 */
65 public int getNumberOfPages(){
66 return mPages.size();
67 }
68
69 /**
70 * Returns the {@link PageFormat} of the page specified by
71 * <code>pageIndex</code>.
72 * @param pageIndex the zero based index of the page whose
73 * <code>PageFormat</code> is being requested
74 * @return the <code>PageFormat</code> describing the size and
75 * orientation of the page.
76 * @throws IndexOutOfBoundsException if the <code>Pageable</code>
77 * does not contain the requested page
78 */
150 * If the <code>painter</code> or <code>page</code>
151 * argument is <code>null</code>
152 */
153 public void append(Printable painter, PageFormat page, int numPages) {
154 BookPage bookPage = new BookPage(painter, page);
155 int pageIndex = mPages.size();
156 int newSize = pageIndex + numPages;
157
158 mPages.setSize(newSize);
159 for(int i = pageIndex; i < newSize; i++){
160 mPages.setElementAt(bookPage, i);
161 }
162 }
163
164 /**
165 * Return the BookPage for the page specified by 'pageIndex'.
166 */
167 private BookPage getPage(int pageIndex)
168 throws ArrayIndexOutOfBoundsException
169 {
170 return (BookPage) mPages.elementAt(pageIndex);
171 }
172
173 /**
174 * The BookPage inner class describes an individual
175 * page in a Book through a PageFormat-Printable pair.
176 */
177 private class BookPage {
178 /**
179 * The size and orientation of the page.
180 */
181 private PageFormat mFormat;
182
183 /**
184 * The instance that will draw the page.
185 */
186 private Printable mPainter;
187
188 /**
189 * A new instance where 'format' describes the page's
190 * size and orientation and 'painter' is the instance
|
1 /*
2 * Copyright (c) 1997, 2014, 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
30 /**
31 * The <code>Book</code> class provides a representation of a document in
32 * which pages may have different page formats and page painters. This
33 * class uses the {@link Pageable} interface to interact with a
34 * {@link PrinterJob}.
35 * @see Pageable
36 * @see PrinterJob
37 */
38
39 public class Book implements Pageable {
40
41 /* Class Constants */
42
43 /* Class Variables */
44
45 /* Instance Variables */
46
47 /**
48 * The set of pages that make up the Book.
49 */
50 private Vector<BookPage> mPages;
51
52 /* Instance Methods */
53
54 /**
55 * Creates a new, empty <code>Book</code>.
56 */
57 public Book() {
58 mPages = new Vector<>();
59 }
60
61 /**
62 * Returns the number of pages in this <code>Book</code>.
63 * @return the number of pages this <code>Book</code> contains.
64 */
65 public int getNumberOfPages(){
66 return mPages.size();
67 }
68
69 /**
70 * Returns the {@link PageFormat} of the page specified by
71 * <code>pageIndex</code>.
72 * @param pageIndex the zero based index of the page whose
73 * <code>PageFormat</code> is being requested
74 * @return the <code>PageFormat</code> describing the size and
75 * orientation of the page.
76 * @throws IndexOutOfBoundsException if the <code>Pageable</code>
77 * does not contain the requested page
78 */
150 * If the <code>painter</code> or <code>page</code>
151 * argument is <code>null</code>
152 */
153 public void append(Printable painter, PageFormat page, int numPages) {
154 BookPage bookPage = new BookPage(painter, page);
155 int pageIndex = mPages.size();
156 int newSize = pageIndex + numPages;
157
158 mPages.setSize(newSize);
159 for(int i = pageIndex; i < newSize; i++){
160 mPages.setElementAt(bookPage, i);
161 }
162 }
163
164 /**
165 * Return the BookPage for the page specified by 'pageIndex'.
166 */
167 private BookPage getPage(int pageIndex)
168 throws ArrayIndexOutOfBoundsException
169 {
170 return mPages.elementAt(pageIndex);
171 }
172
173 /**
174 * The BookPage inner class describes an individual
175 * page in a Book through a PageFormat-Printable pair.
176 */
177 private class BookPage {
178 /**
179 * The size and orientation of the page.
180 */
181 private PageFormat mFormat;
182
183 /**
184 * The instance that will draw the page.
185 */
186 private Printable mPainter;
187
188 /**
189 * A new instance where 'format' describes the page's
190 * size and orientation and 'painter' is the instance
|