Example usage for java.awt.print PageFormat REVERSE_LANDSCAPE

List of usage examples for java.awt.print PageFormat REVERSE_LANDSCAPE

Introduction

In this page you can find the example usage for java.awt.print PageFormat REVERSE_LANDSCAPE.

Prototype

int REVERSE_LANDSCAPE

To view the source code for java.awt.print PageFormat REVERSE_LANDSCAPE.

Click Source Link

Document

The origin is at the top right of the paper with x running top to bottom and y running right to left.

Usage

From source file:freemind.controller.Controller.java

private boolean acquirePrinterJobAndPageFormat() {
    if (printerJob == null) {
        try {/*from   w w  w  . j  a va  2s  . co  m*/
            printerJob = PrinterJob.getPrinterJob();
        } catch (SecurityException ex) {
            isPrintingAllowed = false;
            return false;
        }
    }
    if (pageFormat == null) {
        pageFormat = printerJob.defaultPage();
        if (Tools.safeEquals(getProperty("page_orientation"), "landscape")) {
            pageFormat.setOrientation(PageFormat.LANDSCAPE);
        } else if (Tools.safeEquals(getProperty("page_orientation"), "portrait")) {
            pageFormat.setOrientation(PageFormat.PORTRAIT);
        } else if (Tools.safeEquals(getProperty("page_orientation"), "reverse_landscape")) {
            pageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE);
        }
    }
    return true;
}

From source file:org.pentaho.reporting.engine.classic.core.modules.parser.bundle.layout.PageDefinitionReadHandler.java

/**
 * Creates the pageFormat by using the given Attributes. If an PageFormat name is given, the named PageFormat is used
 * and the parameters width and height are ignored. If no name is defined, height and width attributes are used to
 * create the pageformat. The attributes define the dimension of the PageFormat in points, where the printing
 * resolution is defined at 72 pixels per inch.
 *
 * @param defaultPageFormat/*from  w w  w. ja  va 2  s. c om*/
 *          the page format.
 * @param atts
 *          the element attributes.
 * @return the page format.
 * @throws SAXException
 *           if there is an error parsing the report.
 */
private PageFormat configurePageSize(final PageFormat defaultPageFormat, final Attributes atts)
        throws SAXException {
    final String pageformatName = atts.getValue(getUri(), "pageformat");

    final int orientationVal;
    final String orientation = atts.getValue(getUri(), "orientation");
    if (orientation == null) {
        orientationVal = PageFormat.PORTRAIT;
    } else if ("landscape".equals(orientation)) {
        orientationVal = PageFormat.LANDSCAPE;
    } else if ("reverse-landscape".equals(orientation)) {
        orientationVal = PageFormat.REVERSE_LANDSCAPE;
    } else {
        orientationVal = PageFormat.PORTRAIT;
    }

    if (pageformatName != null) {
        final Paper p = PageFormatFactory.getInstance().createPaper(pageformatName);
        if (p == null) {
            PageDefinitionReadHandler.logger.warn("Paper size '" + pageformatName + "' is not regognized.");
            return defaultPageFormat;
        }
        return PageFormatFactory.getInstance().createPageFormat(p, orientationVal);
    }

    if (atts.getValue(getUri(), "width") != null && atts.getValue(getUri(), "height") != null) {
        final int[] pageformatData = new int[2];
        pageformatData[0] = ParserUtil.parseInt(atts.getValue(getUri(), "width"),
                "Specified attribute 'width' is not valid", getLocator());
        pageformatData[1] = ParserUtil.parseInt(atts.getValue(getUri(), "height"),
                "Specified attribute 'height' is not valid", getLocator());
        final Paper p = PageFormatFactory.getInstance().createPaper(pageformatData);
        if (p == null) {
            PageDefinitionReadHandler.logger.warn("Unable to create the requested Paper size with width "
                    + pageformatData[0] + " and height " + pageformatData[1]);
            return defaultPageFormat;
        }
        return PageFormatFactory.getInstance().createPageFormat(p, orientationVal);
    }

    PageDefinitionReadHandler.logger.info("Insufficient Data to create a pageformat: Returned default.");
    return defaultPageFormat;
}

From source file:org.pentaho.reporting.engine.classic.core.modules.parser.bundle.layout.PageDefinitionReadHandler.java

/**
 * Handles the page format.//from   w  ww. ja  va 2 s  .c  o  m
 *
 * @param atts
 *          the attributes.
 * @throws SAXException
 *           if a parser error occurs or the validation failed.
 * @noinspection SuspiciousNameCombination
 */
private PageFormat configurePageSizeAndMargins(final Attributes atts, PageFormat format) throws SAXException {
    // (1) Grab the existing default ...
    float defTopMargin = (float) format.getImageableY();
    float defBottomMargin = (float) (format.getHeight() - format.getImageableHeight() - format.getImageableY());
    float defLeftMargin = (float) format.getImageableX();
    float defRightMargin = (float) (format.getWidth() - format.getImageableWidth() - format.getImageableX());

    // (2) Now configure the new paper-size
    format = configurePageSize(format, atts);

    // (3) Reconfigure margins as requested
    defTopMargin = ParserUtil.parseFloat(atts.getValue(getUri(), "margin-top"), defTopMargin);
    defBottomMargin = ParserUtil.parseFloat(atts.getValue(getUri(), "margin-bottom"), defBottomMargin);
    defLeftMargin = ParserUtil.parseFloat(atts.getValue(getUri(), "margin-left"), defLeftMargin);
    defRightMargin = ParserUtil.parseFloat(atts.getValue(getUri(), "margin-right"), defRightMargin);

    final Paper p = format.getPaper();
    switch (format.getOrientation()) {
    case PageFormat.PORTRAIT:
        PageFormatFactory.getInstance().setBorders(p, defTopMargin, defLeftMargin, defBottomMargin,
                defRightMargin);
        break;
    case PageFormat.REVERSE_LANDSCAPE:
        PageFormatFactory.getInstance().setBorders(p, defLeftMargin, defBottomMargin, defRightMargin,
                defTopMargin);
        break;
    case PageFormat.LANDSCAPE:
        PageFormatFactory.getInstance().setBorders(p, defRightMargin, defTopMargin, defLeftMargin,
                defBottomMargin);
        break;
    default:
        // will not happen..
        throw new IllegalArgumentException("Unexpected paper orientation.");
    }

    format.setPaper(p);
    return format;
}

From source file:org.pentaho.reporting.engine.classic.core.modules.parser.ext.readhandlers.PageReadHandler.java

/**
 * Handles the page format.//from   w  w w.j av a2  s. com
 *
 * @param atts
 *          the attributes.
 * @throws SAXException
 *           if a parser error occurs or the validation failed.
 * @noinspection SuspiciousNameCombination
 */
private void handlePageFormat(final Attributes atts) throws SAXException {
    final MasterReport report = (MasterReport) getRootHandler()
            .getHelperObject(ReportParserUtil.HELPER_OBJ_REPORT_NAME);

    // grab the default page definition ...
    PageFormat format = report.getPageDefinition().getPageFormat(0);
    float defTopMargin = (float) format.getImageableY();
    float defBottomMargin = (float) (format.getHeight() - format.getImageableHeight() - format.getImageableY());
    float defLeftMargin = (float) format.getImageableX();
    float defRightMargin = (float) (format.getWidth() - format.getImageableWidth() - format.getImageableX());

    format = createPageFormat(format, atts);

    defTopMargin = ParserUtil.parseFloat(atts.getValue(getUri(), PageReadHandler.TOPMARGIN_ATT), defTopMargin);
    defBottomMargin = ParserUtil.parseFloat(atts.getValue(getUri(), PageReadHandler.BOTTOMMARGIN_ATT),
            defBottomMargin);
    defLeftMargin = ParserUtil.parseFloat(atts.getValue(getUri(), PageReadHandler.LEFTMARGIN_ATT),
            defLeftMargin);
    defRightMargin = ParserUtil.parseFloat(atts.getValue(getUri(), PageReadHandler.RIGHTMARGIN_ATT),
            defRightMargin);

    final Paper p = format.getPaper();
    switch (format.getOrientation()) {
    case PageFormat.PORTRAIT:
        PageFormatFactory.getInstance().setBorders(p, defTopMargin, defLeftMargin, defBottomMargin,
                defRightMargin);
        break;
    case PageFormat.LANDSCAPE:
        // right, top, left, bottom
        PageFormatFactory.getInstance().setBorders(p, defRightMargin, defTopMargin, defLeftMargin,
                defBottomMargin);
        break;
    case PageFormat.REVERSE_LANDSCAPE:
        PageFormatFactory.getInstance().setBorders(p, defLeftMargin, defBottomMargin, defRightMargin,
                defTopMargin);
        break;
    default:
        // will not happen..
        throw new IllegalArgumentException("Unexpected paper orientation.");
    }

    format.setPaper(p);
    pageFormat = format;
}

From source file:org.pentaho.reporting.engine.classic.core.modules.parser.ext.readhandlers.PageReadHandler.java

/**
 * Creates the pageFormat by using the given Attributes. If an PageFormat name is given, the named PageFormat is used
 * and the parameters width and height are ignored. If no name is defined, height and width attributes are used to
 * create the pageformat. The attributes define the dimension of the PageFormat in points, where the printing
 * resolution is defined at 72 pixels per inch.
 *
 * @param format/*from  w  w  w  .  jav  a2  s  . c  om*/
 *          the page format.
 * @param atts
 *          the element attributes.
 * @return the page format.
 * @throws SAXException
 *           if there is an error parsing the report.
 */
private PageFormat createPageFormat(final PageFormat format, final Attributes atts) throws SAXException {
    final String pageformatName = atts.getValue(getUri(), PageReadHandler.PAGEFORMAT_ATT);

    final int orientationVal;
    final String orientation = atts.getValue(getUri(), PageReadHandler.ORIENTATION_ATT);
    if (orientation == null) {
        orientationVal = PageFormat.PORTRAIT;
    } else if (orientation.equals(PageReadHandler.ORIENTATION_LANDSCAPE_VAL)) {
        orientationVal = PageFormat.LANDSCAPE;
    } else if (orientation.equals(PageReadHandler.ORIENTATION_REVERSE_LANDSCAPE_VAL)) {
        orientationVal = PageFormat.REVERSE_LANDSCAPE;
    } else if (orientation.equals(PageReadHandler.ORIENTATION_PORTRAIT_VAL)) {
        orientationVal = PageFormat.PORTRAIT;
    } else {
        throw new ParseException("Orientation value in REPORT-Tag is invalid.",
                getRootHandler().getDocumentLocator());
    }
    if (pageformatName != null) {
        final Paper p = PageFormatFactory.getInstance().createPaper(pageformatName);
        if (p == null) {
            PageReadHandler.logger.warn("Unable to create the requested Paper. " + pageformatName);
            return format;
        }
        return PageFormatFactory.getInstance().createPageFormat(p, orientationVal);
    }

    if (atts.getValue(getUri(), PageReadHandler.WIDTH_ATT) != null
            && atts.getValue(getUri(), PageReadHandler.HEIGHT_ATT) != null) {
        final int[] pageformatData = new int[2];
        pageformatData[0] = ParserUtil.parseInt(atts.getValue(getUri(), PageReadHandler.WIDTH_ATT),
                "No Width set", getLocator());
        pageformatData[1] = ParserUtil.parseInt(atts.getValue(getUri(), PageReadHandler.HEIGHT_ATT),
                "No Height set", getLocator());
        final Paper p = PageFormatFactory.getInstance().createPaper(pageformatData);
        if (p == null) {
            PageReadHandler.logger.warn("Unable to create the requested Paper. Paper={" + pageformatData[0]
                    + ", " + pageformatData[1] + '}');
            return format;
        }
        return PageFormatFactory.getInstance().createPageFormat(p, orientationVal);
    }

    PageReadHandler.logger.info("Insufficient Data to create a pageformat: Returned default.");
    return format;
}

From source file:org.pentaho.reporting.engine.classic.core.modules.parser.simple.readhandlers.JFreeReportReadHandler.java

/**
 * Starts parsing./*w  ww .ja  v a2 s.c o  m*/
 *
 * @param attrs
 *          the attributes.
 * @throws org.xml.sax.SAXException
 *           if there is a parsing error.
 * @noinspection SuspiciousNameCombination
 */
protected void startParsing(final PropertyAttributes attrs) throws SAXException {
    RootXmlReadHandler rootHandler = getRootHandler();
    final Object maybeReport = rootHandler.getHelperObject(ReportParserUtil.HELPER_OBJ_REPORT_NAME);
    final MasterReport report;
    if (maybeReport instanceof MasterReport == false) {
        // replace it ..
        report = new MasterReport();
        report.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.SOURCE, rootHandler.getSource());
    } else {
        report = (MasterReport) maybeReport;
    }

    final int groupCount = report.getGroupCount();
    for (int i = 0; i < groupCount; i++) {
        final Group g = report.getGroup(i);
        if (g instanceof RelationalGroup) {
            groupList.add((RelationalGroup) g);
        } else {
            throw new ParseException("The existing report contains non-default groups. "
                    + "This parser cannot handle such a construct.");
        }
    }

    final RootXmlReadHandler parser = rootHandler;
    if (ReportParserUtil.isIncluded(parser) == false) {
        final String query = attrs.getValue(getUri(), "query");
        if (query != null) {
            report.setQuery(query);
        }

        final String name = attrs.getValue(getUri(), JFreeReportReadHandler.NAME_ATT);
        if (name != null) {
            report.setName(name);
        }

        PageFormat format = report.getPageDefinition().getPageFormat(0);
        float defTopMargin = (float) format.getImageableY();
        float defBottomMargin = (float) (format.getHeight() - format.getImageableHeight()
                - format.getImageableY());
        float defLeftMargin = (float) format.getImageableX();
        float defRightMargin = (float) (format.getWidth() - format.getImageableWidth()
                - format.getImageableX());

        format = createPageFormat(format, attrs);

        defTopMargin = ParserUtil.parseFloat(attrs.getValue(getUri(), JFreeReportReadHandler.TOPMARGIN_ATT),
                defTopMargin);
        defBottomMargin = ParserUtil
                .parseFloat(attrs.getValue(getUri(), JFreeReportReadHandler.BOTTOMMARGIN_ATT), defBottomMargin);
        defLeftMargin = ParserUtil.parseFloat(attrs.getValue(getUri(), JFreeReportReadHandler.LEFTMARGIN_ATT),
                defLeftMargin);
        defRightMargin = ParserUtil.parseFloat(attrs.getValue(getUri(), JFreeReportReadHandler.RIGHTMARGIN_ATT),
                defRightMargin);

        final Paper p = format.getPaper();
        switch (format.getOrientation()) {
        case PageFormat.PORTRAIT:
            PageFormatFactory.getInstance().setBorders(p, defTopMargin, defLeftMargin, defBottomMargin,
                    defRightMargin);
            break;
        case PageFormat.LANDSCAPE:
            // right, top, left, bottom
            PageFormatFactory.getInstance().setBorders(p, defRightMargin, defTopMargin, defLeftMargin,
                    defBottomMargin);
            break;
        case PageFormat.REVERSE_LANDSCAPE:
            PageFormatFactory.getInstance().setBorders(p, defLeftMargin, defBottomMargin, defRightMargin,
                    defTopMargin);
            break;
        default:
            throw new IllegalStateException("Unexpected paper orientation.");
        }

        final int pageSpan = ParserUtil.parseInt(attrs.getValue(getUri(), JFreeReportReadHandler.PAGESPAN_ATT),
                1);

        format.setPaper(p);
        report.setPageDefinition(new SimplePageDefinition(format, pageSpan, 1));
    }
    if (rootHandler.getHelperObject(ReportParserUtil.HELPER_OBJ_LEGACY_STYLES) instanceof HashMap == false) {
        rootHandler.setHelperObject(ReportParserUtil.HELPER_OBJ_LEGACY_STYLES,
                new HashMap<String, ElementStyleSheet>());
    }
    rootHandler.setHelperObject(ReportParserUtil.HELPER_OBJ_REPORT_NAME, report);

    final String useMinChunkWidth = attrs.getValue(getUri(), "use-min-chunkwidth");
    if (useMinChunkWidth != null) {
        report.getStyle().setStyleProperty(ElementStyleKeys.USE_MIN_CHUNKWIDTH,
                ReportParserUtil.parseBoolean(useMinChunkWidth, getLocator()));
    }

    report.setCompatibilityLevel(ClassicEngineBoot.computeVersionId(3, 8, 0));
    this.report = report;
}

From source file:org.pentaho.reporting.engine.classic.core.modules.parser.simple.readhandlers.JFreeReportReadHandler.java

/**
 * Creates the pageFormat by using the given Attributes. If an PageFormat name is given, the named PageFormat is used
 * and the parameters width and height are ignored. If no name is defined, height and width attributes are used to
 * create the pageformat. The attributes define the dimension of the PageFormat in points, where the printing
 * resolution is defined at 72 pixels per inch.
 *
 * @param format/*  ww w  .j  a  v a 2 s  .com*/
 *          the page format.
 * @param atts
 *          the element attributes.
 * @return the page format.
 * @throws SAXException
 *           if there is an error parsing the report.
 */
private PageFormat createPageFormat(final PageFormat format, final Attributes atts) throws SAXException {
    final String pageformatName = atts.getValue(getUri(), JFreeReportReadHandler.PAGEFORMAT_ATT);

    final int orientationVal;
    final String orientation = atts.getValue(getUri(), JFreeReportReadHandler.ORIENTATION_ATT);
    if (orientation == null) {
        orientationVal = PageFormat.PORTRAIT;
    } else if (orientation.equals(JFreeReportReadHandler.ORIENTATION_LANDSCAPE_VAL)) {
        orientationVal = PageFormat.LANDSCAPE;
    } else if (orientation.equals(JFreeReportReadHandler.ORIENTATION_REVERSE_LANDSCAPE_VAL)) {
        orientationVal = PageFormat.REVERSE_LANDSCAPE;
    } else if (orientation.equals(JFreeReportReadHandler.ORIENTATION_PORTRAIT_VAL)) {
        orientationVal = PageFormat.PORTRAIT;
    } else {
        throw new ParseException("Orientation value in REPORT-Tag is invalid.",
                getRootHandler().getDocumentLocator());
    }
    if (pageformatName != null) {
        final Paper p = PageFormatFactory.getInstance().createPaper(pageformatName);
        if (p == null) {
            JFreeReportReadHandler.logger.warn("Unable to create the requested Paper. " + pageformatName);
            return format;
        }
        return PageFormatFactory.getInstance().createPageFormat(p, orientationVal);
    }

    if (atts.getValue(getUri(), JFreeReportReadHandler.WIDTH_ATT) != null
            && atts.getValue(getUri(), JFreeReportReadHandler.HEIGHT_ATT) != null) {
        final int[] pageformatData = new int[2];
        pageformatData[0] = ParserUtil.parseInt(atts.getValue(getUri(), JFreeReportReadHandler.WIDTH_ATT),
                "No Width set", getLocator());
        pageformatData[1] = ParserUtil.parseInt(atts.getValue(getUri(), JFreeReportReadHandler.HEIGHT_ATT),
                "No Height set", getLocator());
        final Paper p = PageFormatFactory.getInstance().createPaper(pageformatData);
        if (p == null) {
            JFreeReportReadHandler.logger.warn("Unable to create the requested Paper. Paper={"
                    + pageformatData[0] + ", " + pageformatData[1] + '}');
            return format;
        }
        return PageFormatFactory.getInstance().createPageFormat(p, orientationVal);
    }

    JFreeReportReadHandler.logger.info("Insufficient Data to create a pageformat: Returned default.");
    return format;
}

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  w w  w.j  av  a2  s .  c  om

    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;
}

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

private static OrientationRequested mapOrientation(final int orientation) {
    switch (orientation) {
    case PageFormat.LANDSCAPE:
        return OrientationRequested.LANDSCAPE;
    case PageFormat.REVERSE_LANDSCAPE:
        return OrientationRequested.REVERSE_LANDSCAPE;
    case PageFormat.PORTRAIT:
        return OrientationRequested.PORTRAIT;
    default://w w  w.j  a  va  2 s . c  om
        throw new IllegalArgumentException("The given value is no valid PageFormat orientation.");
    }
}