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.JasperViewer;
35 import ar.com.fdvs.dj.domain.DynamicReport;
36 import ar.com.fdvs.dj.domain.Style;
37 import ar.com.fdvs.dj.domain.builders.ColumnBuilder;
38 import ar.com.fdvs.dj.domain.builders.DynamicReportBuilder;
39 import ar.com.fdvs.dj.domain.constants.Border;
40 import ar.com.fdvs.dj.domain.constants.HorizontalAlign;
41 import ar.com.fdvs.dj.domain.constants.Transparency;
42 import ar.com.fdvs.dj.domain.entities.columns.AbstractColumn;
43
44 public class FixedColumnWidhTest extends BaseDjReportTest {
45
46 public DynamicReport buildReport() throws Exception {
47
48 Style detailStyle = new Style();
49 detailStyle.setBorder(Border.THIN);detailStyle.setBorderColor(Color.BLACK);detailStyle.setStretchWithOverflow(false);
50
51 Style headerStyle = new Style(); headerStyle.setBackgroundColor(new Color(230,230,230));headerStyle.setTransparency(Transparency.OPAQUE);
52
53 Style titleStyle = new Style();
54 Style subtitleStyle = new Style();
55 Style amountStyle = new Style(); amountStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
56
57 /***
58 * Creates the DynamicReportBuilder and sets the basic options for
59 * the report
60 */
61 DynamicReportBuilder drb = new DynamicReportBuilder();
62 drb.setTitle("November 2006 sales report")
63 .setSubtitle("The items in this report correspond "
64 +"to the main products: DVDs, Books, Foods and Magazines")
65 .setDetailHeight(17)
66 .setMargins(30, 20, 30, 15)
67 .setDefaultStyles(titleStyle, subtitleStyle, headerStyle, detailStyle)
68 .setColumnsPerPage(1);
69
70 /***
71 * Note that we still didn't call the build() method
72 */
73
74 /***
75 * Column definitions. We use a new ColumnBuilder instance for each
76 * column, the ColumnBuilder.getNew() method returns a new instance
77 * of the builder
78 */
79 AbstractColumn columnState = ColumnBuilder.getNew()
80 .setColumnProperty("state", String.class.getName())
81 .setTitle("State")
82 .setWidth(85)
83 .build();
84
85
86 AbstractColumn columnBranch = ColumnBuilder.getNew()
87 .setColumnProperty("branch", String.class.getName())
88 .setTitle("Branch").setWidth(85).setTruncateSuffix("...")
89 .build();
90
91 AbstractColumn columnaProductLine = ColumnBuilder.getNew()
92 .setColumnProperty("productLine", String.class.getName())
93 .setTitle("Product Line").setWidth(250).setFixedWidth(true)
94 .build();
95
96 AbstractColumn columnaItem = ColumnBuilder.getNew()
97 .setColumnProperty("item", String.class.getName())
98 .setTitle("Item").setWidth(85)
99 .build();
100
101 AbstractColumn columnCode = ColumnBuilder.getNew()
102 .setColumnProperty("id", Long.class.getName())
103 .setTitle("ID").setWidth(40)
104 .build();
105
106 AbstractColumn columnaCantidad = ColumnBuilder.getNew()
107 .setColumnProperty("quantity", Long.class.getName())
108 .setTitle("Quantity").setWidth(80)
109 .build();
110
111 AbstractColumn columnAmount = ColumnBuilder.getNew()
112 .setColumnProperty("amount", Float.class.getName())
113 .setTitle("Amount").setWidth(90)
114 .setFixedWidth(true)
115 .setPattern("$ 0.00")
116 .build();
117
118 /***
119 * We add the columns to the report (through the builder) in the order
120 * we want them to appear
121 */
122 drb.addColumn(columnState);
123 drb.addColumn(columnBranch);
124 drb.addColumn(columnaProductLine);
125 drb.addColumn(columnaItem);
126 drb.addColumn(columnCode);
127 drb.addColumn(columnaCantidad);
128 drb.addColumn(columnAmount);
129
130 /***
131 * add some more options to the report (through the builder)
132 */
133 drb.setUseFullPageWidth(true);
134
135
136
137 DynamicReport dr = drb.build();
138
139
140
141 return dr;
142 }
143
144 public static void main(String[] args) throws Exception {
145 FixedColumnWidhTest test = new FixedColumnWidhTest();
146 test.testReport();
147 JasperViewer.viewReport(test.jp);
148 }
149
150 }