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
34 import net.sf.jasperreports.view.JasperDesignViewer;
35 import net.sf.jasperreports.view.JasperViewer;
36 import ar.com.fdvs.dj.domain.AutoText;
37 import ar.com.fdvs.dj.domain.DJCalculation;
38 import ar.com.fdvs.dj.domain.DynamicReport;
39 import ar.com.fdvs.dj.domain.Style;
40 import ar.com.fdvs.dj.domain.builders.ColumnBuilder;
41 import ar.com.fdvs.dj.domain.builders.DynamicReportBuilder;
42 import ar.com.fdvs.dj.domain.builders.GroupBuilder;
43 import ar.com.fdvs.dj.domain.constants.Border;
44 import ar.com.fdvs.dj.domain.constants.Font;
45 import ar.com.fdvs.dj.domain.constants.GroupLayout;
46 import ar.com.fdvs.dj.domain.constants.HorizontalAlign;
47 import ar.com.fdvs.dj.domain.constants.Transparency;
48 import ar.com.fdvs.dj.domain.constants.VerticalAlign;
49 import ar.com.fdvs.dj.domain.entities.DJGroup;
50 import ar.com.fdvs.dj.domain.entities.columns.AbstractColumn;
51 import ar.com.fdvs.dj.domain.entities.columns.PropertyColumn;
52
53 public class GroupsReportTest extends BaseDjReportTest {
54
55 public DynamicReport buildReport() throws Exception {
56
57 Style detailStyle = new Style("detail");
58
59 Style headerStyle = new Style("header");
60 headerStyle.setFont(Font.ARIAL_MEDIUM_BOLD);
61 headerStyle.setBorderBottom(Border.PEN_1_POINT());
62 headerStyle.setBackgroundColor(Color.gray);
63 headerStyle.setTextColor(Color.white);
64 headerStyle.setHorizontalAlign(HorizontalAlign.CENTER);
65 headerStyle.setVerticalAlign(VerticalAlign.MIDDLE);
66 headerStyle.setTransparency(Transparency.OPAQUE);
67
68 Style headerVariables = new Style("headerVariables");
69 headerVariables.setFont(Font.ARIAL_BIG_BOLD);
70 headerVariables.setBorderBottom(Border.THIN());
71 headerVariables.setHorizontalAlign(HorizontalAlign.RIGHT);
72 headerVariables.setVerticalAlign(VerticalAlign.TOP);
73 headerVariables.setStretchWithOverflow(true);
74
75 Style groupVariables = new Style("groupVariables");
76 groupVariables.setFont(Font.ARIAL_MEDIUM_BOLD);
77 groupVariables.setTextColor(Color.BLUE);
78 groupVariables.setBorderBottom(Border.THIN());
79 groupVariables.setHorizontalAlign(HorizontalAlign.RIGHT);
80 groupVariables.setVerticalAlign(VerticalAlign.BOTTOM);
81
82 Style titleStyle = new Style("titleStyle");
83 titleStyle.setFont(new Font(18, Font._FONT_VERDANA, true));
84 Style importeStyle = new Style();
85 importeStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
86 Style oddRowStyle = new Style();
87 oddRowStyle.setBorder(Border.NO_BORDER());
88 oddRowStyle.setBackgroundColor(Color.LIGHT_GRAY);
89 oddRowStyle.setTransparency(Transparency.OPAQUE);
90
91 DynamicReportBuilder drb = new DynamicReportBuilder();
92 Integer margin = new Integer(20);
93 drb
94 .setTitleStyle(titleStyle)
95 .setTitle("November " + getYear() +" sales report")
96 .setSubtitle("The items in this report correspond "
97 +"to the main products: DVDs, Books, Foods and Magazines")
98 .setDetailHeight(new Integer(15)).setLeftMargin(margin)
99 .setRightMargin(margin).setTopMargin(margin).setBottomMargin(margin)
100 .setPrintBackgroundOnOddRows(true)
101 .setGrandTotalLegend("Grand Total")
102 .setGrandTotalLegendStyle(headerVariables)
103 .setOddRowBackgroundStyle(oddRowStyle);
104
105
106 AbstractColumn columnState = ColumnBuilder.getNew()
107 .setColumnProperty("state", String.class.getName()).setTitle(
108 "State").setWidth(new Integer(85))
109 .setStyle(titleStyle).setHeaderStyle(titleStyle).build();
110
111 AbstractColumn columnBranch = ColumnBuilder.getNew()
112 .setColumnProperty("branch", String.class.getName()).setTitle(
113 "Branch").setWidth(new Integer(85)).setStyle(
114 detailStyle).setHeaderStyle(headerStyle).build();
115
116 AbstractColumn columnaProductLine = ColumnBuilder.getNew()
117 .setColumnProperty("productLine", String.class.getName())
118 .setTitle("Product Line").setWidth(new Integer(85)).setStyle(
119 detailStyle).setHeaderStyle(headerStyle).build();
120
121 AbstractColumn columnaItem = ColumnBuilder.getNew()
122 .setColumnProperty("item", String.class.getName()).setTitle(
123 "Item").setWidth(new Integer(85)).setStyle(detailStyle)
124 .setHeaderStyle(headerStyle).build();
125
126 AbstractColumn columnCode = ColumnBuilder.getNew()
127 .setColumnProperty("id", Long.class.getName()).setTitle("ID")
128 .setWidth(new Integer(40)).setStyle(importeStyle)
129 .setHeaderStyle(headerStyle).build();
130
131 AbstractColumn columnaQuantity = ColumnBuilder.getNew()
132 .setColumnProperty("quantity", Long.class.getName()).setTitle(
133 "Quantity").setWidth(new Integer(25)).setStyle(
134 importeStyle).setHeaderStyle(headerStyle).build();
135
136 AbstractColumn columnAmount = ColumnBuilder.getNew()
137 .setColumnProperty("amount", Float.class.getName()).setTitle(
138 "Amount").setWidth(new Integer(100))
139 .setPattern("$ 0.00").setStyle(importeStyle).setHeaderStyle(
140 headerStyle).build();
141
142 drb.addGlobalHeaderVariable(columnAmount, DJCalculation.SUM,headerVariables);
143 drb.addGlobalHeaderVariable(columnaQuantity, DJCalculation.SUM,headerVariables);
144 drb.addGlobalFooterVariable(columnAmount, DJCalculation.SUM,headerVariables);
145 drb.addGlobalFooterVariable(columnaQuantity, DJCalculation.SUM,headerVariables);
146 drb.setGlobalHeaderVariableHeight(new Integer(25));
147 drb.setGlobalFooterVariableHeight(new Integer(25));
148
149 GroupBuilder gb1 = new GroupBuilder();
150
151
152 DJGroup g1 = gb1.setCriteriaColumn((PropertyColumn) columnState)
153 .addFooterVariable(columnaQuantity,DJCalculation.SUM,groupVariables)
154
155 .addHeaderVariable(columnaQuantity,DJCalculation.SUM,groupVariables)
156 .addHeaderVariable(columnAmount,DJCalculation.SUM,groupVariables)
157 .setGroupLayout(GroupLayout.VALUE_IN_HEADER)
158 .setFooterVariablesHeight(new Integer(20))
159 .setFooterHeight(new Integer(50),true)
160 .setHeaderVariablesHeight(new Integer(35))
161 .build();
162
163 GroupBuilder gb2 = new GroupBuilder();
164 DJGroup g2 = gb2.setCriteriaColumn((PropertyColumn) columnBranch)
165 .addFooterVariable(columnAmount,
166 DJCalculation.SUM)
167 .addFooterVariable(columnaQuantity, DJCalculation.SUM)
168 .build();
169
170 drb.addColumn(columnState);
171 drb.addColumn(columnBranch);
172 drb.addColumn(columnaProductLine);
173 drb.addColumn(columnaItem);
174 drb.addColumn(columnCode);
175 drb.addColumn(columnaQuantity);
176 drb.addColumn(columnAmount);
177
178 drb.addGroup(g1);
179
180
181 drb.setUseFullPageWidth(true);
182 drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_SLASH_Y, AutoText.POSITION_FOOTER, AutoText.ALIGNMENT_RIGHT);
183
184 DynamicReport dr = drb.build();
185 return dr;
186 }
187
188 public static void main(String[] args) throws Exception {
189 GroupsReportTest test = new GroupsReportTest();
190 test.testReport();
191 test.exportToJRXML();
192 JasperViewer.viewReport(test.jp);
193 JasperDesignViewer.viewReportDesign(test.jr);
194 }
195
196 }