use of javax.print.attribute.PrintRequestAttributeSet 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.PrintRequestAttributeSet in project jgnash by ccavanaugh.
the class PrintableCheckLayout method getPageFormat.
public PageFormat getPageFormat() {
PrintRequestAttributeSet printAttributes = checkLayout.getPrintAttributes();
if (pageFormat == null) {
// create a default pageFormat
PageFormat format = getPrinterJob().defaultPage();
Paper paper = format.getPaper();
MediaSizeName media = (MediaSizeName) printAttributes.get(Media.class);
MediaSize ms = MediaSize.getMediaSizeForName(media);
MediaPrintableArea ma = (MediaPrintableArea) printAttributes.get(MediaPrintableArea.class);
if (ma != null) {
int INCH = MediaPrintableArea.INCH;
paper.setImageableArea((ma.getX(INCH) * 72), (ma.getY(INCH) * 72), (ma.getWidth(INCH) * 72), (ma.getHeight(INCH) * 72));
}
if (ms != null) {
paper.setSize((ms.getX(Size2DSyntax.INCH) * 72), (ms.getY(Size2DSyntax.INCH) * 72));
}
format.setPaper(paper);
OrientationRequested or = (OrientationRequested) printAttributes.get(OrientationRequested.class);
if (or != null) {
if (or == OrientationRequested.LANDSCAPE) {
format.setOrientation(PageFormat.LANDSCAPE);
} else if (or == OrientationRequested.REVERSE_LANDSCAPE) {
format.setOrientation(PageFormat.REVERSE_LANDSCAPE);
} else if (or == OrientationRequested.PORTRAIT) {
format.setOrientation(PageFormat.PORTRAIT);
} else if (or == OrientationRequested.REVERSE_PORTRAIT) {
format.setOrientation(PageFormat.PORTRAIT);
}
}
pageFormat = format;
}
return pageFormat;
}
use of javax.print.attribute.PrintRequestAttributeSet in project camel by apache.
the class PrinterPrintTest method printToMiddleTray.
@Test
public void printToMiddleTray() throws Exception {
PrinterEndpoint endpoint = new PrinterEndpoint();
PrinterConfiguration configuration = new PrinterConfiguration();
configuration.setHostname("localhost");
configuration.setPort(631);
configuration.setPrintername("DefaultPrinter");
configuration.setMediaSizeName(MediaSizeName.ISO_A4);
configuration.setInternalSides(Sides.ONE_SIDED);
configuration.setInternalOrientation(OrientationRequested.PORTRAIT);
configuration.setMediaTray("middle");
PrinterProducer producer = new PrinterProducer(endpoint, configuration);
producer.start();
PrinterOperations printerOperations = producer.getPrinterOperations();
PrintRequestAttributeSet attributeSet = printerOperations.getPrintRequestAttributeSet();
Attribute attribute = attributeSet.get(javax.print.attribute.standard.Media.class);
assertNotNull(attribute);
assertTrue(attribute instanceof MediaTray);
MediaTray mediaTray = (MediaTray) attribute;
assertEquals("middle", mediaTray.toString());
}
use of javax.print.attribute.PrintRequestAttributeSet in project camel by apache.
the class PrinterOperations method print.
public void print(Doc doc, String jobName) throws PrintException {
// we need create a new job for each print
DocPrintJob job = getPrintService().createPrintJob();
PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet(printRequestAttributeSet);
attrs.add(new JobName(jobName, Locale.getDefault()));
job.print(doc, attrs);
}
use of javax.print.attribute.PrintRequestAttributeSet in project camel by apache.
the class PrinterProducer method assignPrintAttributes.
private PrintRequestAttributeSet assignPrintAttributes() throws PrintException {
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
if (config.getCopies() >= 1) {
printRequestAttributeSet.add(new Copies(config.getCopies()));
} else {
throw new PrintException("Number of print copies should be greater than zero");
}
printRequestAttributeSet.add(config.getMediaSizeName());
printRequestAttributeSet.add(config.getInternalSides());
printRequestAttributeSet.add(config.getInternalOrientation());
if (config.getMediaTray() != null) {
MediaTray mediaTray = resolveMediaTray(config.getMediaTray());
if (mediaTray == null) {
throw new PrintException("mediatray not found " + config.getMediaTray());
}
printRequestAttributeSet.add(mediaTray);
}
return printRequestAttributeSet;
}
Aggregations