Search in sources :

Example 21 with PrintService

use of javax.print.PrintService in project jdk8u_jdk by JetBrains.

the class UnixPrintServiceLookup method getPrintServices.

private PrintService[] getPrintServices(PrintServiceAttributeSet serviceSet) {
    if (serviceSet == null || serviceSet.isEmpty()) {
        return getPrintServices();
    }
    /* Typically expect that if a service attribute is specified that
         * its a printer name and there ought to be only one match.
         * Directly retrieve that service and confirm
         * that it meets the other requirements.
         * If printer name isn't mentioned then go a slow path checking
         * all printers if they meet the reqiremements.
         */
    PrintService[] services;
    PrinterName name = (PrinterName) serviceSet.get(PrinterName.class);
    PrintService defService;
    if (name != null && (defService = getDefaultPrintService()) != null) {
        /* To avoid execing a unix command  see if the client is asking
             * for the default printer by name, since we already have that
             * initialised.
             */
        PrinterName defName = (PrinterName) defService.getAttribute(PrinterName.class);
        if (defName != null && name.equals(defName)) {
            if (matchesAttributes(defService, serviceSet)) {
                services = new PrintService[1];
                services[0] = defService;
                return services;
            } else {
                return new PrintService[0];
            }
        } else {
            /* Its not the default service */
            PrintService service = getServiceByName(name);
            if (service != null && matchesAttributes(service, serviceSet)) {
                services = new PrintService[1];
                services[0] = service;
                return services;
            } else {
                return new PrintService[0];
            }
        }
    } else {
        /* specified service attributes don't include a name.*/
        Vector matchedServices = new Vector();
        services = getPrintServices();
        for (int i = 0; i < services.length; i++) {
            if (matchesAttributes(services[i], serviceSet)) {
                matchedServices.add(services[i]);
            }
        }
        services = new PrintService[matchedServices.size()];
        for (int i = 0; i < services.length; i++) {
            services[i] = (PrintService) matchedServices.elementAt(i);
        }
        return services;
    }
}
Also used : PrinterName(javax.print.attribute.standard.PrinterName) Vector(java.util.Vector) MultiDocPrintService(javax.print.MultiDocPrintService) PrintService(javax.print.PrintService)

Example 22 with PrintService

use of javax.print.PrintService in project jdk8u_jdk by JetBrains.

the class WPrinterJob method getPrinterAttrib.

//** BEGIN Functions called by native code for querying/updating attributes
private final String getPrinterAttrib() {
    // getPrintService will get current print service or default if none
    PrintService service = this.getPrintService();
    String name = (service != null) ? service.getName() : null;
    return name;
}
Also used : Win32PrintService(sun.print.Win32PrintService) PrintService(javax.print.PrintService)

Example 23 with PrintService

use of javax.print.PrintService in project jdk8u_jdk by JetBrains.

the class Win32PrintJob method printableJob.

public void printableJob(Printable printable) throws PrintException {
    try {
        synchronized (this) {
            if (job != null) {
                // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new sun.awt.windows.WPrinterJob();
            }
        }
        PrintService svc = getPrintService();
        job.setPrintService(svc);
        if (copies == 0) {
            Copies c = (Copies) svc.getDefaultAttributeValue(Copies.class);
            copies = c.getValue();
        }
        if (mediaName == null) {
            Object media = svc.getDefaultAttributeValue(Media.class);
            if (media instanceof MediaSizeName) {
                mediaName = (MediaSizeName) media;
                mediaSize = MediaSize.getMediaSizeForName(mediaName);
            }
        }
        if (orient == null) {
            orient = (OrientationRequested) svc.getDefaultAttributeValue(OrientationRequested.class);
        }
        job.setCopies(copies);
        job.setJobName(jobName);
        PageFormat pf = new PageFormat();
        if (mediaSize != null) {
            Paper p = new Paper();
            p.setSize(mediaSize.getX(MediaSize.INCH) * 72.0, mediaSize.getY(MediaSize.INCH) * 72.0);
            p.setImageableArea(72.0, 72.0, p.getWidth() - 144.0, p.getHeight() - 144.0);
            pf.setPaper(p);
        }
        if (orient == OrientationRequested.REVERSE_LANDSCAPE) {
            pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
        } else if (orient == OrientationRequested.LANDSCAPE) {
            pf.setOrientation(PageFormat.LANDSCAPE);
        }
        job.setPrintable(printable, pf);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
Also used : PrintException(javax.print.PrintException) MediaSizeName(javax.print.attribute.standard.MediaSizeName) Copies(javax.print.attribute.standard.Copies) PrintService(javax.print.PrintService)

Example 24 with PrintService

use of javax.print.PrintService in project jdk8u_jdk by JetBrains.

the class Win32PrintJob method pageableJob.

public void pageableJob(Pageable pageable) throws PrintException {
    try {
        synchronized (this) {
            if (job != null) {
                // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new sun.awt.windows.WPrinterJob();
            }
        }
        PrintService svc = getPrintService();
        job.setPrintService(svc);
        if (copies == 0) {
            Copies c = (Copies) svc.getDefaultAttributeValue(Copies.class);
            copies = c.getValue();
        }
        job.setCopies(copies);
        job.setJobName(jobName);
        job.setPageable(pageable);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
Also used : PrintException(javax.print.PrintException) Copies(javax.print.attribute.standard.Copies) PrintService(javax.print.PrintService)

Example 25 with PrintService

use of javax.print.PrintService in project jdk8u_jdk by JetBrains.

the class Win32PrintServiceLookup method getPrintServices.

public PrintService[] getPrintServices(DocFlavor flavor, AttributeSet attributes) {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPrintJobAccess();
    }
    PrintRequestAttributeSet requestSet = null;
    PrintServiceAttributeSet serviceSet = null;
    if (attributes != null && !attributes.isEmpty()) {
        requestSet = new HashPrintRequestAttributeSet();
        serviceSet = new HashPrintServiceAttributeSet();
        Attribute[] attrs = attributes.toArray();
        for (int i = 0; i < attrs.length; i++) {
            if (attrs[i] instanceof PrintRequestAttribute) {
                requestSet.add(attrs[i]);
            } else if (attrs[i] instanceof PrintServiceAttribute) {
                serviceSet.add(attrs[i]);
            }
        }
    }
    /*
         * Special case: If client is asking for a particular printer
         * (by name) then we can save time by getting just that service
         * to check against the rest of the specified attributes.
         */
    PrintService[] services = null;
    if (serviceSet != null && serviceSet.get(PrinterName.class) != null) {
        PrinterName name = (PrinterName) serviceSet.get(PrinterName.class);
        PrintService service = getPrintServiceByName(name.getValue());
        if (service == null || !matchingService(service, serviceSet)) {
            services = new PrintService[0];
        } else {
            services = new PrintService[1];
            services[0] = service;
        }
    } else {
        services = getPrintServices();
    }
    if (services.length == 0) {
        return services;
    } else {
        ArrayList matchingServices = new ArrayList();
        for (int i = 0; i < services.length; i++) {
            try {
                if (services[i].getUnsupportedAttributes(flavor, requestSet) == null) {
                    matchingServices.add(services[i]);
                }
            } catch (IllegalArgumentException e) {
            }
        }
        services = new PrintService[matchingServices.size()];
        return (PrintService[]) matchingServices.toArray(services);
    }
}
Also used : PrintServiceAttribute(javax.print.attribute.PrintServiceAttribute) Attribute(javax.print.attribute.Attribute) PrintRequestAttribute(javax.print.attribute.PrintRequestAttribute) ArrayList(java.util.ArrayList) HashPrintServiceAttributeSet(javax.print.attribute.HashPrintServiceAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintService(javax.print.PrintService) MultiDocPrintService(javax.print.MultiDocPrintService) PrinterName(javax.print.attribute.standard.PrinterName) PrintRequestAttribute(javax.print.attribute.PrintRequestAttribute) PrintServiceAttribute(javax.print.attribute.PrintServiceAttribute) PrintServiceAttributeSet(javax.print.attribute.PrintServiceAttributeSet) HashPrintServiceAttributeSet(javax.print.attribute.HashPrintServiceAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet)

Aggregations

PrintService (javax.print.PrintService)48 StreamPrintService (javax.print.StreamPrintService)13 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)13 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)13 PrinterException (java.awt.print.PrinterException)10 PageFormat (java.awt.print.PageFormat)9 IOException (java.io.IOException)8 MultiDocPrintService (javax.print.MultiDocPrintService)8 DocFlavor (javax.print.DocFlavor)7 Copies (javax.print.attribute.standard.Copies)7 MediaSizeName (javax.print.attribute.standard.MediaSizeName)7 HeadlessException (java.awt.HeadlessException)6 File (java.io.File)6 DocPrintJob (javax.print.DocPrintJob)5 PrintException (javax.print.PrintException)5 Destination (javax.print.attribute.standard.Destination)5 Media (javax.print.attribute.standard.Media)5 MediaSize (javax.print.attribute.standard.MediaSize)5 Paper (java.awt.print.Paper)4 ArrayList (java.util.ArrayList)4