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.Collection;
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.core.BarcodeTypes;
41  import ar.com.fdvs.dj.domain.DynamicReport;
42  import ar.com.fdvs.dj.domain.Style;
43  import ar.com.fdvs.dj.domain.builders.FastReportBuilder;
44  import ar.com.fdvs.dj.domain.builders.StyleBuilder;
45  import ar.com.fdvs.dj.domain.constants.Border;
46  import ar.com.fdvs.dj.domain.constants.HorizontalAlign;
47  import ar.com.fdvs.dj.domain.constants.ImageScaleMode;
48  import ar.com.fdvs.dj.domain.constants.Stretching;
49  import ar.com.fdvs.dj.test.domain.Product;
50  import ar.com.fdvs.dj.util.SortUtils;
51  
52  public class BarcodeColumnReportTest2 extends BaseDjReportTest {
53  
54  
55  	public DynamicReport buildReport() throws Exception {
56  
57  
58  		Style style = new StyleBuilder(true).setHorizontalAlign(HorizontalAlign.CENTER).build();
59  		Style defStyle = new StyleBuilder(true).
60  			setBorderBottom(Border.THIN())
61  			.setStretching(Stretching.RELATIVE_TO_TALLEST_OBJECT)
62  			.setPaddingBottom(3)
63  			.setPaddingTop(3)
64  			.build();
65  		/**
66  		 * Creates the DynamicReportBuilder and sets the basic options for
67  		 * the report
68  		 */
69  		FastReportBuilder drb = new FastReportBuilder();
70  		Style title = null;
71  		Style subtitle = null;
72  		Style columnHeader = null;
73  		drb.addColumn("State", "state", String.class.getName(),20,defStyle)
74  			.addColumn("Branch", "branch", String.class.getName(),30,defStyle)
75  			.addColumn("Quantity", "quantity", Long.class.getName(),60,defStyle,null,true)
76  			.addColumn("Amount", "amount", Float.class.getName(),70,defStyle,null,true)
77  			.addBarcodeColumn("Bar-Code", "amount", Long.class.getName(), BarcodeTypes.USD3, true, false,null, 100, true, ImageScaleMode.FILL, defStyle)
78  			.addGroups(1)
79  			.setDetailHeight(30)
80  			.addField("productLine",  String.class.getName())
81  			.setTitle("November " + getYear() +" sales report")
82  			.setSubtitle("This report was generated at " + new Date())
83  			.setDefaultStyles(title, subtitle, columnHeader, defStyle)
84  			.setUseFullPageWidth(true);
85  
86  		DynamicReport dr = drb.build();
87  
88  		return dr;
89  	}
90  	
91  	protected JRDataSource getDataSource() {
92  		Collection dummyCollection = TestRepositoryProducts.getDummyCollection();
93  		dummyCollection.add(new Product( new Long("1"),
94  				"book",
95  				"Harry Potter 7",
96  				"Florida",
97  				"Main Street, Main Street, Main Street, Main Street, Main Street, Main Street, " +
98  				"Main Street, Main Street, Main Street, Main Street, Main Street, Main Street, " +
99  				"Main Street, Main Street, Main Street, Main Street, Main Street (end)",
100 				new Long("2500"), new Float("10000")));
101 		dummyCollection = SortUtils.sortCollection(dummyCollection,dr.getColumns());
102 
103 		JRDataSource ds = new JRBeanCollectionDataSource(dummyCollection);		//Create a JRDataSource, the Collection used
104 																										//here contains dummy hardcoded objects...
105 		return ds;
106 	}	
107 
108 	public static void main(String[] args) throws Exception {
109 		BarcodeColumnReportTest2 test = new BarcodeColumnReportTest2();
110 		test.testReport();
111 		JasperViewer.viewReport(test.jp);	//finally display the report report
112 		JasperDesignViewer.viewReportDesign(test.jr);
113 	}
114 
115 }