Package net.sf.jasperreports.engine.design

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


    expression = new JRDesignExpression();
    expression.setValueClass(java.lang.String.class);
    expression.setText("$F{City}");
    group.setExpression(expression);

    JRDesignBand band = new JRDesignBand();
    band.setHeight(20);
    JRDesignTextField textField = new JRDesignTextField();
    textField.setX(0);
    textField.setY(4);
    textField.setWidth(515);
    textField.setHeight(15);
    textField.setBackcolor(new Color(0xC0, 0xC0, 0xC0));
    textField.setMode(ModeEnum.OPAQUE);
    textField.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
    textField.setStyle(boldStyle);
    expression = new JRDesignExpression();
    expression.setValueClass(java.lang.String.class);
    expression.setText("\"  \" + String.valueOf($V{CityNumber}) + \". \" + String.valueOf($F{City})");
    textField.setExpression(expression);
    band.addElement(textField);
    JRDesignLine line = new JRDesignLine();
    line.setX(0);
    line.setY(19);
    line.setWidth(515);
    line.setHeight(0);
    band.addElement(line);
    ((JRDesignSection)group.getGroupHeaderSection()).addBand(band);

    band = new JRDesignBand();
    band.setHeight(20);
    line = new JRDesignLine();
    line.setX(0);
    line.setY(-1);
    line.setWidth(515);
    line.setHeight(0);
    band.addElement(line);
    JRDesignStaticText staticText = new JRDesignStaticText();
    staticText.setX(400);
    staticText.setY(0);
    staticText.setWidth(60);
    staticText.setHeight(15);
    staticText.setHorizontalAlignment(HorizontalAlignEnum.RIGHT);
    staticText.setStyle(boldStyle);
    staticText.setText("Count : ");
    band.addElement(staticText);
    textField = new JRDesignTextField();
    textField.setX(460);
    textField.setY(0);
    textField.setWidth(30);
    textField.setHeight(15);
    textField.setHorizontalAlignment(HorizontalAlignEnum.RIGHT);
    textField.setStyle(boldStyle);
    expression = new JRDesignExpression();
    expression.setValueClass(java.lang.Integer.class);
    expression.setText("$V{CityGroup_COUNT}");
    textField.setExpression(expression);
    band.addElement(textField);
    ((JRDesignSection)group.getGroupFooterSection()).addBand(band);

    jasperDesign.addGroup(group);

    //Title
    band = new JRDesignBand();
    band.setHeight(50);
    line = new JRDesignLine();
    line.setX(0);
    line.setY(0);
    line.setWidth(515);
    line.setHeight(0);
    band.addElement(line);
    textField = new JRDesignTextField();
    textField.setBlankWhenNull(true);
    textField.setX(0);
    textField.setY(10);
    textField.setWidth(515);
    textField.setHeight(30);
    textField.setHorizontalAlignment(HorizontalAlignEnum.CENTER);
    textField.setStyle(normalStyle);
    textField.setFontSize(22);
    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);
    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 = new JRDesignStaticText();
    staticText.setX(0);
    staticText.setY(0);
    staticText.setWidth(55);
    staticText.setHeight(15);
    staticText.setForecolor(Color.white);
    staticText.setBackcolor(new Color(0x33, 0x33, 0x33));
    staticText.setMode(ModeEnum.OPAQUE);
    staticText.setHorizontalAlignment(HorizontalAlignEnum.CENTER);
    staticText.setStyle(boldStyle);
    staticText.setText("ID");
    frame.addElement(staticText);
    staticText = new JRDesignStaticText();
    staticText.setX(55);
    staticText.setY(0);
    staticText.setWidth(205);
    staticText.setHeight(15);
    staticText.setForecolor(Color.white);
    staticText.setBackcolor(new Color(0x33, 0x33, 0x33));
    staticText.setMode(ModeEnum.OPAQUE);
    staticText.setStyle(boldStyle);
    staticText.setText("Name");
    frame.addElement(staticText);
    staticText = new JRDesignStaticText();
    staticText.setX(260);
    staticText.setY(0);
    staticText.setWidth(255);
    staticText.setHeight(15);
    staticText.setForecolor(Color.white);
    staticText.setBackcolor(new Color(0x33, 0x33, 0x33));
    staticText.setMode(ModeEnum.OPAQUE);
    staticText.setStyle(boldStyle);
    staticText.setText("Street");
    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);
    expression = new JRDesignExpression();
    expression.setValueClass(java.lang.Integer.class);
    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);
    expression = new JRDesignExpression();
    expression.setValueClass(java.lang.String.class);
    expression.setText("$F{FirstName} + \" \" + $F{LastName}");
    textField.setExpression(expression);
    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);
    expression = new JRDesignExpression();
    expression.setValueClass(java.lang.String.class);
    expression.setText("$F{Street}");
    textField.setExpression(expression);
    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;
  }
View Full Code Here


      sText.setHeight(50);
      sText.setText(jasperDesign.getName());
      sText.setFontSize(16);
      sText.setBold(true);

      JRDesignBand band = new JRDesignBand();
      band.setHeight(50);
      band.addElement(sText);

      jasperDesign.setTitle(band);
   
      // add page footer for page numbers
      band = new JRDesignBand();
      band.setHeight(15);

      sText = new JRDesignStaticText();
      sText.setX(0);
      sText.setY(0);
      sText.setHeight(15);
      sText.setWidth(40);
      sText.setText("Page:");

      band.addElement(sText);

      JRDesignExpression exp = new JRDesignExpression();
      exp.addVariableChunk("PAGE_NUMBER");
      exp.setValueClass(Integer.class);

      JRDesignTextField txt = new JRDesignTextField();
      txt.setExpression(exp);
      txt.setX(40);
      txt.setY(0);
      txt.setHeight(15);
      txt.setWidth(100);

      band.addElement(txt);

      jasperDesign.setPageFooter(band);
    }

    JRDesignBand emptyBand = new JRDesignBand();
    emptyBand.setHeight(0);
    jasperDesign.setPageHeader(emptyBand);
    jasperDesign.setColumnFooter(emptyBand);
    jasperDesign.setSummary(emptyBand);

    JRField[] fields = jasperDesign.getFields();

    // add column header and detail bands
    JRDesignBand bandDetail = new JRDesignBand();
    bandDetail.setHeight(20);

    JRDesignBand bandHeader = new JRDesignBand();
    bandHeader.setHeight(20);
   
    int fieldWidth = (jasperDesign.getPageWidth() - jasperDesign.getLeftMargin()
        - jasperDesign.getRightMargin() - (fields.length - 1) * jasperDesign.getColumnSpacing())
        / fields.length; 

    for (int i = 0; i < fields.length; i++)
    {
      try
      {
        JRField field = fields[i];

        JRDesignExpression exp = new JRDesignExpression();
        exp.addFieldChunk(field.getName());
       
        if (field.getValueClassName().equals("java.sql.Date"))
        {
          // JasperReports does not support java.sql.Date in text field expression
          exp.setValueClass(java.util.Date.class);
        }
        else
        {
          exp.setValueClass(field.getValueClass());
        }

        JRDesignTextField txt = new JRDesignTextField();
        txt.setExpression(exp);
        txt.setX(i * fieldWidth);
        txt.setY(0);
        txt.setHeight(20);
        txt.setWidth(fieldWidth);

        if (field.getValueClass().equals(Double.class))
        {
          txt.setPattern("0.00");
        }

        bandDetail.addElement(txt);

        JRDesignStaticText sText = new JRDesignStaticText();
        sText.setX(i * fieldWidth);
        sText.setY(0);
        sText.setHeight(20);
        sText.setWidth(fieldWidth);
        sText.setText(field.getName());
        sText.setUnderline(true);

        bandHeader.addElement(sText);
      }
      catch (Exception e)
      {
        log.warn(e);
      }
View Full Code Here

      throw new NullJasperDesignException("Null JasperDesign when add text fields") ;
   
    locateTextFields( )
    //JRDesignBand jrdBand = (JRDesignBand)getDesign().getDetail(); 
       
    JRDesignBand textFieldBand = new JRDesignBand( );   
    textFieldBand.setHeight( 20 ); //^~
   
    //Title band
    JRDesignBand titleBand = new JRDesignBand( );
    titleBand.setHeight( 20 );
   
    //titleBand.setSplitAllowed(true);
   
    for( DynamicColumn item: reportParam.getDynamicColumns() ){
      if( !item.isHidden() ){
        //add text field
        JRDesignTextField textField = new JRDesignTextField();
        textField.setX( item.getX() );
        textField.setY( item.getY() );
        textField.setWidth( item.getWidth() );
        textField.setHeight( item.getHeight() );
        //textField.setPositionType(JRElement.POSITION_TYPE_FLOAT); //
        textField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_LEFT );
        //textField.setStyle( design.getDefaultStyle() );
       
        JRDesignExpression expression = new JRDesignExpression();
        expression.setValueClass( item.getClazz() );
        expression.setText( "$F{" + item.getField() +"}" );
        textField.setExpression(expression);
       
        textFieldBand.addElement( textField )
       
        //add column header
        JRDesignStaticText columnHeaderText = new JRDesignStaticText();     
        columnHeaderText.setText( item.getCaption() );
        columnHeaderText.setX( item.getX() );
        columnHeaderText.setY( 0 );
        columnHeaderText.setWidth( item.getWidth() );
        columnHeaderText.setHeight( 20 );//~^
        columnHeaderText.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_LEFT );
        columnHeaderText.setStyleNameReference( CAPTION_STYLE_NAME );
        titleBand.addElement( columnHeaderText );
      }
    }
   
    design.setDetail( textFieldBand );
    design.setTitle( titleBand );
View Full Code Here

   * @param title
   * @throws NullJasperDesignException
   * @throws JRException
   */
  public void addTitle( String title ) throws NullJasperDesignException, JRException{
    JRDesignBand band = new JRDesignBand();
    band.setHeight(50);
   
    JRDesignStaticText staticText = new JRDesignStaticText();
    staticText.setX(10);
    staticText.setY(0);
    staticText.setWidth( design.getPageWidth() );
    staticText.setHeight(15);
    staticText.setStyleNameReference( TITLE_STYLE_NAME );

    staticText.setText( title );
    band.addElement(staticText);
   
    design.setTitle(band);
  }
View Full Code Here

      throw new NullJasperDesignException("Null JasperDesign when add text fields") ;
   
    locateTextFields( )
    //JRDesignBand jrdBand = (JRDesignBand)getDesign().getDetail(); 
       
    JRDesignBand textFieldBand = new JRDesignBand( );   
    textFieldBand.setHeight( 20 ); //^~
   
    JRDesignBand columnHeaderBand = new JRDesignBand( );
    columnHeaderBand.setHeight( 20 ); //^~
   
    for( DynamicColumn item: reportParam.getDynamicColumns() ){
      if( !item.isHidden() ){
        //add text field
        JRDesignTextField textField = new JRDesignTextField();
        textField.setX( item.getX() );
        textField.setY( item.getY() );
        textField.setWidth( item.getWidth() );
        textField.setHeight( item.getHeight() );
        //textField.setPositionType(JRElement.POSITION_TYPE_FLOAT); //
        textField.setHorizontalAlignment( HorizontalAlignEnum.LEFT );
        //textField.setStyle( design.getDefaultStyle() );
       
        JRDesignExpression expression = new JRDesignExpression();
        expression.setValueClass( item.getClazz() );
        expression.setText( "$F{" + item.getField() +"}" );
        textField.setExpression(expression)
        textField.setBlankWhenNull( true );
       
        textFieldBand.addElement( textField )
       
        //add column header
        JRDesignStaticText columnHeaderText = new JRDesignStaticText();     
        columnHeaderText.setText( item.getCaption() );
        columnHeaderText.setX( item.getX() );
        columnHeaderText.setY( 0 );
        columnHeaderText.setWidth( item.getWidth() );
        columnHeaderText.setHeight( 20 );//~^
        columnHeaderText.setHorizontalAlignment( HorizontalAlignEnum.CENTER );
        //columnHeaderText.setStyleNameReference( CAPTION_STYLE_NAME );
        columnHeaderText.setBold( true );
        columnHeaderBand.addElement( columnHeaderText );
      }
    }
   
    design.setDetail( textFieldBand );
    design.setColumnHeader( columnHeaderBand );
View Full Code Here

    design.setColumnHeader( columnHeaderBand );
  }
 
  @SuppressWarnings("deprecation")
  public void addSummary( String summary ){
    JRDesignBand band = new JRDesignBand();
    band.setHeight(50);
   
    JRDesignStaticText staticText = new JRDesignStaticText();
    staticText.setX(10);
    staticText.setY(0);
    staticText.setWidth( design.getPageWidth() );
    staticText.setHeight(15);
    staticText.setHorizontalAlignment( JRAlignment.HORIZONTAL_ALIGN_CENTER );

    staticText.setText( summary );
    band.addElement(staticText);
   
    design.setSummary( band );
  }
View Full Code Here

   * Adds title and subtitle to the TitleBand when it applies.
   * If title is not present then subtitle will be ignored
   */
  protected void generateTitleBand() {
    log.debug("Generating title band...");
    JRDesignBand band = (JRDesignBand) getDesign().getPageHeader();
    int yOffset = 0;

    //If title is not present then subtitle will be ignored
    if (getReport().getTitle() == null)
      return;

    if (band != null && !getDesign().isTitleNewPage()){
      //Title and subtitle comes afer the page header
      yOffset = band.getHeight();

    } else {
      band = (JRDesignBand) getDesign().getTitle();
      if (band == null){
        band = new JRDesignBand();
        getDesign().setTitle(band);
      }
    }

    JRDesignExpression printWhenExpression = new JRDesignExpression();
    printWhenExpression.setValueClass(Boolean.class);
    printWhenExpression.setText(EXPRESSION_TRUE_WHEN_FIRST_PAGE);

    JRDesignTextField title = new JRDesignTextField();
    JRDesignExpression exp = new JRDesignExpression();
    exp.setText("\"" + getReport().getTitle() + "\"");
    exp.setValueClass(String.class);
    title.setExpression(exp);
    title.setWidth(getReport().getOptions().getPrintableWidth());
    title.setHeight(getReport().getOptions().getTitleHeight().intValue());
    title.setY(yOffset);
    title.setPrintWhenExpression(printWhenExpression);
    title.setRemoveLineWhenBlank(true);
    applyStyleToElement(getReport().getTitleStyle(), title);
    title.setStretchType(JRGraphicElement.STRETCH_TYPE_NO_STRETCH);
    band.addElement(title);

    JRDesignTextField subtitle = new JRDesignTextField();
    if (getReport().getSubtitle() != null) {
      JRDesignExpression exp2 = new JRDesignExpression();
      exp2.setText("\"" + getReport().getSubtitle() + "\"");
      exp2.setValueClass(String.class);
      subtitle.setExpression(exp2);
      subtitle.setWidth(getReport().getOptions().getPrintableWidth());
      subtitle.setHeight(getReport().getOptions().getSubtitleHeight().intValue());
      subtitle.setY(title.getY() + title.getHeight());
      subtitle.setPrintWhenExpression(printWhenExpression);
      subtitle.setRemoveLineWhenBlank(true);
      applyStyleToElement(getReport().getSubtitleStyle(), subtitle);
      title.setStretchType(JRGraphicElement.STRETCH_TYPE_NO_STRETCH);
      band.addElement(subtitle);
    }

  }
View Full Code Here

      JRDesignGroup jgroup = getJRGroupFromDJGroup(columnsGroup);

      jgroup.setStartNewPage(columnsGroup.getStartInNewPage().booleanValue());
      jgroup.setStartNewColumn(columnsGroup.getStartInNewColumn().booleanValue());

      JRDesignBand header = (JRDesignBand) jgroup.getGroupHeader();
      JRDesignBand footer = (JRDesignBand) jgroup.getGroupFooter();
      header.setHeight(columnsGroup.getHeaderHeight().intValue());
      footer.setHeight(columnsGroup.getFooterHeight().intValue());

      header.setSplitAllowed(columnsGroup.isAllowHeaderSplit());
      footer.setSplitAllowed(columnsGroup.isAllowFooterSplit());

      if (columnsGroup.getLayout().isPrintHeaders()) {
        boolean found = false;
        boolean skipPreviousGroupHeaders = false;
        int groupIdx = getReport().getColumnsGroups().indexOf(columnsGroup);
View Full Code Here

      DJCrosstab djcross = (DJCrosstab) iterator.next();

      Dj2JrCrosstabBuilder djcb = new Dj2JrCrosstabBuilder();

      JRDesignCrosstab crosst = djcb.createCrosstab(djcross,this);
      JRDesignBand band = (JRDesignBand) jgroup.getGroupHeader();
      if (djcross.getBottomSpace() != 0){
        JRDesignRectangle rect = createBlankRectableCrosstab(djcross.getBottomSpace(), 0);
        LayoutUtils.moveBandsElemnts(rect.getHeight(), band);
        band.addElement(rect);
      }
      LayoutUtils.moveBandsElemnts(crosst.getHeight(), band);
      band.addElement(crosst);
      if (djcross.getTopSpace() != 0){
        LayoutUtils.moveBandsElemnts(djcross.getTopSpace(), band);
        JRDesignRectangle rect = createBlankRectableCrosstab(djcross.getBottomSpace(), 0);
        band.addElement(rect);
      }

    }

    for (Iterator iterator = columnsGroup.getFooterCrosstabs().iterator(); iterator.hasNext();) {
      DJCrosstab djcross = (DJCrosstab) iterator.next();

      Dj2JrCrosstabBuilder djcb = new Dj2JrCrosstabBuilder();

      JRDesignCrosstab crosst = djcb.createCrosstab(djcross,this);
      JRDesignBand band = (JRDesignBand) jgroup.getGroupFooter();
      int yOffset = LayoutUtils.findVerticalOffset(band);
      if (djcross.getTopSpace() != 0){
//        moveBandsElemnts(djcross.getTopSpace(), band);
        JRDesignRectangle rect = createBlankRectableCrosstab(djcross.getBottomSpace(), yOffset);
        rect.setPositionType(JRDesignElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);
        band.addElement(rect);
        crosst.setY(rect.getY() + rect.getHeight());
      }

      band.addElement(crosst);


      if (djcross.getBottomSpace() != 0){
        JRDesignRectangle rect = createBlankRectableCrosstab(djcross.getBottomSpace(), crosst.getY() + crosst.getHeight());
        band.addElement(rect);
      }
    }


  }
View Full Code Here

   * @param columnsGroup
   * @param jgroup
   */
  protected void layoutGroupSubreports(DJGroup columnsGroup, JRDesignGroup jgroup) {
    log.debug("Starting subreport layout...");
    JRDesignBand footerBand = (JRDesignBand) jgroup.getGroupFooter();
    JRDesignBand headerBand = (JRDesignBand) jgroup.getGroupHeader();

    layOutSubReportInBand(columnsGroup, headerBand, DJConstants.HEADER);
    layOutSubReportInBand(columnsGroup, footerBand, DJConstants.FOOTER);

  }
View Full Code Here

TOP

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

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.