List of usage examples for javax.print.event PrintJobAdapter PrintJobAdapter
PrintJobAdapter
From source file:Main.java
public static void main(String args[]) throws Exception { String filename = args[0];/*w w w .j a v a 2 s. c om*/ DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; PrintService printService = PrintServiceLookup.lookupDefaultPrintService(); DocPrintJob job = printService.createPrintJob(); PrintJobListener listener = new PrintJobAdapter() { public void printDataTransferCompleted(PrintJobEvent e) { System.out.println("Good-bye"); System.exit(0); } }; job.addPrintJobListener(listener); PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); FileInputStream fis = new FileInputStream(filename); DocAttributeSet das = new HashDocAttributeSet(); Doc doc = new SimpleDoc(fis, flavor, das); job.print(doc, pras); Thread.sleep(10000); }
From source file:OneFourDialog.java
public static void main(String args[]) throws Exception { String filename = args[0];/*from www . ja v a2s . c o m*/ PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras); PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService(); PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService, DocFlavor.INPUT_STREAM.GIF, pras); if (service != null) { DocPrintJob job = service.createPrintJob(); PrintJobListener listener = new PrintJobAdapter() { public void printDataTransferCompleted(PrintJobEvent e) { System.exit(0); } }; job.addPrintJobListener(listener); FileInputStream fis = new FileInputStream(filename); DocAttributeSet das = new HashDocAttributeSet(); Doc doc = new SimpleDoc(fis, flavor, das); job.print(doc, pras); Thread.sleep(10000); } }
From source file:Main.java
PrintJobWatcher(DocPrintJob job) { job.addPrintJobListener(new PrintJobAdapter() { public void printJobCanceled(PrintJobEvent pje) { synchronized (PrintJobWatcher.this) { done = true;//from w w w. jav a 2s. co m PrintJobWatcher.this.notify(); } } public void printJobCompleted(PrintJobEvent pje) { synchronized (PrintJobWatcher.this) { done = true; PrintJobWatcher.this.notify(); } } public void printJobFailed(PrintJobEvent pje) { synchronized (PrintJobWatcher.this) { done = true; PrintJobWatcher.this.notify(); } } public void printJobNoMoreEvents(PrintJobEvent pje) { synchronized (PrintJobWatcher.this) { done = true; PrintJobWatcher.this.notify(); } } }); }
From source file:Main.java
PrintJobWatcher(DocPrintJob job) { job.addPrintJobListener(new PrintJobAdapter() { public void printJobCanceled(PrintJobEvent pje) { synchronized (PrintJobWatcher.this) { done = true;//from ww w . ja v a 2 s . c o m PrintJobWatcher.this.notify(); } } public void printJobCompleted(PrintJobEvent pje) { synchronized (PrintJobWatcher.this) { done = true; PrintJobWatcher.this.notify(); } } public void printJobFailed(PrintJobEvent pje) { synchronized (PrintJobWatcher.this) { done = true; PrintJobWatcher.this.notify(); } } public void printJobNoMoreEvents(PrintJobEvent pje) { synchronized (PrintJobWatcher.this) { done = true; PrintJobWatcher.this.notify(); } } }); }
From source file:JuliaSet3.java
public void printToService(PrintService service, PrintRequestAttributeSet printAttributes) { // Wrap ourselves in the PrintableComponent class defined by JuliaSet2. String title = "Julia set for c={" + cx + "," + cy + "}"; Printable printable = new PrintableComponent(this, title); // Now create a Doc that encapsulate the Printable object and its type DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; Doc doc = new SimpleDoc(printable, flavor, null); // Java 1.1 uses PrintJob. // Java 1.2 uses PrinterJob. // Java 1.4 uses DocPrintJob. Create one from the service DocPrintJob job = service.createPrintJob(); // Set up a dialog box to monitor printing status final JOptionPane pane = new JOptionPane("Printing...", JOptionPane.PLAIN_MESSAGE); JDialog dialog = pane.createDialog(this, "Print Status"); // This listener object updates the dialog as the status changes job.addPrintJobListener(new PrintJobAdapter() { public void printJobCompleted(PrintJobEvent e) { pane.setMessage("Printing complete."); }//from w w w.jav a 2 s .c o m public void printDataTransferCompleted(PrintJobEvent e) { pane.setMessage("Document transfered to printer."); } public void printJobRequiresAttention(PrintJobEvent e) { pane.setMessage("Check printer: out of paper?"); } public void printJobFailed(PrintJobEvent e) { pane.setMessage("Print job failed"); } }); // Show the dialog, non-modal. dialog.setModal(false); dialog.show(); // Now print the Doc to the DocPrintJob try { job.print(doc, printAttributes); } catch (PrintException e) { // Display any errors to the dialog box pane.setMessage(e.toString()); } }
From source file:Print.java
public static void printToService(PrintService service, String filename, PrintRequestAttributeSet attributes) throws IOException { // Figure out what type of file we're printing DocFlavor flavor = getFlavorFromFilename(filename); // Open the file InputStream in = new FileInputStream(filename); // Create a Doc object to print from the file and flavor. Doc doc = new SimpleDoc(in, flavor, null); // Create a print job from the service DocPrintJob job = service.createPrintJob(); // Monitor the print job with a listener job.addPrintJobListener(new PrintJobAdapter() { public void printJobCompleted(PrintJobEvent e) { System.out.println("Print job complete"); System.exit(0);/*from w ww. j a va2 s. c om*/ } public void printDataTransferCompleted(PrintJobEvent e) { System.out.println("Document transfered to printer"); } public void printJobRequiresAttention(PrintJobEvent e) { System.out.println("Print job requires attention"); System.out.println("Check printer: out of paper?"); } public void printJobFailed(PrintJobEvent e) { System.out.println("Print job failed"); System.exit(1); } }); // Now print the document, catching errors try { job.print(doc, attributes); } catch (PrintException e) { System.out.println(e); System.exit(1); } }