1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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.domain.AutoText;
41 import ar.com.fdvs.dj.domain.DynamicReport;
42 import ar.com.fdvs.dj.domain.Style;
43 import ar.com.fdvs.dj.domain.builders.FastReportBuilder;
44 import ar.com.fdvs.dj.domain.builders.StyleBuilder;
45 import ar.com.fdvs.dj.domain.constants.Font;
46
47 public class AutotextReportTest extends BaseDjReportTest {
48
49 public DynamicReport buildReport() throws Exception {
50
51 FastReportBuilder drb = new FastReportBuilder();
52 drb.addColumn("State", "state", String.class.getName(),30)
53 .addColumn("Branch", "branch", String.class.getName(),30)
54 .addColumn("Product Line", "productLine", String.class.getName(),50)
55 .addColumn("Item", "item", String.class.getName(),50)
56 .addColumn("Item Code", "id", Long.class.getName(),30,true)
57 .addColumn("Quantity", "quantity", Long.class.getName(),60,true)
58 .addColumn("Amount", "amount", Float.class.getName(),70,true)
59 .addGroups(2)
60 .setTitle("November 2006 sales report")
61 .setSubtitle("This report was generated at " + new Date())
62 .setUseFullPageWidth(true);
63
64
65 Style atStyle = new StyleBuilder(true).setFont(Font.COMIC_SANS_SMALL).setTextColor(Color.red).build();
66 Style atStyle2 = new StyleBuilder(true).setFont(new Font(9, Font._FONT_TIMES_NEW_ROMAN, false, true, false)).setTextColor(Color.BLUE).build();
67
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
72 drb.addAutoText(AutoText.AUTOTEXT_PAGE_X, AutoText.POSITION_HEADER, AutoText.ALIGNMENT_LEFT,200,40, atStyle);
73 drb.addAutoText("Autotext below Page counter", AutoText.POSITION_FOOTER, AutoText.ALIGNMENT_LEFT);
74
75
76 drb.addAutoText("Created by <b>msimone</b>", AutoText.POSITION_FOOTER, AutoText.ALIGNMENT_RIGHT,200);
77 drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_SLASH_Y, AutoText.POSITION_FOOTER, AutoText.ALIGNMENT_RIGHT,30,30,atStyle2);
78
79 drb.addAutoText(AutoText.AUTOTEXT_CREATED_ON, AutoText.POSITION_FOOTER, AutoText.ALIGNMENT_LEFT,AutoText.PATTERN_DATE_DATE_TIME);
80
81
82 drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_OF_Y, AutoText.POSITION_HEADER, AutoText.ALIGNMENT_LEFT,100,40);
83 drb.addAutoText("Autotext at top-left", AutoText.POSITION_HEADER, AutoText.ALIGNMENT_LEFT,200);
84
85 drb.addAutoText("Autotext at top-left (2)", AutoText.POSITION_HEADER, AutoText.ALIGNMENT_LEFT,200);
86 drb.addAutoText("Autotext at top-center", AutoText.POSITION_HEADER, AutoText.ALIGNMENT_CENTER,200,atStyle);
87 DynamicReport dr = drb.build();
88
89
90 drb.setReportLocale(new Locale("es","AR"));
91
92
93
94 return dr;
95 }
96
97 public static void main(String[] args) throws Exception {
98 AutotextReportTest test = new AutotextReportTest();
99 test.testReport();
100 JasperViewer.viewReport(test.jp);
101 JasperDesignViewer.viewReportDesign(DynamicJasperHelper.generateJasperReport(test.dr, test.getLayoutManager(),new HashMap()));
102 }
103
104 }