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.builders.GroupBuilder;
40  import ar.com.fdvs.dj.domain.constants.Font;
41  import ar.com.fdvs.dj.domain.constants.GroupLayout;
42  import ar.com.fdvs.dj.domain.constants.HorizontalAlign;
43  import ar.com.fdvs.dj.domain.entities.DJGroup;
44  import ar.com.fdvs.dj.domain.entities.columns.AbstractColumn;
45  import ar.com.fdvs.dj.domain.entities.columns.PropertyColumn;
46  
47  /**
48   * This test aims to generate a report with almost no styles, ensuring that there are no errors
49   * as result of the lack of style or fonts.
50   * 
51   * See bug 2817859 at SF
52   * 
53   * @author mamana
54   *
55   */
56  public class StylesReportTest4 extends BaseDjReportTest {
57  
58  	public DynamicReport buildReport() throws Exception {
59  		
60  		DynamicReportBuilder drb = new DynamicReportBuilder();
61  		Integer margin = new Integer(20);
62  		drb.setTitle("November " + getYear() +" sales report")					//defines the title of the report
63  			.setSubtitle("The items in this report correspond "
64  					+"to the main products: DVDs, Books, Foods and Magazines")
65  			.setTitleHeight(new Integer(30))
66  			.setSubtitleHeight(new Integer(20))
67  			.setDetailHeight(new Integer(15))
68  			.setLeftMargin(margin)
69  			.setRightMargin(margin)
70  			.setTopMargin(margin)
71  			.setBottomMargin(margin)
72  			.setColumnsPerPage(new Integer(1))
73  			.setColumnSpace(new Integer(5));
74  
75  		Style style1 = new Style("style1");
76  		style1.setFont(Font.ARIAL_MEDIUM_BOLD);
77  		style1.setHorizontalAlign(HorizontalAlign.CENTER);
78  		drb.addStyle(style1);
79  
80  		Style style2 = Style.createBlankStyle("style2", "style1");
81  		style2.setTextColor(Color.BLUE);
82  		drb.addStyle(style2);
83  		
84  		AbstractColumn columnState = ColumnBuilder.getNew().setColumnProperty("state", String.class.getName())
85  			.setTitle("State").setWidth(new Integer(85))
86  			.setStyle(style1).build();
87  
88  		AbstractColumn columnBranch = ColumnBuilder.getNew().setColumnProperty("branch", String.class.getName())
89  			.setTitle("Branch").setWidth(new Integer(85))
90  			.setStyle(style2).build();
91  
92  		drb.addColumn(columnBranch);
93  		drb.addColumn(columnState);		
94  
95  		DJGroup g1 = new GroupBuilder()
96  		.setCriteriaColumn((PropertyColumn) columnBranch)
97  
98  		.setGroupLayout(GroupLayout.VALUE_IN_HEADER_WITH_HEADERS_AND_COLUMN_NAME)
99  		.build();
100 		drb.addGroup(g1);
101 		
102 		drb.setUseFullPageWidth(true);
103 
104 		DynamicReport dr = drb.build();
105 		return dr;
106 	}
107 
108 	public static void main(String[] args) throws Exception {
109 		StylesReportTest4 test = new StylesReportTest4();
110 		test.testReport();
111 		JasperViewer.viewReport(test.jp);
112 	}
113 
114 }