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  
46  public class StylesReportTest extends BaseDjReportTest {
47  
48  	public DynamicReport buildReport() throws Exception {
49  
50  		Style detailStyle = new Style();
51  		Style headerStyle = new Style();
52  		headerStyle.setFont(Font.ARIAL_MEDIUM_BOLD);
53  		headerStyle.setBorderTop(Border.PEN_2_POINT);
54  		headerStyle.setBorderBottom(Border.THIN);
55  		headerStyle.setBackgroundColor(Color.blue);
56  		headerStyle.setTransparency(Transparency.OPAQUE);
57  		headerStyle.setTextColor(Color.white);
58  		headerStyle.setHorizontalAlign(HorizontalAlign.CENTER);
59  		headerStyle.setVerticalAlign(VerticalAlign.MIDDLE);
60  
61  		Style titleStyle = new Style();
62  		titleStyle.setFont(new Font(18,Font._FONT_VERDANA,true));
63  		Style numberStyle = new Style();
64  		numberStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
65  		Style amountStyle = new Style();
66  		amountStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
67  		amountStyle.setBackgroundColor(Color.cyan);
68  		amountStyle.setTransparency(Transparency.OPAQUE);
69  		Style oddRowStyle = new Style();
70  		oddRowStyle.setBorder(Border.THIN);
71  		Color veryLightGrey = new Color(230,230,230);
72  		Color veryLightBlue = new Color(210,210,250);
73  		oddRowStyle.setBorderColor(veryLightBlue);
74  		oddRowStyle.setBackgroundColor(veryLightGrey);oddRowStyle.setTransparency(Transparency.OPAQUE);
75  
76  		DynamicReportBuilder drb = new DynamicReportBuilder();
77  		Integer margin = new Integer(20);
78  		drb.setTitle("November 2006 sales report")					//defines the title of the report
79  			.setSubtitle("The items in this report correspond "
80  					+"to the main products: DVDs, Books, Foods and Magazines")
81  			.setTitleStyle(titleStyle).setTitleHeight(new Integer(30))
82  			.setSubtitleHeight(new Integer(20))
83  			.setDetailHeight(new Integer(15))
84  			.setLeftMargin(margin)
85  			.setRightMargin(margin)
86  			.setTopMargin(margin)
87  			.setBottomMargin(margin)
88  			.setPrintBackgroundOnOddRows(true)
89  			.setOddRowBackgroundStyle(oddRowStyle)
90  			.setColumnsPerPage(new Integer(1))
91  			.setColumnSpace(new Integer(5));
92  
93  		AbstractColumn columnState = ColumnBuilder.getNew().setColumnProperty("state", String.class.getName())
94  			.setTitle("State").setWidth(new Integer(85))
95  			.setStyle(detailStyle).setHeaderStyle(headerStyle).build();
96  
97  		AbstractColumn columnBranch = ColumnBuilder.getNew().setColumnProperty("branch", String.class.getName())
98  			.setTitle("Branch").setWidth(new Integer(85))
99  			.setStyle(detailStyle).setHeaderStyle(headerStyle).build();
100 
101 		AbstractColumn columnaProductLine = ColumnBuilder.getNew().setColumnProperty("productLine", String.class.getName())
102 			.setTitle("Product Line").setWidth(new Integer(85))
103 			.setStyle(detailStyle).setHeaderStyle(headerStyle).build();
104 
105 		AbstractColumn columnaItem = ColumnBuilder.getNew().setColumnProperty("item", String.class.getName())
106 			.setTitle("item").setWidth(new Integer(85))
107 			.setStyle(detailStyle).setHeaderStyle(headerStyle).build();
108 
109 		AbstractColumn columnCode = ColumnBuilder.getNew().setColumnProperty("id", Long.class.getName())
110 			.setTitle("ID").setWidth(new Integer(40))
111 			.setStyle(numberStyle).setHeaderStyle(headerStyle).build();
112 
113 		AbstractColumn columnaCantidad = ColumnBuilder.getNew().setColumnProperty("quantity", Long.class.getName())
114 			.setTitle("Quantity").setWidth(new Integer(80))
115 			.setStyle(numberStyle).setHeaderStyle(headerStyle).build();
116 
117 		AbstractColumn columnAmount = ColumnBuilder.getNew().setColumnProperty("amount", Float.class.getName())
118 			.setTitle("Amount").setWidth(new Integer(90)).setPattern("$ 0.00")
119 			.setStyle(amountStyle).setHeaderStyle(headerStyle).build();
120 
121 		drb.addColumn(columnState);
122 		drb.addColumn(columnBranch);
123 		drb.addColumn(columnaProductLine);
124 		drb.addColumn(columnaItem);
125 		drb.addColumn(columnCode);
126 		drb.addColumn(columnaCantidad);
127 		drb.addColumn(columnAmount);
128 
129 		drb.setUseFullPageWidth(true);
130 
131 		DynamicReport dr = drb.build();
132 		return dr;
133 	}
134 
135 	public static void main(String[] args) throws Exception {
136 		StylesReportTest test = new StylesReportTest();
137 		test.testReport();
138 		JasperViewer.viewReport(test.jp);
139 	}
140 
141 }