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.watermark;
31  
32  
33  import ar.com.fdvs.dj.domain.DJCalculation;
34  import ar.com.fdvs.dj.domain.DJValueFormatter;
35  import ar.com.fdvs.dj.domain.DJWaterMark;
36  import ar.com.fdvs.dj.domain.DynamicReport;
37  import ar.com.fdvs.dj.domain.builders.FastReportBuilder;
38  import ar.com.fdvs.dj.test.BaseDjReportTest;
39  import net.sf.jasperreports.view.JasperDesignViewer;
40  import net.sf.jasperreports.view.JasperViewer;
41  
42  import java.util.Date;
43  import java.util.Map;
44  
45  public class WatermarkReportTest3 extends BaseDjReportTest {
46  
47  	public DynamicReport buildReport() throws Exception {
48  
49  
50  		/**
51  		 * Creates the DynamicReportBuilder and sets the basic options for
52  		 * the report
53  		 */
54  		FastReportBuilder drb = new FastReportBuilder();
55  		drb.addColumn("State", "state", String.class.getName(),30)
56  			.addColumn("Branch", "branch", String.class.getName(),30)
57  			.addColumn("Product Line", "productLine", String.class.getName(),50)
58  			.addColumn("Item", "item", String.class.getName(),50)
59  			.addColumn("Item Code", "id", Long.class.getName(),30,true)
60  			.addColumn("Quantity", "quantity", Long.class.getName(),60,true)
61  			.addColumn("Amount", "amount", Float.class.getName(),70,true)
62  			.addGroups(2)
63  			.setTitle("November " + getYear() + " sales report")
64  			.setSubtitle("This report was generated at " + new Date())
65  			.addWatermark(new DJWaterMark("DRAFT"))
66  			.setUseFullPageWidth(true);
67  
68          drb.addGlobalFooterVariable(drb.getColumn(4), DJCalculation.COUNT, null, new DJValueFormatter() {
69  
70              public String getClassName() {
71                  return String.class.getName();
72              }
73  
74              public Object evaluate(Object value, Map fields, Map variables,   Map parameters) {
75                  return (value == null ? "0" : value.toString()) + " Clients";
76              }
77          });
78  
79  
80  		DynamicReport dr = drb.build();
81  
82  		return dr;
83  	}
84  
85  	public static void main(String[] args) throws Exception {
86  		WatermarkReportTest3 test = new WatermarkReportTest3();
87  		test.testReport();
88  		test.exportToJRXML();
89  		JasperViewer.viewReport(test.jp);	//finally display the report report
90  		JasperDesignViewer.viewReportDesign(test.jr);
91  	}
92  
93  }