List of usage examples for java.awt.print PageFormat getWidth
public double getWidth()
From source file:org.pentaho.reporting.engine.classic.core.modules.parser.simple.readhandlers.JFreeReportReadHandler.java
/** * Starts parsing./*w w w. ja va 2 s.com*/ * * @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()); b.append(", height="); b.append(pf.getHeight());//from w w w . java2 s . co m 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.//from w w w . ja va 2 s .c om */ 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); }