Search in sources :

Example 6 with PrintServiceAttributeSet

use of javax.print.attribute.PrintServiceAttributeSet 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)

Example 7 with PrintServiceAttributeSet

use of javax.print.attribute.PrintServiceAttributeSet in project jdk8u_jdk by JetBrains.

the class PSPrinterJob method printDialog.

/* Instance Methods */
/**
     * Presents the user a dialog for changing properties of the
     * print job interactively.
     * @returns false if the user cancels the dialog and
     *          true otherwise.
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
     * returns true.
     * @see java.awt.GraphicsEnvironment#isHeadless
     */
public boolean printDialog() throws HeadlessException {
    if (GraphicsEnvironment.isHeadless()) {
        throw new HeadlessException();
    }
    if (attributes == null) {
        attributes = new HashPrintRequestAttributeSet();
    }
    attributes.add(new Copies(getCopies()));
    attributes.add(new JobName(getJobName(), null));
    boolean doPrint = false;
    DialogTypeSelection dts = (DialogTypeSelection) attributes.get(DialogTypeSelection.class);
    if (dts == DialogTypeSelection.NATIVE) {
        // Remove DialogTypeSelection.NATIVE to prevent infinite loop in
        // RasterPrinterJob.
        attributes.remove(DialogTypeSelection.class);
        doPrint = printDialog(attributes);
        // restore attribute
        attributes.add(DialogTypeSelection.NATIVE);
    } else {
        doPrint = printDialog(attributes);
    }
    if (doPrint) {
        JobName jobName = (JobName) attributes.get(JobName.class);
        if (jobName != null) {
            setJobName(jobName.getValue());
        }
        Copies copies = (Copies) attributes.get(Copies.class);
        if (copies != null) {
            setCopies(copies.getValue());
        }
        Destination dest = (Destination) attributes.get(Destination.class);
        if (dest != null) {
            try {
                mDestType = RasterPrinterJob.FILE;
                mDestination = (new File(dest.getURI())).getPath();
            } catch (Exception e) {
                mDestination = "out.ps";
            }
        } else {
            mDestType = RasterPrinterJob.PRINTER;
            PrintService pServ = getPrintService();
            if (pServ != null) {
                mDestination = pServ.getName();
                if (isMac) {
                    PrintServiceAttributeSet psaSet = pServ.getAttributes();
                    if (psaSet != null) {
                        mDestination = psaSet.get(PrinterName.class).toString();
                    }
                }
            }
        }
    }
    return doPrint;
}
Also used : Destination(javax.print.attribute.standard.Destination) HeadlessException(java.awt.HeadlessException) Copies(javax.print.attribute.standard.Copies) JobName(javax.print.attribute.standard.JobName) File(java.io.File) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) HeadlessException(java.awt.HeadlessException) CharConversionException(java.io.CharConversionException) PrinterException(java.awt.print.PrinterException) PrinterIOException(java.awt.print.PrinterIOException) IOException(java.io.IOException) PrintServiceAttributeSet(javax.print.attribute.PrintServiceAttributeSet) DialogTypeSelection(javax.print.attribute.standard.DialogTypeSelection) PrintService(javax.print.PrintService) StreamPrintService(javax.print.StreamPrintService)

Example 8 with PrintServiceAttributeSet

use of javax.print.attribute.PrintServiceAttributeSet in project jdk8u_jdk by JetBrains.

the class ServiceNotifier method run.

/* A heuristic is used to calculate sleep time.
     * 10 times the time taken to loop through all the listeners, with
     * a minimum of 15 seconds. Ensures this won't take more than 10%
     * of available time.
     */
public void run() {
    long minSleepTime = 15000;
    long sleepTime = 2000;
    HashPrintServiceAttributeSet attrs;
    PrintServiceAttributeEvent attrEvent;
    PrintServiceAttributeListener listener;
    PrintServiceAttributeSet psa;
    while (!stop) {
        try {
            Thread.sleep(sleepTime);
        } catch (InterruptedException e) {
        }
        synchronized (this) {
            if (listeners == null) {
                continue;
            }
            long startTime = System.currentTimeMillis();
            if (listeners != null) {
                if (service instanceof AttributeUpdater) {
                    psa = ((AttributeUpdater) service).getUpdatedAttributes();
                } else {
                    psa = service.getAttributes();
                }
                if (psa != null && !psa.isEmpty()) {
                    for (int i = 0; i < listeners.size(); i++) {
                        listener = (PrintServiceAttributeListener) listeners.elementAt(i);
                        attrs = new HashPrintServiceAttributeSet(psa);
                        attrEvent = new PrintServiceAttributeEvent(service, attrs);
                        listener.attributeUpdate(attrEvent);
                    }
                }
            }
            sleepTime = (System.currentTimeMillis() - startTime) * 10;
            if (sleepTime < minSleepTime) {
                sleepTime = minSleepTime;
            }
        }
    }
}
Also used : PrintServiceAttributeListener(javax.print.event.PrintServiceAttributeListener) PrintServiceAttributeEvent(javax.print.event.PrintServiceAttributeEvent) HashPrintServiceAttributeSet(javax.print.attribute.HashPrintServiceAttributeSet) PrintServiceAttributeSet(javax.print.attribute.PrintServiceAttributeSet) HashPrintServiceAttributeSet(javax.print.attribute.HashPrintServiceAttributeSet)

Example 9 with PrintServiceAttributeSet

use of javax.print.attribute.PrintServiceAttributeSet in project jdk8u_jdk by JetBrains.

the class PSStreamPrintService method getAttributes.

public PrintServiceAttributeSet getAttributes() {
    PrintServiceAttributeSet attrs = new HashPrintServiceAttributeSet();
    attrs.add(ColorSupported.SUPPORTED);
    return AttributeSetUtilities.unmodifiableView(attrs);
}
Also used : HashPrintServiceAttributeSet(javax.print.attribute.HashPrintServiceAttributeSet) PrintServiceAttributeSet(javax.print.attribute.PrintServiceAttributeSet) HashPrintServiceAttributeSet(javax.print.attribute.HashPrintServiceAttributeSet)

Example 10 with PrintServiceAttributeSet

use of javax.print.attribute.PrintServiceAttributeSet in project jdk8u_jdk by JetBrains.

the class Win32MediaSize method getDynamicAttributes.

private PrintServiceAttributeSet getDynamicAttributes() {
    PrintServiceAttributeSet attrs = new HashPrintServiceAttributeSet();
    attrs.add(getPrinterIsAcceptingJobs());
    attrs.add(getQueuedJobCount());
    return attrs;
}
Also used : HashPrintServiceAttributeSet(javax.print.attribute.HashPrintServiceAttributeSet) PrintServiceAttributeSet(javax.print.attribute.PrintServiceAttributeSet) HashPrintServiceAttributeSet(javax.print.attribute.HashPrintServiceAttributeSet)

Aggregations

PrintServiceAttributeSet (javax.print.attribute.PrintServiceAttributeSet)15 HashPrintServiceAttributeSet (javax.print.attribute.HashPrintServiceAttributeSet)13 PrintService (javax.print.PrintService)5 Attribute (javax.print.attribute.Attribute)4 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)4 PrintServiceAttribute (javax.print.attribute.PrintServiceAttribute)4 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 MultiDocPrintService (javax.print.MultiDocPrintService)2 StreamPrintService (javax.print.StreamPrintService)2 PrintRequestAttribute (javax.print.attribute.PrintRequestAttribute)2 PrinterName (javax.print.attribute.standard.PrinterName)2 PrinterState (javax.print.attribute.standard.PrinterState)2 PrinterStateReasons (javax.print.attribute.standard.PrinterStateReasons)2 TemplateException (freemarker.template.TemplateException)1 HeadlessException (java.awt.HeadlessException)1 PrinterException (java.awt.print.PrinterException)1 PrinterIOException (java.awt.print.PrinterIOException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1