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  import java.awt.Color;
33  
34  import net.sf.jasperreports.view.JasperViewer;
35  import ar.com.fdvs.dj.domain.DynamicReport;
36  import ar.com.fdvs.dj.domain.Style;
37  import ar.com.fdvs.dj.domain.builders.ColumnBuilder;
38  import ar.com.fdvs.dj.domain.builders.DynamicReportBuilder;
39  import ar.com.fdvs.dj.domain.constants.Border;
40  import ar.com.fdvs.dj.domain.constants.Font;
41  import ar.com.fdvs.dj.domain.constants.HorizontalAlign;
42  import ar.com.fdvs.dj.domain.constants.Transparency;
43  import ar.com.fdvs.dj.domain.constants.VerticalAlign;
44  import ar.com.fdvs.dj.domain.entities.columns.AbstractColumn;
45  import ar.com.fdvs.dj.util.customexpression.RecordsInPageCustomExpression;
46  
47  public class LineNumberReportTest extends BaseDjReportTest {
48  
49  	public DynamicReport buildReport() throws Exception {
50  
51  		Style detailStyle = new Style();
52  		Style headerStyle = new Style();
53  		headerStyle.setFont(Font.ARIAL_MEDIUM_BOLD); headerStyle.setBorder(Border.PEN_2_POINT());
54  		headerStyle.setHorizontalAlign(HorizontalAlign.CENTER); headerStyle.setVerticalAlign(VerticalAlign.MIDDLE);
55  
56  		Style titleStyle = new Style();
57  		titleStyle.setFont(new Font(18,Font._FONT_VERDANA,true));
58  		Style amountStyle = new Style();
59  		amountStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
60  		Style oddRowStyle = new Style();
61  		oddRowStyle.setBorder(Border.NO_BORDER());
62  		Color veryLightGrey = new Color(230,230,230);
63  		oddRowStyle.setBackgroundColor(veryLightGrey);oddRowStyle.setTransparency(Transparency.OPAQUE);
64  
65  		DynamicReportBuilder drb = new DynamicReportBuilder();
66  		Integer margin = new Integer(20);
67  		drb
68  			.setTitle("November " + getYear() +" sales report")					//defines the title of the report
69  			.setSubtitle("The items in this report correspond "
70  					+"to the main products: DVDs, Books, Foods and Magazines")
71  					.setTitleStyle(titleStyle).setTitleHeight(new Integer(30))
72  			.setSubtitleHeight(new Integer(20))
73  			.setDetailHeight(new Integer(15))
74  			.setLeftMargin(margin)
75  			.setRightMargin(margin)
76  			.setTopMargin(margin)
77  			.setBottomMargin(margin)
78  			.setPrintBackgroundOnOddRows(true)
79  			.setOddRowBackgroundStyle(oddRowStyle);
80  
81  		AbstractColumn columnState = ColumnBuilder.getNew().setColumnProperty("state", String.class.getName())
82  			.setTitle("State").setWidth(new Integer(85))
83  			.setStyle(detailStyle).setHeaderStyle(headerStyle).build();
84  
85  		AbstractColumn columnaItem = ColumnBuilder.getNew().setColumnProperty("item", String.class.getName())
86  			.setTitle("item").setWidth(new Integer(85))
87  			.setStyle(detailStyle).setHeaderStyle(headerStyle).build();
88  
89  		AbstractColumn columnCode = ColumnBuilder.getNew().setColumnProperty("id", Long.class.getName())
90  			.setTitle("ID").setWidth(new Integer(40))
91  			.setStyle(amountStyle).setHeaderStyle(headerStyle).build();
92  
93  		AbstractColumn columnaCantidad = ColumnBuilder.getNew().setColumnProperty("quantity", Long.class.getName())
94  			.setTitle("Quantity").setWidth(new Integer(80))
95  			.setStyle(amountStyle).setHeaderStyle(headerStyle).build();
96  
97  		AbstractColumn columnAmount = ColumnBuilder.getNew().setColumnProperty("amount", Float.class.getName())
98  			.setTitle("Amount").setWidth(new Integer(90)).setPattern("$ 0.00")
99  			.setStyle(amountStyle).setHeaderStyle(headerStyle).build();
100 
101 		AbstractColumn columnaCustomExpression = ColumnBuilder.getNew()
102 		.setCustomExpression(new RecordsInPageCustomExpression())
103 		.setTitle("No.").setWidth(new Integer(25))
104 		.setStyle(detailStyle).setHeaderStyle(headerStyle).build();
105 
106 		drb.addColumn(columnaCustomExpression);
107 		drb.addColumn(columnState);
108 		drb.addColumn(columnaItem);
109 		drb.addColumn(columnCode);
110 		drb.addColumn(columnaCantidad);
111 		drb.addColumn(columnAmount);
112 
113 		drb.setUseFullPageWidth(true);
114 
115 		drb.addField("productLine", String.class.getName());
116 		drb.addField("branch", String.class.getName());
117 
118 		DynamicReport dr = drb.build();
119 		return dr;
120 	}
121 
122 
123 	public static void main(String[] args) throws Exception {
124 		LineNumberReportTest test = new LineNumberReportTest();
125 		test.testReport();
126 		JasperViewer.viewReport(test.jp);
127 	}
128 
129 }