home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-20 | 3.7 KB | 172 lines |
- /*
- * @(#)Book.java 1.4 98/03/18
- *
- * Copyright 1997, 1998 by Sun Microsystems, Inc.,
- * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
- * All rights reserved.
- *
- * This software is the confidential and proprietary information
- * of Sun Microsystems, Inc. ("Confidential Information"). You
- * shall not disclose such Confidential Information and shall use
- * it only in accordance with the terms of the license agreement
- * you entered into with Sun.
- */
-
- package java.awt.print;
-
- import java.util.Vector;
-
- /**
- * A Book maintains a list of pages to be printed.
- */
-
- public class Book implements Pageable {
-
- /* Class Constants */
-
- /* Class Variables */
-
- /* Instance Variables */
-
- /**
- * The set of pages that make up the Book.
- */
- private Vector mPages;
-
- /* Instance Methods */
-
- /**
- * Create a new, empty book.
- */
- public Book() {
- mPages = new Vector();
- }
-
- /**
- * Return the number of pages in this document.
- */
- public int getNumberOfPages(){
- return mPages.size();
- }
-
- public PageContext getPage(int pageIndex)
- throws IndexOutOfBoundsException {
- return (BookPageContext) mPages.elementAt(pageIndex);
- }
-
- /**
- * Set the page format and the painter for a
- * given page number. If the page specified is not
- * already in the book, then an IndexOutOfBoundsException
- * excpetion is thrown.
- */
- public void setPage(int pageNumber, PageFormat page, Printable painter)
- throws IndexOutOfBoundsException
- {
- mPages.setElementAt(new BookPageContext(page, painter, pageNumber),
- pageNumber);
- }
-
- /**
- * Append a single page to the end of this
- * document.
- */
- public void append(PageFormat page, Printable painter)
- {
- int pageIndex = mPages.size();
- mPages.addElement(new BookPageContext(page, painter, pageIndex));
- }
-
- /**
- * Append 'numPages' pages to the end of this document.
- * Each of the pages is associated with 'page'.
- */
- public void append(PageFormat page, Printable painter, int numPages)
- {
- int pageIndex = mPages.size();
- int newSize = pageIndex + numPages;
-
- mPages.setSize(newSize);
-
- for(int i = pageIndex; i < newSize; i++){
- setPage(i, page, painter);
- }
- }
-
- /**
- * The BookPageContext inner class describes an individual
- * page in a Book.
- */
- protected class BookPageContext implements PageContext
- {
- /**
- * The size and orientation of the page.
- */
- private PageFormat mFormat;
-
- /**
- * The instance that will draw the page.
- */
- private Printable mPainter;
-
- /**
- * The zero based index of this page inthe Book,
- */
- private int mIndex;
-
- /**
- * A new instance where 'format' describes the page's
- * size and orientation and 'painter' is the instance
- * that will draw the page's graphics.
- */
- protected BookPageContext(PageFormat format, Printable painter,
- int pageIndex) {
- set(format, painter);
- mIndex = pageIndex;
- }
-
- /**
- * Set the paper size and orientation, 'format', as
- * well as the instance that will draw the page,
- * 'painter'.
- */
- protected void set(PageFormat format, Printable painter) {
- mFormat = format;
- mPainter = painter;
- }
-
- /**
- * Return the instance that paints the
- * page.
- */
- public Printable getPagePainter() {
- return mPainter;
- }
-
- /**
- * Return the format of the page.
- */
- public PageFormat getPageFormat() {
- return mFormat;
- }
-
- /**
- * Return the name of the given page. This is
- * simply the page index plus 1 converted to
- * a String.
- */
- public String getPageName() {
- return Integer.toString(mIndex + 1);
- }
-
- /**
- * Return this page's index.
- */
- public int getPageIndex() {
- return mIndex;
- }
-
- }
- }
-
-