예제 #1
0
  @Override
  public JRDesignComponentElement createJRElement(JasperDesign jasperDesign) {
    JRDesignComponentElement el = new JRDesignComponentElement();
    UPCAComponent component = new UPCAComponent();
    JRDesignExpression exp = new JRDesignExpression();
    exp.setText("\"12345678901\""); // $NON-NLS-1$
    component.setCodeExpression(exp);
    el.setComponent(component);
    el.setComponentKey(
        new ComponentKey(
            "http://jasperreports.sourceforge.net/jasperreports/components",
            "jr",
            "UPCA")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    DefaultManager.INSTANCE.applyDefault(this.getClass(), el);

    return el;
  }
예제 #2
0
  public static JasperDesign enrichJasperDesign(JasperDesign jasperDesign, String[] columns)
      throws JRException {

    JRDesignField field;
    JRDesignStaticText staticText;

    JRDesignFrame frame = new JRDesignFrame();
    JRDesignTextField textField;
    // Bands

    JRDesignBand band = new JRDesignBand();
    band.setHeight(20);
    //		jasperDesign.setColumnHeader(band);
    int c = 0;
    for (String column : columns) {
      field = createField(column);
      field.setValueClass(java.lang.String.class);
      jasperDesign.addField(field);

      staticText = createStaticText(column, 0, 0);
      staticText.setStyle(createBoldStyle(9));
      band.addElement(staticText);
      jasperDesign.setColumnHeader(band);
      //			frame.addElement(staticText);

      band = new JRDesignBand();
      band.setHeight(20);
      textField = createTextField(0, 4);
      textField.setStretchWithOverflow(true);
      textField.setStyle(createNormalStyle(9));

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

    //		= createTextField(0, 4);
    //		band.addElement(textField);

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

    return jasperDesign;
  }
예제 #3
0
  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;
  }
예제 #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;
  }
예제 #5
0
 public static JRDesignExpression createExpression(String expr) {
   JRDesignExpression expression = new JRDesignExpression();
   //	expression.setValueClass(java.lang.Integer.class);
   expression.setText("$F{" + expr + "}");
   return expression;
 }
예제 #6
0
 protected JRDesignTextField createJRTextField(
     String key,
     String expression,
     int x,
     int y,
     int w,
     int h,
     String fontName,
     int fontSize,
     int fontStyle) {
   JRDesignTextField txf = new JRDesignTextField();
   //        if (!print && drawBounds) {
   //            txf.setBorder((byte) 1);
   //        }
   txf.setStretchWithOverflow(false);
   txf.setBlankWhenNull(true);
   txf.setEvaluationTime(JRExpression.EVALUATION_TIME_NOW);
   txf.setHyperlinkType(JRDesignTextField.HYPERLINK_TYPE_NONE);
   txf.setForecolor(Color.BLACK);
   txf.setBackcolor(Color.WHITE);
   txf.setKey(key);
   txf.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);
   txf.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);
   txf.setPrintRepeatedValues(true);
   txf.setRemoveLineWhenBlank(false);
   txf.setPrintInFirstWholeBand(false);
   txf.setPrintWhenDetailOverflows(false);
   txf.setHorizontalAlignment(JRTextElement.HORIZONTAL_ALIGN_CENTER); // textAlignment
   txf.setVerticalAlignment((JRTextElement.VERTICAL_ALIGN_TOP));
   txf.setRotation(JRTextElement.ROTATION_NONE);
   txf.setLineSpacing(JRTextElement.LINE_SPACING_SINGLE);
   txf.setMode(JRTextElement.MODE_OPAQUE);
   JRDesignExpression txfValue = new JRDesignExpression();
   txfValue.setValueClass(String.class);
   txfValue.setText(expression);
   txf.setExpression(txfValue);
   txf.setX(x);
   txf.setY(y);
   txf.setWidth(w);
   txf.setHeight(h);
   //        JRReportFont font = new JRDesignReportFont();
   txf.setFontName(fontName);
   txf.setFontSize(fontSize);
   txf.setBold((fontStyle & Font.BOLD) != 0);
   txf.setItalic((fontStyle & Font.ITALIC) != 0);
   txf.setUnderline(false);
   txf.setPdfEmbedded(false);
   txf.setPdfEncoding("Cp1252");
   txf.setStrikeThrough(false);
   txf.setPdfFontName("Helvetica");
   JRReportFont rfont = new JRDesignReportFont();
   rfont.setFontName(fontName);
   rfont.setFontSize(fontSize);
   rfont.setBold((fontStyle & Font.BOLD) != 0);
   rfont.setItalic((fontStyle & Font.ITALIC) != 0);
   rfont.setUnderline(false);
   rfont.setPdfEmbedded(false);
   rfont.setPdfEncoding("Cp1252");
   rfont.setStrikeThrough(false);
   txf.setReportFont(rfont);
   rfont.setPdfFontName("Helvetica");
   JRDesignStyle style = new JRDesignStyle();
   style.setFontName(fontName);
   txf.setStyle(style);
   return txf;
 }
  protected Object transformEntity(Entity entity) {

    DJGroupVariable groupVariable = (DJGroupVariable) entity;
    AbstractColumn col = groupVariable.getColumnToApplyOperation();

    String variableName = groupVariable.getName();
    log.debug("transforming group variable " + variableName);
    DJCalculation op = groupVariable.getOperation();

    JRDesignExpression expression = new JRDesignExpression();

    // only variables from the last registered group are important now
    List groupsList = getDjd().getGroupsList();
    JRDesignGroup registeredGroup = (JRDesignGroup) groupsList.get(groupsList.size() - 1);

    if (col instanceof ExpressionColumn
        && ((ExpressionColumn) col).getExpressionForCalculation() != null) {
      ExpressionColumn expcol = (ExpressionColumn) col;
      expression.setText(expcol.getTextForExpressionForCalculartion());
      expression.setValueClassName(expcol.getExpressionForCalculation().getClassName());
    } else if (col instanceof PercentageColumn) {
      PercentageColumn pcol = (PercentageColumn) col;
      expression.setText(pcol.getPercentageColumn().getTextForExpression());
      expression.setValueClassName(pcol.getPercentageColumn().getValueClassNameForExpression());

      DJGroup djgroup = groupVariable.getGroup();
      registeredGroup =
          LayoutUtils.findParentJRGroup(djgroup, getDynamicReport(), getDjd(), getLayoutManager());
    } else {
      if (col.getTextFormatter() != null) {
        PropertyColumn pcol = (PropertyColumn) col;
        expression.setText("$F{" + pcol.getColumnProperty().getProperty() + "}");
        expression.setValueClassName(pcol.getColumnProperty().getValueClassName());
      } else {
        expression.setText(col.getTextForExpression());
        expression.setValueClassName(col.getValueClassNameForExpression());
      }
    }

    JRDesignVariable variable = new JRDesignVariable();
    variable.setExpression(expression);
    variable.setCalculation(CalculationEnum.getByValue(groupVariable.getOperation().getValue()));
    variable.setName(variableName);

    variable.setResetType(ResetTypeEnum.GROUP);
    variable.setResetGroup(registeredGroup);

    String valueClassName = col.getVariableClassName(op);
    String initialExpression = col.getInitialExpression(op);

    //		if (DJCalculation.SYSTEM.equals(groupVariable.getOperation())){
    //			variable.setValueClassName(Object.class.getName());
    //		} else {
    //		}
    variable.setValueClassName(valueClassName);

    if (initialExpression != null) {
      JRDesignExpression initialExp = new JRDesignExpression();
      initialExp.setText(initialExpression);
      initialExp.setValueClassName(valueClassName);
      variable.setInitialValueExpression(initialExp);
    }

    return variable;
  }