Search in sources :

Example 6 with OrientationRequested

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

the class RasterPrinterJob method updateAttributesWithPageFormat.

protected void updateAttributesWithPageFormat(PrintService service, PageFormat page, PrintRequestAttributeSet pageAttributes) {
    if (service == null || page == null || pageAttributes == null) {
        return;
    }
    float x = (float) Math.rint((page.getPaper().getWidth() * Size2DSyntax.INCH) / (72.0)) / (float) Size2DSyntax.INCH;
    float y = (float) Math.rint((page.getPaper().getHeight() * Size2DSyntax.INCH) / (72.0)) / (float) Size2DSyntax.INCH;
    // We should limit the list where we search the matching
    // media, this will prevent mapping to wrong media ex. Ledger
    // can be mapped to B.  Especially useful when creating
    // custom MediaSize.
    Media[] mediaList = (Media[]) service.getSupportedAttributeValues(Media.class, null, null);
    Media media = null;
    try {
        media = CustomMediaSizeName.findMedia(mediaList, x, y, Size2DSyntax.INCH);
    } catch (IllegalArgumentException iae) {
    }
    if ((media == null) || !(service.isAttributeValueSupported(media, null, null))) {
        media = (Media) service.getDefaultAttributeValue(Media.class);
    }
    OrientationRequested orient;
    switch(page.getOrientation()) {
        case PageFormat.LANDSCAPE:
            orient = OrientationRequested.LANDSCAPE;
            break;
        case PageFormat.REVERSE_LANDSCAPE:
            orient = OrientationRequested.REVERSE_LANDSCAPE;
            break;
        default:
            orient = OrientationRequested.PORTRAIT;
    }
    if (media != null) {
        pageAttributes.add(media);
    }
    pageAttributes.add(orient);
    float ix = (float) (page.getPaper().getImageableX() / DPI);
    float iw = (float) (page.getPaper().getImageableWidth() / DPI);
    float iy = (float) (page.getPaper().getImageableY() / DPI);
    float ih = (float) (page.getPaper().getImageableHeight() / DPI);
    if (ix < 0)
        ix = 0f;
    if (iy < 0)
        iy = 0f;
    try {
        pageAttributes.add(new MediaPrintableArea(ix, iy, iw, ih, MediaPrintableArea.INCH));
    } catch (IllegalArgumentException iae) {
    }
}
Also used : MediaPrintableArea(javax.print.attribute.standard.MediaPrintableArea) Media(javax.print.attribute.standard.Media) OrientationRequested(javax.print.attribute.standard.OrientationRequested)

Example 7 with OrientationRequested

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

the class WPrinterJob method getOrientAttrib.

/* Orientation */
private final int getOrientAttrib() {
    int orient = PageFormat.PORTRAIT;
    OrientationRequested orientReq = (attributes == null) ? null : (OrientationRequested) attributes.get(OrientationRequested.class);
    if (orientReq == null) {
        orientReq = (OrientationRequested) myService.getDefaultAttributeValue(OrientationRequested.class);
    }
    if (orientReq != null) {
        if (orientReq == OrientationRequested.REVERSE_LANDSCAPE) {
            orient = PageFormat.REVERSE_LANDSCAPE;
        } else if (orientReq == OrientationRequested.LANDSCAPE) {
            orient = PageFormat.LANDSCAPE;
        }
    }
    return orient;
}
Also used : OrientationRequested(javax.print.attribute.standard.OrientationRequested)

Example 8 with OrientationRequested

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

the class Win32MediaSize 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) {
        if (!isDocFlavorSupported(flavor)) {
            throw new IllegalArgumentException(flavor + " is an unsupported flavor");
        // if postscript & category is already specified within the
        //  PostScript data we return null
        } else if (isAutoSense(flavor) || (isPostScriptFlavor(flavor) && (isPSDocAttr(category)))) {
            return null;
        }
    }
    if (!isAttributeCategorySupported(category)) {
        return null;
    }
    if (category == JobName.class) {
        return new JobName("Java Printing", null);
    } else if (category == RequestingUserName.class) {
        String userName = "";
        try {
            userName = System.getProperty("user.name", "");
        } catch (SecurityException se) {
        }
        return new RequestingUserName(userName, null);
    } else if (category == ColorSupported.class) {
        int caps = getPrinterCapabilities();
        if ((caps & DEVCAP_COLOR) != 0) {
            return ColorSupported.SUPPORTED;
        } else {
            return ColorSupported.NOT_SUPPORTED;
        }
    } else if (category == Chromaticity.class) {
        if (flavor == null || flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE) || flavor.equals(DocFlavor.BYTE_ARRAY.GIF) || flavor.equals(DocFlavor.INPUT_STREAM.GIF) || flavor.equals(DocFlavor.URL.GIF) || flavor.equals(DocFlavor.BYTE_ARRAY.JPEG) || flavor.equals(DocFlavor.INPUT_STREAM.JPEG) || flavor.equals(DocFlavor.URL.JPEG) || flavor.equals(DocFlavor.BYTE_ARRAY.PNG) || flavor.equals(DocFlavor.INPUT_STREAM.PNG) || flavor.equals(DocFlavor.URL.PNG)) {
            int caps = getPrinterCapabilities();
            if ((caps & DEVCAP_COLOR) == 0) {
                Chromaticity[] arr = new Chromaticity[1];
                arr[0] = Chromaticity.MONOCHROME;
                return (arr);
            } else {
                Chromaticity[] arr = new Chromaticity[2];
                arr[0] = Chromaticity.MONOCHROME;
                arr[1] = Chromaticity.COLOR;
                return (arr);
            }
        } else {
            return null;
        }
    } else if (category == Destination.class) {
        try {
            return new Destination((new File("out.prn")).toURI());
        } catch (SecurityException se) {
            try {
                return new Destination(new URI("file:out.prn"));
            } catch (URISyntaxException e) {
                return null;
            }
        }
    } else if (category == OrientationRequested.class) {
        if (flavor == null || flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) || flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE) || flavor.equals(DocFlavor.INPUT_STREAM.GIF) || flavor.equals(DocFlavor.INPUT_STREAM.JPEG) || flavor.equals(DocFlavor.INPUT_STREAM.PNG) || flavor.equals(DocFlavor.BYTE_ARRAY.GIF) || flavor.equals(DocFlavor.BYTE_ARRAY.JPEG) || flavor.equals(DocFlavor.BYTE_ARRAY.PNG) || flavor.equals(DocFlavor.URL.GIF) || flavor.equals(DocFlavor.URL.JPEG) || flavor.equals(DocFlavor.URL.PNG)) {
            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)) {
        synchronized (this) {
            if (gotCopies == false) {
                nCopies = getCopiesSupported(printer, getPort());
                gotCopies = true;
            }
        }
        return new CopiesSupported(1, nCopies);
    } else if (category == Media.class) {
        initMedia();
        int len = (mediaSizeNames == null) ? 0 : mediaSizeNames.length;
        MediaTray[] trays = getMediaTrays();
        len += (trays == null) ? 0 : trays.length;
        Media[] arr = new Media[len];
        if (mediaSizeNames != null) {
            System.arraycopy(mediaSizeNames, 0, arr, 0, mediaSizeNames.length);
        }
        if (trays != null) {
            System.arraycopy(trays, 0, arr, len - trays.length, trays.length);
        }
        return arr;
    } else if (category == MediaPrintableArea.class) {
        // if getting printable area for a specific media size
        Media mediaName = null;
        if ((attributes != null) && ((mediaName = (Media) attributes.get(Media.class)) != null)) {
            if (!(mediaName instanceof MediaSizeName)) {
                // if an instance of MediaTray, fall thru returning
                // all MediaPrintableAreas
                mediaName = null;
            }
        }
        MediaPrintableArea[] mpas = getMediaPrintables((MediaSizeName) mediaName);
        if (mpas != null) {
            MediaPrintableArea[] arr = new MediaPrintableArea[mpas.length];
            System.arraycopy(mpas, 0, arr, 0, mpas.length);
            return arr;
        } else {
            return null;
        }
    } else if (category == SunAlternateMedia.class) {
        return new SunAlternateMedia((Media) getDefaultAttributeValue(Media.class));
    } 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 == PrinterResolution.class) {
        PrinterResolution[] supportedRes = getPrintResolutions();
        if (supportedRes == null) {
            return null;
        }
        PrinterResolution[] arr = new PrinterResolution[supportedRes.length];
        System.arraycopy(supportedRes, 0, arr, 0, supportedRes.length);
        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 if (category == PrintQuality.class) {
        PrintQuality[] arr = new PrintQuality[3];
        arr[0] = PrintQuality.DRAFT;
        arr[1] = PrintQuality.HIGH;
        arr[2] = PrintQuality.NORMAL;
        return arr;
    } 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.COLLATED;
            arr[1] = SheetCollate.UNCOLLATED;
            return arr;
        } else {
            return null;
        }
    } else if (category == Fidelity.class) {
        Fidelity[] arr = new Fidelity[2];
        arr[0] = Fidelity.FIDELITY_FALSE;
        arr[1] = Fidelity.FIDELITY_TRUE;
        return arr;
    } else {
        return null;
    }
}
Also used : Destination(javax.print.attribute.standard.Destination) Fidelity(javax.print.attribute.standard.Fidelity) PrintServiceAttribute(javax.print.attribute.PrintServiceAttribute) Attribute(javax.print.attribute.Attribute) PrintQuality(javax.print.attribute.standard.PrintQuality) JobName(javax.print.attribute.standard.JobName) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) OrientationRequested(javax.print.attribute.standard.OrientationRequested) MediaPrintableArea(javax.print.attribute.standard.MediaPrintableArea) PrinterResolution(javax.print.attribute.standard.PrinterResolution) Sides(javax.print.attribute.standard.Sides) PageRanges(javax.print.attribute.standard.PageRanges) MediaSizeName(javax.print.attribute.standard.MediaSizeName) Media(javax.print.attribute.standard.Media) SheetCollate(javax.print.attribute.standard.SheetCollate) RequestingUserName(javax.print.attribute.standard.RequestingUserName) CopiesSupported(javax.print.attribute.standard.CopiesSupported) Chromaticity(javax.print.attribute.standard.Chromaticity) File(java.io.File)

Example 9 with OrientationRequested

use of javax.print.attribute.standard.OrientationRequested 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;
}
Also used : PageFormat(java.awt.print.PageFormat) MediaPrintableArea(javax.print.attribute.standard.MediaPrintableArea) MediaSize(javax.print.attribute.standard.MediaSize) MediaSizeName(javax.print.attribute.standard.MediaSizeName) Media(javax.print.attribute.standard.Media) Paper(java.awt.print.Paper) OrientationRequested(javax.print.attribute.standard.OrientationRequested) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet)

Example 10 with OrientationRequested

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

the class PrinterJob method getPageFormat.

/**
     * Calculates a <code>PageFormat</code> with values consistent with those
     * supported by the current <code>PrintService</code> for this job
     * (ie the value returned by <code>getPrintService()</code>) and media,
     * printable area and orientation contained in <code>attributes</code>.
     * <p>
     * Calling this method does not update the job.
     * It is useful for clients that have a set of attributes obtained from
     * <code>printDialog(PrintRequestAttributeSet attributes)</code>
     * and need a PageFormat to print a Pageable object.
     * @param attributes a set of printing attributes, for example obtained
     * from calling printDialog. If <code>attributes</code> is null a default
     * PageFormat is returned.
     * @return a <code>PageFormat</code> whose settings conform with
     * those of the current service and the specified attributes.
     * @since 1.6
     */
public PageFormat getPageFormat(PrintRequestAttributeSet attributes) {
    PrintService service = getPrintService();
    PageFormat pf = defaultPage();
    if (service == null || attributes == null) {
        return pf;
    }
    Media media = (Media) attributes.get(Media.class);
    MediaPrintableArea mpa = (MediaPrintableArea) attributes.get(MediaPrintableArea.class);
    OrientationRequested orientReq = (OrientationRequested) attributes.get(OrientationRequested.class);
    if (media == null && mpa == null && orientReq == null) {
        return pf;
    }
    Paper paper = pf.getPaper();
    /* If there's a media but no media printable area, we can try
         * to retrieve the default value for mpa and use that.
         */
    if (mpa == null && media != null && service.isAttributeCategorySupported(MediaPrintableArea.class)) {
        Object mpaVals = service.getSupportedAttributeValues(MediaPrintableArea.class, null, attributes);
        if (mpaVals instanceof MediaPrintableArea[] && ((MediaPrintableArea[]) mpaVals).length > 0) {
            mpa = ((MediaPrintableArea[]) mpaVals)[0];
        }
    }
    if (media != null && service.isAttributeValueSupported(media, null, attributes)) {
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName) media;
            MediaSize msz = MediaSize.getMediaSizeForName(msn);
            if (msz != null) {
                double inch = 72.0;
                double paperWid = msz.getX(MediaSize.INCH) * inch;
                double paperHgt = msz.getY(MediaSize.INCH) * inch;
                paper.setSize(paperWid, paperHgt);
                if (mpa == null) {
                    paper.setImageableArea(inch, inch, paperWid - 2 * inch, paperHgt - 2 * inch);
                }
            }
        }
    }
    if (mpa != null && service.isAttributeValueSupported(mpa, null, attributes)) {
        float[] printableArea = mpa.getPrintableArea(MediaPrintableArea.INCH);
        for (int i = 0; i < printableArea.length; i++) {
            printableArea[i] = printableArea[i] * 72.0f;
        }
        paper.setImageableArea(printableArea[0], printableArea[1], printableArea[2], printableArea[3]);
    }
    if (orientReq != null && service.isAttributeValueSupported(orientReq, null, attributes)) {
        int orient;
        if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
            orient = PageFormat.REVERSE_LANDSCAPE;
        } else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
            orient = PageFormat.LANDSCAPE;
        } else {
            orient = PageFormat.PORTRAIT;
        }
        pf.setOrientation(orient);
    }
    pf.setPaper(paper);
    pf = validatePage(pf);
    return pf;
}
Also used : MediaSize(javax.print.attribute.standard.MediaSize) MediaSizeName(javax.print.attribute.standard.MediaSizeName) Media(javax.print.attribute.standard.Media) OrientationRequested(javax.print.attribute.standard.OrientationRequested) PrintService(javax.print.PrintService) MediaPrintableArea(javax.print.attribute.standard.MediaPrintableArea)

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