< prev index next >

src/java.desktop/share/classes/java/awt/print/PrinterJob.java

Print this page




  55      * associated with the default printer.
  56      * If no printers are available on the system, a PrinterJob will still
  57      * be returned from this method, but {@code getPrintService()}
  58      * will return {@code null}, and calling
  59      * {@link #print() print} with this {@code PrinterJob} might
  60      * generate an exception.  Applications that need to determine if
  61      * there are suitable printers before creating a {@code PrinterJob}
  62      * should ensure that the array returned from
  63      * {@link #lookupPrintServices() lookupPrintServices} is not empty.
  64      * @return a new {@code PrinterJob}.
  65      *
  66      * @throws  SecurityException if a security manager exists and its
  67      *          {@link java.lang.SecurityManager#checkPrintJobAccess}
  68      *          method disallows this thread from creating a print job request
  69      */
  70     public static PrinterJob getPrinterJob() {
  71         SecurityManager security = System.getSecurityManager();
  72         if (security != null) {
  73             security.checkPrintJobAccess();
  74         }
  75         return java.security.AccessController.doPrivileged(
  76             new java.security.PrivilegedAction<PrinterJob>() {
  77             public PrinterJob run() {
  78                 String nm = System.getProperty("java.awt.printerjob", null);
  79                 try {
  80                     return (PrinterJob)Class.forName(nm).
  81                                              getConstructor().newInstance();
  82                 } catch (ClassNotFoundException e) {
  83                     throw new AWTError("PrinterJob not found: " + nm);
  84                 } catch (ReflectiveOperationException e) {
  85                  throw new AWTError("Could not instantiate PrinterJob: " + nm);
  86                 }
  87             }
  88         });
  89     }
  90 
  91     /**
  92      * A convenience method which looks up 2D print services.
  93      * Services returned from this method may be installed on
  94      * {@code PrinterJob}s which support print services.
  95      * Calling this method is equivalent to calling
  96      * {@link javax.print.PrintServiceLookup#lookupPrintServices(
  97      * DocFlavor, AttributeSet)
  98      * PrintServiceLookup.lookupPrintServices()}
  99      * and specifying a Pageable DocFlavor.
 100      * @return a possibly empty array of 2D print services.
 101      * @since     1.4
 102      */
 103     public static PrintService[] lookupPrintServices() {
 104         return PrintServiceLookup.
 105             lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
 106     }
 107 
 108 




  55      * associated with the default printer.
  56      * If no printers are available on the system, a PrinterJob will still
  57      * be returned from this method, but {@code getPrintService()}
  58      * will return {@code null}, and calling
  59      * {@link #print() print} with this {@code PrinterJob} might
  60      * generate an exception.  Applications that need to determine if
  61      * there are suitable printers before creating a {@code PrinterJob}
  62      * should ensure that the array returned from
  63      * {@link #lookupPrintServices() lookupPrintServices} is not empty.
  64      * @return a new {@code PrinterJob}.
  65      *
  66      * @throws  SecurityException if a security manager exists and its
  67      *          {@link java.lang.SecurityManager#checkPrintJobAccess}
  68      *          method disallows this thread from creating a print job request
  69      */
  70     public static PrinterJob getPrinterJob() {
  71         SecurityManager security = System.getSecurityManager();
  72         if (security != null) {
  73             security.checkPrintJobAccess();
  74         }
  75         return sun.print.PlatformPrinterJobProxy.getPrinterJob();













  76     }
  77 
  78     /**
  79      * A convenience method which looks up 2D print services.
  80      * Services returned from this method may be installed on
  81      * {@code PrinterJob}s which support print services.
  82      * Calling this method is equivalent to calling
  83      * {@link javax.print.PrintServiceLookup#lookupPrintServices(
  84      * DocFlavor, AttributeSet)
  85      * PrintServiceLookup.lookupPrintServices()}
  86      * and specifying a Pageable DocFlavor.
  87      * @return a possibly empty array of 2D print services.
  88      * @since     1.4
  89      */
  90     public static PrintService[] lookupPrintServices() {
  91         return PrintServiceLookup.
  92             lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
  93     }
  94 
  95 


< prev index next >