jdk/src/share/classes/java/awt/print/Printable.java
author erikj
Thu, 07 Jun 2012 18:05:09 -0700
changeset 12813 c10ab96dcf41
parent 5506 202f599c92aa
child 16734 da1901d79073
permissions -rw-r--r--
7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI Reviewed-by: ohair, ohrstrom, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt.print;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * The <code>Printable</code> interface is implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * by the <code>print</code> methods of the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * page painter, which is called by the printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * system to render a page.  When building a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * {@link Pageable}, pairs of {@link PageFormat}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * instances and instances that implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * this interface are used to describe each page. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * instance implementing <code>Printable</code> is called to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * print the page's graphics.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * A <code>Printable(..)</code> may be set on a <code>PrinterJob</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * When the client subsequently initiates printing by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <code>PrinterJob.print(..)</code> control
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * is handed to the printing system until all pages have been printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * It does this by calling <code>Printable.print(..)</code> until
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * all pages in the document have been printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * In using the <code>Printable</code> interface the printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * commits to image the contents of a page whenever
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * requested by the printing system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * The parameters to <code>Printable.print(..)</code> include a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <code>PageFormat</code> which describes the printable area of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * the page, needed for calculating the contents that will fit the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * page, and the page index, which specifies the zero-based print
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * stream index of the requested page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * For correct printing behaviour, the following points should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * observed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <li> The printing system may request a page index more than once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * On each occasion equal PageFormat parameters will be supplied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <li>The printing system will call <code>Printable.print(..)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * with page indexes which increase monotonically, although as noted above,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * the <code>Printable</code> should expect multiple calls for a page index
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * and that page indexes may be skipped, when page ranges are specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * by the client, or by a user through a print dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <li>If multiple collated copies of a document are requested, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * printer cannot natively support this, then the document may be imaged
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * multiple times. Printing will start each copy from the lowest print
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * stream page index page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <li>With the exception of re-imaging an entire document for multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * collated copies, the increasing page index order means that when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * page N is requested if a client needs to calculate page break position,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * it may safely discard any state related to pages < N, and make current
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * that for page N. "State" usually is just the calculated position in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * document that corresponds to the start of the page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * <li>When called by the printing system the <code>Printable</code> must
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * inspect and honour the supplied PageFormat parameter as well as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * page index.  The format of the page to be drawn is specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * supplied PageFormat. The size, orientation and imageable area of the page
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * is therefore already determined and rendering must be within this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * imageable area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * This is key to correct printing behaviour, and it has the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * implication that the client has the responsibility of tracking
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * what content belongs on the specified page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * <li>When the <code>Printable</code> is obtained from a client-supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * <code>Pageable</code> then the client may provide different PageFormats
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * for each page index. Calculations of page breaks must account for this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * @see java.awt.print.Pageable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * @see java.awt.print.PageFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * @see java.awt.print.PrinterJob
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
public interface Printable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Returned from {@link #print(Graphics, PageFormat, int)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * to signify that the requested page was rendered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    int PAGE_EXISTS = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Returned from <code>print</code> to signify that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * <code>pageIndex</code> is too large and that the requested page
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * does not exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    int NO_SUCH_PAGE = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Prints the page at the specified index into the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * {@link Graphics} context in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * format.  A <code>PrinterJob</code> calls the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <code>Printable</code> interface to request that a page be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * rendered into the context specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * <code>graphics</code>.  The format of the page to be drawn is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * specified by <code>pageFormat</code>.  The zero based index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * of the requested page is specified by <code>pageIndex</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * If the requested page does not exist then this method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * The <code>Graphics</code> class or subclass implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * {@link PrinterGraphics} interface to provide additional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * information.  If the <code>Printable</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * aborts the print job then it throws a {@link PrinterException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @param graphics the context into which the page is drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @param pageFormat the size and orientation of the page being drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @param pageIndex the zero based index of the page to be drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @return PAGE_EXISTS if the page is rendered successfully
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *         or NO_SUCH_PAGE if <code>pageIndex</code> specifies a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *         non-existent page.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @exception java.awt.print.PrinterException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *         thrown when the print job is terminated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                 throws PrinterException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
}