use of sun.print.SunMinMaxPage in project jdk8u_jdk by JetBrains.
the class PrintJob2D method copyAttributes.
/* From JobAttributes we will copy job name and duplex printing
* and destination.
* The majority of the rest of the attributes are reflected
* attributes.
*
* From PageAttributes we copy color, media size, orientation,
* origin type, resolution and print quality.
* We use the media, orientation in creating the page format, and
* the origin type to set its imageable area.
*
* REMIND: Interpretation of resolution, additional media sizes.
*/
private void copyAttributes(PrintService printServ) {
attributes = new HashPrintRequestAttributeSet();
attributes.add(new JobName(docTitle, null));
PrintService pServ = printServ;
String printerName = jobAttributes.getPrinter();
if (printerName != null && printerName != "" && !printerName.equals(pServ.getName())) {
// Search for the given printerName in the list of PrintServices
PrintService[] services = PrinterJob.lookupPrintServices();
try {
for (int i = 0; i < services.length; i++) {
if (printerName.equals(services[i].getName())) {
printerJob.setPrintService(services[i]);
pServ = services[i];
break;
}
}
} catch (PrinterException pe) {
}
}
DestinationType dest = jobAttributes.getDestination();
if (dest == DestinationType.FILE && pServ.isAttributeCategorySupported(Destination.class)) {
String fileName = jobAttributes.getFileName();
Destination defaultDest;
if (fileName == null && (defaultDest = (Destination) pServ.getDefaultAttributeValue(Destination.class)) != null) {
attributes.add(defaultDest);
} else {
URI uri = null;
try {
if (fileName != null) {
if (fileName.equals("")) {
fileName = ".";
}
} else {
// defaultDest should not be null. The following code
// is only added to safeguard against a possible
// buggy implementation of a PrintService having a
// null default Destination.
fileName = "out.prn";
}
uri = (new File(fileName)).toURI();
} catch (SecurityException se) {
try {
// '\\' file separator is illegal character in opaque
// part and causes URISyntaxException, so we replace
// it with '/'
fileName = fileName.replace('\\', '/');
uri = new URI("file:" + fileName);
} catch (URISyntaxException e) {
}
}
if (uri != null) {
attributes.add(new Destination(uri));
}
}
}
attributes.add(new SunMinMaxPage(jobAttributes.getMinPage(), jobAttributes.getMaxPage()));
SidesType sType = jobAttributes.getSides();
if (sType == SidesType.TWO_SIDED_LONG_EDGE) {
attributes.add(Sides.TWO_SIDED_LONG_EDGE);
} else if (sType == SidesType.TWO_SIDED_SHORT_EDGE) {
attributes.add(Sides.TWO_SIDED_SHORT_EDGE);
} else if (sType == SidesType.ONE_SIDED) {
attributes.add(Sides.ONE_SIDED);
}
MultipleDocumentHandlingType hType = jobAttributes.getMultipleDocumentHandling();
if (hType == MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_COLLATED_COPIES) {
attributes.add(SheetCollate.COLLATED);
} else {
attributes.add(SheetCollate.UNCOLLATED);
}
attributes.add(new Copies(jobAttributes.getCopies()));
attributes.add(new PageRanges(jobAttributes.getFromPage(), jobAttributes.getToPage()));
if (pageAttributes.getColor() == ColorType.COLOR) {
attributes.add(Chromaticity.COLOR);
} else {
attributes.add(Chromaticity.MONOCHROME);
}
pageFormat = printerJob.defaultPage();
if (pageAttributes.getOrientationRequested() == OrientationRequestedType.LANDSCAPE) {
pageFormat.setOrientation(PageFormat.LANDSCAPE);
attributes.add(OrientationRequested.LANDSCAPE);
} else {
pageFormat.setOrientation(PageFormat.PORTRAIT);
attributes.add(OrientationRequested.PORTRAIT);
}
MediaType media = pageAttributes.getMedia();
MediaSizeName msn = mapMedia(media);
if (msn != null) {
attributes.add(msn);
}
PrintQualityType qType = pageAttributes.getPrintQuality();
if (qType == PrintQualityType.DRAFT) {
attributes.add(PrintQuality.DRAFT);
} else if (qType == PrintQualityType.NORMAL) {
attributes.add(PrintQuality.NORMAL);
} else if (qType == PrintQualityType.HIGH) {
attributes.add(PrintQuality.HIGH);
}
}
Aggregations