Path: blob/master/src/java.desktop/share/classes/javax/print/DocPrintJob.java
41153 views
/*1* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.print;2627import javax.print.attribute.PrintJobAttributeSet;28import javax.print.attribute.PrintRequestAttributeSet;29import javax.print.event.PrintJobAttributeListener;30import javax.print.event.PrintJobListener;3132/**33* This interface represents a print job that can print a specified document34* with a set of job attributes. An object implementing this interface is35* obtained from a print service.36*/37public interface DocPrintJob {3839/**40* Determines the {@link PrintService} object to which this print job object41* is bound.42*43* @return {@code PrintService} object44*/45public PrintService getPrintService();4647/**48* Obtains this Print Job's set of printing attributes. The returned49* attribute set object is unmodifiable. The returned attribute set object50* is a "snapshot" of this Print Job's attribute set at the time of the51* {@code getAttributes()} method call; that is, the returned attribute52* set's object's contents will not be updated if this Print Job's attribute53* set's contents change in the future. To detect changes in attribute54* values, call {@code getAttributes()} again and compare the new attribute55* set to the previous attribute set; alternatively, register a listener for56* print job events. The returned value may be an empty set but should not57* be {@code null}.58*59* @return the print job attributes60*/61public PrintJobAttributeSet getAttributes();6263/**64* Registers a listener for event occurring during this print job. If65* listener is {@code null}, no exception is thrown and no action is66* performed. If listener is already registered, it will be registered67* again.68*69* @param listener the object implementing the listener interface70* @see #removePrintJobListener71*/72public void addPrintJobListener(PrintJobListener listener);7374/**75* Removes a listener from this print job. This method performs no function,76* nor does it throw an exception, if the listener specified by the argument77* was not previously added to this print job. If listener is {@code null},78* no exception is thrown and no action is performed. If a listener was79* registered more than once only one of the registrations will be removed.80*81* @param listener the object implementing the listener interface82* @see #addPrintJobListener83*/84public void removePrintJobListener(PrintJobListener listener);8586/**87* Registers a listener for changes in the specified attributes. If listener88* is {@code null}, no exception is thrown and no action is performed. To89* determine the attribute updates that may be reported by this job, a90* client can call {@code getAttributes()} and identify the subset that are91* interesting and likely to be reported to the listener. Clients expecting92* to be updated about changes in a specific job attribute should verify it93* is in that set, but updates about an attribute will be made only if it94* changes and this is detected by the job. Also updates may be subject to95* batching by the job. To minimize overhead in print job processing it is96* recommended to listen on only that subset of attributes which are likely97* to change. If the specified set is empty no attribute updates will be98* reported to the listener. If the attribute set is {@code null}, then this99* means to listen on all dynamic attributes that the job supports. This may100* result in no update notifications if a job can not report any attribute101* updates.102* <p>103* If listener is already registered, it will be registered again.104*105* @param listener the object implementing the listener interface106* @param attributes the attributes to listen on, or {@code null} to mean107* all attributes that can change, as determined by the job108* @see #removePrintJobAttributeListener109*/110public void addPrintJobAttributeListener(111PrintJobAttributeListener listener,112PrintJobAttributeSet attributes);113114/**115* Removes an attribute listener from this print job. This method performs116* no function, nor does it throw an exception, if the listener specified by117* the argument was not previously added to this print job. If the listener118* is {@code null}, no exception is thrown and no action is performed. If a119* listener is registered more than once, even for a different set of120* attributes, no guarantee is made which listener is removed.121*122* @param listener the object implementing the listener interface123* @see #addPrintJobAttributeListener124*/125public void removePrintJobAttributeListener(126PrintJobAttributeListener listener);127128/**129* Prints a document with the specified job attributes. This method should130* only be called once for a given print job. Calling it again will not131* result in a new job being spooled to the printer. The service132* implementation will define policy for service interruption and recovery.133* When the print method returns, printing may not yet have completed as134* printing may happen asynchronously, perhaps in a different thread.135* Application clients which want to monitor the success or failure should136* register a {@code PrintJobListener}.137* <p>138* Print service implementors should close any print data streams (ie139* {@code Reader} or {@code InputStream} implementations) that they obtain140* from the client doc. Robust clients may still wish to verify this. An141* exception is always generated if a {@code DocFlavor} cannot be printed.142*143* @param doc the document to be printed. It must be a flavor supported by144* this PrintJob.145* @param attributes the job attributes to be applied to this print job. If146* this parameter is {@code null} then the default attributes are147* used.148* @throws PrintException the exception additionally may implement an149* interface that more precisely describes the cause of the150* exception151* <ul>152* <li>{@code FlavorException}. If the document has a flavor not153* supported by this print job.154* <li>{@code AttributeException}. If one or more of the155* attributes are not valid for this print job.156* </ul>157*/158public void print(Doc doc, PrintRequestAttributeSet attributes)159throws PrintException;160161}162163164