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. 103 * @return a possibly empty array of 2D print services. 104 * @since 1.4 105 */ 106 public static PrintService[] lookupPrintServices() { 107 return PrintServiceLookup. 108 lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null); | 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). 83 getConstructor().newInstance(); 84 } catch (ClassNotFoundException e) { 85 throw new AWTError("PrinterJob not found: " + nm); 86 } catch (ReflectiveOperationException e) { 87 throw new AWTError("Could not instantiate PrinterJob: " + nm); 88 } 89 } 90 }); 91 } 92 93 /** 94 * A convenience method which looks up 2D print services. 95 * Services returned from this method may be installed on 96 * {@code PrinterJob}s which support print services. 97 * Calling this method is equivalent to calling 98 * {@link javax.print.PrintServiceLookup#lookupPrintServices( 99 * DocFlavor, AttributeSet) 100 * PrintServiceLookup.lookupPrintServices()} 101 * and specifying a Pageable DocFlavor. 102 * @return a possibly empty array of 2D print services. 103 * @since 1.4 104 */ 105 public static PrintService[] lookupPrintServices() { 106 return PrintServiceLookup. 107 lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null); |