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