Search in sources :

Example 6 with HashPrintServiceAttributeSet

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

use of javax.print.attribute.HashPrintServiceAttributeSet 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 8 with HashPrintServiceAttributeSet

use of javax.print.attribute.HashPrintServiceAttributeSet 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 9 with HashPrintServiceAttributeSet

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

Example 10 with HashPrintServiceAttributeSet

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

the class UnixPrintService method getUpdatedAttributes.

public PrintServiceAttributeSet getUpdatedAttributes() {
    PrintServiceAttributeSet currSet = getDynamicAttributes();
    if (lastSet == null) {
        lastSet = currSet;
        return AttributeSetUtilities.unmodifiableView(currSet);
    } else {
        PrintServiceAttributeSet updates = new HashPrintServiceAttributeSet();
        Attribute[] attrs = currSet.toArray();
        Attribute attr;
        for (int i = 0; i < attrs.length; i++) {
            attr = attrs[i];
            if (!lastSet.containsValue(attr)) {
                updates.add(attr);
            }
        }
        lastSet = currSet;
        return AttributeSetUtilities.unmodifiableView(updates);
    }
}
Also used : PrintServiceAttribute(javax.print.attribute.PrintServiceAttribute) Attribute(javax.print.attribute.Attribute) HashPrintServiceAttributeSet(javax.print.attribute.HashPrintServiceAttributeSet) PrintServiceAttributeSet(javax.print.attribute.PrintServiceAttributeSet) HashPrintServiceAttributeSet(javax.print.attribute.HashPrintServiceAttributeSet)

Aggregations

HashPrintServiceAttributeSet (javax.print.attribute.HashPrintServiceAttributeSet)12 PrintServiceAttributeSet (javax.print.attribute.PrintServiceAttributeSet)12 Attribute (javax.print.attribute.Attribute)4 PrintServiceAttribute (javax.print.attribute.PrintServiceAttribute)4 ArrayList (java.util.ArrayList)2 MultiDocPrintService (javax.print.MultiDocPrintService)2 PrintService (javax.print.PrintService)2 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)2 PrintRequestAttribute (javax.print.attribute.PrintRequestAttribute)2 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)2 PrinterState (javax.print.attribute.standard.PrinterState)2 PrinterStateReasons (javax.print.attribute.standard.PrinterStateReasons)2 PrinterName (javax.print.attribute.standard.PrinterName)1 PrintServiceAttributeEvent (javax.print.event.PrintServiceAttributeEvent)1 PrintServiceAttributeListener (javax.print.event.PrintServiceAttributeListener)1