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