1 7 8 package java.awt.print; 9 10 import java.util.Vector ; 11 12 20 21 public class Book implements Pageable { 22 23 24 25 26 27 28 29 32 private Vector mPages; 33 34 35 36 39 public Book() { 40 mPages = new Vector (); 41 } 42 43 47 public int getNumberOfPages(){ 48 return mPages.size(); 49 } 50 51 61 public PageFormat getPageFormat(int pageIndex) 62 throws IndexOutOfBoundsException 63 { 64 return getPage(pageIndex).getPageFormat(); 65 } 66 67 76 public Printable getPrintable(int pageIndex) 77 throws IndexOutOfBoundsException 78 { 79 return getPage(pageIndex).getPrintable(); 80 } 81 82 95 public void setPage(int pageIndex, Printable painter, PageFormat page) 96 throws IndexOutOfBoundsException 97 { 98 if (painter == null) { 99 throw new NullPointerException ("painter is null"); 100 } 101 102 if (page == null) { 103 throw new NullPointerException ("page is null"); 104 } 105 106 mPages.setElementAt(new BookPage(painter, page), pageIndex); 107 } 108 109 118 public void append(Printable painter, PageFormat page) { 119 mPages.addElement(new BookPage(painter, page)); 120 } 121 122 135 public void append(Printable painter, PageFormat page, int numPages) { 136 BookPage bookPage = new BookPage(painter, page); 137 int pageIndex = mPages.size(); 138 int newSize = pageIndex + numPages; 139 140 mPages.setSize(newSize); 141 for(int i = pageIndex; i < newSize; i++){ 142 mPages.setElementAt(bookPage, i); 143 } 144 } 145 146 149 private BookPage getPage(int pageIndex) 150 throws ArrayIndexOutOfBoundsException 151 { 152 return (BookPage) mPages.elementAt(pageIndex); 153 } 154 155 159 private class BookPage { 160 163 private PageFormat mFormat; 164 165 168 private Printable mPainter; 169 170 178 BookPage(Printable painter, PageFormat format) { 179 180 if (painter == null || format == null) { 181 throw new NullPointerException (); 182 } 183 184 mFormat = format; 185 mPainter = painter; 186 } 187 188 192 Printable getPrintable() { 193 return mPainter; 194 } 195 196 199 PageFormat getPageFormat() { 200 return mFormat; 201 } 202 } 203 } 204 | Popular Tags |