src/windows/classes/sun/print/Win32PrintJob.java

Print this page




  62 import javax.print.attribute.standard.Copies;
  63 import javax.print.attribute.standard.DocumentName;
  64 import javax.print.attribute.standard.Fidelity;
  65 import javax.print.attribute.standard.JobName;
  66 import javax.print.attribute.standard.JobOriginatingUserName;
  67 import javax.print.attribute.standard.Media;
  68 import javax.print.attribute.standard.MediaSize;
  69 import javax.print.attribute.standard.MediaSizeName;
  70 import javax.print.attribute.standard.OrientationRequested;
  71 import javax.print.attribute.standard.RequestingUserName;
  72 import javax.print.attribute.standard.Destination;
  73 import javax.print.attribute.standard.PrinterIsAcceptingJobs;
  74 import javax.print.attribute.standard.PrinterState;
  75 import javax.print.attribute.standard.PrinterStateReason;
  76 import javax.print.attribute.standard.PrinterStateReasons;
  77 
  78 import java.awt.print.*;
  79 
  80 public class Win32PrintJob implements CancelablePrintJob {
  81 
  82     transient private Vector jobListeners;
  83     transient private Vector attrListeners;
  84     transient private Vector listenedAttributeSets;
  85 
  86     private Win32PrintService service;
  87     private boolean fidelity;
  88     private boolean printing = false;
  89     private boolean printReturned = false;
  90     private PrintRequestAttributeSet reqAttrSet = null;
  91     private PrintJobAttributeSet jobAttrSet = null;
  92     private PrinterJob job;
  93     private Doc doc;
  94     private String mDestination = null;
  95 
  96     /* these variables used globally to store reference to the print
  97      * data retrieved as a stream. On completion these are always closed
  98      * if non-null.
  99      */
 100     private InputStream instream = null;
 101     private Reader reader = null;
 102 
 103     /* default values overridden by those extracted from the attributes */
 104     private String jobName = "Java Printing";


 122     }
 123 
 124     public PrintJobAttributeSet getAttributes() {
 125         synchronized (this) {
 126             if (jobAttrSet == null) {
 127                 /* just return an empty set until the job is submitted */
 128                 PrintJobAttributeSet jobSet = new HashPrintJobAttributeSet();
 129                 return AttributeSetUtilities.unmodifiableView(jobSet);
 130             } else {
 131               return jobAttrSet;
 132             }
 133         }
 134     }
 135 
 136     public void addPrintJobListener(PrintJobListener listener) {
 137         synchronized (this) {
 138             if (listener == null) {
 139                 return;
 140             }
 141             if (jobListeners == null) {
 142                 jobListeners = new Vector();
 143             }
 144             jobListeners.add(listener);
 145         }
 146     }
 147 
 148     public void removePrintJobListener(PrintJobListener listener) {
 149         synchronized (this) {
 150             if (listener == null || jobListeners == null ) {
 151                 return;
 152             }
 153             jobListeners.remove(listener);
 154             if (jobListeners.isEmpty()) {
 155                 jobListeners = null;
 156             }
 157         }
 158     }
 159 
 160 
 161     /* Closes any stream already retrieved for the data.
 162      * We want to avoid unnecessarily asking the Doc to create a stream only


 210 
 211     private void notifyEvent(int reason) {
 212 
 213         /* since this method should always get called, here's where
 214          * we will perform the clean up of any data stream supplied.
 215          */
 216         switch (reason) {
 217             case PrintJobEvent.DATA_TRANSFER_COMPLETE:
 218             case PrintJobEvent.JOB_CANCELED :
 219             case PrintJobEvent.JOB_FAILED :
 220             case PrintJobEvent.NO_MORE_EVENTS :
 221             case PrintJobEvent.JOB_COMPLETE :
 222                 closeDataStreams();
 223         }
 224 
 225         synchronized (this) {
 226             if (jobListeners != null) {
 227                 PrintJobListener listener;
 228                 PrintJobEvent event = new PrintJobEvent(this, reason);
 229                 for (int i = 0; i < jobListeners.size(); i++) {
 230                     listener = (PrintJobListener)(jobListeners.elementAt(i));
 231                     switch (reason) {
 232 
 233                         case PrintJobEvent.JOB_COMPLETE :
 234                             listener.printJobCompleted(event);
 235                             break;
 236 
 237                         case PrintJobEvent.JOB_CANCELED :
 238                             listener.printJobCanceled(event);
 239                             break;
 240 
 241                         case PrintJobEvent.JOB_FAILED :
 242                             listener.printJobFailed(event);
 243                             break;
 244 
 245                         case PrintJobEvent.DATA_TRANSFER_COMPLETE :
 246                             listener.printDataTransferCompleted(event);
 247                             break;
 248 
 249                         case PrintJobEvent.NO_MORE_EVENTS :
 250                             listener.printJobNoMoreEvents(event);
 251                             break;
 252 
 253                         default:
 254                             break;
 255                     }
 256                 }
 257             }
 258        }
 259     }
 260 
 261     public void addPrintJobAttributeListener(
 262                                   PrintJobAttributeListener listener,
 263                                   PrintJobAttributeSet attributes) {
 264         synchronized (this) {
 265             if (listener == null) {
 266                 return;
 267             }
 268             if (attrListeners == null) {
 269                 attrListeners = new Vector();
 270                 listenedAttributeSets = new Vector();
 271             }
 272             attrListeners.add(listener);
 273             if (attributes == null) {
 274                 attributes = new HashPrintJobAttributeSet();
 275             }
 276             listenedAttributeSets.add(attributes);
 277         }
 278     }
 279 
 280     public void removePrintJobAttributeListener(
 281                                         PrintJobAttributeListener listener) {
 282         synchronized (this) {
 283             if (listener == null || attrListeners == null ) {
 284                 return;
 285             }
 286             int index = attrListeners.indexOf(listener);
 287             if (index == -1) {
 288                 return;
 289             } else {
 290                 attrListeners.remove(index);


 653                         str = ((URL)(doc.getPrintData())).toString();
 654                     }
 655                 } catch (IOException e) {
 656                 }
 657                 jobName = new JobName(str, null);
 658                 jobAttrSet.add(jobName);
 659             }
 660         }
 661 
 662         jobAttrSet = AttributeSetUtilities.unmodifiableView(jobAttrSet);
 663     }
 664 
 665     private void getAttributeValues(DocFlavor flavor) throws PrintException {
 666 
 667         if (reqAttrSet.get(Fidelity.class) == Fidelity.FIDELITY_TRUE) {
 668             fidelity = true;
 669         } else {
 670             fidelity = false;
 671         }
 672 
 673         Class category;
 674         Attribute [] attrs = reqAttrSet.toArray();
 675         for (int i=0; i<attrs.length; i++) {
 676             Attribute attr = attrs[i];
 677             category = attr.getCategory();
 678             if (fidelity == true) {
 679                 if (!service.isAttributeCategorySupported(category)) {
 680                     notifyEvent(PrintJobEvent.JOB_FAILED);
 681                     throw new PrintJobAttributeException(
 682                         "unsupported category: " + category, category, null);
 683                 } else if
 684                     (!service.isAttributeValueSupported(attr, flavor, null)) {
 685                     notifyEvent(PrintJobEvent.JOB_FAILED);
 686                     throw new PrintJobAttributeException(
 687                         "unsupported attribute: " + attr, null, attr);
 688                 }
 689             }
 690             if (category == Destination.class) {
 691               URI uri = ((Destination)attr).getURI();
 692               if (!"file".equals(uri.getScheme())) {
 693                 notifyEvent(PrintJobEvent.JOB_FAILED);




  62 import javax.print.attribute.standard.Copies;
  63 import javax.print.attribute.standard.DocumentName;
  64 import javax.print.attribute.standard.Fidelity;
  65 import javax.print.attribute.standard.JobName;
  66 import javax.print.attribute.standard.JobOriginatingUserName;
  67 import javax.print.attribute.standard.Media;
  68 import javax.print.attribute.standard.MediaSize;
  69 import javax.print.attribute.standard.MediaSizeName;
  70 import javax.print.attribute.standard.OrientationRequested;
  71 import javax.print.attribute.standard.RequestingUserName;
  72 import javax.print.attribute.standard.Destination;
  73 import javax.print.attribute.standard.PrinterIsAcceptingJobs;
  74 import javax.print.attribute.standard.PrinterState;
  75 import javax.print.attribute.standard.PrinterStateReason;
  76 import javax.print.attribute.standard.PrinterStateReasons;
  77 
  78 import java.awt.print.*;
  79 
  80 public class Win32PrintJob implements CancelablePrintJob {
  81 
  82     transient private Vector<PrintJobListener> jobListeners;
  83     transient private Vector<PrintJobAttributeListener> attrListeners;
  84     transient private Vector<PrintJobAttributeSet> listenedAttributeSets;
  85 
  86     private Win32PrintService service;
  87     private boolean fidelity;
  88     private boolean printing = false;
  89     private boolean printReturned = false;
  90     private PrintRequestAttributeSet reqAttrSet = null;
  91     private PrintJobAttributeSet jobAttrSet = null;
  92     private PrinterJob job;
  93     private Doc doc;
  94     private String mDestination = null;
  95 
  96     /* these variables used globally to store reference to the print
  97      * data retrieved as a stream. On completion these are always closed
  98      * if non-null.
  99      */
 100     private InputStream instream = null;
 101     private Reader reader = null;
 102 
 103     /* default values overridden by those extracted from the attributes */
 104     private String jobName = "Java Printing";


 122     }
 123 
 124     public PrintJobAttributeSet getAttributes() {
 125         synchronized (this) {
 126             if (jobAttrSet == null) {
 127                 /* just return an empty set until the job is submitted */
 128                 PrintJobAttributeSet jobSet = new HashPrintJobAttributeSet();
 129                 return AttributeSetUtilities.unmodifiableView(jobSet);
 130             } else {
 131               return jobAttrSet;
 132             }
 133         }
 134     }
 135 
 136     public void addPrintJobListener(PrintJobListener listener) {
 137         synchronized (this) {
 138             if (listener == null) {
 139                 return;
 140             }
 141             if (jobListeners == null) {
 142                 jobListeners = new Vector<>();
 143             }
 144             jobListeners.add(listener);
 145         }
 146     }
 147 
 148     public void removePrintJobListener(PrintJobListener listener) {
 149         synchronized (this) {
 150             if (listener == null || jobListeners == null ) {
 151                 return;
 152             }
 153             jobListeners.remove(listener);
 154             if (jobListeners.isEmpty()) {
 155                 jobListeners = null;
 156             }
 157         }
 158     }
 159 
 160 
 161     /* Closes any stream already retrieved for the data.
 162      * We want to avoid unnecessarily asking the Doc to create a stream only


 210 
 211     private void notifyEvent(int reason) {
 212 
 213         /* since this method should always get called, here's where
 214          * we will perform the clean up of any data stream supplied.
 215          */
 216         switch (reason) {
 217             case PrintJobEvent.DATA_TRANSFER_COMPLETE:
 218             case PrintJobEvent.JOB_CANCELED :
 219             case PrintJobEvent.JOB_FAILED :
 220             case PrintJobEvent.NO_MORE_EVENTS :
 221             case PrintJobEvent.JOB_COMPLETE :
 222                 closeDataStreams();
 223         }
 224 
 225         synchronized (this) {
 226             if (jobListeners != null) {
 227                 PrintJobListener listener;
 228                 PrintJobEvent event = new PrintJobEvent(this, reason);
 229                 for (int i = 0; i < jobListeners.size(); i++) {
 230                     listener = jobListeners.elementAt(i);
 231                     switch (reason) {
 232 
 233                         case PrintJobEvent.JOB_COMPLETE :
 234                             listener.printJobCompleted(event);
 235                             break;
 236 
 237                         case PrintJobEvent.JOB_CANCELED :
 238                             listener.printJobCanceled(event);
 239                             break;
 240 
 241                         case PrintJobEvent.JOB_FAILED :
 242                             listener.printJobFailed(event);
 243                             break;
 244 
 245                         case PrintJobEvent.DATA_TRANSFER_COMPLETE :
 246                             listener.printDataTransferCompleted(event);
 247                             break;
 248 
 249                         case PrintJobEvent.NO_MORE_EVENTS :
 250                             listener.printJobNoMoreEvents(event);
 251                             break;
 252 
 253                         default:
 254                             break;
 255                     }
 256                 }
 257             }
 258        }
 259     }
 260 
 261     public void addPrintJobAttributeListener(
 262                                   PrintJobAttributeListener listener,
 263                                   PrintJobAttributeSet attributes) {
 264         synchronized (this) {
 265             if (listener == null) {
 266                 return;
 267             }
 268             if (attrListeners == null) {
 269                 attrListeners = new Vector<>();
 270                 listenedAttributeSets = new Vector<>();
 271             }
 272             attrListeners.add(listener);
 273             if (attributes == null) {
 274                 attributes = new HashPrintJobAttributeSet();
 275             }
 276             listenedAttributeSets.add(attributes);
 277         }
 278     }
 279 
 280     public void removePrintJobAttributeListener(
 281                                         PrintJobAttributeListener listener) {
 282         synchronized (this) {
 283             if (listener == null || attrListeners == null ) {
 284                 return;
 285             }
 286             int index = attrListeners.indexOf(listener);
 287             if (index == -1) {
 288                 return;
 289             } else {
 290                 attrListeners.remove(index);


 653                         str = ((URL)(doc.getPrintData())).toString();
 654                     }
 655                 } catch (IOException e) {
 656                 }
 657                 jobName = new JobName(str, null);
 658                 jobAttrSet.add(jobName);
 659             }
 660         }
 661 
 662         jobAttrSet = AttributeSetUtilities.unmodifiableView(jobAttrSet);
 663     }
 664 
 665     private void getAttributeValues(DocFlavor flavor) throws PrintException {
 666 
 667         if (reqAttrSet.get(Fidelity.class) == Fidelity.FIDELITY_TRUE) {
 668             fidelity = true;
 669         } else {
 670             fidelity = false;
 671         }
 672 
 673         Class<? extends Attribute> category;
 674         Attribute [] attrs = reqAttrSet.toArray();
 675         for (int i=0; i<attrs.length; i++) {
 676             Attribute attr = attrs[i];
 677             category = attr.getCategory();
 678             if (fidelity == true) {
 679                 if (!service.isAttributeCategorySupported(category)) {
 680                     notifyEvent(PrintJobEvent.JOB_FAILED);
 681                     throw new PrintJobAttributeException(
 682                         "unsupported category: " + category, category, null);
 683                 } else if
 684                     (!service.isAttributeValueSupported(attr, flavor, null)) {
 685                     notifyEvent(PrintJobEvent.JOB_FAILED);
 686                     throw new PrintJobAttributeException(
 687                         "unsupported attribute: " + attr, null, attr);
 688                 }
 689             }
 690             if (category == Destination.class) {
 691               URI uri = ((Destination)attr).getURI();
 692               if (!"file".equals(uri.getScheme())) {
 693                 notifyEvent(PrintJobEvent.JOB_FAILED);