Package net.sf.jasperreports.engine.design

Examples of net.sf.jasperreports.engine.design.JRDesignExpression


public abstract class AutoTextExpressionUtils {

  private static final String PAGE_NUMBER_VAR = "$V{PAGE_NUMBER}";

  public static JRDesignExpression getPageNumberExpression(String before, String after, boolean useI18n) {
    JRDesignExpression expression = new JRDesignExpression();
    String text = null;
    if (useI18n) {
      if (!emptyString(before)){
        before = "$R{" + before + "}";
      } else {before = "\"" + before + "\"";}
      if (!emptyString(after)){
        after = "$R{" + after + "}";
      } else {after = "\"" + after + "\"";}
       text = before + "+\" \" + " + PAGE_NUMBER_VAR + "+\" \" + " + after;
    } else {
      if (emptyString(before)){
        before = "\"\"";
      } else {before = "\"" + before + "\"";}
      if (emptyString(after)){
        after = "\"\"";
      } else {after = "\"" + after + "\"";}
      text = before + "+\" \" + " + PAGE_NUMBER_VAR + "+\" \" + " + after;

    }
    expression.setText( text );
    expression.setValueClass(String.class);
    return expression;
  }
View Full Code Here


     dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT,locale);
    else if (AutoText.PATTERN_DATE_TIME_ONLY ==  pattern)
       dateFormatter = DateFormat.getTimeInstance(DateFormat.DEFAULT,locale);
    else
      dateFormatter = DateFormat.getDateTimeInstance(DateFormat.DEFAULT,DateFormat.DEFAULT,locale);
    JRDesignExpression expression = new JRDesignExpression();
    String text = before + "+\" \" + \"" + dateFormatter.format(new Date()) + "\" +\" \" + " + after;
//    expression.setText( "\"" + before + "\" + " + "\"" + new Date() + "\" + \"" + after + "\"");
    expression.setText( text );
    expression.setValueClass(String.class);
    return expression;
  }
View Full Code Here

   */
  public static void addMessage(int yOffset, JasperDesign design, DynamicReport report, JRDesignBand band, AutoText autoText) {
    int height = autoText.getHeight().intValue();

    JRDesignTextField textfield = new JRDesignTextField();
    JRDesignExpression expression = new JRDesignExpression();
    expression.setValueClass(String.class);
    expression.setText( "\"" + autoText.getMessageKey() + "\"");
    textfield.setExpression(expression);
    textfield.setHeight(autoText.getHeight().intValue());
    textfield.setStyledText(true);
    if (AutoText.WIDTH_NOT_SET.equals(autoText.getWidth())){
      textfield.setWidth(report.getOptions().getPrintableWidth());
View Full Code Here

      return;
    JRDesignBand band = new JRDesignBand();
    getDesign().setNoData(band);

    JRDesignTextField text = new JRDesignTextField();
    JRDesignExpression expression = ExpressionUtils.createStringExpression("\""+whenNoDataText+"\"");
    text.setExpression(expression);

    if (style == null){
      style = getReport().getOptions().getDefaultDetailStyle();
    }
View Full Code Here

       * Barcode column
       */
      if (column instanceof BarCodeColumn) {
        BarCodeColumn barcodeColumn = (BarCodeColumn)column;
        JRDesignImage image = new JRDesignImage(new JRDesignStyle().getDefaultStyleProvider());
        JRDesignExpression imageExp = new JRDesignExpression();
//        imageExp.setText("ar.com.fdvs.dj.core.BarcodeHelper.getBarcodeImage("+barcodeColumn.getBarcodeType() + ", "+ column.getTextForExpression()+ ", "+ barcodeColumn.isShowText() + ", " + barcodeColumn.isCheckSum() + ", " + barcodeColumn.getApplicationIdentifier() + ","+ column.getWidth() +", "+ report.getOptions().getDetailHeight().intValue() + " )" );

        //Do not pass column height and width mecause barbecue
        //generates the image with wierd dimensions. Pass 0 in both cases
        String applicationIdentifier = barcodeColumn.getApplicationIdentifier();
        if (applicationIdentifier != null && !"".equals(applicationIdentifier.trim()) ){
          applicationIdentifier = "$F{" + applicationIdentifier + "}";
        } else {
          applicationIdentifier = "\"\"";
        }
        imageExp.setText("ar.com.fdvs.dj.core.BarcodeHelper.getBarcodeImage("+barcodeColumn.getBarcodeType() + ", "+ column.getTextForExpression()+ ", "+ barcodeColumn.isShowText() + ", " + barcodeColumn.isCheckSum() + ", " + applicationIdentifier + ",0,0 )" );


        imageExp.setValueClass(java.awt.Image.class);
        image.setExpression(imageExp);
        image.setHeight(getReport().getOptions().getDetailHeight().intValue());
        image.setWidth(column.getWidth().intValue());
        image.setX(column.getPosX().intValue());
        image.setScaleImage(barcodeColumn.getScaleMode().getValue());

        image.setOnErrorType(JRDesignImage.ON_ERROR_TYPE_ICON); //FIXME should we provide control of this to the user?

        applyStyleToElement(column.getStyle(), image);

        detail.addElement(image);
      }
      /**
       * Image columns
       */
      else if (column instanceof ImageColumn) {
        ImageColumn imageColumn = (ImageColumn)column;
        JRDesignImage image = new JRDesignImage(new JRDesignStyle().getDefaultStyleProvider());
        JRDesignExpression imageExp = new JRDesignExpression();
        imageExp.setText(column.getTextForExpression());

        imageExp.setValueClassName(imageColumn.getColumnProperty().getValueClassName());
        image.setExpression(imageExp);
        image.setHeight(getReport().getOptions().getDetailHeight().intValue());
        image.setWidth(column.getWidth().intValue());
        image.setX(column.getPosX().intValue());
        image.setScaleImage(imageColumn.getScaleMode().getValue());
View Full Code Here

    String variablesMap = DJDefaultScriptlet.class.getName() + ".getCurrentVariables()";   

    String evalMethodParams =  fieldsMap +", " + variablesMap + ", " + parametersMap + ", " + columExpression;

    String text = "(("+ConditionStyleExpression.class.getName()+")$P{"+condition.getName()+"})."+CustomExpression.EVAL_METHOD_NAME+"("+evalMethodParams+")";
    JRDesignExpression expression = new JRDesignExpression();
    expression.setValueClass(Boolean.class);
    expression.setText(text);
    return expression;
  }
View Full Code Here

      AbstractColumn col = (AbstractColumn) iter.next();
      if (col.getTitle() == null)
        continue;

      JRDesignExpression expression = new JRDesignExpression();
      JRDesignTextField textField = new JRDesignTextField();
      expression.setText("\""+ col.getTitle() + "\"");

      expression.setValueClass(String.class);

      textField.setKey("header_"+col.getTitle());
      textField.setExpression(expression);

      textField.setX(col.getPosX().intValue());
View Full Code Here

   * @param DJGroup group
   * @return JRDesignTextField
   */
  protected JRDesignTextField generateTextFieldFromColumn(AbstractColumn col, int height, DJGroup group) {
    JRDesignTextField textField = new JRDesignTextField();
    JRDesignExpression exp = new JRDesignExpression();

    if (col.getPattern() != null && "".equals(col.getPattern().trim())) {
      textField.setPattern(col.getPattern());
        }

    exp.setText(col.getTextForExpression());
    exp.setValueClassName(col.getValueClassNameForExpression());
    textField.setExpression(exp);
    textField.setWidth(col.getWidth().intValue());
    textField.setX(col.getPosX().intValue());
    textField.setY(col.getPosY().intValue());
    textField.setHeight(height);

    textField.setBlankWhenNull(col.getBlankWhenNull());

    textField.setPattern(col.getPattern());

    textField.setPrintRepeatedValues(col.getPrintRepeatedValues().booleanValue());

        textField.setPrintWhenDetailOverflows(true);

        Style columnStyle = col.getStyle();
        if (columnStyle == null)
          columnStyle = report.getOptions().getDefaultDetailStyle();

        applyStyleToElement(columnStyle, textField);
        JRDesignStyle jrstyle = (JRDesignStyle) textField.getStyle();

        if (group != null) {
          int index = getReport().getColumnsGroups().indexOf(group);
//            JRDesignGroup previousGroup = (JRDesignGroup) getDesign().getGroupsList().get(index);
            JRDesignGroup previousGroup = getJRGroupFromDJGroup(group);
            textField.setPrintWhenGroupChanges(previousGroup);

            /**
             * Since a group column can share the style with non group columns, if oddRow coloring is enabled,
             * we modified this shared style to have a colored background on odd rows. We dont want that for group
             * columns, that's why we create our own style from the existing one, and remove proper odd-row conditional
             * style if present
             */
            JRDesignStyle groupStyle = new JRDesignStyle();
            try {
              if (jrstyle != null)
                BeanUtils.copyProperties(groupStyle, jrstyle);
      } catch (Exception e) {
        throw new DJException("Could not copy properties for shared group style: " + e.getMessage(),e);
      }

      groupStyle.setName(groupStyle.getFontName() +"_for_group_"+index);
      textField.setStyle(groupStyle);
      try {
        design.addStyle(groupStyle);
      } catch (JRException e) { /**e.printStackTrace(); //Already there, nothing to do **/}

        } else {
          if (getReport().getOptions().isPrintBackgroundOnOddRows() &&
              (jrstyle.getConditionalStyles() == null || jrstyle.getConditionalStyles().length == 0)) {
            // No group column so this is a detail text field
          JRDesignExpression expression = new JRDesignExpression();
          expression.setValueClass(Boolean.class);
          expression.setText(EXPRESSION_TRUE_WHEN_ODD);

          Style oddRowBackgroundStyle = getReport().getOptions().getOddRowBackgroundStyle();

          JRDesignConditionalStyle condStyle = new JRDesignConditionalStyle();
          condStyle.setBackcolor(oddRowBackgroundStyle.getBackgroundColor());
View Full Code Here

      try { clazz = Class.forName(col.getValueClassNameForExpression());
      } catch (ClassNotFoundException e) {
        throw new DJException("Exeption creating chart variable: " + e.getMessage(),e);
      }

      JRDesignExpression expression = new JRDesignExpression();
      //FIXME Only PropertyColumn allowed?
      expression.setText("$F{" + ((PropertyColumn) col).getColumnProperty().getProperty()  + "}");
      expression.setValueClass(clazz);

      JRDesignVariable var = new JRDesignVariable();
      var.setValueClass(clazz);
      var.setExpression(expression);
      var.setCalculation(chart.getOperation());
View Full Code Here

   * - Use a property of the current row.
   * @param sr
   * @return
   */
  public static JRDesignExpression getParameterExpression(Subreport sr) {
    JRDesignExpression exp = new JRDesignExpression();
    exp.setValueClassName(java.util.Map.class.getName());
    if (sr.isUseParentReportParameters()){
      exp.setText(REPORT_PARAMETERS_MAP);
      return exp;
    }

    if (sr.getParametersExpression() == null)
      return null;

    if (sr.getParametersMapOrigin() == DJConstants.SUBREPORT_PARAMETER_MAP_ORIGIN_PARAMETER){
      exp.setText(REPORT_PARAMETERS_MAP + ".get( \""+ sr.getParametersExpression() +"\" )");
      return exp;
    }

    if (sr.getParametersMapOrigin() == DJConstants.SUBREPORT_PARAMETER_MAP_ORIGIN_FIELD){
      exp.setText("$F{"+ sr.getParametersExpression() +"}");
      return exp;
    }

    return null;
  }
View Full Code Here

TOP

Related Classes of net.sf.jasperreports.engine.design.JRDesignExpression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.