Example usage for javax.print.attribute PrintRequestAttributeSet get

List of usage examples for javax.print.attribute PrintRequestAttributeSet get

Introduction

In this page you can find the example usage for javax.print.attribute PrintRequestAttributeSet get.

Prototype

public Attribute get(Class<?> category);

Source Link

Document

Returns the attribute value which this attribute set contains in the given attribute category.

Usage

From source file:org.pentaho.reporting.engine.classic.extensions.modules.java14print.Java14PrintUtil.java

public static PageFormat extractPageFormat(final PrintRequestAttributeSet attributeSet) {
    final Media media = (Media) attributeSet.get(Media.class);
    final MediaPrintableArea printableArea = (MediaPrintableArea) attributeSet.get(MediaPrintableArea.class);
    final OrientationRequested orientationRequested = (OrientationRequested) attributeSet
            .get(OrientationRequested.class);

    final MediaSize mediaSize = lookupMediaSize(media);
    if (mediaSize == null) {
        logger.warn("Unknown media encountered, unable to compute page sizes.");
    }//from  ww  w . j a  va  2s.  com

    final PageFormat pageFormat = new PageFormat();
    pageFormat.setPaper(createPaper(mediaSize, printableArea));
    if (OrientationRequested.PORTRAIT.equals(orientationRequested)) {
        pageFormat.setOrientation(PageFormat.PORTRAIT);
    } else if (OrientationRequested.LANDSCAPE.equals(orientationRequested)) {
        pageFormat.setOrientation(PageFormat.LANDSCAPE);
    } else if (OrientationRequested.REVERSE_LANDSCAPE.equals(orientationRequested)) {
        pageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE);
    } else if (OrientationRequested.REVERSE_PORTRAIT.equals(orientationRequested)) {
        pageFormat.setOrientation(PageFormat.PORTRAIT);
    }
    return pageFormat;
}