jdk/src/java.desktop/share/classes/java/awt/print/PrinterJob.java
author avstepan
Mon, 11 Jan 2016 17:51:54 +0300
changeset 35667 ed476aba94de
parent 26749 b6598aa90114
child 37706 818b9c789c6c
permissions -rw-r--r--
8138838: docs cleanup for java.desktop Summary: docs cleanup for java.desktop Reviewed-by: serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
24549
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 23010
diff changeset
     2
 * Copyright (c) 1997, 2014, 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: 1740
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: 1740
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: 1740
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1740
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1740
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.AWTError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.HeadlessException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.print.DocFlavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.print.PrintService;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.print.PrintServiceLookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.print.StreamPrintServiceFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.print.attribute.PrintRequestAttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.print.attribute.standard.Media;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.print.attribute.standard.MediaPrintableArea;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.print.attribute.standard.MediaSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.print.attribute.standard.MediaSizeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.print.attribute.standard.OrientationRequested;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.security.action.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
    46
 * The {@code PrinterJob} class is the principal class that controls
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * printing. An application calls methods in this class to set up a job,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * optionally to invoke a print dialog with the user, and then to print
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * the pages of the job.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
public abstract class PrinterJob {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 /* Public Class Methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
    56
     * Creates and returns a {@code PrinterJob} which is initially
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * associated with the default printer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * If no printers are available on the system, a PrinterJob will still
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
    59
     * be returned from this method, but {@code getPrintService()}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
    60
     * will return {@code null}, and calling
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
    61
     * {@link #print() print} with this {@code PrinterJob} might
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * generate an exception.  Applications that need to determine if
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
    63
     * there are suitable printers before creating a {@code PrinterJob}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * should ensure that the array returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * {@link #lookupPrintServices() lookupPrintServices} is not empty.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
    66
     * @return a new {@code PrinterJob}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @throws  SecurityException if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *          {@link java.lang.SecurityManager#checkPrintJobAccess}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *          method disallows this thread from creating a print job request
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public static PrinterJob getPrinterJob() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            security.checkPrintJobAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        }
24549
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 23010
diff changeset
    77
        return java.security.AccessController.doPrivileged(
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 23010
diff changeset
    78
            new java.security.PrivilegedAction<PrinterJob>() {
147a5c8b7793 8039109: Fix unchecked and raw lint warnings in java.awt
darcy
parents: 23010
diff changeset
    79
            public PrinterJob run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                String nm = System.getProperty("java.awt.printerjob", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                    return (PrinterJob)Class.forName(nm).newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                    throw new AWTError("PrinterJob not found: " + nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                } catch (InstantiationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                 throw new AWTError("Could not instantiate PrinterJob: " + nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                } catch (IllegalAccessException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                    throw new AWTError("Could not access PrinterJob: " + nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * A convenience method which looks up 2D print services.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Services returned from this method may be installed on
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
    97
     * {@code PrinterJob}s which support print services.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Calling this method is equivalent to calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * {@link javax.print.PrintServiceLookup#lookupPrintServices(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * DocFlavor, AttributeSet)
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 5506
diff changeset
   101
     * PrintServiceLookup.lookupPrintServices()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * and specifying a Pageable DocFlavor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @return a possibly empty array of 2D print services.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @since     1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public static PrintService[] lookupPrintServices() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        return PrintServiceLookup.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * A convenience method which locates factories for stream print
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * services which can image 2D graphics.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Sample usage :
21777
c0a423e43b0d 8025235: [javadoc] fix some errors in 2D
yan
parents: 20451
diff changeset
   116
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * FileOutputStream outstream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * StreamPrintService psPrinter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * String psMimeType = "application/postscript";
1740
fb0972d6e026 6665212: PrinterJob class, method lookupStreamPrintServices(), "fos" in docs is unknown
jgodinez
parents: 2
diff changeset
   120
     * PrinterJob pj = PrinterJob.getPrinterJob();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * StreamPrintServiceFactory[] factories =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *     PrinterJob.lookupStreamPrintServices(psMimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * if (factories.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *     try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *         outstream = new File("out.ps");
1740
fb0972d6e026 6665212: PrinterJob class, method lookupStreamPrintServices(), "fos" in docs is unknown
jgodinez
parents: 2
diff changeset
   127
     *         psPrinter =  factories[0].getPrintService(outstream);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *         // psPrinter can now be set as the service on a PrinterJob
1740
fb0972d6e026 6665212: PrinterJob class, method lookupStreamPrintServices(), "fos" in docs is unknown
jgodinez
parents: 2
diff changeset
   129
     *         pj.setPrintService(psPrinter)
fb0972d6e026 6665212: PrinterJob class, method lookupStreamPrintServices(), "fos" in docs is unknown
jgodinez
parents: 2
diff changeset
   130
     *     } catch (Exception e) {
fb0972d6e026 6665212: PrinterJob class, method lookupStreamPrintServices(), "fos" in docs is unknown
jgodinez
parents: 2
diff changeset
   131
     *         e.printStackTrace();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * }
21777
c0a423e43b0d 8025235: [javadoc] fix some errors in 2D
yan
parents: 20451
diff changeset
   134
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Services returned from this method may be installed on
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   136
     * {@code PrinterJob} instances which support print services.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Calling this method is equivalent to calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * {@link javax.print.StreamPrintServiceFactory#lookupStreamPrintServiceFactories(DocFlavor, String)
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 5506
diff changeset
   139
     * StreamPrintServiceFactory.lookupStreamPrintServiceFactories()
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 5506
diff changeset
   140
     * } and specifying a Pageable DocFlavor.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @param mimeType the required output format, or null to mean any format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @return a possibly empty array of 2D stream print service factories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @since     1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public static StreamPrintServiceFactory[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        lookupStreamPrintServices(String mimeType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                                       DocFlavor.SERVICE_FORMATTED.PAGEABLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                                       mimeType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 /* Public Methods */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   157
     * A {@code PrinterJob} object should be created using the
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 5506
diff changeset
   158
     * static {@link #getPrinterJob() getPrinterJob} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public PrinterJob() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * Returns the service (printer) for this printer job.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Implementations of this class which do not support print services
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * may return null.  null will also be returned if no printers are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @return the service for this printer job.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @see #setPrintService(PrintService)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @see #getPrinterJob()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @since     1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public PrintService getPrintService() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Associate this PrinterJob with a new PrintService.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * This method is overridden by subclasses which support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * specifying a Print Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   182
     * Throws {@code PrinterException} if the specified service
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   183
     * cannot support the {@code Pageable} and
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   184
     * {@code Printable} interfaces necessary to support 2D printing.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @param service a print service that supports 2D printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @exception PrinterException if the specified service does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * 2D printing, or this PrinterJob class does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * setting a 2D print service, or the specified service is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * otherwise not a valid print service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @see #getPrintService
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @since     1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public void setPrintService(PrintService service)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        throws PrinterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            throw new PrinterException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                         "Setting a service is not supported on this class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   200
     * Calls {@code painter} to render the pages.  The pages in the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * document to be printed by this
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   202
     * {@code PrinterJob} are rendered by the {@link Printable}
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   203
     * object, {@code painter}.  The {@link PageFormat} for each page
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * is the default page format.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   205
     * @param painter the {@code Printable} that renders each page of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public abstract void setPrintable(Printable painter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   211
     * Calls {@code painter} to render the pages in the specified
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   212
     * {@code format}.  The pages in the document to be printed by
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   213
     * this {@code PrinterJob} are rendered by the
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   214
     * {@code Printable} object, {@code painter}. The
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   215
     * {@code PageFormat} of each page is {@code format}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   216
     * @param painter the {@code Printable} called to render
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *          each page of the document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @param format the size and orientation of each page to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *                   be printed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public abstract void setPrintable(Printable painter, PageFormat format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   224
     * Queries {@code document} for the number of pages and
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   225
     * the {@code PageFormat} and {@code Printable} for each
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   226
     * page held in the {@code Pageable} instance,
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   227
     * {@code document}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @param document the pages to be printed. It can not be
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   229
     * {@code null}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   230
     * @exception NullPointerException the {@code Pageable} passed in
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   231
     * was {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @see PageFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @see Printable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public abstract void setPageable(Pageable document)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        throws NullPointerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Presents a dialog to the user for changing the properties of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * the print job.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * This method will display a native dialog if a native print
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * service is selected, and user choice of printers will be restricted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * to these native print services.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * To present the cross platform print dialog for all services,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * including native ones instead use
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   246
     * {@code printDialog(PrintRequestAttributeSet)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * PrinterJob implementations which can use PrintService's will update
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * the PrintService for this PrinterJob to reflect the new service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * selected by the user.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   251
     * @return {@code true} if the user does not cancel the dialog;
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   252
     * {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public abstract boolean printDialog() throws HeadlessException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * A convenience method which displays a cross-platform print dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * for all services which are capable of printing 2D graphics using the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   262
     * {@code Pageable} interface. The selected printer when the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * dialog is initially displayed will reflect the print service currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * attached to this print job.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * If the user changes the print service, the PrinterJob will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * updated to reflect this, unless the user cancels the dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * As well as allowing the user to select the destination printer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * the user can also select values of various print request attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * The attributes parameter on input will reflect the applications
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * required initial selections in the user dialog. Attributes not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * specified display using the default for the service. On return it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * will reflect the user's choices. Selections may be updated by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * the implementation to be consistent with the supported values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * for the currently selected print service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * As the user scrolls to a new print service selection, the values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * copied are based on the settings for the previous service, together
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * with any user changes. The values are not based on the original
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * settings supplied by the client.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * With the exception of selected printer, the PrinterJob state is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * not updated to reflect the user's changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * For the selections to affect a printer job, the attributes must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * be specified in the call to the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   286
     * {@code print(PrintRequestAttributeSet)} method. If using
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * the Pageable interface, clients which intend to use media selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * by the user must create a PageFormat derived from the user's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * If the user cancels the dialog, the attributes will not reflect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * any changes made by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @param attributes on input is application supplied attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * on output the contents are updated to reflect user choices.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * This parameter may not be null.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   295
     * @return {@code true} if the user does not cancel the dialog;
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   296
     * {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * returns true.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   299
     * @exception NullPointerException if {@code attributes} parameter
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @since     1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    public boolean printDialog(PrintRequestAttributeSet attributes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        if (attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            throw new NullPointerException("attributes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return printDialog();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * Displays a dialog that allows modification of a
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   316
     * {@code PageFormat} instance.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   317
     * The {@code page} argument is used to initialize controls
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * in the page setup dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * If the user cancels the dialog then this method returns the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   320
     * original {@code page} object unmodified.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * If the user okays the dialog then this method returns a new
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   322
     * {@code PageFormat} object with the indicated changes.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   323
     * In either case, the original {@code page} object is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * not modified.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   325
     * @param page the default {@code PageFormat} presented to the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *                  user for modification
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   327
     * @return    the original {@code page} object if the dialog
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   328
     *            is cancelled; a new {@code PageFormat} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *            containing the format indicated by the user if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *            dialog is acknowledged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @since     1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    public abstract PageFormat pageDialog(PageFormat page)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        throws HeadlessException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * A convenience method which displays a cross-platform page setup dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * The choices available will reflect the print service currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * set on this PrinterJob.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * The attributes parameter on input will reflect the client's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * required initial selections in the user dialog. Attributes which are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * not specified display using the default for the service. On return it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * will reflect the user's choices. Selections may be updated by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * the implementation to be consistent with the supported values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * for the currently selected print service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * The return value will be a PageFormat equivalent to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * selections in the PrintRequestAttributeSet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * If the user cancels the dialog, the attributes will not reflect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * any changes made by the user, and the return value will be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @param attributes on input is application supplied attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * on output the contents are updated to reflect user choices.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * This parameter may not be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @return a page format if the user does not cancel the dialog;
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   359
     * {@code null} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * returns true.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   362
     * @exception NullPointerException if {@code attributes} parameter
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @since     1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    public PageFormat pageDialog(PrintRequestAttributeSet attributes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        if (attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            throw new NullPointerException("attributes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        return pageDialog(defaultPage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   378
     * Clones the {@code PageFormat} argument and alters the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * clone to describe a default page size and orientation.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   380
     * @param page the {@code PageFormat} to be cloned and altered
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   381
     * @return clone of {@code page}, altered to describe a default
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   382
     *                      {@code PageFormat}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    public abstract PageFormat defaultPage(PageFormat page);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   387
     * Creates a new {@code PageFormat} instance and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * sets it to a default size and orientation.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   389
     * @return a {@code PageFormat} set to a default size and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *          orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public PageFormat defaultPage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        return defaultPage(new PageFormat());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   397
     * Calculates a {@code PageFormat} with values consistent with those
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   398
     * supported by the current {@code PrintService} for this job
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   399
     * (ie the value returned by {@code getPrintService()}) and media,
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   400
     * printable area and orientation contained in {@code attributes}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * Calling this method does not update the job.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * It is useful for clients that have a set of attributes obtained from
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   404
     * {@code printDialog(PrintRequestAttributeSet attributes)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * and need a PageFormat to print a Pageable object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @param attributes a set of printing attributes, for example obtained
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   407
     * from calling printDialog. If {@code attributes} is null a default
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * PageFormat is returned.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   409
     * @return a {@code PageFormat} whose settings conform with
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * those of the current service and the specified attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public PageFormat getPageFormat(PrintRequestAttributeSet attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        PrintService service = getPrintService();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        PageFormat pf = defaultPage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        if (service == null || attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            return pf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        Media media = (Media)attributes.get(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        MediaPrintableArea mpa =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            (MediaPrintableArea)attributes.get(MediaPrintableArea.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        OrientationRequested orientReq =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
           (OrientationRequested)attributes.get(OrientationRequested.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        if (media == null && mpa == null && orientReq == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
           return pf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        Paper paper = pf.getPaper();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        /* If there's a media but no media printable area, we can try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
         * to retrieve the default value for mpa and use that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        if (mpa == null && media != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            service.isAttributeCategorySupported(MediaPrintableArea.class)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            Object mpaVals =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                service.getSupportedAttributeValues(MediaPrintableArea.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                                                    null, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            if (mpaVals instanceof MediaPrintableArea[] &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                ((MediaPrintableArea[])mpaVals).length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                mpa = ((MediaPrintableArea[])mpaVals)[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        if (media != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            service.isAttributeValueSupported(media, null, attributes)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            if (media instanceof MediaSizeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                MediaSizeName msn = (MediaSizeName)media;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                MediaSize msz = MediaSize.getMediaSizeForName(msn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                if (msz != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                    double inch = 72.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    double paperWid = msz.getX(MediaSize.INCH) * inch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                    double paperHgt = msz.getY(MediaSize.INCH) * inch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    paper.setSize(paperWid, paperHgt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                    if (mpa == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                        paper.setImageableArea(inch, inch,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                                               paperWid-2*inch,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                                               paperHgt-2*inch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        if (mpa != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            service.isAttributeValueSupported(mpa, null, attributes)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            float [] printableArea =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                mpa.getPrintableArea(MediaPrintableArea.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            for (int i=0; i < printableArea.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                printableArea[i] = printableArea[i]*72.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            paper.setImageableArea(printableArea[0], printableArea[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                                   printableArea[2], printableArea[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        if (orientReq != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            service.isAttributeValueSupported(orientReq, null, attributes)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            int orient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                orient = PageFormat.REVERSE_LANDSCAPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                orient = PageFormat.LANDSCAPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                orient = PageFormat.PORTRAIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            pf.setOrientation(orient);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        pf.setPaper(paper);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        pf = validatePage(pf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        return pf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   496
     * Returns the clone of {@code page} with its settings
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * adjusted to be compatible with the current printer of this
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   498
     * {@code PrinterJob}.  For example, the returned
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   499
     * {@code PageFormat} could have its imageable area
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * adjusted to fit within the physical area of the paper that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * is used by the current printer.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   502
     * @param page the {@code PageFormat} that is cloned and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     *          whose settings are changed to be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *          the current printer
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   505
     * @return a {@code PageFormat} that is cloned from
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   506
     *          {@code page} and whose settings are changed
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   507
     *          to conform with this {@code PrinterJob}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    public abstract PageFormat validatePage(PageFormat page);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * Prints a set of pages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * @exception PrinterException an error in the print system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     *            caused the job to be aborted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * @see Book
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * @see Pageable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @see Printable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    public abstract void print() throws PrinterException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * Prints a set of pages using the settings in the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * set. The default implementation ignores the attribute set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * Note that some attributes may be set directly on the PrinterJob
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * by equivalent method calls, (for example), copies:
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   527
     * {@code setCopies(int)}, job name: {@code setJobName(String)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * and specifying media size and orientation though the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   529
     * {@code PageFormat} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * If a supported attribute-value is specified in this attribute set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * it will take precedence over the API settings for this print()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * operation only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * The following behaviour is specified for PageFormat:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * If a client uses the Printable interface, then the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   536
     * {@code attributes} parameter to this method is examined
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * for attributes which specify media (by size), orientation, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * imageable area, and those are used to construct a new PageFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * which is passed to the Printable object's print() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * See {@link Printable} for an explanation of the required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * behaviour of a Printable to ensure optimal printing via PrinterJob.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * For clients of the Pageable interface, the PageFormat will always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * be as supplied by that interface, on a per page basis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * These behaviours allow an application to directly pass the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * user settings returned from
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   547
     * {@code printDialog(PrintRequestAttributeSet attributes} to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * this print() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * @param attributes a set of attributes for the job
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * @exception PrinterException an error in the print system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     *            caused the job to be aborted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * @see Book
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * @see Pageable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * @see Printable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    public void print(PrintRequestAttributeSet attributes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        throws PrinterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        print();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * Sets the number of copies to be printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * @param copies the number of copies to be printed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * @see #getCopies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    public abstract void setCopies(int copies);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * Gets the number of copies to be printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * @return the number of copies to be printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * @see #setCopies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    public abstract int getCopies();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * Gets the name of the printing user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * @return the name of the printing user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    public abstract String getUserName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * Sets the name of the document to be printed.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   585
     * The document name can not be {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * @param jobName the name of the document to be printed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * @see #getJobName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    public abstract void setJobName(String jobName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * Gets the name of the document to be printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * @return the name of the document to be printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * @see #setJobName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    public abstract String getJobName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * Cancels a print job that is in progress.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * {@link #print() print} has been called but has not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * returned then this method signals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * that the job should be cancelled at the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * chance. If there is no print job in progress then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * this call does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    public abstract void cancel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   609
     * Returns {@code true} if a print job is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * in progress, but is going to be cancelled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * at the next opportunity; otherwise returns
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   612
     * {@code false}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   613
     * @return {@code true} if the job in progress
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 26749
diff changeset
   614
     * is going to be cancelled; {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    public abstract boolean isCancelled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
}