Search in sources :

Example 16 with MediaSizeName

use of javax.print.attribute.standard.MediaSizeName in project jdk8u_jdk by JetBrains.

the class PSStreamPrintService method getSupportedAttributeValues.

public Object getSupportedAttributeValues(Class<? extends Attribute> category, DocFlavor flavor, AttributeSet attributes) {
    if (category == null) {
        throw new NullPointerException("null category");
    }
    if (!Attribute.class.isAssignableFrom(category)) {
        throw new IllegalArgumentException(category + " does not implement Attribute");
    }
    if (flavor != null && !isDocFlavorSupported(flavor)) {
        throw new IllegalArgumentException(flavor + " is an unsupported flavor");
    }
    if (!isAttributeCategorySupported(category)) {
        return null;
    }
    if (category == Chromaticity.class) {
        Chromaticity[] arr = new Chromaticity[1];
        arr[0] = Chromaticity.COLOR;
        //arr[1] = Chromaticity.MONOCHROME;
        return (arr);
    } else if (category == JobName.class) {
        return new JobName("", null);
    } else if (category == RequestingUserName.class) {
        return new RequestingUserName("", null);
    } else if (category == OrientationRequested.class) {
        if (flavor == null || flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
            OrientationRequested[] arr = new OrientationRequested[3];
            arr[0] = OrientationRequested.PORTRAIT;
            arr[1] = OrientationRequested.LANDSCAPE;
            arr[2] = OrientationRequested.REVERSE_LANDSCAPE;
            return arr;
        } else {
            return null;
        }
    } else if ((category == Copies.class) || (category == CopiesSupported.class)) {
        return new CopiesSupported(1, MAXCOPIES);
    } else if (category == Media.class) {
        Media[] arr = new Media[mediaSizes.length];
        System.arraycopy(mediaSizes, 0, arr, 0, mediaSizes.length);
        return arr;
    } else if (category == Fidelity.class) {
        Fidelity[] arr = new Fidelity[2];
        arr[0] = Fidelity.FIDELITY_FALSE;
        arr[1] = Fidelity.FIDELITY_TRUE;
        return arr;
    } else if (category == MediaPrintableArea.class) {
        if (attributes == null) {
            return null;
        }
        MediaSize mediaSize = (MediaSize) attributes.get(MediaSize.class);
        if (mediaSize == null) {
            Media media = (Media) attributes.get(Media.class);
            if (media != null && media instanceof MediaSizeName) {
                MediaSizeName msn = (MediaSizeName) media;
                mediaSize = MediaSize.getMediaSizeForName(msn);
            }
        }
        if (mediaSize == null) {
            return null;
        } else {
            MediaPrintableArea[] arr = new MediaPrintableArea[1];
            float w = mediaSize.getX(MediaSize.INCH);
            float h = mediaSize.getY(MediaSize.INCH);
            /* For dimensions >= 5 inches use 0.5 inch margins.
                 * For smaller dimensions, use 10% margins.
                 */
            float xmargin = 0.5f;
            float ymargin = 0.5f;
            if (w < 5f) {
                xmargin = w / 10;
            }
            if (h < 5f) {
                ymargin = h / 10;
            }
            arr[0] = new MediaPrintableArea(xmargin, ymargin, w - 2 * xmargin, h - 2 * ymargin, MediaSize.INCH);
            return arr;
        }
    } else if (category == PageRanges.class) {
        if (flavor == null || flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
            PageRanges[] arr = new PageRanges[1];
            arr[0] = new PageRanges(1, Integer.MAX_VALUE);
            return arr;
        } else {
            return null;
        }
    } else if (category == SheetCollate.class) {
        if (flavor == null || flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
            SheetCollate[] arr = new SheetCollate[2];
            arr[0] = SheetCollate.UNCOLLATED;
            arr[1] = SheetCollate.COLLATED;
            return arr;
        } else {
            SheetCollate[] arr = new SheetCollate[1];
            arr[0] = SheetCollate.UNCOLLATED;
            return arr;
        }
    } else if (category == Sides.class) {
        if (flavor == null || flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
            Sides[] arr = new Sides[3];
            arr[0] = Sides.ONE_SIDED;
            arr[1] = Sides.TWO_SIDED_LONG_EDGE;
            arr[2] = Sides.TWO_SIDED_SHORT_EDGE;
            return arr;
        } else {
            return null;
        }
    } else {
        return null;
    }
}
Also used : Fidelity(javax.print.attribute.standard.Fidelity) PageRanges(javax.print.attribute.standard.PageRanges) MediaSize(javax.print.attribute.standard.MediaSize) PrintServiceAttribute(javax.print.attribute.PrintServiceAttribute) Attribute(javax.print.attribute.Attribute) MediaSizeName(javax.print.attribute.standard.MediaSizeName) JobName(javax.print.attribute.standard.JobName) Media(javax.print.attribute.standard.Media) OrientationRequested(javax.print.attribute.standard.OrientationRequested) MediaPrintableArea(javax.print.attribute.standard.MediaPrintableArea) SheetCollate(javax.print.attribute.standard.SheetCollate) RequestingUserName(javax.print.attribute.standard.RequestingUserName) CopiesSupported(javax.print.attribute.standard.CopiesSupported) Chromaticity(javax.print.attribute.standard.Chromaticity) Sides(javax.print.attribute.standard.Sides)

Example 17 with MediaSizeName

use of javax.print.attribute.standard.MediaSizeName in project jdk8u_jdk by JetBrains.

the class PSStreamPrintJob method getAttributeValues.

private void getAttributeValues(DocFlavor flavor) throws PrintException {
    Attribute attr;
    Class category;
    if (reqAttrSet.get(Fidelity.class) == Fidelity.FIDELITY_TRUE) {
        fidelity = true;
    } else {
        fidelity = false;
    }
    Attribute[] attrs = reqAttrSet.toArray();
    for (int i = 0; i < attrs.length; i++) {
        attr = attrs[i];
        category = attr.getCategory();
        if (fidelity == true) {
            if (!service.isAttributeCategorySupported(category)) {
                notifyEvent(PrintJobEvent.JOB_FAILED);
                throw new PrintJobAttributeException("unsupported category: " + category, category, null);
            } else if (!service.isAttributeValueSupported(attr, flavor, null)) {
                notifyEvent(PrintJobEvent.JOB_FAILED);
                throw new PrintJobAttributeException("unsupported attribute: " + attr, null, attr);
            }
        }
        if (category == JobName.class) {
            jobName = ((JobName) attr).getValue();
        } else if (category == Copies.class) {
            copies = ((Copies) attr).getValue();
        } else if (category == Media.class) {
            if (attr instanceof MediaSizeName && service.isAttributeValueSupported(attr, null, null)) {
                mediaSize = MediaSize.getMediaSizeForName((MediaSizeName) attr);
            }
        } else if (category == OrientationRequested.class) {
            orient = (OrientationRequested) attr;
        }
    }
}
Also used : Fidelity(javax.print.attribute.standard.Fidelity) PrintJobAttribute(javax.print.attribute.PrintJobAttribute) PrintRequestAttribute(javax.print.attribute.PrintRequestAttribute) Attribute(javax.print.attribute.Attribute) MediaSizeName(javax.print.attribute.standard.MediaSizeName) Copies(javax.print.attribute.standard.Copies) java.awt.print(java.awt.print) OrientationRequested(javax.print.attribute.standard.OrientationRequested)

Example 18 with MediaSizeName

use of javax.print.attribute.standard.MediaSizeName in project jdk8u_jdk by JetBrains.

the class PrintJob2D method updateAttributes.

private void updateAttributes() {
    Copies c = (Copies) attributes.get(Copies.class);
    jobAttributes.setCopies(c.getValue());
    SunPageSelection sel = (SunPageSelection) attributes.get(SunPageSelection.class);
    if (sel == SunPageSelection.RANGE) {
        jobAttributes.setDefaultSelection(DefaultSelectionType.RANGE);
    } else if (sel == SunPageSelection.SELECTION) {
        jobAttributes.setDefaultSelection(DefaultSelectionType.SELECTION);
    } else {
        jobAttributes.setDefaultSelection(DefaultSelectionType.ALL);
    }
    Destination dest = (Destination) attributes.get(Destination.class);
    if (dest != null) {
        jobAttributes.setDestination(DestinationType.FILE);
        jobAttributes.setFileName(dest.getURI().getPath());
    } else {
        jobAttributes.setDestination(DestinationType.PRINTER);
    }
    PrintService serv = printerJob.getPrintService();
    if (serv != null) {
        jobAttributes.setPrinter(serv.getName());
    }
    PageRanges range = (PageRanges) attributes.get(PageRanges.class);
    int[][] members = range.getMembers();
    jobAttributes.setPageRanges(members);
    SheetCollate collation = (SheetCollate) attributes.get(SheetCollate.class);
    if (collation == SheetCollate.COLLATED) {
        jobAttributes.setMultipleDocumentHandling(MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_COLLATED_COPIES);
    } else {
        jobAttributes.setMultipleDocumentHandling(MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES);
    }
    Sides sides = (Sides) attributes.get(Sides.class);
    if (sides == Sides.TWO_SIDED_LONG_EDGE) {
        jobAttributes.setSides(SidesType.TWO_SIDED_LONG_EDGE);
    } else if (sides == Sides.TWO_SIDED_SHORT_EDGE) {
        jobAttributes.setSides(SidesType.TWO_SIDED_SHORT_EDGE);
    } else {
        jobAttributes.setSides(SidesType.ONE_SIDED);
    }
    // PageAttributes
    Chromaticity color = (Chromaticity) attributes.get(Chromaticity.class);
    if (color == Chromaticity.COLOR) {
        pageAttributes.setColor(ColorType.COLOR);
    } else {
        pageAttributes.setColor(ColorType.MONOCHROME);
    }
    OrientationRequested orient = (OrientationRequested) attributes.get(OrientationRequested.class);
    if (orient == OrientationRequested.LANDSCAPE) {
        pageAttributes.setOrientationRequested(OrientationRequestedType.LANDSCAPE);
    } else {
        pageAttributes.setOrientationRequested(OrientationRequestedType.PORTRAIT);
    }
    PrintQuality qual = (PrintQuality) attributes.get(PrintQuality.class);
    if (qual == PrintQuality.DRAFT) {
        pageAttributes.setPrintQuality(PrintQualityType.DRAFT);
    } else if (qual == PrintQuality.HIGH) {
        pageAttributes.setPrintQuality(PrintQualityType.HIGH);
    } else {
        // NORMAL
        pageAttributes.setPrintQuality(PrintQualityType.NORMAL);
    }
    Media msn = (Media) attributes.get(Media.class);
    if (msn != null && msn instanceof MediaSizeName) {
        MediaType mType = unMapMedia((MediaSizeName) msn);
        if (mType != null) {
            pageAttributes.setMedia(mType);
        }
    }
    debugPrintAttributes(false, false);
}
Also used : Destination(javax.print.attribute.standard.Destination) PageRanges(javax.print.attribute.standard.PageRanges) MediaSizeName(javax.print.attribute.standard.MediaSizeName) PrintQuality(javax.print.attribute.standard.PrintQuality) Media(javax.print.attribute.standard.Media) OrientationRequested(javax.print.attribute.standard.OrientationRequested) PrintService(javax.print.PrintService) SheetCollate(javax.print.attribute.standard.SheetCollate) Copies(javax.print.attribute.standard.Copies) SunPageSelection(sun.print.SunPageSelection) Chromaticity(javax.print.attribute.standard.Chromaticity) Sides(javax.print.attribute.standard.Sides)

Example 19 with MediaSizeName

use of javax.print.attribute.standard.MediaSizeName in project jdk8u_jdk by JetBrains.

the class RasterPrinterJob method defaultPage.

/**
     * The passed in PageFormat will be copied and altered to describe
     * the default page size and orientation of the PrinterJob's
     * current printer.
     * Platform subclasses which can access the actual default paper size
     * for a printer may override this method.
     */
public PageFormat defaultPage(PageFormat page) {
    PageFormat newPage = (PageFormat) page.clone();
    newPage.setOrientation(PageFormat.PORTRAIT);
    Paper newPaper = new Paper();
    double ptsPerInch = 72.0;
    double w, h;
    Media media = null;
    PrintService service = getPrintService();
    if (service != null) {
        MediaSize size;
        media = (Media) service.getDefaultAttributeValue(Media.class);
        if (media instanceof MediaSizeName && ((size = MediaSize.getMediaSizeForName((MediaSizeName) media)) != null)) {
            w = size.getX(MediaSize.INCH) * ptsPerInch;
            h = size.getY(MediaSize.INCH) * ptsPerInch;
            newPaper.setSize(w, h);
            newPaper.setImageableArea(ptsPerInch, ptsPerInch, w - 2.0 * ptsPerInch, h - 2.0 * ptsPerInch);
            newPage.setPaper(newPaper);
            return newPage;
        }
    }
    /* Default to A4 paper outside North America.
         */
    String defaultCountry = Locale.getDefault().getCountry();
    if (// ie "C"
    !Locale.getDefault().equals(Locale.ENGLISH) && defaultCountry != null && !defaultCountry.equals(Locale.US.getCountry()) && !defaultCountry.equals(Locale.CANADA.getCountry())) {
        double mmPerInch = 25.4;
        w = Math.rint((210.0 * ptsPerInch) / mmPerInch);
        h = Math.rint((297.0 * ptsPerInch) / mmPerInch);
        newPaper.setSize(w, h);
        newPaper.setImageableArea(ptsPerInch, ptsPerInch, w - 2.0 * ptsPerInch, h - 2.0 * ptsPerInch);
    }
    newPage.setPaper(newPaper);
    return newPage;
}
Also used : PageFormat(java.awt.print.PageFormat) MediaSize(javax.print.attribute.standard.MediaSize) MediaSizeName(javax.print.attribute.standard.MediaSizeName) Media(javax.print.attribute.standard.Media) Paper(java.awt.print.Paper) PrintService(javax.print.PrintService) StreamPrintService(javax.print.StreamPrintService)

Example 20 with MediaSizeName

use of javax.print.attribute.standard.MediaSizeName in project adempiere by adempiere.

the class PrintDataExcelExporter method formatPage.

@Override
protected void formatPage(HSSFSheet sheet) {
    super.formatPage(sheet);
    MPrintPaper paper = MPrintPaper.get(this.m_printFormat.getAD_PrintPaper_ID());
    //
    // Set paper size:
    short paperSize = -1;
    MediaSizeName mediaSizeName = paper.getMediaSize().getMediaSizeName();
    if (MediaSizeName.NA_LETTER.equals(mediaSizeName)) {
        paperSize = HSSFPrintSetup.LETTER_PAPERSIZE;
    } else if (MediaSizeName.NA_LEGAL.equals(mediaSizeName)) {
        paperSize = HSSFPrintSetup.LEGAL_PAPERSIZE;
    } else if (MediaSizeName.EXECUTIVE.equals(mediaSizeName)) {
        paperSize = HSSFPrintSetup.EXECUTIVE_PAPERSIZE;
    } else if (MediaSizeName.ISO_A4.equals(mediaSizeName)) {
        paperSize = HSSFPrintSetup.A4_PAPERSIZE;
    } else if (MediaSizeName.ISO_A5.equals(mediaSizeName)) {
        paperSize = HSSFPrintSetup.A5_PAPERSIZE;
    } else if (MediaSizeName.NA_NUMBER_10_ENVELOPE.equals(mediaSizeName)) {
        paperSize = HSSFPrintSetup.ENVELOPE_10_PAPERSIZE;
    } else //		}
    if (MediaSizeName.MONARCH_ENVELOPE.equals(mediaSizeName)) {
        paperSize = HSSFPrintSetup.ENVELOPE_MONARCH_PAPERSIZE;
    }
    if (paperSize != -1) {
        sheet.getPrintSetup().setPaperSize(paperSize);
    }
    //
    // Set Landscape/Portrait:
    sheet.getPrintSetup().setLandscape(paper.isLandscape());
    //
    // Set Paper Margin:
    sheet.setMargin(HSSFSheet.TopMargin, ((double) paper.getMarginTop()) / 72);
    sheet.setMargin(HSSFSheet.RightMargin, ((double) paper.getMarginRight()) / 72);
    sheet.setMargin(HSSFSheet.LeftMargin, ((double) paper.getMarginLeft()) / 72);
    sheet.setMargin(HSSFSheet.BottomMargin, ((double) paper.getMarginBottom()) / 72);
//
}
Also used : MediaSizeName(javax.print.attribute.standard.MediaSizeName) MPrintPaper(org.compiere.print.MPrintPaper)

Aggregations

MediaSizeName (javax.print.attribute.standard.MediaSizeName)31 Media (javax.print.attribute.standard.Media)16 MediaSize (javax.print.attribute.standard.MediaSize)16 OrientationRequested (javax.print.attribute.standard.OrientationRequested)14 MediaPrintableArea (javax.print.attribute.standard.MediaPrintableArea)11 Attribute (javax.print.attribute.Attribute)9 Destination (javax.print.attribute.standard.Destination)9 Chromaticity (javax.print.attribute.standard.Chromaticity)8 Copies (javax.print.attribute.standard.Copies)8 Fidelity (javax.print.attribute.standard.Fidelity)8 JobName (javax.print.attribute.standard.JobName)8 File (java.io.File)7 URI (java.net.URI)7 PrintService (javax.print.PrintService)7 PageRanges (javax.print.attribute.standard.PageRanges)7 SheetCollate (javax.print.attribute.standard.SheetCollate)7 Sides (javax.print.attribute.standard.Sides)7 RequestingUserName (javax.print.attribute.standard.RequestingUserName)5 PageFormat (java.awt.print.PageFormat)4 Paper (java.awt.print.Paper)4