1 7 8 package java.awt.print; 9 10 import java.awt.AWTError ; 11 import java.awt.HeadlessException ; 12 import java.util.Enumeration ; 13 14 import javax.print.DocFlavor ; 15 import javax.print.PrintService ; 16 import javax.print.PrintServiceLookup ; 17 import javax.print.StreamPrintServiceFactory ; 18 import javax.print.attribute.PrintRequestAttributeSet ; 19 20 import sun.security.action.GetPropertyAction; 21 22 28 public abstract class PrinterJob { 29 30 31 32 45 public static PrinterJob getPrinterJob() { 46 SecurityManager security = System.getSecurityManager(); 47 if (security != null) { 48 security.checkPrintJobAccess(); 49 } 50 return (PrinterJob ) java.security.AccessController.doPrivileged( 51 new java.security.PrivilegedAction () { 52 public Object run() { 53 String nm = System.getProperty("java.awt.printerjob", null); 54 try { 55 return (PrinterJob )Class.forName(nm).newInstance(); 56 } catch (ClassNotFoundException e) { 57 throw new AWTError ("PrinterJob not found: " + nm); 58 } catch (InstantiationException e) { 59 throw new AWTError ("Could not instantiate PrinterJob: " + nm); 60 } catch (IllegalAccessException e) { 61 throw new AWTError ("Could not access PrinterJob: " + nm); 62 } 63 } 64 }); 65 } 66 67 79 public static PrintService [] lookupPrintServices() { 80 return PrintServiceLookup. 81 lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null); 82 } 83 84 85 116 public static StreamPrintServiceFactory [] 117 lookupStreamPrintServices(String mimeType) { 118 return StreamPrintServiceFactory.lookupStreamPrintServiceFactories( 119 DocFlavor.SERVICE_FORMATTED.PAGEABLE, 120 mimeType); 121 } 122 123 124 125 126 130 public PrinterJob() { 131 } 132 133 141 public PrintService getPrintService() { 142 return null; 143 } 144 145 161 public void setPrintService(PrintService service) 162 throws PrinterException { 163 throw new PrinterException ( 164 "Setting a service is not supported on this class"); 165 } 166 167 176 public abstract void setPrintable(Printable painter); 177 178 189 public abstract void setPrintable(Printable painter, PageFormat format); 190 191 203 public abstract void setPageable(Pageable document) 204 throws NullPointerException ; 205 206 225 public abstract boolean printDialog() throws HeadlessException ; 226 227 273 public boolean printDialog(PrintRequestAttributeSet attributes) 274 throws HeadlessException { 275 276 if (attributes == null) { 277 throw new NullPointerException ("attributes"); 278 } 279 return printDialog(); 280 } 281 282 304 public abstract PageFormat pageDialog(PageFormat page) 305 throws HeadlessException ; 306 307 336 public PageFormat pageDialog(PrintRequestAttributeSet attributes) 337 throws HeadlessException { 338 339 if (attributes == null) { 340 throw new NullPointerException ("attributes"); 341 } 342 return pageDialog(defaultPage()); 343 } 344 345 352 public abstract PageFormat defaultPage(PageFormat page); 353 354 360 public PageFormat defaultPage() { 361 return defaultPage(new PageFormat ()); 362 } 363 364 378 public abstract PageFormat validatePage(PageFormat page); 379 380 388 public abstract void print() throws PrinterException ; 389 390 427 public void print(PrintRequestAttributeSet attributes) 428 throws PrinterException { 429 print(); 430 } 431 432 437 public abstract void setCopies(int copies); 438 439 444 public abstract int getCopies(); 445 446 450 public abstract String getUserName(); 451 452 458 public abstract void setJobName(String jobName); 459 460 465 public abstract String getJobName(); 466 467 475 public abstract void cancel(); 476 477 485 public abstract boolean isCancelled(); 486 487 } 488 | Popular Tags |