Search in sources :

Example 1 with OrientationRequested

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

the class CPaper method setPrintRequestAttributeSet.

//  getPrintRequestAttributes
/**
	 *  Set Print Request Attributes
	 *  @param prats PrintRequestAttributeSet
	 */
public void setPrintRequestAttributeSet(PrintRequestAttributeSet prats) {
    boolean landscape = m_landscape;
    MediaSize ms = m_mediaSize;
    MediaPrintableArea area = getMediaPrintableArea();
    Attribute[] atts = prats.toArray();
    for (int i = 0; i < atts.length; i++) {
        if (atts[i] instanceof OrientationRequested) {
            OrientationRequested or = (OrientationRequested) atts[i];
            if (or.equals(OrientationRequested.PORTRAIT))
                landscape = false;
            else
                landscape = true;
        } else if (atts[i] instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName) atts[i];
            ms = MediaSize.getMediaSizeForName(msn);
        } else if (atts[i] instanceof MediaPrintableArea) {
            area = (MediaPrintableArea) atts[i];
        } else
            //	unhandeled
            System.out.println(atts[i].getName() + " = " + atts[i] + " - " + atts[i].getCategory());
    }
    //
    setMediaSize(ms, landscape);
    setMediaPrintableArea(area);
}
Also used : MediaPrintableArea(javax.print.attribute.standard.MediaPrintableArea) MediaSize(javax.print.attribute.standard.MediaSize) Attribute(javax.print.attribute.Attribute) MediaSizeName(javax.print.attribute.standard.MediaSizeName) OrientationRequested(javax.print.attribute.standard.OrientationRequested)

Example 2 with OrientationRequested

use of javax.print.attribute.standard.OrientationRequested 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 3 with OrientationRequested

use of javax.print.attribute.standard.OrientationRequested 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 4 with OrientationRequested

use of javax.print.attribute.standard.OrientationRequested 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 5 with OrientationRequested

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

the class RasterPrinterJob method attributeToPageFormat.

private PageFormat attributeToPageFormat(PrintService service, PrintRequestAttributeSet attSet) {
    PageFormat page = defaultPage();
    if (service == null) {
        return page;
    }
    OrientationRequested orient = (OrientationRequested) attSet.get(OrientationRequested.class);
    if (orient == null) {
        orient = (OrientationRequested) service.getDefaultAttributeValue(OrientationRequested.class);
    }
    if (orient == OrientationRequested.REVERSE_LANDSCAPE) {
        page.setOrientation(PageFormat.REVERSE_LANDSCAPE);
    } else if (orient == OrientationRequested.LANDSCAPE) {
        page.setOrientation(PageFormat.LANDSCAPE);
    } else {
        page.setOrientation(PageFormat.PORTRAIT);
    }
    Media media = (Media) attSet.get(Media.class);
    MediaSize size = getMediaSize(media, service, page);
    Paper paper = new Paper();
    //units == 1 to avoid FP error
    float[] dim = size.getSize(1);
    double w = Math.rint((dim[0] * 72.0) / Size2DSyntax.INCH);
    double h = Math.rint((dim[1] * 72.0) / Size2DSyntax.INCH);
    paper.setSize(w, h);
    MediaPrintableArea area = (MediaPrintableArea) attSet.get(MediaPrintableArea.class);
    if (area == null) {
        area = getDefaultPrintableArea(page, w, h);
    }
    double ix, iw, iy, ih;
    // Should pass in same unit as updatePageAttributes
    // to avoid rounding off errors.
    ix = Math.rint(area.getX(MediaPrintableArea.INCH) * DPI);
    iy = Math.rint(area.getY(MediaPrintableArea.INCH) * DPI);
    iw = Math.rint(area.getWidth(MediaPrintableArea.INCH) * DPI);
    ih = Math.rint(area.getHeight(MediaPrintableArea.INCH) * DPI);
    paper.setImageableArea(ix, iy, iw, ih);
    page.setPaper(paper);
    return page;
}
Also used : PageFormat(java.awt.print.PageFormat) MediaPrintableArea(javax.print.attribute.standard.MediaPrintableArea) MediaSize(javax.print.attribute.standard.MediaSize) Media(javax.print.attribute.standard.Media) Paper(java.awt.print.Paper) OrientationRequested(javax.print.attribute.standard.OrientationRequested)

Aggregations

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