View Javadoc

1   /*
2    * DynamicJasper: A library for creating reports dynamically by specifying
3    * columns, groups, styles, etc. at runtime. It also saves a lot of development
4    * time in many cases! (http://sourceforge.net/projects/dynamicjasper)
5    *
6    * Copyright (C) 2008  FDV Solutions (http://www.fdvsolutions.com)
7    *
8    * This library is free software; you can redistribute it and/or
9    * modify it under the terms of the GNU Lesser General Public
10   *
11   * License as published by the Free Software Foundation; either
12   *
13   * version 2.1 of the License, or (at your option) any later version.
14   *
15   * This library is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   *
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19   *
20   * Lesser General Public License for more details.
21   *
22   * You should have received a copy of the GNU Lesser General Public
23   * License along with this library; if not, write to the Free Software
24   *
25   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
26   *
27   *
28   */
29  
30  package ar.com.fdvs.dj.test;
31  
32  
33  import java.util.Collections;
34  import java.util.Date;
35  
36  import net.sf.jasperreports.engine.JRDataSource;
37  import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
38  import net.sf.jasperreports.view.JasperDesignViewer;
39  import net.sf.jasperreports.view.JasperViewer;
40  import ar.com.fdvs.dj.domain.AutoText;
41  import ar.com.fdvs.dj.domain.DynamicReport;
42  import ar.com.fdvs.dj.domain.ImageBanner;
43  import ar.com.fdvs.dj.domain.Style;
44  import ar.com.fdvs.dj.domain.builders.FastReportBuilder;
45  import ar.com.fdvs.dj.domain.builders.StyleBuilder;
46  import ar.com.fdvs.dj.domain.constants.Font;
47  import ar.com.fdvs.dj.domain.constants.HorizontalAlign;
48  import ar.com.fdvs.dj.domain.constants.ImageScaleMode;
49  
50  public class WhenNoDataTest extends BaseDjReportTest {
51  
52  	public DynamicReport buildReport() throws Exception {
53  
54  
55  		/**
56  		 * Creates the DynamicReportBuilder and sets the basic options for
57  		 * the report
58  		 */
59  		FastReportBuilder drb = new FastReportBuilder();
60  		Style noDataStyle = new StyleBuilder(false)
61  								.setFont(Font.ARIAL_MEDIUM_BOLD)
62  								.setHorizontalAlign(HorizontalAlign.CENTER).build();
63  		drb.addColumn("State", "state", String.class.getName(),30)
64  //			.addColumn("Branch", "branch", String.class.getName(),30)
65  //			.addColumn("Product Line", "productLine", String.class.getName(),50)
66  //			.addColumn("Item", "item", String.class.getName(),50)
67  //			.addColumn("Item Code", "id", Long.class.getName(),30,true)
68  //			.addColumn("Quantity", "quantity", Long.class.getName(),60,true)
69  //			.addColumn("Amount", "amount", Float.class.getName(),70,true)
70  //			.addGroups(2)
71  			.addAutoText(AutoText.AUTOTEXT_PAGE_X,AutoText.POSITION_HEADER,AutoText.ALIGNMENT_LEFT)
72  			.setTitle("November " + getYear() +" sales report")
73  			.setSubtitle("This report was generated at " + new Date())
74  //			.setWhenNoData("No data for this report", noDataStyle)
75  //			.setWhenNoData("No data for this report", noDataStyle,true,false)
76  			.setWhenNoData("No data for this report", null,true,true)
77  			.setUseFullPageWidth(true)
78  //			.addFirstPageImageBanner(System.getProperty("user.dir") +"/target/test-classes/images/logo_fdv_solutions_60.jpg", new Integer(197), new Integer(60), ImageBanner.ALIGN_LEFT)
79  //			.addFirstPageImageBanner(System.getProperty("user.dir") +"/target/test-classes/images/dynamicJasper_60.jpg", new Integer(300), new Integer(60), ImageBanner.ALIGN_RIGHT)
80  			.addImageBanner(System.getProperty("user.dir") +"/target/test-classes/images/logo_fdv_solutions_60.jpg", new Integer(100), new Integer(25), ImageBanner.ALIGN_LEFT, ImageScaleMode.FILL)
81  			.addImageBanner(System.getProperty("user.dir") +"/target/test-classes/images/dynamicJasper_60.jpg", new Integer(150), new Integer(25), ImageBanner.ALIGN_RIGHT, ImageScaleMode.FILL);
82  			
83  		
84  		drb.setTemplateFile("templates/TemplateReportTest.jrxml");
85  
86  		DynamicReport dr = drb.build();
87  
88  		return dr;
89  	}
90  
91  	public static void main(String[] args) throws Exception {
92  		WhenNoDataTest test = new WhenNoDataTest();
93  		test.testReport();
94  		JasperViewer.viewReport(test.jp);	//finally display the report report
95  		JasperDesignViewer.viewReportDesign(test.jr);
96  	}
97  
98  	protected JRDataSource getDataSource() {
99  		return new JRBeanCollectionDataSource(Collections.EMPTY_LIST);
100 	}
101 
102 }
103