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