001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Igor A. Pyankov
019: * @version $Revision$
020: */package java.awt.print;
021:
022: import java.util.Vector;
023:
024: import org.apache.harmony.awt.internal.nls.Messages;
025:
026: public class Book implements Pageable {
027:
028: private final Vector<innerPage> bookPages;
029:
030: // innerPage - class to describe inner structure of Book
031: private class innerPage {
032: private final PageFormat pageFormat;
033: private final Printable pagePainter;
034:
035: /* constructor */
036: innerPage(Printable painter, PageFormat page) {
037: super ();
038: if (painter == null) {
039: // awt.01='{0}' parameter is null
040: throw new NullPointerException(Messages.getString(
041: "awt.01", "painter")); //$NON-NLS-1$ //$NON-NLS-2$
042: }
043: if (page == null) {
044: // awt.01='{0}' parameter is null
045: throw new NullPointerException(Messages.getString(
046: "awt.01", "page")); //$NON-NLS-1$ //$NON-NLS-2$
047: }
048: pagePainter = painter;
049: pageFormat = page;
050: return;
051: }
052:
053: PageFormat getPageFormat() {
054: return pageFormat;
055: }
056:
057: Printable getPrintable() {
058: return pagePainter;
059: }
060: }
061:
062: public Book() {
063: bookPages = new Vector<innerPage>();
064: }
065:
066: public void append(Printable painter, PageFormat page) {
067: bookPages.addElement(new innerPage(painter, page));
068: }
069:
070: public void append(Printable painter, PageFormat page, int numPages) {
071: innerPage newpage = new innerPage(painter, page);
072: int orign_length = bookPages.size();
073: int new_length = orign_length + numPages;
074: bookPages.setSize(new_length);
075: for (int i = orign_length; i < new_length; i++) {
076: bookPages.setElementAt(newpage, i);
077: }
078: }
079:
080: public int getNumberOfPages() {
081: return bookPages.size();
082: }
083:
084: public PageFormat getPageFormat(int pageIndex)
085: throws IndexOutOfBoundsException {
086:
087: if (pageIndex >= getNumberOfPages()) {
088: // awt.5E=pageIndex is more than book size
089: throw new IndexOutOfBoundsException(Messages
090: .getString("awt.5E")); //$NON-NLS-1$
091: }
092: return bookPages.elementAt(pageIndex).getPageFormat();
093: }
094:
095: public Printable getPrintable(int pageIndex)
096: throws IndexOutOfBoundsException {
097:
098: if (pageIndex >= getNumberOfPages()) {
099: // awt.5E=pageIndex is more than book size
100: throw new IndexOutOfBoundsException(Messages
101: .getString("awt.5E")); //$NON-NLS-1$
102: }
103: return bookPages.elementAt(pageIndex).getPrintable();
104: }
105:
106: public void setPage(int pageIndex, Printable painter,
107: PageFormat page) throws IndexOutOfBoundsException {
108:
109: if (painter == null) {
110: throw new NullPointerException(Messages.getString(
111: "awt.01", "painter")); //$NON-NLS-1$
112: }
113:
114: if (page == null) {
115: throw new NullPointerException(Messages.getString(
116: "awt.01", "page")); //$NON-NLS-1$
117: }
118:
119: if (pageIndex >= getNumberOfPages()) {
120: // awt.5E=pageIndex is more than book size
121: throw new IndexOutOfBoundsException(Messages
122: .getString("awt.5E")); //$NON-NLS-1$
123: }
124: bookPages.setElementAt(new innerPage(painter, page), pageIndex);
125: }
126: }
|