Showing the changes to java/pkg/java/awt/print (24 of 18352 files). Show all
Unified · Split
Binary file not shown.
Binary file not shown.
| @@ -0,0 +1,221 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2000, 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 | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package java.awt.print; | ||
| 27 | |||
| 28 | import java.util.Vector; | ||
| 29 | |||
| 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 | */ | ||
| 79 | public PageFormat getPageFormat(int pageIndex) | ||
| 80 | throws IndexOutOfBoundsException | ||
| 81 | { | ||
| 82 | return getPage(pageIndex).getPageFormat(); | ||
| 83 | } | ||
| 84 | |||
| 85 | /** | ||
| 86 | * Returns the {@link Printable} instance responsible for rendering | ||
| 87 | * the page specified by <code>pageIndex</code>. | ||
| 88 | * @param pageIndex the zero based index of the page whose | ||
| 89 | * <code>Printable</code> is being requested | ||
| 90 | * @return the <code>Printable</code> that renders the page. | ||
| 91 | * @throws IndexOutOfBoundsException if the <code>Pageable</code> | ||
| 92 | * does not contain the requested page | ||
| 93 | */ | ||
| 94 | public Printable getPrintable(int pageIndex) | ||
| 95 | throws IndexOutOfBoundsException | ||
| 96 | { | ||
| 97 | return getPage(pageIndex).getPrintable(); | ||
| 98 | } | ||
| 99 | |||
| 100 | /** | ||
| 101 | * Sets the <code>PageFormat</code> and the <code>Painter</code> for a | ||
| 102 | * specified page number. | ||
| 103 | * @param pageIndex the zero based index of the page whose | ||
| 104 | * painter and format is altered | ||
| 105 | * @param painter the <code>Printable</code> instance that | ||
| 106 | * renders the page | ||
| 107 | * @param page the size and orientation of the page | ||
| 108 | * @throws IndexOutOfBoundsException if the specified | ||
| 109 | * page is not already in this <code>Book</code> | ||
| 110 | * @throws NullPointerException if the <code>painter</code> or | ||
| 111 | * <code>page</code> argument is <code>null</code> | ||
| 112 | */ | ||
| 113 | public void setPage(int pageIndex, Printable painter, PageFormat page) | ||
| 114 | throws IndexOutOfBoundsException | ||
| 115 | { | ||
| 116 | if (painter == null) { | ||
| 117 | throw new NullPointerException("painter is null"); | ||
| 118 | } | ||
| 119 | |||
| 120 | if (page == null) { | ||
| 121 | throw new NullPointerException("page is null"); | ||
| 122 | } | ||
| 123 | |||
| 124 | mPages.setElementAt(new BookPage(painter, page), pageIndex); | ||
| 125 | } | ||
| 126 | |||
| 127 | /** | ||
| 128 | * Appends a single page to the end of this <code>Book</code>. | ||
| 129 | * @param painter the <code>Printable</code> instance that | ||
| 130 | * renders the page | ||
| 131 | * @param page the size and orientation of the page | ||
| 132 | * @throws <code>NullPointerException</code> | ||
| 133 | * If the <code>painter</code> or <code>page</code> | ||
| 134 | * argument is <code>null</code> | ||
| 135 | */ | ||
| 136 | public void append(Printable painter, PageFormat page) { | ||
| 137 | mPages.addElement(new BookPage(painter, page)); | ||
| 138 | } | ||
| 139 | |||
| 140 | /** | ||
| 141 | * Appends <code>numPages</code> pages to the end of this | ||
| 142 | * <code>Book</code>. Each of the pages is associated with | ||
| 143 | * <code>page</code>. | ||
| 144 | * @param painter the <code>Printable</code> instance that renders | ||
| 145 | * the page | ||
| 146 | * @param page the size and orientation of the page | ||
| 147 | * @param numPages the number of pages to be added to the | ||
| 148 | * this <code>Book</code>. | ||
| 149 | * @throws <code>NullPointerException</code> | ||
| 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 | ||
| 191 | * that will draw the page's graphics. | ||
| 192 | * @throws NullPointerException | ||
| 193 | * If the <code>painter</code> or <code>format</code> | ||
| 194 | * argument is <code>null</code> | ||
| 195 | */ | ||
| 196 | BookPage(Printable painter, PageFormat format) { | ||
| 197 | |||
| 198 | if (painter == null || format == null) { | ||
| 199 | throw new NullPointerException(); | ||
| 200 | } | ||
| 201 | |||
| 202 | mFormat = format; | ||
| 203 | mPainter = painter; | ||
| 204 | } | ||
| 205 | |||
| 206 | /** | ||
| 207 | * Return the instance that paints the | ||
| 208 | * page. | ||
| 209 | */ | ||
| 210 | Printable getPrintable() { | ||
| 211 | return mPainter; | ||
| 212 | } | ||
| 213 | |||
| 214 | /** | ||
| 215 | * Return the format of the page. | ||
| 216 | */ | ||
| 217 | PageFormat getPageFormat() { | ||
| 218 | return mFormat; | ||
| 219 | } | ||
| 220 | } | ||
| 221 | } | ||
Binary file not shown.
| @@ -0,0 +1,363 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2000, 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 | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package java.awt.print; | ||
| 27 | |||
| 28 | import java.awt.geom.AffineTransform; | ||
| 29 | import java.awt.geom.Point2D; | ||
| 30 | import java.awt.geom.Rectangle2D; | ||
| 31 | |||
| 32 | /** | ||
| 33 | * The <code>PageFormat</code> class describes the size and | ||
| 34 | * orientation of a page to be printed. | ||
| 35 | */ | ||
| 36 | public class PageFormat implements Cloneable | ||
| 37 | { | ||
| 38 | |||
| 39 | /* Class Constants */ | ||
| 40 | |||
| 41 | /** | ||
| 42 | * The origin is at the bottom left of the paper with | ||
| 43 | * x running bottom to top and y running left to right. | ||
| 44 | * Note that this is not the Macintosh landscape but | ||
| 45 | * is the Window's and PostScript landscape. | ||
| 46 | */ | ||
| 47 | public static final int LANDSCAPE = 0; | ||
| 48 | |||
| 49 | /** | ||
| 50 | * The origin is at the top left of the paper with | ||
| 51 | * x running to the right and y running down the | ||
| 52 | * paper. | ||
| 53 | */ | ||
| 54 | public static final int PORTRAIT = 1; | ||
| 55 | |||
| 56 | /** | ||
| 57 | * The origin is at the top right of the paper with x | ||
| 58 | * running top to bottom and y running right to left. | ||
| 59 | * Note that this is the Macintosh landscape. | ||
| 60 | */ | ||
| 61 | public static final int REVERSE_LANDSCAPE = 2; | ||
| 62 | |||
| 63 | /* Instance Variables */ | ||
| 64 | |||
| 65 | /** | ||
| 66 | * A description of the physical piece of paper. | ||
| 67 | */ | ||
| 68 | private Paper mPaper; | ||
| 69 | |||
| 70 | /** | ||
| 71 | * The orientation of the current page. This will be | ||
| 72 | * one of the constants: PORTRIAT, LANDSCAPE, or | ||
| 73 | * REVERSE_LANDSCAPE, | ||
| 74 | */ | ||
| 75 | private int mOrientation = PORTRAIT; | ||
| 76 | |||
| 77 | /* Constructors */ | ||
| 78 | |||
| 79 | /** | ||
| 80 | * Creates a default, portrait-oriented | ||
| 81 | * <code>PageFormat</code>. | ||
| 82 | */ | ||
| 83 | public PageFormat() | ||
| 84 | { | ||
| 85 | mPaper = new Paper(); | ||
| 86 | } | ||
| 87 | |||
| 88 | /* Instance Methods */ | ||
| 89 | |||
| 90 | /** | ||
| 91 | * Makes a copy of this <code>PageFormat</code> with the same | ||
| 92 | * contents as this <code>PageFormat</code>. | ||
| 93 | * @return a copy of this <code>PageFormat</code>. | ||
| 94 | */ | ||
| 95 | public Object clone() { | ||
| 96 | PageFormat newPage; | ||
| 97 | |||
| 98 | try { | ||
| 99 | newPage = (PageFormat) super.clone(); | ||
| 100 | newPage.mPaper = (Paper)mPaper.clone(); | ||
| 101 | |||
| 102 | } catch (CloneNotSupportedException e) { | ||
| 103 | e.printStackTrace(); | ||
| 104 | newPage = null; // should never happen. | ||
| 105 | } | ||
| 106 | |||
| 107 | return newPage; | ||
| 108 | } | ||
| 109 | |||
| 110 | |||
| 111 | /** | ||
| 112 | * Returns the width, in 1/72nds of an inch, of the page. | ||
| 113 | * This method takes into account the orientation of the | ||
| 114 | * page when determining the width. | ||
| 115 | * @return the width of the page. | ||
| 116 | */ | ||
| 117 | public double getWidth() { | ||
| 118 | double width; | ||
| 119 | int orientation = getOrientation(); | ||
| 120 | |||
| 121 | if (orientation == PORTRAIT) { | ||
| 122 | width = mPaper.getWidth(); | ||
| 123 | } else { | ||
| 124 | width = mPaper.getHeight(); | ||
| 125 | } | ||
| 126 | |||
| 127 | return width; | ||
| 128 | } | ||
| 129 | |||
| 130 | /** | ||
| 131 | * Returns the height, in 1/72nds of an inch, of the page. | ||
| 132 | * This method takes into account the orientation of the | ||
| 133 | * page when determining the height. | ||
| 134 | * @return the height of the page. | ||
| 135 | */ | ||
| 136 | public double getHeight() { | ||
| 137 | double height; | ||
| 138 | int orientation = getOrientation(); | ||
| 139 | |||
| 140 | if (orientation == PORTRAIT) { | ||
| 141 | height = mPaper.getHeight(); | ||
| 142 | } else { | ||
| 143 | height = mPaper.getWidth(); | ||
| 144 | } | ||
| 145 | |||
| 146 | return height; | ||
| 147 | } | ||
| 148 | |||
| 149 | /** | ||
| 150 | * Returns the x coordinate of the upper left point of the | ||
| 151 | * imageable area of the <code>Paper</code> object | ||
| 152 | * associated with this <code>PageFormat</code>. | ||
| 153 | * This method takes into account the | ||
| 154 | * orientation of the page. | ||
| 155 | * @return the x coordinate of the upper left point of the | ||
| 156 | * imageable area of the <code>Paper</code> object | ||
| 157 | * associated with this <code>PageFormat</code>. | ||
| 158 | */ | ||
| 159 | public double getImageableX() { | ||
| 160 | double x; | ||
| 161 | |||
| 162 | switch (getOrientation()) { | ||
| 163 | |||
| 164 | case LANDSCAPE: | ||
| 165 | x = mPaper.getHeight() | ||
| 166 | - (mPaper.getImageableY() + mPaper.getImageableHeight()); | ||
| 167 | break; | ||
| 168 | |||
| 169 | case PORTRAIT: | ||
| 170 | x = mPaper.getImageableX(); | ||
| 171 | break; | ||
| 172 | |||
| 173 | case REVERSE_LANDSCAPE: | ||
| 174 | x = mPaper.getImageableY(); | ||
| 175 | break; | ||
| 176 | |||
| 177 | default: | ||
| 178 | /* This should never happen since it signifies that the | ||
| 179 | * PageFormat is in an invalid orientation. | ||
| 180 | */ | ||
| 181 | throw new InternalError("unrecognized orientation"); | ||
| 182 | |||
| 183 | } | ||
| 184 | |||
| 185 | return x; | ||
| 186 | } | ||
| 187 | |||
| 188 | /** | ||
| 189 | * Returns the y coordinate of the upper left point of the | ||
| 190 | * imageable area of the <code>Paper</code> object | ||
| 191 | * associated with this <code>PageFormat</code>. | ||
| 192 | * This method takes into account the | ||
| 193 | * orientation of the page. | ||
| 194 | * @return the y coordinate of the upper left point of the | ||
| 195 | * imageable area of the <code>Paper</code> object | ||
| 196 | * associated with this <code>PageFormat</code>. | ||
| 197 | */ | ||
| 198 | public double getImageableY() { | ||
| 199 | double y; | ||
| 200 | |||
| 201 | switch (getOrientation()) { | ||
| 202 | |||
| 203 | case LANDSCAPE: | ||
| 204 | y = mPaper.getImageableX(); | ||
| 205 | break; | ||
| 206 | |||
| 207 | case PORTRAIT: | ||
| 208 | y = mPaper.getImageableY(); | ||
| 209 | break; | ||
| 210 | |||
| 211 | case REVERSE_LANDSCAPE: | ||
| 212 | y = mPaper.getWidth() | ||
| 213 | - (mPaper.getImageableX() + mPaper.getImageableWidth()); | ||
| 214 | break; | ||
| 215 | |||
| 216 | default: | ||
| 217 | /* This should never happen since it signifies that the | ||
| 218 | * PageFormat is in an invalid orientation. | ||
| 219 | */ | ||
| 220 | throw new InternalError("unrecognized orientation"); | ||
| 221 | |||
| 222 | } | ||
| 223 | |||
| 224 | return y; | ||
| 225 | } | ||
| 226 | |||
| 227 | /** | ||
| 228 | * Returns the width, in 1/72nds of an inch, of the imageable | ||
| 229 | * area of the page. This method takes into account the orientation | ||
| 230 | * of the page. | ||
| 231 | * @return the width of the page. | ||
| 232 | */ | ||
| 233 | public double getImageableWidth() { | ||
| 234 | double width; | ||
| 235 | |||
| 236 | if (getOrientation() == PORTRAIT) { | ||
| 237 | width = mPaper.getImageableWidth(); | ||
| 238 | } else { | ||
| 239 | width = mPaper.getImageableHeight(); | ||
| 240 | } | ||
| 241 | |||
| 242 | return width; | ||
| 243 | } | ||
| 244 | |||
| 245 | /** | ||
| 246 | * Return the height, in 1/72nds of an inch, of the imageable | ||
| 247 | * area of the page. This method takes into account the orientation | ||
| 248 | * of the page. | ||
| 249 | * @return the height of the page. | ||
| 250 | */ | ||
| 251 | public double getImageableHeight() { | ||
| 252 | double height; | ||
| 253 | |||
| 254 | if (getOrientation() == PORTRAIT) { | ||
| 255 | height = mPaper.getImageableHeight(); | ||
| 256 | } else { | ||
| 257 | height = mPaper.getImageableWidth(); | ||
| 258 | } | ||
| 259 | |||
| 260 | return height; | ||
| 261 | } | ||
| 262 | |||
| 263 | |||
| 264 | /** | ||
| 265 | * Returns a copy of the {@link Paper} object associated | ||
| 266 | * with this <code>PageFormat</code>. Changes made to the | ||
| 267 | * <code>Paper</code> object returned from this method do not | ||
| 268 | * affect the <code>Paper</code> object of this | ||
| 269 | * <code>PageFormat</code>. To update the <code>Paper</code> | ||
| 270 | * object of this <code>PageFormat</code>, create a new | ||
| 271 | * <code>Paper</code> object and set it into this | ||
| 272 | * <code>PageFormat</code> by using the {@link #setPaper(Paper)} | ||
| 273 | * method. | ||
| 274 | * @return a copy of the <code>Paper</code> object associated | ||
| 275 | * with this <code>PageFormat</code>. | ||
| 276 | * @see #setPaper | ||
| 277 | */ | ||
| 278 | public Paper getPaper() { | ||
| 279 | return (Paper)mPaper.clone(); | ||
| 280 | } | ||
| 281 | |||
| 282 | /** | ||
| 283 | * Sets the <code>Paper</code> object for this | ||
| 284 | * <code>PageFormat</code>. | ||
| 285 | * @param paper the <code>Paper</code> object to which to set | ||
| 286 | * the <code>Paper</code> object for this <code>PageFormat</code>. | ||
| 287 | * @exception <code>NullPointerException</code> | ||
| 288 | * a null paper instance was passed as a parameter. | ||
| 289 | * @see #getPaper | ||
| 290 | */ | ||
| 291 | public void setPaper(Paper paper) { | ||
| 292 | mPaper = (Paper)paper.clone(); | ||
| 293 | } | ||
| 294 | |||
| 295 | /** | ||
| 296 | * Sets the page orientation. <code>orientation</code> must be | ||
| 297 | * one of the constants: PORTRAIT, LANDSCAPE, | ||
| 298 | * or REVERSE_LANDSCAPE. | ||
| 299 | * @param orientation the new orientation for the page | ||
| 300 | * @throws IllegalArgumentException if | ||
| 301 | * an unknown orientation was requested | ||
| 302 | * @see #getOrientation | ||
| 303 | */ | ||
| 304 | public void setOrientation(int orientation) throws IllegalArgumentException | ||
| 305 | { | ||
| 306 | if (0 <= orientation && orientation <= REVERSE_LANDSCAPE) { | ||
| 307 | mOrientation = orientation; | ||
| 308 | } else { | ||
| 309 | throw new IllegalArgumentException(); | ||
| 310 | } | ||
| 311 | } | ||
| 312 | |||
| 313 | /** | ||
| 314 | * Returns the orientation of this <code>PageFormat</code>. | ||
| 315 | * @return this <code>PageFormat</code> object's orientation. | ||
| 316 | * @see #setOrientation | ||
| 317 | */ | ||
| 318 | public int getOrientation() { | ||
| 319 | return mOrientation; | ||
| 320 | } | ||
| 321 | |||
| 322 | /** | ||
| 323 | * Returns a transformation matrix that translates user | ||
| 324 | * space rendering to the requested orientation | ||
| 325 | * of the page. The values are placed into the | ||
| 326 | * array as | ||
| 327 | * { m00, m10, m01, m11, m02, m12} in | ||
| 328 | * the form required by the {@link AffineTransform} | ||
| 329 | * constructor. | ||
| 330 | * @return the matrix used to translate user space rendering | ||
| 331 | * to the orientation of the page. | ||
| 332 | * @see java.awt.geom.AffineTransform | ||
| 333 | */ | ||
| 334 | public double[] getMatrix() { | ||
| 335 | double[] matrix = new double[6]; | ||
| 336 | |||
| 337 | switch (mOrientation) { | ||
| 338 | |||
| 339 | case LANDSCAPE: | ||
| 340 | matrix[0] = 0; matrix[1] = -1; | ||
| 341 | matrix[2] = 1; matrix[3] = 0; | ||
| 342 | matrix[4] = 0; matrix[5] = mPaper.getHeight(); | ||
| 343 | break; | ||
| 344 | |||
| 345 | case PORTRAIT: | ||
| 346 | matrix[0] = 1; matrix[1] = 0; | ||
| 347 | matrix[2] = 0; matrix[3] = 1; | ||
| 348 | matrix[4] = 0; matrix[5] = 0; | ||
| 349 | break; | ||
| 350 | |||
| 351 | case REVERSE_LANDSCAPE: | ||
| 352 | matrix[0] = 0; matrix[1] = 1; | ||
| 353 | matrix[2] = -1; matrix[3] = 0; | ||
| 354 | matrix[4] = mPaper.getWidth(); matrix[5] = 0; | ||
| 355 | break; | ||
| 356 | |||
| 357 | default: | ||
| 358 | throw new IllegalArgumentException(); | ||
| 359 | } | ||
| 360 | |||
| 361 | return matrix; | ||
| 362 | } | ||
| 363 | } | ||
Binary file not shown.
| @@ -0,0 +1,83 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1998, 2000, 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 | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package java.awt.print; | ||
| 27 | |||
| 28 | /** | ||
| 29 | * The <code>Pageable</code> implementation represents a set of | ||
| 30 | * pages to be printed. The <code>Pageable</code> object returns | ||
| 31 | * the total number of pages in the set as well as the | ||
| 32 | * {@link PageFormat} and {@link Printable} for a specified page. | ||
| 33 | * @see java.awt.print.PageFormat | ||
| 34 | * @see java.awt.print.Printable | ||
| 35 | */ | ||
| 36 | public interface Pageable { | ||
| 37 | |||
| 38 | /** | ||
| 39 | * This constant is returned from the | ||
| 40 | * {@link #getNumberOfPages() getNumberOfPages} | ||
| 41 | * method if a <code>Pageable</code> implementation does not know | ||
| 42 | * the number of pages in its set. | ||
| 43 | */ | ||
| 44 | int UNKNOWN_NUMBER_OF_PAGES = -1; | ||
| 45 | |||
| 46 | /** | ||
| 47 | * Returns the number of pages in the set. | ||
| 48 | * To enable advanced printing features, | ||
| 49 | * it is recommended that <code>Pageable</code> | ||
| 50 | * implementations return the true number of pages | ||
| 51 | * rather than the | ||
| 52 | * UNKNOWN_NUMBER_OF_PAGES constant. | ||
| 53 | * @return the number of pages in this <code>Pageable</code>. | ||
| 54 | */ | ||
| 55 | int getNumberOfPages(); | ||
| 56 | |||
| 57 | /** | ||
| 58 | * Returns the <code>PageFormat</code> of the page specified by | ||
| 59 | * <code>pageIndex</code>. | ||
| 60 | * @param pageIndex the zero based index of the page whose | ||
| 61 | * <code>PageFormat</code> is being requested | ||
| 62 | * @return the <code>PageFormat</code> describing the size and | ||
| 63 | * orientation. | ||
| 64 | * @throws IndexOutOfBoundsException if | ||
| 65 | * the <code>Pageable</code> does not contain the requested | ||
| 66 | * page. | ||
| 67 | */ | ||
| 68 | PageFormat getPageFormat(int pageIndex) | ||
| 69 | throws IndexOutOfBoundsException; | ||
| 70 | |||
| 71 | /** | ||
| 72 | * Returns the <code>Printable</code> instance responsible for | ||
| 73 | * rendering the page specified by <code>pageIndex</code>. | ||
| 74 | * @param pageIndex the zero based index of the page whose | ||
| 75 | * <code>Printable</code> is being requested | ||
| 76 | * @return the <code>Printable</code> that renders the page. | ||
| 77 | * @throws IndexOutOfBoundsException if | ||
| 78 | * the <code>Pageable</code> does not contain the requested | ||
| 79 | * page. | ||
| 80 | */ | ||
| 81 | Printable getPrintable(int pageIndex) | ||
| 82 | throws IndexOutOfBoundsException; | ||
| 83 | } | ||
Binary file not shown.
| @@ -0,0 +1,209 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2006, 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 | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package java.awt.print; | ||
| 27 | |||
| 28 | import java.awt.geom.Rectangle2D; | ||
| 29 | |||
| 30 | /** | ||
| 31 | * The <code>Paper</code> class describes the physical characteristics of | ||
| 32 | * a piece of paper. | ||
| 33 | * <p> | ||
| 34 | * When creating a <code>Paper</code> object, it is the application's | ||
| 35 | * responsibility to ensure that the paper size and the imageable area | ||
| 36 | * are compatible. For example, if the paper size is changed from | ||
| 37 | * 11 x 17 to 8.5 x 11, the application might need to reduce the | ||
| 38 | * imageable area so that whatever is printed fits on the page. | ||
| 39 | * <p> | ||
| 40 | * @see #setSize(double, double) | ||
| 41 | * @see #setImageableArea(double, double, double, double) | ||
| 42 | */ | ||
| 43 | public class Paper implements Cloneable { | ||
| 44 | |||
| 45 | /* Private Class Variables */ | ||
| 46 | |||
| 47 | private static final int INCH = 72; | ||
| 48 | private static final double LETTER_WIDTH = 8.5 * INCH; | ||
| 49 | private static final double LETTER_HEIGHT = 11 * INCH; | ||
| 50 | |||
| 51 | /* Instance Variables */ | ||
| 52 | |||
| 53 | /** | ||
| 54 | * The height of the physical page in 1/72nds | ||
| 55 | * of an inch. The number is stored as a floating | ||
| 56 | * point value rather than as an integer | ||
| 57 | * to facilitate the conversion from metric | ||
| 58 | * units to 1/72nds of an inch and then back. | ||
| 59 | * (This may or may not be a good enough reason | ||
| 60 | * for a float). | ||
| 61 | */ | ||
| 62 | private double mHeight; | ||
| 63 | |||
| 64 | /** | ||
| 65 | * The width of the physical page in 1/72nds | ||
| 66 | * of an inch. | ||
| 67 | */ | ||
| 68 | private double mWidth; | ||
| 69 | |||
| 70 | /** | ||
| 71 | * The area of the page on which drawing will | ||
| 72 | * be visable. The area outside of this | ||
| 73 | * rectangle but on the Page generally | ||
| 74 | * reflects the printer's hardware margins. | ||
| 75 | * The origin of the physical page is | ||
| 76 | * at (0, 0) with this rectangle provided | ||
| 77 | * in that coordinate system. | ||
| 78 | */ | ||
| 79 | private Rectangle2D mImageableArea; | ||
| 80 | |||
| 81 | /* Constructors */ | ||
| 82 | |||
| 83 | /** | ||
| 84 | * Creates a letter sized piece of paper | ||
| 85 | * with one inch margins. | ||
| 86 | */ | ||
| 87 | public Paper() { | ||
| 88 | mHeight = LETTER_HEIGHT; | ||
| 89 | mWidth = LETTER_WIDTH; | ||
| 90 | mImageableArea = new Rectangle2D.Double(INCH, INCH, | ||
| 91 | mWidth - 2 * INCH, | ||
| 92 | mHeight - 2 * INCH); | ||
| 93 | } | ||
| 94 | |||
| 95 | /* Instance Methods */ | ||
| 96 | |||
| 97 | /** | ||
| 98 | * Creates a copy of this <code>Paper</code> with the same contents | ||
| 99 | * as this <code>Paper</code>. | ||
| 100 | * @return a copy of this <code>Paper</code>. | ||
| 101 | */ | ||
| 102 | public Object clone() { | ||
| 103 | |||
| 104 | Paper newPaper; | ||
| 105 | |||
| 106 | try { | ||
| 107 | /* It's okay to copy the reference to the imageable | ||
| 108 | * area into the clone since we always return a copy | ||
| 109 | * of the imageable area when asked for it. | ||
| 110 | */ | ||
| 111 | newPaper = (Paper) super.clone(); | ||
| 112 | |||
| 113 | } catch (CloneNotSupportedException e) { | ||
| 114 | e.printStackTrace(); | ||
| 115 | newPaper = null; // should never happen. | ||
| 116 | } | ||
| 117 | |||
| 118 | return newPaper; | ||
| 119 | } | ||
| 120 | |||
| 121 | /** | ||
| 122 | * Returns the height of the page in 1/72nds of an inch. | ||
| 123 | * @return the height of the page described by this | ||
| 124 | * <code>Paper</code>. | ||
| 125 | */ | ||
| 126 | public double getHeight() { | ||
| 127 | return mHeight; | ||
| 128 | } | ||
| 129 | |||
| 130 | /** | ||
| 131 | * Sets the width and height of this <code>Paper</code> | ||
| 132 | * object, which represents the properties of the page onto | ||
| 133 | * which printing occurs. | ||
| 134 | * The dimensions are supplied in 1/72nds of | ||
| 135 | * an inch. | ||
| 136 | * @param width the value to which to set this <code>Paper</code> | ||
| 137 | * object's width | ||
| 138 | * @param height the value to which to set this <code>Paper</code> | ||
| 139 | * object's height | ||
| 140 | */ | ||
| 141 | public void setSize(double width, double height) { | ||
| 142 | mWidth = width; | ||
| 143 | mHeight = height; | ||
| 144 | } | ||
| 145 | |||
| 146 | /** | ||
| 147 | * Returns the width of the page in 1/72nds | ||
| 148 | * of an inch. | ||
| 149 | * @return the width of the page described by this | ||
| 150 | * <code>Paper</code>. | ||
| 151 | */ | ||
| 152 | public double getWidth() { | ||
| 153 | return mWidth; | ||
| 154 | } | ||
| 155 | |||
| 156 | /** | ||
| 157 | * Sets the imageable area of this <code>Paper</code>. The | ||
| 158 | * imageable area is the area on the page in which printing | ||
| 159 | * occurs. | ||
| 160 | * @param x the X coordinate to which to set the | ||
| 161 | * upper-left corner of the imageable area of this <code>Paper</code> | ||
| 162 | * @param y the Y coordinate to which to set the | ||
| 163 | * upper-left corner of the imageable area of this <code>Paper</code> | ||
| 164 | * @param width the value to which to set the width of the | ||
| 165 | * imageable area of this <code>Paper</code> | ||
| 166 | * @param height the value to which to set the height of the | ||
| 167 | * imageable area of this <code>Paper</code> | ||
| 168 | */ | ||
| 169 | public void setImageableArea(double x, double y, | ||
| 170 | double width, double height) { | ||
| 171 | mImageableArea = new Rectangle2D.Double(x, y, width,height); | ||
| 172 | } | ||
| 173 | |||
| 174 | /** | ||
| 175 | * Returns the x coordinate of the upper-left corner of this | ||
| 176 | * <code>Paper</code> object's imageable area. | ||
| 177 | * @return the x coordinate of the imageable area. | ||
| 178 | */ | ||
| 179 | public double getImageableX() { | ||
| 180 | return mImageableArea.getX(); | ||
| 181 | } | ||
| 182 | |||
| 183 | /** | ||
| 184 | * Returns the y coordinate of the upper-left corner of this | ||
| 185 | * <code>Paper</code> object's imageable area. | ||
| 186 | * @return the y coordinate of the imageable area. | ||
| 187 | */ | ||
| 188 | public double getImageableY() { | ||
| 189 | return mImageableArea.getY(); | ||
| 190 | } | ||
| 191 | |||
| 192 | /** | ||
| 193 | * Returns the width of this <code>Paper</code> object's imageable | ||
| 194 | * area. | ||
| 195 | * @return the width of the imageable area. | ||
| 196 | */ | ||
| 197 | public double getImageableWidth() { | ||
| 198 | return mImageableArea.getWidth(); | ||
| 199 | } | ||
| 200 | |||
| 201 | /** | ||
| 202 | * Returns the height of this <code>Paper</code> object's imageable | ||
| 203 | * area. | ||
| 204 | * @return the height of the imageable area. | ||
| 205 | */ | ||
| 206 | public double getImageableHeight() { | ||
| 207 | return mImageableArea.getHeight(); | ||
| 208 | } | ||
| 209 | } | ||
Binary file not shown.
| @@ -0,0 +1,143 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2005, 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 | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package java.awt.print; | ||
| 27 | |||
| 28 | import java.awt.Graphics; | ||
| 29 | |||
| 30 | /** | ||
| 31 | * The <code>Printable</code> interface is implemented | ||
| 32 | * by the <code>print</code> methods of the current | ||
| 33 | * page painter, which is called by the printing | ||
| 34 | * system to render a page. When building a | ||
| 35 | * {@link Pageable}, pairs of {@link PageFormat} | ||
| 36 | * instances and instances that implement | ||
| 37 | * this interface are used to describe each page. The | ||
| 38 | * instance implementing <code>Printable</code> is called to | ||
| 39 | * print the page's graphics. | ||
| 40 | * <p> | ||
| 41 | * A <code>Printable(..)</code> may be set on a <code>PrinterJob</code>. | ||
| 42 | * When the client subsequently initiates printing by calling | ||
| 43 | * <code>PrinterJob.print(..)</code> control | ||
| 44 | * <p> | ||
| 45 | * is handed to the printing system until all pages have been printed. | ||
| 46 | * It does this by calling <code>Printable.print(..)</code> until | ||
| 47 | * all pages in the document have been printed. | ||
| 48 | * In using the <code>Printable</code> interface the printing | ||
| 49 | * commits to image the contents of a page whenever | ||
| 50 | * requested by the printing system. | ||
| 51 | * <p> | ||
| 52 | * The parameters to <code>Printable.print(..)</code> include a | ||
| 53 | * <code>PageFormat</code> which describes the printable area of | ||
| 54 | * the page, needed for calculating the contents that will fit the | ||
| 55 | * page, and the page index, which specifies the zero-based print | ||
| 56 | * stream index of the requested page. | ||
| 57 | * <p> | ||
| 58 | * For correct printing behaviour, the following points should be | ||
| 59 | * observed: | ||
| 60 | * <ul> | ||
| 61 | * <li> The printing system may request a page index more than once. | ||
| 62 | * On each occasion equal PageFormat parameters will be supplied. | ||
| 63 | * | ||
| 64 | * <li>The printing system will call <code>Printable.print(..)</code> | ||
| 65 | * with page indexes which increase monotonically, although as noted above, | ||
| 66 | * the <code>Printable</code> should expect multiple calls for a page index | ||
| 67 | * and that page indexes may be skipped, when page ranges are specified | ||
| 68 | * by the client, or by a user through a print dialog. | ||
| 69 | * | ||
| 70 | * <li>If multiple collated copies of a document are requested, and the | ||
| 71 | * printer cannot natively support this, then the document may be imaged | ||
| 72 | * multiple times. Printing will start each copy from the lowest print | ||
| 73 | * stream page index page. | ||
| 74 | * | ||
| 75 | * <li>With the exception of re-imaging an entire document for multiple | ||
| 76 | * collated copies, the increasing page index order means that when | ||
| 77 | * page N is requested if a client needs to calculate page break position, | ||
| 78 | * it may safely discard any state related to pages < N, and make current | ||
| 79 | * that for page N. "State" usually is just the calculated position in the | ||
| 80 | * document that corresponds to the start of the page. | ||
| 81 | * | ||
| 82 | * <li>When called by the printing system the <code>Printable</code> must | ||
| 83 | * inspect and honour the supplied PageFormat parameter as well as the | ||
| 84 | * page index. The format of the page to be drawn is specified by the | ||
| 85 | * supplied PageFormat. The size, orientation and imageable area of the page | ||
| 86 | * is therefore already determined and rendering must be within this | ||
| 87 | * imageable area. | ||
| 88 | * This is key to correct printing behaviour, and it has the | ||
| 89 | * implication that the client has the responsibility of tracking | ||
| 90 | * what content belongs on the specified page. | ||
| 91 | * | ||
| 92 | * <li>When the <code>Printable</code> is obtained from a client-supplied | ||
| 93 | * <code>Pageable</code> then the client may provide different PageFormats | ||
| 94 | * for each page index. Calculations of page breaks must account for this. | ||
| 95 | * </ul> | ||
| 96 | * <p> | ||
| 97 | * @see java.awt.print.Pageable | ||
| 98 | * @see java.awt.print.PageFormat | ||
| 99 | * @see java.awt.print.PrinterJob | ||
| 100 | */ | ||
| 101 | public interface Printable { | ||
| 102 | |||
| 103 | /** | ||
| 104 | * Returned from {@link #print(Graphics, PageFormat, int)} | ||
| 105 | * to signify that the requested page was rendered. | ||
| 106 | */ | ||
| 107 | int PAGE_EXISTS = 0; | ||
| 108 | |||
| 109 | /** | ||
| 110 | * Returned from <code>print</code> to signify that the | ||
| 111 | * <code>pageIndex</code> is too large and that the requested page | ||
| 112 | * does not exist. | ||
| 113 | */ | ||
| 114 | int NO_SUCH_PAGE = 1; | ||
| 115 | |||
| 116 | /** | ||
| 117 | * Prints the page at the specified index into the specified | ||
| 118 | * {@link Graphics} context in the specified | ||
| 119 | * format. A <code>PrinterJob</code> calls the | ||
| 120 | * <code>Printable</code> interface to request that a page be | ||
| 121 | * rendered into the context specified by | ||
| 122 | * <code>graphics</code>. The format of the page to be drawn is | ||
| 123 | * specified by <code>pageFormat</code>. The zero based index | ||
| 124 | * of the requested page is specified by <code>pageIndex</code>. | ||
| 125 | * If the requested page does not exist then this method returns | ||
| 126 | * NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned. | ||
| 127 | * The <code>Graphics</code> class or subclass implements the | ||
| 128 | * {@link PrinterGraphics} interface to provide additional | ||
| 129 | * information. If the <code>Printable</code> object | ||
| 130 | * aborts the print job then it throws a {@link PrinterException}. | ||
| 131 | * @param graphics the context into which the page is drawn | ||
| 132 | * @param pageFormat the size and orientation of the page being drawn | ||
| 133 | * @param pageIndex the zero based index of the page to be drawn | ||
| 134 | * @return PAGE_EXISTS if the page is rendered successfully | ||
| 135 | * or NO_SUCH_PAGE if <code>pageIndex</code> specifies a | ||
| 136 | * non-existent page. | ||
| 137 | * @exception java.awt.print.PrinterException | ||
| 138 | * thrown when the print job is terminated. | ||
| 139 | */ | ||
| 140 | int print(Graphics graphics, PageFormat pageFormat, int pageIndex) | ||
| 141 | throws PrinterException; | ||
| 142 | |||
| 143 | } | ||
Binary file not shown.
| @@ -0,0 +1,55 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1998, 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 | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package java.awt.print; | ||
| 27 | |||
| 28 | /** | ||
| 29 | * The <code>PrinterAbortException</code> class is a subclass of | ||
| 30 | * {@link PrinterException} and is used to indicate that a user | ||
| 31 | * or application has terminated the print job while it was in | ||
| 32 | * the process of printing. | ||
| 33 | */ | ||
| 34 | |||
| 35 | public class PrinterAbortException extends PrinterException { | ||
| 36 | |||
| 37 | /** | ||
| 38 | * Constructs a new <code>PrinterAbortException</code> with no | ||
| 39 | * detail message. | ||
| 40 | */ | ||
| 41 | public PrinterAbortException() { | ||
| 42 | super(); | ||
| 43 | } | ||
| 44 | |||
| 45 | /** | ||
| 46 | * Constructs a new <code>PrinterAbortException</code> with | ||
| 47 | * the specified detail message. | ||
| 48 | * @param msg the message to be generated when a | ||
| 49 | * <code>PrinterAbortException</code> is thrown | ||
| 50 | */ | ||
| 51 | public PrinterAbortException(String msg) { | ||
| 52 | super(msg); | ||
| 53 | } | ||
| 54 | |||
| 55 | } | ||
Binary file not shown.
| @@ -0,0 +1,53 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1998, 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 | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package java.awt.print; | ||
| 27 | |||
| 28 | /** | ||
| 29 | * The <code>PrinterException</code> class and its subclasses are used | ||
| 30 | * to indicate that an exceptional condition has occurred in the print | ||
| 31 | * system. | ||
| 32 | */ | ||
| 33 | |||
| 34 | public class PrinterException extends Exception { | ||
| 35 | |||
| 36 | /** | ||
| 37 | * Constructs a new <code>PrinterException</code> object | ||
| 38 | * without a detail message. | ||
| 39 | */ | ||
| 40 | public PrinterException() { | ||
| 41 | |||
| 42 | } | ||
| 43 | |||
| 44 | /** | ||
| 45 | * Constructs a new <code>PrinterException</code> object | ||
| 46 | * with the specified detail message. | ||
| 47 | * @param msg the message to generate when a | ||
| 48 | * <code>PrinterException</code> is thrown | ||
| 49 | */ | ||
| 50 | public PrinterException(String msg) { | ||
| 51 | super(msg); | ||
| 52 | } | ||
| 53 | } | ||
Binary file not shown.
| @@ -0,0 +1,47 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1998, 1999, 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 | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package java.awt.print; | ||
| 27 | |||
| 28 | /** | ||
| 29 | * The <code>PrinterGraphics</code> interface is implemented by | ||
| 30 | * {@link java.awt.Graphics} objects that are passed to | ||
| 31 | * {@link Printable} objects to render a page. It allows an | ||
| 32 | * application to find the {@link PrinterJob} object that is | ||
| 33 | * controlling the printing. | ||
| 34 | */ | ||
| 35 | |||
| 36 | public interface PrinterGraphics { | ||
| 37 | |||
| 38 | /** | ||
| 39 | * Returns the <code>PrinterJob</code> that is controlling the | ||
| 40 | * current rendering request. | ||
| 41 | * @return the <code>PrinterJob</code> controlling the current | ||
| 42 | * rendering request. | ||
| 43 | * @see java.awt.print.Printable | ||
| 44 | */ | ||
| 45 | PrinterJob getPrinterJob(); | ||
| 46 | |||
| 47 | } | ||
Binary file not shown.
| @@ -0,0 +1,88 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1998, 2000, 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 | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package java.awt.print; | ||
| 27 | import java.io.IOException; | ||
| 28 | |||
| 29 | /** | ||
| 30 | * The <code>PrinterIOException</code> class is a subclass of | ||
| 31 | * {@link PrinterException} and is used to indicate that an IO error | ||
| 32 | * of some sort has occurred while printing. | ||
| 33 | * | ||
| 34 | * <p>As of release 1.4, this exception has been retrofitted to conform to | ||
| 35 | * the general purpose exception-chaining mechanism. The | ||
| 36 | * "<code>IOException</code> that terminated the print job" | ||
| 37 | * that is provided at construction time and accessed via the | ||
| 38 | * {@link #getIOException()} method is now known as the <i>cause</i>, | ||
| 39 | * and may be accessed via the {@link Throwable#getCause()} method, | ||
| 40 | * as well as the aforementioned "legacy method." | ||
| 41 | */ | ||
| 42 | public class PrinterIOException extends PrinterException { | ||
| 43 | static final long serialVersionUID = 5850870712125932846L; | ||
| 44 | |||
| 45 | /** | ||
| 46 | * The IO error that terminated the print job. | ||
| 47 | * @serial | ||
| 48 | */ | ||
| 49 | private IOException mException; | ||
| 50 | |||
| 51 | /** | ||
| 52 | * Constructs a new <code>PrinterIOException</code> | ||
| 53 | * with the string representation of the specified | ||
| 54 | * {@link IOException}. | ||
| 55 | * @param exception the specified <code>IOException</code> | ||
| 56 | */ | ||
| 57 | public PrinterIOException(IOException exception) { | ||
| 58 | initCause(null); // Disallow subsequent initCause | ||
| 59 | mException = exception; | ||
| 60 | } | ||
| 61 | |||
| 62 | /** | ||
| 63 | * Returns the <code>IOException</code> that terminated | ||
| 64 | * the print job. | ||
| 65 | * | ||
| 66 | * <p>This method predates the general-purpose exception chaining facility. | ||
| 67 | * The {@link Throwable#getCause()} method is now the preferred means of | ||
| 68 | * obtaining this information. | ||
| 69 | * | ||
| 70 | * @return the <code>IOException</code> that terminated | ||
| 71 | * the print job. | ||
| 72 | * @see IOException | ||
| 73 | */ | ||
| 74 | public IOException getIOException() { | ||
| 75 | return mException; | ||
| 76 | } | ||
| 77 | |||
| 78 | /** | ||
| 79 | * Returns the the cause of this exception (the <code>IOException</code> | ||
| 80 | * that terminated the print job). | ||
| 81 | * | ||
| 82 | * @return the cause of this exception. | ||
| 83 | * @since 1.4 | ||
| 84 | */ | ||
| 85 | public Throwable getCause() { | ||
| 86 | return mException; | ||
| 87 | } | ||
| 88 | } | ||
Binary file not shown.
Binary file not shown.
| @@ -0,0 +1,619 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2006, 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 | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package java.awt.print; | ||
| 27 | |||
| 28 | import java.awt.AWTError; | ||
| 29 | import java.awt.HeadlessException; | ||
| 30 | import java.util.Enumeration; | ||
| 31 | |||
| 32 | import javax.print.DocFlavor; | ||
| 33 | import javax.print.PrintService; | ||
| 34 | import javax.print.PrintServiceLookup; | ||
| 35 | import javax.print.StreamPrintServiceFactory; | ||
| 36 | import javax.print.attribute.PrintRequestAttributeSet; | ||
| 37 | import javax.print.attribute.standard.Media; | ||
| 38 | import javax.print.attribute.standard.MediaPrintableArea; | ||
| 39 | import javax.print.attribute.standard.MediaSize; | ||
| 40 | import javax.print.attribute.standard.MediaSizeName; | ||
| 41 | import javax.print.attribute.standard.OrientationRequested; | ||
| 42 | |||
| 43 | import sun.security.action.GetPropertyAction; | ||
| 44 | |||
| 45 | /** | ||
| 46 | * The <code>PrinterJob</code> class is the principal class that controls | ||
| 47 | * printing. An application calls methods in this class to set up a job, | ||
| 48 | * optionally to invoke a print dialog with the user, and then to print | ||
| 49 | * the pages of the job. | ||
| 50 | */ | ||
| 51 | public abstract class PrinterJob { | ||
| 52 | |||
| 53 | /* Public Class Methods */ | ||
| 54 | |||
| 55 | /** | ||
| 56 | * Creates and returns a <code>PrinterJob</code> which is initially | ||
| 57 | * associated with the default printer. | ||
| 58 | * If no printers are available on the system, a PrinterJob will still | ||
| 59 | * be returned from this method, but <code>getPrintService()</code> | ||
| 60 | * will return <code>null</code>, and calling | ||
| 61 | * {@link #print() print} with this <code>PrinterJob</code> might | ||
| 62 | * generate an exception. Applications that need to determine if | ||
| 63 | * there are suitable printers before creating a <code>PrinterJob</code> | ||
| 64 | * should ensure that the array returned from | ||
| 65 | * {@link #lookupPrintServices() lookupPrintServices} is not empty. | ||
| 66 | * @return a new <code>PrinterJob</code>. | ||
| 67 | * | ||
| 68 | * @throws SecurityException if a security manager exists and its | ||
| 69 | * {@link java.lang.SecurityManager#checkPrintJobAccess} | ||
| 70 | * method disallows this thread from creating a print job request | ||
| 71 | */ | ||
| 72 | public static PrinterJob getPrinterJob() { | ||
| 73 | SecurityManager security = System.getSecurityManager(); | ||
| 74 | if (security != null) { | ||
| 75 | security.checkPrintJobAccess(); | ||
| 76 | } | ||
| 77 | return (PrinterJob) java.security.AccessController.doPrivileged( | ||
| 78 | new java.security.PrivilegedAction() { | ||
| 79 | public Object run() { | ||
| 80 | String nm = System.getProperty("java.awt.printerjob", null); | ||
| 81 | try { | ||
| 82 | return (PrinterJob)Class.forName(nm).newInstance(); | ||
| 83 | } catch (ClassNotFoundException e) { | ||
| 84 | throw new AWTError("PrinterJob not found: " + nm); | ||
| 85 | } catch (InstantiationException e) { | ||
| 86 | throw new AWTError("Could not instantiate PrinterJob: " + nm); | ||
| 87 | } catch (IllegalAccessException e) { | ||
| 88 | throw new AWTError("Could not access PrinterJob: " + nm); | ||
| 89 | } | ||
| 90 | } | ||
| 91 | }); | ||
| 92 | } | ||
| 93 | |||
| 94 | /** | ||
| 95 | * A convenience method which looks up 2D print services. | ||
| 96 | * Services returned from this method may be installed on | ||
| 97 | * <code>PrinterJob</code>s which support print services. | ||
| 98 | * Calling this method is equivalent to calling | ||
| 99 | * {@link javax.print.PrintServiceLookup#lookupPrintServices( | ||
| 100 | * DocFlavor, AttributeSet) | ||
| 101 | * <code>PrintServiceLookup.lookupPrintServices()</code>} | ||
| 102 | * and specifying a Pageable DocFlavor. | ||
| 103 | * @return a possibly empty array of 2D print services. | ||
| 104 | * @since 1.4 | ||
| 105 | */ | ||
| 106 | public static PrintService[] lookupPrintServices() { | ||
| 107 | return PrintServiceLookup. | ||
| 108 | lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null); | ||
| 109 | } | ||
| 110 | |||
| 111 | |||
| 112 | /** | ||
| 113 | * A convenience method which locates factories for stream print | ||
| 114 | * services which can image 2D graphics. | ||
| 115 | * Sample usage : | ||
| 116 | * <pre> | ||
| 117 | * FileOutputStream outstream; | ||
| 118 | * StreamPrintService psPrinter; | ||
| 119 | * String psMimeType = "application/postscript"; | ||
| 120 | * PrinterJob pj = PrinterJob.getPrinterJob(); | ||
| 121 | * | ||
| 122 | * StreamPrintServiceFactory[] factories = | ||
| 123 | * PrinterJob.lookupStreamPrintServices(psMimeType); | ||
| 124 | * if (factories.length > 0) { | ||
| 125 | * try { | ||
| 126 | * outstream = new File("out.ps"); | ||
| 127 | * psPrinter = factories[0].getPrintService(outstream); | ||
| 128 | * // psPrinter can now be set as the service on a PrinterJob | ||
| 129 | * pj.setPrintService(psPrinter) | ||
| 130 | * } catch (Exception e) { | ||
| 131 | * e.printStackTrace(); | ||
| 132 | * } | ||
| 133 | * } | ||
| 134 | * </pre> | ||
| 135 | * Services returned from this method may be installed on | ||
| 136 | * <code>PrinterJob</code> instances which support print services. | ||
| 137 | * Calling this method is equivalent to calling | ||
| 138 | * {@link javax.print.StreamPrintServiceFactory#lookupStreamPrintServiceFactories(DocFlavor, String) | ||
| 139 | * <code>StreamPrintServiceFactory.lookupStreamPrintServiceFactories() | ||
| 140 | * </code>} and specifying a Pageable DocFlavor. | ||
| 141 | * | ||
| 142 | * @param mimeType the required output format, or null to mean any format. | ||
| 143 | * @return a possibly empty array of 2D stream print service factories. | ||
| 144 | * @since 1.4 | ||
| 145 | */ | ||
| 146 | public static StreamPrintServiceFactory[] | ||
| 147 | lookupStreamPrintServices(String mimeType) { | ||
| 148 | return StreamPrintServiceFactory.lookupStreamPrintServiceFactories( | ||
| 149 | DocFlavor.SERVICE_FORMATTED.PAGEABLE, | ||
| 150 | mimeType); | ||
| 151 | } | ||
| 152 | |||
| 153 | |||
| 154 | /* Public Methods */ | ||
| 155 | |||
| 156 | /** | ||
| 157 | * A <code>PrinterJob</code> object should be created using the | ||
| 158 | * static {@link #getPrinterJob() <code>getPrinterJob</code>} method. | ||
| 159 | */ | ||
| 160 | public PrinterJob() { | ||
| 161 | } | ||
| 162 | |||
| 163 | /** | ||
| 164 | * Returns the service (printer) for this printer job. | ||
| 165 | * Implementations of this class which do not support print services | ||
| 166 | * may return null. null will also be returned if no printers are | ||
| 167 | * available. | ||
| 168 | * @return the service for this printer job. | ||
| 169 | * @see #setPrintService(PrintService) | ||
| 170 | * @see #getPrinterJob() | ||
| 171 | * @since 1.4 | ||
| 172 | */ | ||
| 173 | public PrintService getPrintService() { | ||
| 174 | return null; | ||
| 175 | } | ||
| 176 | |||
| 177 | /** | ||
| 178 | * Associate this PrinterJob with a new PrintService. | ||
| 179 | * This method is overridden by subclasses which support | ||
| 180 | * specifying a Print Service. | ||
| 181 | * | ||
| 182 | * Throws <code>PrinterException</code> if the specified service | ||
| 183 | * cannot support the <code>Pageable</code> and | ||
| 184 | * <code>Printable</code> interfaces necessary to support 2D printing. | ||
| 185 | * @param service a print service that supports 2D printing | ||
| 186 | * @exception PrinterException if the specified service does not support | ||
| 187 | * 2D printing, or this PrinterJob class does not support | ||
| 188 | * setting a 2D print service, or the specified service is | ||
| 189 | * otherwise not a valid print service. | ||
| 190 | * @see #getPrintService | ||
| 191 | * @since 1.4 | ||
| 192 | */ | ||
| 193 | public void setPrintService(PrintService service) | ||
| 194 | throws PrinterException { | ||
| 195 | throw new PrinterException( | ||
| 196 | "Setting a service is not supported on this class"); | ||
| 197 | } | ||
| 198 | |||
| 199 | /** | ||
| 200 | * Calls <code>painter</code> to render the pages. The pages in the | ||
| 201 | * document to be printed by this | ||
| 202 | * <code>PrinterJob</code> are rendered by the {@link Printable} | ||
| 203 | * object, <code>painter</code>. The {@link PageFormat} for each page | ||
| 204 | * is the default page format. | ||
| 205 | * @param painter the <code>Printable</code> that renders each page of | ||
| 206 | * the document. | ||
| 207 | */ | ||
| 208 | public abstract void setPrintable(Printable painter); | ||
| 209 | |||
| 210 | /** | ||
| 211 | * Calls <code>painter</code> to render the pages in the specified | ||
| 212 | * <code>format</code>. The pages in the document to be printed by | ||
| 213 | * this <code>PrinterJob</code> are rendered by the | ||
| 214 | * <code>Printable</code> object, <code>painter</code>. The | ||
| 215 | * <code>PageFormat</code> of each page is <code>format</code>. | ||
| 216 | * @param painter the <code>Printable</code> called to render | ||
| 217 | * each page of the document | ||
| 218 | * @param format the size and orientation of each page to | ||
| 219 | * be printed | ||
| 220 | */ | ||
| 221 | public abstract void setPrintable(Printable painter, PageFormat format); | ||
| 222 | |||
| 223 | /** | ||
| 224 | * Queries <code>document</code> for the number of pages and | ||
| 225 | * the <code>PageFormat</code> and <code>Printable</code> for each | ||
| 226 | * page held in the <code>Pageable</code> instance, | ||
| 227 | * <code>document</code>. | ||
| 228 | * @param document the pages to be printed. It can not be | ||
| 229 | * <code>null</code>. | ||
| 230 | * @exception NullPointerException the <code>Pageable</code> passed in | ||
| 231 | * was <code>null</code>. | ||
| 232 | * @see PageFormat | ||
| 233 | * @see Printable | ||
| 234 | */ | ||
| 235 | public abstract void setPageable(Pageable document) | ||
| 236 | throws NullPointerException; | ||
| 237 | |||
| 238 | /** | ||
| 239 | * Presents a dialog to the user for changing the properties of | ||
| 240 | * the print job. | ||
| 241 | * This method will display a native dialog if a native print | ||
| 242 | * service is selected, and user choice of printers will be restricted | ||
| 243 | * to these native print services. | ||
| 244 | * To present the cross platform print dialog for all services, | ||
| 245 | * including native ones instead use | ||
| 246 | * <code>printDialog(PrintRequestAttributeSet)</code>. | ||
| 247 | * <p> | ||
| 248 | * PrinterJob implementations which can use PrintService's will update | ||
| 249 | * the PrintService for this PrinterJob to reflect the new service | ||
| 250 | * selected by the user. | ||
| 251 | * @return <code>true</code> if the user does not cancel the dialog; | ||
| 252 | * <code>false</code> otherwise. | ||
| 253 | * @exception HeadlessException if GraphicsEnvironment.isHeadless() | ||
| 254 | * returns true. | ||
| 255 | * @see java.awt.GraphicsEnvironment#isHeadless | ||
| 256 | */ | ||
| 257 | public abstract boolean printDialog() throws HeadlessException; | ||
| 258 | |||
| 259 | /** | ||
| 260 | * A convenience method which displays a cross-platform print dialog | ||
| 261 | * for all services which are capable of printing 2D graphics using the | ||
| 262 | * <code>Pageable</code> interface. The selected printer when the | ||
| 263 | * dialog is initially displayed will reflect the print service currently | ||
| 264 | * attached to this print job. | ||
| 265 | * If the user changes the print service, the PrinterJob will be | ||
| 266 | * updated to reflect this, unless the user cancels the dialog. | ||
| 267 | * As well as allowing the user to select the destination printer, | ||
| 268 | * the user can also select values of various print request attributes. | ||
| 269 | * <p> | ||
| 270 | * The attributes parameter on input will reflect the applications | ||
| 271 | * required initial selections in the user dialog. Attributes not | ||
| 272 | * specified display using the default for the service. On return it | ||
| 273 | * will reflect the user's choices. Selections may be updated by | ||
| 274 | * the implementation to be consistent with the supported values | ||
| 275 | * for the currently selected print service. | ||
| 276 | * <p> | ||
| 277 | * As the user scrolls to a new print service selection, the values | ||
| 278 | * copied are based on the settings for the previous service, together | ||
| 279 | * with any user changes. The values are not based on the original | ||
| 280 | * settings supplied by the client. | ||
| 281 | * <p> | ||
| 282 | * With the exception of selected printer, the PrinterJob state is | ||
| 283 | * not updated to reflect the user's changes. | ||
| 284 | * For the selections to affect a printer job, the attributes must | ||
| 285 | * be specified in the call to the | ||
| 286 | * <code>print(PrintRequestAttributeSet)</code> method. If using | ||
| 287 | * the Pageable interface, clients which intend to use media selected | ||
| 288 | * by the user must create a PageFormat derived from the user's | ||
| 289 | * selections. | ||
| 290 | * If the user cancels the dialog, the attributes will not reflect | ||
| 291 | * any changes made by the user. | ||
| 292 | * @param attributes on input is application supplied attributes, | ||
| 293 | * on output the contents are updated to reflect user choices. | ||
| 294 | * This parameter may not be null. | ||
| 295 | * @return <code>true</code> if the user does not cancel the dialog; | ||
| 296 | * <code>false</code> otherwise. | ||
| 297 | * @exception HeadlessException if GraphicsEnvironment.isHeadless() | ||
| 298 | * returns true. | ||
| 299 | * @exception NullPointerException if <code>attributes</code> parameter | ||
| 300 | * is null. | ||
| 301 | * @see java.awt.GraphicsEnvironment#isHeadless | ||
| 302 | * @since 1.4 | ||
| 303 | * | ||
| 304 | */ | ||
| 305 | public boolean printDialog(PrintRequestAttributeSet attributes) | ||
| 306 | throws HeadlessException { | ||
| 307 | |||
| 308 | if (attributes == null) { | ||
| 309 | throw new NullPointerException("attributes"); | ||
| 310 | } | ||
| 311 | return printDialog(); | ||
| 312 | } | ||
| 313 | |||
| 314 | /** | ||
| 315 | * Displays a dialog that allows modification of a | ||
| 316 | * <code>PageFormat</code> instance. | ||
| 317 | * The <code>page</code> argument is used to initialize controls | ||
| 318 | * in the page setup dialog. | ||
| 319 | * If the user cancels the dialog then this method returns the | ||
| 320 | * original <code>page</code> object unmodified. | ||
| 321 | * If the user okays the dialog then this method returns a new | ||
| 322 | * <code>PageFormat</code> object with the indicated changes. | ||
| 323 | * In either case, the original <code>page</code> object is | ||
| 324 | * not modified. | ||
| 325 | * @param page the default <code>PageFormat</code> presented to the | ||
| 326 | * user for modification | ||
| 327 | * @return the original <code>page</code> object if the dialog | ||
| 328 | * is cancelled; a new <code>PageFormat</code> object | ||
| 329 | * containing the format indicated by the user if the | ||
| 330 | * dialog is acknowledged. | ||
| 331 | * @exception HeadlessException if GraphicsEnvironment.isHeadless() | ||
| 332 | * returns true. | ||
| 333 | * @see java.awt.GraphicsEnvironment#isHeadless | ||
| 334 | * @since 1.2 | ||
| 335 | */ | ||
| 336 | public abstract PageFormat pageDialog(PageFormat page) | ||
| 337 | throws HeadlessException; | ||
| 338 | |||
| 339 | /** | ||
| 340 | * A convenience method which displays a cross-platform page setup dialog. | ||
| 341 | * The choices available will reflect the print service currently | ||
| 342 | * set on this PrinterJob. | ||
| 343 | * <p> | ||
| 344 | * The attributes parameter on input will reflect the client's | ||
| 345 | * required initial selections in the user dialog. Attributes which are | ||
| 346 | * not specified display using the default for the service. On return it | ||
| 347 | * will reflect the user's choices. Selections may be updated by | ||
| 348 | * the implementation to be consistent with the supported values | ||
| 349 | * for the currently selected print service. | ||
| 350 | * <p> | ||
| 351 | * The return value will be a PageFormat equivalent to the | ||
| 352 | * selections in the PrintRequestAttributeSet. | ||
| 353 | * If the user cancels the dialog, the attributes will not reflect | ||
| 354 | * any changes made by the user, and the return value will be null. | ||
| 355 | * @param attributes on input is application supplied attributes, | ||
| 356 | * on output the contents are updated to reflect user choices. | ||
| 357 | * This parameter may not be null. | ||
| 358 | * @return a page format if the user does not cancel the dialog; | ||
| 359 | * <code>null</code> otherwise. | ||
| 360 | * @exception HeadlessException if GraphicsEnvironment.isHeadless() | ||
| 361 | * returns true. | ||
| 362 | * @exception NullPointerException if <code>attributes</code> parameter | ||
| 363 | * is null. | ||
| 364 | * @see java.awt.GraphicsEnvironment#isHeadless | ||
| 365 | * @since 1.4 | ||
| 366 | * | ||
| 367 | */ | ||
| 368 | public PageFormat pageDialog(PrintRequestAttributeSet attributes) | ||
| 369 | throws HeadlessException { | ||
| 370 | |||
| 371 | if (attributes == null) { | ||
| 372 | throw new NullPointerException("attributes"); | ||
| 373 | } | ||
| 374 | return pageDialog(defaultPage()); | ||
| 375 | } | ||
| 376 | |||
| 377 | /** | ||
| 378 | * Clones the <code>PageFormat</code> argument and alters the | ||
| 379 | * clone to describe a default page size and orientation. | ||
| 380 | * @param page the <code>PageFormat</code> to be cloned and altered | ||
| 381 | * @return clone of <code>page</code>, altered to describe a default | ||
| 382 | * <code>PageFormat</code>. | ||
| 383 | */ | ||
| 384 | public abstract PageFormat defaultPage(PageFormat page); | ||
| 385 | |||
| 386 | /** | ||
| 387 | * Creates a new <code>PageFormat</code> instance and | ||
| 388 | * sets it to a default size and orientation. | ||
| 389 | * @return a <code>PageFormat</code> set to a default size and | ||
| 390 | * orientation. | ||
| 391 | */ | ||
| 392 | public PageFormat defaultPage() { | ||
| 393 | return defaultPage(new PageFormat()); | ||
| 394 | } | ||
| 395 | |||
| 396 | /** | ||
| 397 | * Calculates a <code>PageFormat</code> with values consistent with those | ||
| 398 | * supported by the current <code>PrintService</code> for this job | ||
| 399 | * (ie the value returned by <code>getPrintService()</code>) and media, | ||
| 400 | * printable area and orientation contained in <code>attributes</code>. | ||
| 401 | * <p> | ||
| 402 | * Calling this method does not update the job. | ||
| 403 | * It is useful for clients that have a set of attributes obtained from | ||
| 404 | * <code>printDialog(PrintRequestAttributeSet attributes)</code> | ||
| 405 | * and need a PageFormat to print a Pageable object. | ||
| 406 | * @param attributes a set of printing attributes, for example obtained | ||
| 407 | * from calling printDialog. If <code>attributes</code> is null a default | ||
| 408 | * PageFormat is returned. | ||
| 409 | * @return a <code>PageFormat</code> whose settings conform with | ||
| 410 | * those of the current service and the specified attributes. | ||
| 411 | * @since 1.6 | ||
| 412 | */ | ||
| 413 | public PageFormat getPageFormat(PrintRequestAttributeSet attributes) { | ||
| 414 | |||
| 415 | PrintService service = getPrintService(); | ||
| 416 | PageFormat pf = defaultPage(); | ||
| 417 | |||
| 418 | if (service == null || attributes == null) { | ||
| 419 | return pf; | ||
| 420 | } | ||
| 421 | |||
| 422 | Media media = (Media)attributes.get(Media.class); | ||
| 423 | MediaPrintableArea mpa = | ||
| 424 | (MediaPrintableArea)attributes.get(MediaPrintableArea.class); | ||
| 425 | OrientationRequested orientReq = | ||
| 426 | (OrientationRequested)attributes.get(OrientationRequested.class); | ||
| 427 | |||
| 428 | if (media == null && mpa == null && orientReq == null) { | ||
| 429 | return pf; | ||
| 430 | } | ||
| 431 | Paper paper = pf.getPaper(); | ||
| 432 | |||
| 433 | /* If there's a media but no media printable area, we can try | ||
| 434 | * to retrieve the default value for mpa and use that. | ||
| 435 | */ | ||
| 436 | if (mpa == null && media != null && | ||
| 437 | service.isAttributeCategorySupported(MediaPrintableArea.class)) { | ||
| 438 | Object mpaVals = | ||
| 439 | service.getSupportedAttributeValues(MediaPrintableArea.class, | ||
| 440 | null, attributes); | ||
| 441 | if (mpaVals instanceof MediaPrintableArea[] && | ||
| 442 | ((MediaPrintableArea[])mpaVals).length > 0) { | ||
| 443 | mpa = ((MediaPrintableArea[])mpaVals)[0]; | ||
| 444 | } | ||
| 445 | } | ||
| 446 | |||
| 447 | if (media != null && | ||
| 448 | service.isAttributeValueSupported(media, null, attributes)) { | ||
| 449 | if (media instanceof MediaSizeName) { | ||
| 450 | MediaSizeName msn = (MediaSizeName)media; | ||
| 451 | MediaSize msz = MediaSize.getMediaSizeForName(msn); | ||
| 452 | if (msz != null) { | ||
| 453 | double inch = 72.0; | ||
| 454 | double paperWid = msz.getX(MediaSize.INCH) * inch; | ||
| 455 | double paperHgt = msz.getY(MediaSize.INCH) * inch; | ||
| 456 | paper.setSize(paperWid, paperHgt); | ||
| 457 | if (mpa == null) { | ||
| 458 | paper.setImageableArea(inch, inch, | ||
| 459 | paperWid-2*inch, | ||
| 460 | paperHgt-2*inch); | ||
| 461 | } | ||
| 462 | } | ||
| 463 | } | ||
| 464 | } | ||
| 465 | |||
| 466 | if (mpa != null && | ||
| 467 | service.isAttributeValueSupported(mpa, null, attributes)) { | ||
| 468 | float [] printableArea = | ||
| 469 | mpa.getPrintableArea(MediaPrintableArea.INCH); | ||
| 470 | for (int i=0; i < printableArea.length; i++) { | ||
| 471 | printableArea[i] = printableArea[i]*72.0f; | ||
| 472 | } | ||
| 473 | paper.setImageableArea(printableArea[0], printableArea[1], | ||
| 474 | printableArea[2], printableArea[3]); | ||
| 475 | } | ||
| 476 | |||
| 477 | if (orientReq != null && | ||
| 478 | service.isAttributeValueSupported(orientReq, null, attributes)) { | ||
| 479 | int orient; | ||
| 480 | if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) { | ||
| 481 | orient = PageFormat.REVERSE_LANDSCAPE; | ||
| 482 | } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) { | ||
| 483 | orient = PageFormat.LANDSCAPE; | ||
| 484 | } else { | ||
| 485 | orient = PageFormat.PORTRAIT; | ||
| 486 | } | ||
| 487 | pf.setOrientation(orient); | ||
| 488 | } | ||
| 489 | |||
| 490 | pf.setPaper(paper); | ||
| 491 | pf = validatePage(pf); | ||
| 492 | return pf; | ||
| 493 | } | ||
| 494 | |||
| 495 | /** | ||
| 496 | * Returns the clone of <code>page</code> with its settings | ||
| 497 | * adjusted to be compatible with the current printer of this | ||
| 498 | * <code>PrinterJob</code>. For example, the returned | ||
| 499 | * <code>PageFormat</code> could have its imageable area | ||
| 500 | * adjusted to fit within the physical area of the paper that | ||
| 501 | * is used by the current printer. | ||
| 502 | * @param page the <code>PageFormat</code> that is cloned and | ||
| 503 | * whose settings are changed to be compatible with | ||
| 504 | * the current printer | ||
| 505 | * @return a <code>PageFormat</code> that is cloned from | ||
| 506 | * <code>page</code> and whose settings are changed | ||
| 507 | * to conform with this <code>PrinterJob</code>. | ||
| 508 | */ | ||
| 509 | public abstract PageFormat validatePage(PageFormat page); | ||
| 510 | |||
| 511 | /** | ||
| 512 | * Prints a set of pages. | ||
| 513 | * @exception PrinterException an error in the print system | ||
| 514 | * caused the job to be aborted. | ||
| 515 | * @see Book | ||
| 516 | * @see Pageable | ||
| 517 | * @see Printable | ||
| 518 | */ | ||
| 519 | public abstract void print() throws PrinterException; | ||
| 520 | |||
| 521 | /** | ||
| 522 | * Prints a set of pages using the settings in the attribute | ||
| 523 | * set. The default implementation ignores the attribute set. | ||
| 524 | * <p> | ||
| 525 | * Note that some attributes may be set directly on the PrinterJob | ||
| 526 | * by equivalent method calls, (for example), copies: | ||
| 527 | * <code>setcopies(int)</code>, job name: <code>setJobName(String)</code> | ||
| 528 | * and specifying media size and orientation though the | ||
| 529 | * <code>PageFormat</code> object. | ||
| 530 | * <p> | ||
| 531 | * If a supported attribute-value is specified in this attribute set, | ||
| 532 | * it will take precedence over the API settings for this print() | ||
| 533 | * operation only. | ||
| 534 | * The following behaviour is specified for PageFormat: | ||
| 535 | * If a client uses the Printable interface, then the | ||
| 536 | * <code>attributes</code> parameter to this method is examined | ||
| 537 | * for attributes which specify media (by size), orientation, and | ||
| 538 | * imageable area, and those are used to construct a new PageFormat | ||
| 539 | * which is passed to the Printable object's print() method. | ||
| 540 | * See {@link Printable} for an explanation of the required | ||
| 541 | * behaviour of a Printable to ensure optimal printing via PrinterJob. | ||
| 542 | * For clients of the Pageable interface, the PageFormat will always | ||
| 543 | * be as supplied by that interface, on a per page basis. | ||
| 544 | * <p> | ||
| 545 | * These behaviours allow an application to directly pass the | ||
| 546 | * user settings returned from | ||
| 547 | * <code>printDialog(PrintRequestAttributeSet attributes</code> to | ||
| 548 | * this print() method. | ||
| 549 | * <p> | ||
| 550 | * | ||
| 551 | * @param attributes a set of attributes for the job | ||
| 552 | * @exception PrinterException an error in the print system | ||
| 553 | * caused the job to be aborted. | ||
| 554 | * @see Book | ||
| 555 | * @see Pageable | ||
| 556 | * @see Printable | ||
| 557 | * @since 1.4 | ||
| 558 | */ | ||
| 559 | public void print(PrintRequestAttributeSet attributes) | ||
| 560 | throws PrinterException { | ||
| 561 | print(); | ||
| 562 | } | ||
| 563 | |||
| 564 | /** | ||
| 565 | * Sets the number of copies to be printed. | ||
| 566 | * @param copies the number of copies to be printed | ||
| 567 | * @see #getCopies | ||
| 568 | */ | ||
| 569 | public abstract void setCopies(int copies); | ||
| 570 | |||
| 571 | /** | ||
| 572 | * Gets the number of copies to be printed. | ||
| 573 | * @return the number of copies to be printed. | ||
| 574 | * @see #setCopies | ||
| 575 | */ | ||
| 576 | public abstract int getCopies(); | ||
| 577 | |||
| 578 | /** | ||
| 579 | * Gets the name of the printing user. | ||
| 580 | * @return the name of the printing user | ||
| 581 | */ | ||
| 582 | public abstract String getUserName(); | ||
| 583 | |||
| 584 | /** | ||
| 585 | * Sets the name of the document to be printed. | ||
| 586 | * The document name can not be <code>null</code>. | ||
| 587 | * @param jobName the name of the document to be printed | ||
| 588 | * @see #getJobName | ||
| 589 | */ | ||
| 590 | public abstract void setJobName(String jobName); | ||
| 591 | |||
| 592 | /** | ||
| 593 | * Gets the name of the document to be printed. | ||
| 594 | * @return the name of the document to be printed. | ||
| 595 | * @see #setJobName | ||
| 596 | */ | ||
| 597 | public abstract String getJobName(); | ||
| 598 | |||
| 599 | /** | ||
| 600 | * Cancels a print job that is in progress. If | ||
| 601 | * {@link #print() print} has been called but has not | ||
| 602 | * returned then this method signals | ||
| 603 | * that the job should be cancelled at the next | ||
| 604 | * chance. If there is no print job in progress then | ||
| 605 | * this call does nothing. | ||
| 606 | */ | ||
| 607 | public abstract void cancel(); | ||
| 608 | |||
| 609 | /** | ||
| 610 | * Returns <code>true</code> if a print job is | ||
| 611 | * in progress, but is going to be cancelled | ||
| 612 | * at the next opportunity; otherwise returns | ||
| 613 | * <code>false</code>. | ||
| 614 | * @return <code>true</code> if the job in progress | ||
| 615 | * is going to be cancelled; <code>false</code> otherwise. | ||
| 616 | */ | ||
| 617 | public abstract boolean isCancelled(); | ||
| 618 | |||
| 619 | } | ||
| @@ -0,0 +1,17 @@ | |||
| 1 | <../../../../../mkconfig | ||
| 2 | |||
| 3 | TARG=\ | ||
| 4 | Book.dis\ | ||
| 5 | Pageable.dis\ | ||
| 6 | PageFormat.dis\ | ||
| 7 | Paper.dis\ | ||
| 8 | Printable.dis\ | ||
| 9 | PrinterAbortException.dis\ | ||
| 10 | PrinterException.dis\ | ||
| 11 | PrinterGraphics.dis\ | ||
| 12 | PrinterIOException.dis\ | ||
| 13 | PrinterJob.dis\ | ||
| 14 | |||
| 15 | DISBIN=$ROOT/java/dis/java/java/java/awt/print | ||
| 16 | |||
| 17 | <$ROOT/mkfiles/mkjava | ||
| @@ -0,0 +1,57 @@ | |||
| 1 | <!-- | ||
| 2 | Copyright (c) 1998, 1999, 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 | ||
| 23 | questions. | ||
| 24 | --> | ||
| 25 | |||
| 26 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> | ||
| 27 | <html> | ||
| 28 | <body bgcolor="white"> | ||
| 29 | |||
| 30 | Provides classes and interfaces for a general printing API. The | ||
| 31 | API includes such features as: | ||
| 32 | <ul> | ||
| 33 | <li>the ability to specify document types | ||
| 34 | <li>mechanisms for control of page setup and page formats | ||
| 35 | <li>the ability to manage job control dialogs | ||
| 36 | </ul> | ||
| 37 | |||
| 38 | |||
| 39 | <!-- | ||
| 40 | <h2>Package Specification</h2> | ||
| 41 | |||
| 42 | ##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT ##### | ||
| 43 | <ul> | ||
| 44 | <li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a> | ||
| 45 | </ul> | ||
| 46 | |||
| 47 | <h2>Related Documentation</h2> | ||
| 48 | |||
| 49 | For overviews, tutorials, examples, guides, and tool documentation, please see: | ||
| 50 | <ul> | ||
| 51 | <li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a> | ||
| 52 | </ul> | ||
| 53 | --> | ||
| 54 | |||
| 55 | @since 1.2 | ||
| 56 | </body> | ||
| 57 | </html> | ||