Example usage for javax.print.event PrintJobEvent toString

List of usage examples for javax.print.event PrintJobEvent toString

Introduction

In this page you can find the example usage for javax.print.event PrintJobEvent toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of this PrintEvent .

Usage

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.");
        }/*w ww  . j a  va2  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());
    }
}