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