author | erikj |
Thu, 07 Jun 2012 18:05:09 -0700 | |
changeset 12813 | c10ab96dcf41 |
parent 5506 | 202f599c92aa |
child 16734 | da1901d79073 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.awt.print; |
|
27 |
||
28 |
import java.awt.Graphics; |
|
29 |
||
12813
c10ab96dcf41
7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents:
5506
diff
changeset
|
30 |
import javax.tools.annotation.GenerateNativeHeader; |
c10ab96dcf41
7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents:
5506
diff
changeset
|
31 |
|
2 | 32 |
/** |
33 |
* The <code>Printable</code> interface is implemented |
|
34 |
* by the <code>print</code> methods of the current |
|
35 |
* page painter, which is called by the printing |
|
36 |
* system to render a page. When building a |
|
37 |
* {@link Pageable}, pairs of {@link PageFormat} |
|
38 |
* instances and instances that implement |
|
39 |
* this interface are used to describe each page. The |
|
40 |
* instance implementing <code>Printable</code> is called to |
|
41 |
* print the page's graphics. |
|
42 |
* <p> |
|
43 |
* A <code>Printable(..)</code> may be set on a <code>PrinterJob</code>. |
|
44 |
* When the client subsequently initiates printing by calling |
|
45 |
* <code>PrinterJob.print(..)</code> control |
|
46 |
* <p> |
|
47 |
* is handed to the printing system until all pages have been printed. |
|
48 |
* It does this by calling <code>Printable.print(..)</code> until |
|
49 |
* all pages in the document have been printed. |
|
50 |
* In using the <code>Printable</code> interface the printing |
|
51 |
* commits to image the contents of a page whenever |
|
52 |
* requested by the printing system. |
|
53 |
* <p> |
|
54 |
* The parameters to <code>Printable.print(..)</code> include a |
|
55 |
* <code>PageFormat</code> which describes the printable area of |
|
56 |
* the page, needed for calculating the contents that will fit the |
|
57 |
* page, and the page index, which specifies the zero-based print |
|
58 |
* stream index of the requested page. |
|
59 |
* <p> |
|
60 |
* For correct printing behaviour, the following points should be |
|
61 |
* observed: |
|
62 |
* <ul> |
|
63 |
* <li> The printing system may request a page index more than once. |
|
64 |
* On each occasion equal PageFormat parameters will be supplied. |
|
65 |
* |
|
66 |
* <li>The printing system will call <code>Printable.print(..)</code> |
|
67 |
* with page indexes which increase monotonically, although as noted above, |
|
68 |
* the <code>Printable</code> should expect multiple calls for a page index |
|
69 |
* and that page indexes may be skipped, when page ranges are specified |
|
70 |
* by the client, or by a user through a print dialog. |
|
71 |
* |
|
72 |
* <li>If multiple collated copies of a document are requested, and the |
|
73 |
* printer cannot natively support this, then the document may be imaged |
|
74 |
* multiple times. Printing will start each copy from the lowest print |
|
75 |
* stream page index page. |
|
76 |
* |
|
77 |
* <li>With the exception of re-imaging an entire document for multiple |
|
78 |
* collated copies, the increasing page index order means that when |
|
79 |
* page N is requested if a client needs to calculate page break position, |
|
80 |
* it may safely discard any state related to pages < N, and make current |
|
81 |
* that for page N. "State" usually is just the calculated position in the |
|
82 |
* document that corresponds to the start of the page. |
|
83 |
* |
|
84 |
* <li>When called by the printing system the <code>Printable</code> must |
|
85 |
* inspect and honour the supplied PageFormat parameter as well as the |
|
86 |
* page index. The format of the page to be drawn is specified by the |
|
87 |
* supplied PageFormat. The size, orientation and imageable area of the page |
|
88 |
* is therefore already determined and rendering must be within this |
|
89 |
* imageable area. |
|
90 |
* This is key to correct printing behaviour, and it has the |
|
91 |
* implication that the client has the responsibility of tracking |
|
92 |
* what content belongs on the specified page. |
|
93 |
* |
|
94 |
* <li>When the <code>Printable</code> is obtained from a client-supplied |
|
95 |
* <code>Pageable</code> then the client may provide different PageFormats |
|
96 |
* for each page index. Calculations of page breaks must account for this. |
|
97 |
* </ul> |
|
98 |
* <p> |
|
99 |
* @see java.awt.print.Pageable |
|
100 |
* @see java.awt.print.PageFormat |
|
101 |
* @see java.awt.print.PrinterJob |
|
102 |
*/ |
|
12813
c10ab96dcf41
7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents:
5506
diff
changeset
|
103 |
/* No native methods here, but the constants are needed in the supporting JNI code */ |
c10ab96dcf41
7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents:
5506
diff
changeset
|
104 |
@GenerateNativeHeader |
2 | 105 |
public interface Printable { |
106 |
||
107 |
/** |
|
108 |
* Returned from {@link #print(Graphics, PageFormat, int)} |
|
109 |
* to signify that the requested page was rendered. |
|
110 |
*/ |
|
111 |
int PAGE_EXISTS = 0; |
|
112 |
||
113 |
/** |
|
114 |
* Returned from <code>print</code> to signify that the |
|
115 |
* <code>pageIndex</code> is too large and that the requested page |
|
116 |
* does not exist. |
|
117 |
*/ |
|
118 |
int NO_SUCH_PAGE = 1; |
|
119 |
||
120 |
/** |
|
121 |
* Prints the page at the specified index into the specified |
|
122 |
* {@link Graphics} context in the specified |
|
123 |
* format. A <code>PrinterJob</code> calls the |
|
124 |
* <code>Printable</code> interface to request that a page be |
|
125 |
* rendered into the context specified by |
|
126 |
* <code>graphics</code>. The format of the page to be drawn is |
|
127 |
* specified by <code>pageFormat</code>. The zero based index |
|
128 |
* of the requested page is specified by <code>pageIndex</code>. |
|
129 |
* If the requested page does not exist then this method returns |
|
130 |
* NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned. |
|
131 |
* The <code>Graphics</code> class or subclass implements the |
|
132 |
* {@link PrinterGraphics} interface to provide additional |
|
133 |
* information. If the <code>Printable</code> object |
|
134 |
* aborts the print job then it throws a {@link PrinterException}. |
|
135 |
* @param graphics the context into which the page is drawn |
|
136 |
* @param pageFormat the size and orientation of the page being drawn |
|
137 |
* @param pageIndex the zero based index of the page to be drawn |
|
138 |
* @return PAGE_EXISTS if the page is rendered successfully |
|
139 |
* or NO_SUCH_PAGE if <code>pageIndex</code> specifies a |
|
140 |
* non-existent page. |
|
141 |
* @exception java.awt.print.PrinterException |
|
142 |
* thrown when the print job is terminated. |
|
143 |
*/ |
|
144 |
int print(Graphics graphics, PageFormat pageFormat, int pageIndex) |
|
145 |
throws PrinterException; |
|
146 |
||
147 |
} |