< prev index next >

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

Print this page




  62      * generate an exception.  Applications that need to determine if
  63      * there are suitable printers before creating a {@code PrinterJob}
  64      * should ensure that the array returned from
  65      * {@link #lookupPrintServices() lookupPrintServices} is not empty.
  66      * @return a new {@code PrinterJob}.
  67      *
  68      * @throws  SecurityException if a security manager exists and its
  69      *          {@link java.lang.SecurityManager#checkPrintJobAccess}
  70      *          method disallows this thread from creating a print job request
  71      */
  72     public static PrinterJob getPrinterJob() {
  73         SecurityManager security = System.getSecurityManager();
  74         if (security != null) {
  75             security.checkPrintJobAccess();
  76         }
  77         return java.security.AccessController.doPrivileged(
  78             new java.security.PrivilegedAction<PrinterJob>() {
  79             public PrinterJob run() {
  80                 String nm = System.getProperty("java.awt.printerjob", null);
  81                 try {
  82                     return (PrinterJob)Class.forName(nm).newInstance();


  83                 } catch (ClassNotFoundException e) {
  84                     throw new AWTError("PrinterJob not found: " + nm);
  85                 } catch (InstantiationException e) {
  86                  throw new AWTError("Could not instantiate PrinterJob: " + nm);
  87                 } catch (IllegalAccessException e) {
  88                     throw new AWTError("Could not access PrinterJob: " + nm);
  89                 }
  90             }
  91         });
  92     }
  93 
  94     /**
  95      * A convenience method which looks up 2D print services.
  96      * Services returned from this method may be installed on
  97      * {@code PrinterJob}s which support print services.
  98      * Calling this method is equivalent to calling
  99      * {@link javax.print.PrintServiceLookup#lookupPrintServices(
 100      * DocFlavor, AttributeSet)
 101      * PrintServiceLookup.lookupPrintServices()}
 102      * and specifying a Pageable DocFlavor.




  62      * generate an exception.  Applications that need to determine if
  63      * there are suitable printers before creating a {@code PrinterJob}
  64      * should ensure that the array returned from
  65      * {@link #lookupPrintServices() lookupPrintServices} is not empty.
  66      * @return a new {@code PrinterJob}.
  67      *
  68      * @throws  SecurityException if a security manager exists and its
  69      *          {@link java.lang.SecurityManager#checkPrintJobAccess}
  70      *          method disallows this thread from creating a print job request
  71      */
  72     public static PrinterJob getPrinterJob() {
  73         SecurityManager security = System.getSecurityManager();
  74         if (security != null) {
  75             security.checkPrintJobAccess();
  76         }
  77         return java.security.AccessController.doPrivileged(
  78             new java.security.PrivilegedAction<PrinterJob>() {
  79             public PrinterJob run() {
  80                 String nm = System.getProperty("java.awt.printerjob", null);
  81                 try {
  82                     @SuppressWarnings("deprecation")
  83                     Object tmp = Class.forName(nm).newInstance();
  84                     return (PrinterJob)tmp;
  85                 } catch (ClassNotFoundException e) {
  86                     throw new AWTError("PrinterJob not found: " + nm);
  87                 } catch (InstantiationException e) {
  88                  throw new AWTError("Could not instantiate PrinterJob: " + nm);
  89                 } catch (IllegalAccessException e) {
  90                     throw new AWTError("Could not access PrinterJob: " + nm);
  91                 }
  92             }
  93         });
  94     }
  95 
  96     /**
  97      * A convenience method which looks up 2D print services.
  98      * Services returned from this method may be installed on
  99      * {@code PrinterJob}s which support print services.
 100      * Calling this method is equivalent to calling
 101      * {@link javax.print.PrintServiceLookup#lookupPrintServices(
 102      * DocFlavor, AttributeSet)
 103      * PrintServiceLookup.lookupPrintServices()}
 104      * and specifying a Pageable DocFlavor.


< prev index next >