Search in sources :

Example 1 with SunMinMaxPage

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);
    }
}
Also used : Destination(javax.print.attribute.standard.Destination) PageRanges(javax.print.attribute.standard.PageRanges) MediaSizeName(javax.print.attribute.standard.MediaSizeName) JobName(javax.print.attribute.standard.JobName) PrinterException(java.awt.print.PrinterException) URISyntaxException(java.net.URISyntaxException) SunMinMaxPage(sun.print.SunMinMaxPage) URI(java.net.URI) PrintService(javax.print.PrintService) Copies(javax.print.attribute.standard.Copies) File(java.io.File) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet)

Aggregations

PrinterException (java.awt.print.PrinterException)1 File (java.io.File)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 PrintService (javax.print.PrintService)1 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)1 Copies (javax.print.attribute.standard.Copies)1 Destination (javax.print.attribute.standard.Destination)1 JobName (javax.print.attribute.standard.JobName)1 MediaSizeName (javax.print.attribute.standard.MediaSizeName)1 PageRanges (javax.print.attribute.standard.PageRanges)1 SunMinMaxPage (sun.print.SunMinMaxPage)1