Example usage for java.awt.print PageFormat getHeight

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

Introduction

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

Prototype

public double getHeight() 

Source Link

Document

Returns the height, in 1/72nds of an inch, of the page.

Usage

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

/**
 * Starts parsing./*from ww  w .  j  a  v a 2s.c om*/
 *
 * @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.util.PageFormatFactory.java

public static String printPageFormat(final PageFormat pf) {
    StringBuffer b = new StringBuffer();
    b.append("PageFormat={width=");
    b.append(pf.getWidth());//from   ww w  .  j  a  v a2  s.  c  om
    b.append(", height=");
    b.append(pf.getHeight());
    b.append(", imageableX=");
    b.append(pf.getImageableX());
    b.append(", imageableY=");
    b.append(pf.getImageableY());
    b.append(", imageableWidth=");
    b.append(pf.getImageableWidth());
    b.append(", imageableHeight=");
    b.append(pf.getImageableHeight());
    b.append(", orientation=").append(pf.getOrientation());
    b.append(", paper=");
    b.append(printPaper(pf.getPaper()));
    b.append("}");
    return b.toString();
}

From source file:org.pentaho.reporting.engine.classic.demo.ancient.demo.nogui.StraightToPNG.java

/**
 * Create the empty image for the given page size.
 *
 * @param pd the page definition that defines the image bounds.
 * @return the generated image./*w  ww  .j  av a  2 s  .  co  m*/
 */
private BufferedImage createImage(final PageDefinition pd) {
    // in this simple case we know, that all pages have the same size..
    final PageFormat pf = pd.getPageFormat(0);

    final double width = pf.getWidth();
    final double height = pf.getHeight();
    //write the report to the temp file
    return new BufferedImage((int) width, (int) height, BufferedImage.TYPE_BYTE_INDEXED);
}