Search in sources :

Example 1 with PrintJobEvent

use of javax.print.event.PrintJobEvent in project jdk8u_jdk by JetBrains.

the class PrintSEUmlauts method main.

public static void main(String[] args) throws Exception {
    GraphicsEnvironment.getLocalGraphicsEnvironment();
    DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
    String mime = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();
    StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, mime);
    if (factories.length == 0) {
        System.out.println("No print service found.");
        return;
    }
    FileOutputStream output = new FileOutputStream("out.ps");
    StreamPrintService service = factories[0].getPrintService(output);
    SimpleDoc doc = new SimpleDoc(new PrintSEUmlauts(), DocFlavor.SERVICE_FORMATTED.PRINTABLE, new HashDocAttributeSet());
    DocPrintJob job = service.createPrintJob();
    job.addPrintJobListener(new PrintJobAdapter() {

        @Override
        public void printJobCompleted(PrintJobEvent pje) {
            testPrintAndExit();
        }
    });
    job.print(doc, new HashPrintRequestAttributeSet());
}
Also used : HashDocAttributeSet(javax.print.attribute.HashDocAttributeSet) DocPrintJob(javax.print.DocPrintJob) StreamPrintService(javax.print.StreamPrintService) SimpleDoc(javax.print.SimpleDoc) FileOutputStream(java.io.FileOutputStream) PrintJobAdapter(javax.print.event.PrintJobAdapter) DocFlavor(javax.print.DocFlavor) StreamPrintServiceFactory(javax.print.StreamPrintServiceFactory) PrintJobEvent(javax.print.event.PrintJobEvent) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet)

Example 2 with PrintJobEvent

use of javax.print.event.PrintJobEvent in project jdk8u_jdk by JetBrains.

the class UnixPrintJob method notifyEvent.

private void notifyEvent(int reason) {
    /* since this method should always get called, here's where
         * we will perform the clean up of any data stream supplied.
         */
    switch(reason) {
        case PrintJobEvent.DATA_TRANSFER_COMPLETE:
        case PrintJobEvent.JOB_CANCELED:
        case PrintJobEvent.JOB_FAILED:
        case PrintJobEvent.NO_MORE_EVENTS:
        case PrintJobEvent.JOB_COMPLETE:
            closeDataStreams();
    }
    synchronized (this) {
        if (jobListeners != null) {
            PrintJobListener listener;
            PrintJobEvent event = new PrintJobEvent(this, reason);
            for (int i = 0; i < jobListeners.size(); i++) {
                listener = (PrintJobListener) (jobListeners.elementAt(i));
                switch(reason) {
                    case PrintJobEvent.JOB_CANCELED:
                        listener.printJobCanceled(event);
                        break;
                    case PrintJobEvent.JOB_FAILED:
                        listener.printJobFailed(event);
                        break;
                    case PrintJobEvent.DATA_TRANSFER_COMPLETE:
                        listener.printDataTransferCompleted(event);
                        break;
                    case PrintJobEvent.NO_MORE_EVENTS:
                        listener.printJobNoMoreEvents(event);
                        break;
                    default:
                        break;
                }
            }
        }
    }
}
Also used : PrintJobEvent(javax.print.event.PrintJobEvent) java.awt.print(java.awt.print) PrintJobListener(javax.print.event.PrintJobListener)

Example 3 with PrintJobEvent

use of javax.print.event.PrintJobEvent in project jdk8u_jdk by JetBrains.

the class PSStreamPrintJob method notifyEvent.

private void notifyEvent(int reason) {
    synchronized (this) {
        if (jobListeners != null) {
            PrintJobListener listener;
            PrintJobEvent event = new PrintJobEvent(this, reason);
            for (int i = 0; i < jobListeners.size(); i++) {
                listener = (PrintJobListener) (jobListeners.elementAt(i));
                switch(reason) {
                    case PrintJobEvent.JOB_CANCELED:
                        listener.printJobCanceled(event);
                        break;
                    case PrintJobEvent.JOB_FAILED:
                        listener.printJobFailed(event);
                        break;
                    case PrintJobEvent.DATA_TRANSFER_COMPLETE:
                        listener.printDataTransferCompleted(event);
                        break;
                    case PrintJobEvent.NO_MORE_EVENTS:
                        listener.printJobNoMoreEvents(event);
                        break;
                    case PrintJobEvent.JOB_COMPLETE:
                        listener.printJobCompleted(event);
                        break;
                    default:
                        break;
                }
            }
        }
    }
}
Also used : PrintJobEvent(javax.print.event.PrintJobEvent) java.awt.print(java.awt.print) PrintJobListener(javax.print.event.PrintJobListener)

Example 4 with PrintJobEvent

use of javax.print.event.PrintJobEvent in project jdk8u_jdk by JetBrains.

the class Win32PrintJob method notifyEvent.

private void notifyEvent(int reason) {
    /* since this method should always get called, here's where
         * we will perform the clean up of any data stream supplied.
         */
    switch(reason) {
        case PrintJobEvent.DATA_TRANSFER_COMPLETE:
        case PrintJobEvent.JOB_CANCELED:
        case PrintJobEvent.JOB_FAILED:
        case PrintJobEvent.NO_MORE_EVENTS:
        case PrintJobEvent.JOB_COMPLETE:
            closeDataStreams();
    }
    synchronized (this) {
        if (jobListeners != null) {
            PrintJobListener listener;
            PrintJobEvent event = new PrintJobEvent(this, reason);
            for (int i = 0; i < jobListeners.size(); i++) {
                listener = (PrintJobListener) (jobListeners.elementAt(i));
                switch(reason) {
                    case PrintJobEvent.JOB_COMPLETE:
                        listener.printJobCompleted(event);
                        break;
                    case PrintJobEvent.JOB_CANCELED:
                        listener.printJobCanceled(event);
                        break;
                    case PrintJobEvent.JOB_FAILED:
                        listener.printJobFailed(event);
                        break;
                    case PrintJobEvent.DATA_TRANSFER_COMPLETE:
                        listener.printDataTransferCompleted(event);
                        break;
                    case PrintJobEvent.NO_MORE_EVENTS:
                        listener.printJobNoMoreEvents(event);
                        break;
                    default:
                        break;
                }
            }
        }
    }
}
Also used : PrintJobEvent(javax.print.event.PrintJobEvent) java.awt.print(java.awt.print) PrintJobListener(javax.print.event.PrintJobListener)

Aggregations

PrintJobEvent (javax.print.event.PrintJobEvent)4 java.awt.print (java.awt.print)3 PrintJobListener (javax.print.event.PrintJobListener)3 FileOutputStream (java.io.FileOutputStream)1 DocFlavor (javax.print.DocFlavor)1 DocPrintJob (javax.print.DocPrintJob)1 SimpleDoc (javax.print.SimpleDoc)1 StreamPrintService (javax.print.StreamPrintService)1 StreamPrintServiceFactory (javax.print.StreamPrintServiceFactory)1 HashDocAttributeSet (javax.print.attribute.HashDocAttributeSet)1 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)1 PrintJobAdapter (javax.print.event.PrintJobAdapter)1