/**
   * Registers the parameter for the value formatter for the given variable and puts it's
   * implementation in the parameters map.
   *
   * @param djVariable
   * @param variableName
   */
  protected void registerValueFormatter(DJGroupVariable djVariable, String variableName) {
    if (djVariable.getValueFormatter() == null) {
      return;
    }

    JRDesignParameter dparam = new JRDesignParameter();
    dparam.setName(variableName + "_vf"); // value formater suffix
    dparam.setValueClassName(DJValueFormatter.class.getName());
    log.debug("Registering value formatter parameter for property " + dparam.getName());
    try {
      getDjd().addParameter(dparam);
    } catch (JRException e) {
      throw new EntitiesRegistrationException(e.getMessage(), e);
    }
    getDjd().getParametersWithValues().put(dparam.getName(), djVariable.getValueFormatter());
  }
Esempio n. 2
0
  public static JasperDesign createJasperDesign() throws JRException {

    // JasperDesign
    JasperDesign jasperDesign = new JasperDesign();
    jasperDesign.setName("ReqIF_Report");
    jasperDesign.setPageWidth(595);
    jasperDesign.setPageHeight(842);
    jasperDesign.setColumnWidth(515);
    jasperDesign.setColumnSpacing(0);
    jasperDesign.setLeftMargin(40);
    jasperDesign.setRightMargin(40);
    jasperDesign.setTopMargin(50);
    jasperDesign.setBottomMargin(50);

    // Fonts
    JRDesignStyle normalStyle = createNormalStyle(9);
    jasperDesign.addStyle(normalStyle);

    JRDesignStyle boldStyle = createBoldStyle(9);
    jasperDesign.addStyle(boldStyle);

    JRDesignStyle italicStyle = createItalicStyle(9);
    jasperDesign.addStyle(italicStyle);

    // Parameters
    JRDesignParameter parameter = new JRDesignParameter();
    parameter.setName("ReportTitle");
    parameter.setValueClass(java.lang.String.class);
    jasperDesign.addParameter(parameter);

    // Query
    JRDesignQuery query = new JRDesignQuery();
    query.setText("");
    jasperDesign.setQuery(query);
    return jasperDesign;
  }
  private static JasperDesign getJasperDesign(List<PropertyDescriptor> props) throws JRException {
    // JasperDesign
    JasperDesign jasperDesign = new JasperDesign();
    jasperDesign.setName("NoXmlDesignReport");
    jasperDesign.setPageWidth(595);
    jasperDesign.setPageHeight(842);
    jasperDesign.setColumnWidth(515);
    jasperDesign.setColumnSpacing(0);
    jasperDesign.setColumnCount(1);
    jasperDesign.setLeftMargin(40);
    jasperDesign.setRightMargin(40);
    jasperDesign.setTopMargin(50);
    jasperDesign.setBottomMargin(50);

    // Fonts
    JRDesignStyle normalStyle = new JRDesignStyle();
    normalStyle.setName("Sans_Normal");
    normalStyle.setDefault(true);
    normalStyle.setFontName("DejaVu Sans");
    normalStyle.setFontSize(12);
    normalStyle.setPdfFontName("Helvetica");
    normalStyle.setPdfEncoding("Cp1252");
    normalStyle.setPdfEmbedded(false);
    jasperDesign.addStyle(normalStyle);

    JRDesignStyle boldStyle = new JRDesignStyle();
    boldStyle.setName("Sans_Bold");
    boldStyle.setFontName("DejaVu Sans");
    boldStyle.setFontSize(12);
    boldStyle.setBold(true);
    boldStyle.setPdfFontName("Helvetica-Bold");
    boldStyle.setPdfEncoding("Cp1252");
    boldStyle.setPdfEmbedded(false);
    jasperDesign.addStyle(boldStyle);

    JRDesignStyle italicStyle = new JRDesignStyle();
    italicStyle.setName("Sans_Italic");
    italicStyle.setFontName("DejaVu Sans");
    italicStyle.setFontSize(12);
    italicStyle.setItalic(true);
    italicStyle.setPdfFontName("Helvetica-Oblique");
    italicStyle.setPdfEncoding("Cp1252");
    italicStyle.setPdfEmbedded(false);
    jasperDesign.addStyle(italicStyle);

    // Parameters
    JRDesignParameter parameter = new JRDesignParameter();
    parameter.setName("ReportTitle");
    parameter.setValueClass(java.lang.String.class);
    jasperDesign.addParameter(parameter);

    // Fields
    int i = 1;
    for (PropertyDescriptor p : props) {
      JRDesignField field = new JRDesignField();
      field.setName(p.getName());
      field.setValueClass(resolveType(p));
      jasperDesign.addField(field);
      i++;
    }

    // Title
    JRDesignBand band = new JRDesignBand();
    band.setHeight(50);

    JRDesignTextField textField = new JRDesignTextField();
    textField.setBlankWhenNull(true);
    textField.setX(0);
    textField.setY(20);
    textField.setWidth(510);
    textField.setHeight(30);
    textField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);
    textField.setStyle(normalStyle);
    textField.setFontSize(22);
    JRDesignExpression expression = new JRDesignExpression();
    expression.setValueClass(java.lang.String.class);
    expression.setText("$P{ReportTitle}");
    textField.setExpression(expression);
    band.addElement(textField);
    jasperDesign.setTitle(band);

    // Page header
    band = new JRDesignBand();
    band.setHeight(20);
    int x = 0;
    for (PropertyDescriptor p : props) {
      JRDesignStaticText staticText = new JRDesignStaticText();
      staticText.setX(x);
      staticText.setY(0);

      if (p.getName().equals("message")) {
        staticText.setWidth(400);
        x += 400;
      } else {
        staticText.setWidth(100);
        x += 100;
      }
      staticText.setHeight(20);
      staticText.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);
      staticText.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);
      staticText.setStyle(boldStyle);
      staticText.setStretchType(JRDesignStaticText.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT);

      staticText.setText(p.getDisplayName());
      band.addElement(staticText);
    }

    jasperDesign.setPageHeader(band);

    // Column header
    band = new JRDesignBand();
    jasperDesign.setColumnHeader(band);

    band = new JRDesignBand();
    band.setHeight(25);
    x = 0;
    for (PropertyDescriptor p : props) {
      textField = new JRDesignTextField();
      textField.setX(x);
      textField.setY(0);
      if (p.getName().equals("message")) {
        textField.setWidth(400);
        x += 400;
      } else {
        textField.setWidth(100);
        x += 100;
      }
      textField.setHeight(20);
      textField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);
      textField.setVerticalAlignment(JRAlignment.VERTICAL_ALIGN_MIDDLE);
      textField.setStyle(normalStyle);
      expression = new JRDesignExpression();
      Class type = resolveType(p);
      expression.setValueClass(type);
      expression.setText("$F{" + p.getName() + "}");
      textField.setExpression(expression);
      textField.setStretchWithOverflow(true);
      band.addElement(textField);
    }

    jasperDesign.setDetail(band);

    // Column footer
    band = new JRDesignBand();
    jasperDesign.setColumnFooter(band);

    // Page footer
    band = new JRDesignBand();
    jasperDesign.setPageFooter(band);

    // Summary
    band = new JRDesignBand();
    jasperDesign.setSummary(band);

    return jasperDesign;
  }
Esempio n. 4
0
  public static JasperDesign getJasperDesign() throws JRException {

    // JasperDesign
    JasperDesign jasperDesign = new JasperDesign();
    jasperDesign.setName("ReqIF_Report");
    jasperDesign.setPageWidth(595);
    jasperDesign.setPageHeight(842);
    jasperDesign.setColumnWidth(515);
    jasperDesign.setColumnSpacing(0);
    jasperDesign.setLeftMargin(40);
    jasperDesign.setRightMargin(40);
    jasperDesign.setTopMargin(50);
    jasperDesign.setBottomMargin(50);

    // Fonts
    JRDesignStyle normalStyle = createNormalStyle(9);
    jasperDesign.addStyle(normalStyle);

    JRDesignStyle boldStyle = createBoldStyle(9);
    jasperDesign.addStyle(boldStyle);

    JRDesignStyle italicStyle = createItalicStyle(9);
    jasperDesign.addStyle(italicStyle);

    // Parameters
    JRDesignParameter parameter = new JRDesignParameter();
    parameter.setName("ReportTitle");
    parameter.setValueClass(java.lang.String.class);
    jasperDesign.addParameter(parameter);

    // Query
    JRDesignQuery query = new JRDesignQuery();
    query.setText("");
    jasperDesign.setQuery(query);

    // Fields
    JRDesignField field = createField("Id");
    jasperDesign.addField(field);

    field = createField("FirstName");
    jasperDesign.addField(field);

    field = createField("LastName");
    jasperDesign.addField(field);

    field = createField("City");
    jasperDesign.addField(field);

    field = createField("Street");
    jasperDesign.addField(field);
    // Bands

    JRDesignBand band = new JRDesignBand();
    band.setHeight(20);

    JRDesignTextField textField = createTextField(0, 4);

    band.addElement(textField);
    JRDesignLine line = createLine(0, 19);
    band.addElement(line);

    band = new JRDesignBand();
    band.setHeight(20);
    line = createLine(0, -1);
    band.addElement(line);

    JRDesignStaticText staticText = new JRDesignStaticText();

    //		band.addElement(staticText);

    //		band.addElement(textField);

    // Page header
    band = new JRDesignBand();
    band.setHeight(20);
    JRDesignFrame frame = new JRDesignFrame();
    frame.setX(0);
    frame.setY(5);
    frame.setWidth(515);
    frame.setHeight(15);
    frame.setForecolor(new Color(0x33, 0x33, 0x33));
    frame.setBackcolor(new Color(0x33, 0x33, 0x33));
    frame.setMode(ModeEnum.OPAQUE);
    band.addElement(frame);

    staticText = createStaticText("ID", 0, 0);
    staticText.setStyle(createBoldStyle(9));
    frame.addElement(staticText);

    staticText = createStaticText("Name", 111, 0);
    staticText.setStyle(createBoldStyle(9));
    frame.addElement(staticText);

    staticText = createStaticText("Street", 260, 0);
    staticText.setStyle(createBoldStyle(9));
    frame.addElement(staticText);

    jasperDesign.setPageHeader(band);

    // Column header
    band = new JRDesignBand();
    jasperDesign.setColumnHeader(band);

    // Detail
    band = new JRDesignBand();
    band.setHeight(20);

    textField = new JRDesignTextField();
    textField.setX(0);
    textField.setY(4);
    textField.setWidth(50);
    textField.setHeight(15);
    textField.setHorizontalAlignment(HorizontalAlignEnum.RIGHT);
    textField.setStyle(normalStyle);

    JRDesignExpression expression = new JRDesignExpression();
    expression.setText("$F{Id}");
    textField.setExpression(expression);
    band.addElement(textField);

    textField = new JRDesignTextField();
    textField.setStretchWithOverflow(true);
    textField.setX(55);
    textField.setY(4);
    textField.setWidth(200);
    textField.setHeight(15);
    textField.setPositionType(PositionTypeEnum.FLOAT);
    textField.setStyle(normalStyle);
    band.addElement(textField);
    textField = new JRDesignTextField();
    textField.setStretchWithOverflow(true);
    textField.setX(260);
    textField.setY(4);
    textField.setWidth(255);
    textField.setHeight(15);
    textField.setPositionType(PositionTypeEnum.FLOAT);
    textField.setStyle(normalStyle);
    band.addElement(textField);

    line = new JRDesignLine();
    line.setX(0);
    line.setY(19);
    line.setWidth(515);
    line.setHeight(0);
    line.setForecolor(new Color(0x80, 0x80, 0x80));
    line.setPositionType(PositionTypeEnum.FLOAT);
    band.addElement(line);

    ((JRDesignSection) jasperDesign.getDetailSection()).addBand(band);

    // Column footer
    band = new JRDesignBand();
    // jasperDesign.setColumnFooter(band);

    // Page footer
    band = new JRDesignBand();
    // jasperDesign.setPageFooter(band);

    // Summary
    band = new JRDesignBand();
    // jasperDesign.setSummary(band);

    return jasperDesign;
  }