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  import java.util.Date;
34  import java.util.HashMap;
35  import java.util.Locale;
36  
37  import net.sf.jasperreports.view.JasperDesignViewer;
38  import net.sf.jasperreports.view.JasperViewer;
39  import ar.com.fdvs.dj.core.DynamicJasperHelper;
40  import ar.com.fdvs.dj.core.layout.HorizontalBandAlignment;
41  import ar.com.fdvs.dj.domain.AutoText;
42  import ar.com.fdvs.dj.domain.DynamicReport;
43  import ar.com.fdvs.dj.domain.ExpressionHelper;
44  import ar.com.fdvs.dj.domain.Style;
45  import ar.com.fdvs.dj.domain.builders.FastReportBuilder;
46  import ar.com.fdvs.dj.domain.builders.StyleBuilder;
47  import ar.com.fdvs.dj.domain.constants.Font;
48  
49  public class AutotextReportTest2 extends BaseDjReportTest {
50  
51  	public DynamicReport buildReport() throws Exception {
52  
53  		FastReportBuilder drb = new FastReportBuilder();
54  		drb.addColumn("State", "state", String.class.getName(),30)
55  			.addColumn("Branch", "branch", String.class.getName(),30)
56  			.addColumn("Product Line", "productLine", String.class.getName(),50)
57  			.addColumn("Item", "item", String.class.getName(),50)
58  			.addColumn("Item Code", "id", Long.class.getName(),30,true)
59  			.addColumn("Quantity", "quantity", Long.class.getName(),60,true)
60  			.addColumn("Amount", "amount", Float.class.getName(),70,true)
61  			.addGroups(2)
62  			.setTitle("November " + getYear() +" sales report")
63  			.setSubtitle("This report was generated at " + new Date())
64  			.setUseFullPageWidth(true);
65  
66  
67  		Style atStyle = new StyleBuilder(true).setFont(Font.COMIC_SANS_SMALL).setTextColor(Color.red).build();
68  		/**
69  		 * Adding many autotexts in the same position (header/footer and aligment) makes them to be one on top of the other
70  		 */		
71  		AutoText autoText = new AutoText(AutoText.AUTOTEXT_CREATED_ON, AutoText.POSITION_HEADER, HorizontalBandAlignment.CENTER);
72  		autoText.setWidth(new Integer(200));
73  		autoText.setStyle(atStyle);
74  		autoText.setPrintWhenExpression(ExpressionHelper.printInFirstPage());
75  		drb.addAutoText(autoText);
76  		
77  		DynamicReport dr = drb.build();
78  
79  		//i18N, you can set a Locale, different than the default in the VM
80  		drb.setReportLocale(new Locale("es","AR"));
81  //		drb.setReportLocale(new Locale("pt","BR"));
82  //		drb.setReportLocale(new Locale("fr","FR"));
83  
84  		return dr;
85  	}
86  
87  	public static void main(String[] args) throws Exception {
88  		AutotextReportTest2 test = new AutotextReportTest2();
89  		test.testReport();
90  		JasperViewer.viewReport(test.jp);
91  		JasperDesignViewer.viewReportDesign(DynamicJasperHelper.generateJasperReport(test.dr, test.getLayoutManager(),new HashMap()));
92  	}
93  
94  }