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);
}
}
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;
}
}
}
}
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);
}
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;
}
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);
}
}
Aggregations