Ejemplo n.º 1
0
  public DynamicReport buildReport() throws Exception {

    DynamicReportBuilder drb = new DynamicReportBuilder();
    Integer margin = new Integer(20);
    drb.setTitle("November" + getYear() + " sales report") // defines the title of the report
        .setSubtitle(
            "The items in this report correspond "
                + "to the main products: DVDs, Books, Foods and Magazines")
        .setTitleHeight(new Integer(30))
        .setSubtitleHeight(new Integer(20))
        .setDetailHeight(new Integer(15))
        .setLeftMargin(margin)
        .setRightMargin(margin)
        .setTopMargin(margin)
        .setBottomMargin(margin)
        .setColumnsPerPage(new Integer(1))
        .setColumnSpace(new Integer(5));

    Style style1 = new Style("style1");
    style1.setFont(Font.ARIAL_MEDIUM_BOLD);
    style1.setHorizontalAlign(HorizontalAlign.CENTER);
    drb.addStyle(style1);

    Style style2 = Style.createBlankStyle("style2", "style1");
    style2.setTextColor(Color.BLUE);
    drb.addStyle(style2);

    AbstractColumn columnState =
        ColumnBuilder.getNew()
            .setColumnProperty("state", String.class.getName())
            .setTitle("State")
            .setWidth(new Integer(85))
            .setStyle(style1)
            .build();

    AbstractColumn columnBranch =
        ColumnBuilder.getNew()
            .setColumnProperty("branch", String.class.getName())
            .setTitle("Branch")
            .setWidth(new Integer(85))
            .setStyle(style2)
            .build();

    drb.addColumn(columnBranch);
    drb.addColumn(columnState);

    DJGroup g1 =
        new GroupBuilder()
            .setCriteriaColumn((PropertyColumn) columnBranch)

            //		.setGroupLayout(GroupLayout.DEFAULT)
            .setGroupLayout(GroupLayout.DEFAULT_WITH_HEADER)
            .build();
    drb.addGroup(g1);

    drb.setUseFullPageWidth(true);

    DynamicReport dr = drb.build();
    return dr;
  }
Ejemplo n.º 2
0
  public DynamicReport buildReport() throws Exception {

    Style detailStyle = new Style();
    Style headerStyle = new Style();
    headerStyle.setFont(Font.ARIAL_MEDIUM_BOLD);
    headerStyle.setBorder(Border.PEN_2_POINT());
    headerStyle.setHorizontalAlign(HorizontalAlign.CENTER);
    headerStyle.setVerticalAlign(VerticalAlign.MIDDLE);

    Style titleStyle = new Style();
    titleStyle.setFont(new Font(18, Font._FONT_VERDANA, true));
    Style importeStyle = new Style();
    importeStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
    Style oddRowStyle = new Style();
    oddRowStyle.setBorder(Border.NO_BORDER());
    oddRowStyle.setBackgroundColor(Color.LIGHT_GRAY);
    oddRowStyle.setTransparency(Transparency.OPAQUE);

    DynamicReportBuilder drb = new DynamicReportBuilder();
    int margin = 20;
    drb.setTitleStyle(titleStyle)
        .setTitle("November" + getYear() + " sales report") // defines the title of the report
        .setSubtitle(
            "The items in this report correspond "
                + "to the main products: DVDs, Books, Foods and Magazines")
        .setDetailHeight(new Integer(15))
        .setLeftMargin(margin)
        .setMargins(margin, margin, margin, margin)
        //				.setPrintBackgroundOnOddRows(true)
        .setPrintColumnNames(false)
        .setOddRowBackgroundStyle(oddRowStyle);

    AbstractColumn columnState =
        ColumnBuilder.getNew()
            .setColumnProperty("state", String.class.getName())
            .setTitle("State")
            .setWidth(new Integer(85))
            .setStyle(detailStyle)
            .setHeaderStyle(headerStyle)
            .build();

    AbstractColumn columnBranch =
        ColumnBuilder.getNew()
            .setColumnProperty("branch", String.class.getName())
            .setTitle("Branch")
            .setWidth(new Integer(85))
            .setStyle(detailStyle)
            .setHeaderStyle(headerStyle)
            .build();

    AbstractColumn columnaProductLine =
        ColumnBuilder.getNew()
            .setColumnProperty("productLine", String.class.getName())
            .setTitle("Product Line")
            .setWidth(new Integer(85))
            .setStyle(detailStyle)
            .setHeaderStyle(headerStyle)
            .build();

    AbstractColumn columnaItem =
        ColumnBuilder.getNew()
            .setColumnProperty("item", String.class.getName())
            .setTitle("Item")
            .setWidth(new Integer(85))
            .setStyle(detailStyle)
            .setHeaderStyle(headerStyle)
            .build();

    AbstractColumn columnCode =
        ColumnBuilder.getNew()
            .setColumnProperty("id", Long.class.getName())
            .setTitle("ID")
            .setWidth(new Integer(40))
            .setStyle(importeStyle)
            .setHeaderStyle(headerStyle)
            .build();

    AbstractColumn columnaQuantity =
        ColumnBuilder.getNew()
            .setColumnProperty("quantity", Long.class.getName())
            .setTitle("Quantity")
            .setWidth(new Integer(80))
            .setStyle(importeStyle)
            .setHeaderStyle(headerStyle)
            .build();

    AbstractColumn columnAmount =
        ColumnBuilder.getNew()
            .setColumnProperty("amount", Float.class.getName())
            .setTitle("Amount")
            .setWidth(new Integer(90))
            .setPattern("$ 0.00")
            .setStyle(importeStyle)
            .setHeaderStyle(headerStyle)
            .build();

    GroupBuilder gb1 = new GroupBuilder();

    //		 define the criteria column to group by (columnState)
    DJGroup g1 =
        gb1.setCriteriaColumn((PropertyColumn) columnState)
            .addFooterVariable(
                columnAmount,
                DJCalculation
                    .SUM) // tell the group place a variable footer of the column "columnAmount"
                          // with the SUM of allvalues of the columnAmount in this group.
            .addFooterVariable(
                columnaQuantity, DJCalculation.SUM) // idem for the columnaQuantity column
            .setGroupLayout(
                GroupLayout
                    .DEFAULT_WITH_HEADER) // tells the group how to be shown, there are
                                          // manyposibilities, see the GroupLayout for more.
            .build();

    GroupBuilder gb2 =
        new GroupBuilder(); // Create another group (using another column as criteria)
    DJGroup g2 =
        gb2.setCriteriaColumn(
                (PropertyColumn)
                    columnBranch) // and we add the same operations for the columnAmount and
            .addFooterVariable(columnAmount, DJCalculation.SUM) // columnaQuantity columns
            .addFooterVariable(columnaQuantity, DJCalculation.SUM)
            .build();

    drb.addColumn(columnState);
    drb.addColumn(columnBranch);
    drb.addColumn(columnaProductLine);
    drb.addColumn(columnaItem);
    drb.addColumn(columnCode);
    drb.addColumn(columnaQuantity);
    drb.addColumn(columnAmount);

    drb.addGroup(g1); // add group g1
    //		drb.addGroup(g2); // add group g2

    drb.setUseFullPageWidth(true);

    DJChartBuilder cb = new DJChartBuilder();
    DJChart chart =
        cb.setType(DJChart.BAR_CHART)
            .setOperation(DJChart.CALCULATION_SUM)
            .setColumnsGroup(g1)
            .addColumn(columnAmount)
            .addColumn(columnaQuantity)
            .setPosition(DJChartOptions.POSITION_HEADER)
            .setShowLabels(true)
            .build();

    drb.addChart(chart); // add chart

    DynamicReport dr = drb.build();

    return dr;
  }