View Javadoc

1   /*
2    * Copyright (c) 2012, FDV Solutions S.A.
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *     * Redistributions of source code must retain the above copyright
8    *       notice, this list of conditions and the following disclaimer.
9    *     * Redistributions in binary form must reproduce the above copyright
10   *       notice, this list of conditions and the following disclaimer in the
11   *       documentation and/or other materials provided with the distribution.
12   *     * Neither the name of the FDV Solutions S.A. nor the
13   *       names of its contributors may be used to endorse or promote products
14   *       derived from this software without specific prior written permission.
15   *
16   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19   * DISCLAIMED. IN NO EVENT SHALL FDV Solutions S.A. BE LIABLE FOR ANY
20   * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26   */
27  
28  package ar.com.fdvs.dj.test;
29  
30  import ar.com.fdvs.dj.core.DynamicJasperHelper;
31  import ar.com.fdvs.dj.domain.AutoText;
32  import ar.com.fdvs.dj.domain.DynamicReport;
33  import ar.com.fdvs.dj.domain.Style;
34  import ar.com.fdvs.dj.domain.builders.FastReportBuilder;
35  import ar.com.fdvs.dj.domain.builders.StyleBuilder;
36  import ar.com.fdvs.dj.domain.constants.Font;
37  import net.sf.jasperreports.view.JasperDesignViewer;
38  import net.sf.jasperreports.view.JasperViewer;
39  
40  import java.awt.*;
41  import java.util.Date;
42  import java.util.HashMap;
43  import java.util.Locale;
44  
45  public class BuiltinFontsReportTest extends BaseDjReportTest {
46  
47  	public DynamicReport buildReport() throws Exception {
48  
49  		FastReportBuilder drb = new FastReportBuilder();
50  		drb.addColumn("State", "state", String.class.getName(),30)
51  			.addColumn("Branch", "branch", String.class.getName(),30)
52  			.addColumn("Product Line", "productLine", String.class.getName(),50)
53  			.addColumn("Item", "item", String.class.getName(),50)
54  			.addColumn("Item Code", "id", Long.class.getName(),30,true)
55  			.addColumn("Quantity", "quantity", Long.class.getName(),60,true)
56  			.addColumn("Amount", "amount", Float.class.getName(),70,true)
57  			.addGroups(2)
58  			.setTitle("November " + getYear() +" sales report")
59  			.setSubtitle("This report was generated at " + new Date())
60  			.setUseFullPageWidth(true);
61  
62  
63  		Style style1 = new StyleBuilder(true).setFont(Font.ARIAL_MEDIUM).build();
64  		Style style2 = new StyleBuilder(true).setFont(Font.COMIC_SANS_MEDIUM).build();
65  		Style style3 = new StyleBuilder(true).setFont(Font.COURIER_NEW_MEDIUM).build();
66  		Style style4 = new StyleBuilder(true).setFont(Font.GEORGIA_MEDIUM).build();
67  		Style style5 = new StyleBuilder(true).setFont(Font.MONOSPACED_MEDIUM).build();
68  		Style style6 = new StyleBuilder(true).setFont(Font.TIMES_NEW_ROMAN_MEDIUM).build();
69  		Style style7 = new StyleBuilder(true).setFont(Font.VERDANA_MEDIUM).build();
70  
71  
72  		drb.addAutoText("Testing the font Arial", AutoText.POSITION_HEADER, AutoText.ALIGNMENT_LEFT,300, style1);
73  		drb.addAutoText("Testing the font Comic Sans MS", AutoText.POSITION_HEADER, AutoText.ALIGNMENT_LEFT,300, style2);
74  		drb.addAutoText("Testing the font Courrier New", AutoText.POSITION_HEADER, AutoText.ALIGNMENT_LEFT,300, style3);
75  		drb.addAutoText("Testing the font Georgia", AutoText.POSITION_HEADER, AutoText.ALIGNMENT_LEFT,300, style4);
76  		drb.addAutoText("Testing the font Monospaced", AutoText.POSITION_HEADER, AutoText.ALIGNMENT_LEFT,300, style5);
77  		drb.addAutoText("Testing the font Times New Roman", AutoText.POSITION_HEADER, AutoText.ALIGNMENT_LEFT,300, style6);
78  		drb.addAutoText("Testing the font Verdana", AutoText.POSITION_HEADER, AutoText.ALIGNMENT_LEFT,300, style7);
79  
80  
81  		DynamicReport dr = drb.build();
82  
83  
84  		return dr;
85  	}
86  
87  	public static void main(String[] args) throws Exception {
88  		BuiltinFontsReportTest test = new BuiltinFontsReportTest();
89  		test.testReport();
90  		JasperViewer.viewReport(test.jp);
91  		JasperDesignViewer.viewReportDesign(DynamicJasperHelper.generateJasperReport(test.dr, test.getLayoutManager(),new HashMap()));
92  	}
93  
94  }