Java Code Examples for net.sf.jasperreports.engine.design.JasperDesign#setPageWidth()

The following examples show how to use net.sf.jasperreports.engine.design.JasperDesign#setPageWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TravelReportFactoryServiceImpl.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Populate the design of a report. Report's main content container is a design.
 *
 * @param report in
 * @return {@link JasperDesign} out
 * @throws Exception because there is a lot of under-the-hood I/O and reflection going on.
 */
@Override
public JasperDesign designSummary(final ReportInfo report) throws Exception {
    final JasperDesign designObj = new JasperDesign();
    final String reportTitle = getReportTitle(report);
    designObj.setName(reportTitle);
    designObj.setTitle(createTitle(report, reportTitle));

    LOG.info("Summary: Loading report parameters");
    addReportParametersFor(report, designObj);
    designObj.addImport(report.getClass().getName());
    LOG.info("Summary: Loading report fields");
    addReportFieldsFor(report, designObj);

    LOG.info("Summary: Setting report dimensions");
    designObj.setPageWidth(595);
    designObj.setPageHeight(REPORT_HEIGHT);
    designObj.setLeftMargin(MARGIN);
    designObj.setRightMargin(MARGIN);
    designObj.setTopMargin(MARGIN);
    designObj.setBottomMargin(MARGIN);

    LOG.info("Summary: Adding header and footer");
    final JRDesignBand header = new JRDesignBand();
    final JRDesignStaticText headerLine4 = h4("Summary").toStaticText();
    addDesignElementTo(header, headerLine4, 0, PAGEHEADER_HEIGHT, 356, 22);
    header.setHeight(PAGEHEADER_HEIGHT * 2);
    designObj.setPageHeader(header);

    LOG.info("Creating report detail");
    final Field summaryField = getFieldWithAnnotation(report, Summary.class);
    final JRBand summary = createSummary(summaryField);

    if (summary != null) {
        designObj.setSummary(summary);
        return designObj;
    }

    return null;
}
 
Example 2
Source File: TravelReportFactoryServiceImpl.java    From kfs with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * A lot like {@link #designReport(ReportInfo)} except it is intended for {@link SubReport}s
 *
 * @param report is an instance of the {@link ReportInfo} which represents a report.
 * @param field {@link Field} instance with a {@link SubReport} annotation
 * @return a {@link JasperDesign} instance used in a {@link JasperReport}
 * @see org.kuali.kfs.module.tem.report.service.TravelReportFactoryService#designReport(org.kuali.kfs.sys.report.ReportInfo)
 */
public JasperDesign designReport(final ReportInfo report, final Field field) throws Exception {
    LOG.info("Designing a subreport for field "+ field.getName());

    LOG.debug("Checking the "+ field.getName()+ " for data");
    try {
        field.setAccessible(true);
        if (field.get(report) == null) {
            return null;
        }
        LOG.debug("Subreport has data. Proceeding to design subreport.");
    }
    catch (Exception e) {
        throw new RuntimeException(e);
    }

    final JasperDesign designObj = new JasperDesign();
    designObj.setName(field.getName());
    designObj.setTitle(createTitle(report, getReportTitle(report)));

    addReportParametersFor(report, designObj);
    designObj.addImport(report.getClass().getName());
    addReportFieldsFor(report, designObj);

    final JRDesignBand titleBand = new JRDesignBand();
    titleBand.setHeight(23);

    final JRDesignStaticText headerLine4 = h4(initialCaps(field.getName())).toStaticText();
    addDesignElementTo(titleBand, headerLine4, 0, 0, 356, 22);

    designObj.setPageHeader(titleBand);

    designObj.setPageWidth(595);
    designObj.setPageHeight(REPORT_HEIGHT);
    designObj.setLeftMargin(MARGIN);
    designObj.setRightMargin(MARGIN);
    designObj.setTopMargin(MARGIN);
    designObj.setBottomMargin(MARGIN);

    if (hasDetail(report)) {
        LOG.debug("Creating detail for subreport");
        designObj.setDetail(createDetail(report, 0));
    }
    else {
        LOG.debug("Creating summary for subreport");
        designObj.setSummary(createSummary(field));
    }

    return designObj;
}
 
Example 3
Source File: TravelReportFactoryServiceImpl.java    From kfs with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Populate the design of a report. Report's main content container is a design.
 *
 * @param report in
 * @return {@link JasperDesign} out
 * @throws Exception because there is a lot of under-the-hood I/O and reflection going on.
 */
@Override
public JasperDesign designReport(final ReportInfo report, final Integer reportIndex) throws Exception {
    final JasperDesign designObj = new JasperDesign();
    final String reportTitle = getReportTitle(report);
    designObj.setName(reportTitle);

    if (reportIndex < 1) {
        designObj.setTitle(createTitle(report, reportTitle));
    }

    LOG.info("Loading report parameters");
    addReportParametersFor(report, designObj);
    designObj.addImport(report.getClass().getName());
    LOG.info("Loading report fields");
    addReportFieldsFor(report, designObj);

    LOG.info("Setting report dimensions");
    designObj.setPageWidth(595);
    designObj.setPageHeight(REPORT_HEIGHT);
    designObj.setLeftMargin(MARGIN);
    designObj.setRightMargin(MARGIN);
    designObj.setTopMargin(MARGIN);
    designObj.setBottomMargin(MARGIN);

    // Groups before detail
    LOG.info("Handling groups");
    addGroupsFor(report, designObj);

    LOG.info("Creating report detail");
    final JRBand detail = createDetail(report, reportIndex);

    if (detail != null) {
        designObj.setDetail(detail);
    }
    else {
        return null;
    }

    return designObj;
}