Book.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /* Book.java -- A mixed group of pages to print.
  2. Copyright (C) 1999 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package java.awt.print;
  32. import java.util.Vector;
  33. /**
  34. * This class allows documents to be created with different paper types,
  35. * page formatters, and painters.
  36. *
  37. * @author Aaron M. Renn (arenn@urbanophile.com)
  38. */
  39. public class Book implements Pageable
  40. {
  41. /*
  42. * Instance Variables
  43. */
  44. // Painter objects for the book
  45. Vector printables = new Vector();
  46. // Page formats for the book
  47. Vector page_formats = new Vector();
  48. /*************************************************************************/
  49. /*
  50. * Constructors
  51. */
  52. /**
  53. * Initializes a new instance of <code>Book</code> that is empty.
  54. */
  55. public
  56. Book()
  57. {
  58. ;
  59. }
  60. /*************************************************************************/
  61. /**
  62. * Returns the number of pages in this book.
  63. *
  64. * @return The number of pages in this book.
  65. */
  66. public int
  67. getNumberOfPages()
  68. {
  69. return(printables.size());
  70. }
  71. /*************************************************************************/
  72. /**
  73. * This method returns the <code>PageFormat</code> object for the
  74. * specified page.
  75. *
  76. * @param page_numbers The number of the page to get information for, where
  77. * page numbers start at 0.
  78. *
  79. * @return The <code>PageFormat</code> object for the specified page.
  80. *
  81. * @exception IndexOutOfBoundsException If the page number is not valid.
  82. */
  83. public PageFormat
  84. getPageFormat(int page_number)
  85. {
  86. return((PageFormat)page_formats.elementAt(page_number));
  87. }
  88. /*************************************************************************/
  89. /**
  90. * This method returns the <code>Printable</code> object for the
  91. * specified page.
  92. *
  93. * @param page_numbers The number of the page to get information for, where
  94. * page numbers start at 0.
  95. *
  96. * @return The <code>Printable</code> object for the specified page.
  97. *
  98. * @exception IndexOutOfBoundsException If the page number is not valid.
  99. */
  100. public Printable
  101. getPrintable(int page_number)
  102. {
  103. return((Printable)printables.elementAt(page_number));
  104. }
  105. /*************************************************************************/
  106. /**
  107. * This method appends a page to the end of the book.
  108. *
  109. * @param printable The <code>Printable</code> for this page.
  110. * @param page_format The <code>PageFormat</code> for this page.
  111. *
  112. * @exception NullPointerException If either argument is <code>null</code>.
  113. */
  114. public void
  115. append(Printable printable, PageFormat page_format)
  116. {
  117. append(printable, page_format, 1);
  118. }
  119. /*************************************************************************/
  120. /**
  121. * This method appends the specified number of pages to the end of the book.
  122. * Each one will be associated with the specified <code>Printable</code>
  123. * and <code>PageFormat</code>.
  124. *
  125. * @param printable The <code>Printable</code> for this page.
  126. * @param page_format The <code>PageFormat</code> for this page.
  127. * @param num_pages The number of pages to append.
  128. *
  129. * @exception NullPointerException If any argument is <code>null</code>.
  130. */
  131. public void
  132. append(Printable painter, PageFormat page_format, int num_pages)
  133. {
  134. for (int i = 0; i < num_pages; i++)
  135. {
  136. printables.addElement(painter);
  137. page_formats.addElement(page_format);
  138. }
  139. }
  140. /*************************************************************************/
  141. /**
  142. * This method changes the <code>Printable</code> and <code>PageFormat</code>
  143. * for the specified page. The page must already exist or an exception
  144. * will be thrown.
  145. *
  146. * @param page_num The page number to alter.
  147. * @param printable The new <code>Printable</code> for the page.
  148. * @param page_format The new <code>PageFormat</code> for the page.
  149. *
  150. * @param IndexOutOfBoundsException If the specified page does not exist.
  151. */
  152. public void
  153. setPage(int page_num, Printable printable, PageFormat page_format)
  154. {
  155. printables.setElementAt(printable, page_num);
  156. page_formats.setElementAt(page_format, page_num);
  157. }
  158. } // class Book