Rev 1571 | Rev 1830 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1574 | jmachado | 1 | package pt.estgp.estgweb.services.questionarios.pedagogico.reportprocessors.utils; |
1553 | jmachado | 2 | |
3 | import org.dom4j.DocumentException; |
||
4 | import org.w3c.dom.Document; |
||
5 | import pt.estgp.estgweb.utils.Dom4jUtil; |
||
6 | |||
7 | import javax.xml.transform.TransformerException; |
||
8 | import java.io.ByteArrayOutputStream; |
||
9 | import java.io.IOException; |
||
10 | import java.io.Serializable; |
||
11 | import java.util.ArrayList; |
||
12 | |||
13 | /** |
||
14 | * Created by jorgemachado on 11/11/16. |
||
15 | */ |
||
16 | public class DataTable implements 1.5.0/docs/api/java/io/Serializable.html">Serializable |
||
17 | { |
||
18 | |||
19 | |||
20 | |||
21 | public DataTable() { |
||
22 | |||
23 | setRows(new ArrayList<Row>()); |
||
24 | } |
||
25 | |||
26 | |||
27 | private ArrayList<Row> rows; |
||
28 | |||
29 | public Row addRow() |
||
30 | { |
||
31 | Row row = new Row(); |
||
32 | rows.add(row); |
||
33 | return row; |
||
34 | } |
||
35 | public Row addRowHeader() |
||
36 | { |
||
37 | Row row = new Row(); |
||
38 | row.setTypeHeader(); |
||
39 | rows.add(row); |
||
40 | return row; |
||
41 | } |
||
42 | public Row addRowNormal() |
||
43 | { |
||
44 | Row row = new Row(); |
||
45 | row.setTypeNormal(); |
||
46 | rows.add(row); |
||
47 | return row; |
||
48 | } |
||
49 | public Row addRowFooter() |
||
50 | { |
||
51 | Row row = new Row(); |
||
52 | row.setTypeFooter(); |
||
53 | rows.add(row); |
||
54 | return row; |
||
55 | } |
||
56 | |||
57 | public ArrayList<Row> getRows() { return rows; } |
||
58 | |||
59 | public void setRows(ArrayList<Row> rows) { |
||
60 | this.rows = rows; |
||
61 | } |
||
62 | |||
63 | public static class Row implements 1.5.0/docs/api/java/io/Serializable.html">Serializable |
||
64 | { |
||
65 | //header, footer, normal |
||
66 | 1.5.0/docs/api/java/lang/String.html">String type = null; |
||
1569 | jmachado | 67 | boolean invisible = false; |
1553 | jmachado | 68 | private ArrayList<Col> cols; |
69 | |||
1567 | jmachado | 70 | |
1553 | jmachado | 71 | public Row() { |
72 | setCols(new ArrayList<Col>()); |
||
73 | } |
||
74 | |||
1569 | jmachado | 75 | public boolean isInvisible() { |
76 | return invisible; |
||
77 | } |
||
78 | |||
79 | public void setInvisible(boolean invisible) { |
||
80 | this.invisible = invisible; |
||
81 | } |
||
82 | |||
1553 | jmachado | 83 | public void setCols(ArrayList<Col> cols) { |
84 | this.cols = cols; |
||
85 | } |
||
86 | |||
87 | public void setTypeNormal() { type = "normal"; } |
||
88 | public void setTypeHeader() { type = "header"; } |
||
89 | public void setTypeFooter() { type = "footer"; } |
||
90 | |||
1567 | jmachado | 91 | |
92 | |||
1553 | jmachado | 93 | public Col addCol() |
94 | { |
||
95 | Col col = new Col(); |
||
96 | cols.add(col); |
||
97 | return col; |
||
98 | } |
||
99 | |||
100 | public Col addColNumberLeft(1.5.0/docs/api/java/lang/String.html">String value) |
||
101 | { Col col = new Col(value); |
||
102 | col.setTypeNumber(); |
||
103 | col.setAlignLeft(); |
||
104 | cols.add(col); |
||
105 | return col; |
||
106 | } |
||
107 | public Col addColNumberRight(1.5.0/docs/api/java/lang/String.html">String value) |
||
1567 | jmachado | 108 | { Col col = new Col(value); |
1553 | jmachado | 109 | col.setTypeNumber(); |
110 | col.setAlignRight(); |
||
111 | cols.add(col); |
||
112 | return col; |
||
113 | } |
||
114 | public Col addColNumberCenter(1.5.0/docs/api/java/lang/String.html">String value) |
||
115 | { Col col = new Col(value); |
||
116 | col.setTypeNumber(); |
||
117 | col.setAlignCenter(); |
||
118 | cols.add(col); |
||
119 | return col; |
||
120 | } |
||
121 | |||
122 | public Col addColTextLeft(1.5.0/docs/api/java/lang/String.html">String value) |
||
123 | { Col col = new Col(value); |
||
124 | col.setTypeText(); |
||
125 | col.setAlignLeft(); |
||
126 | cols.add(col); |
||
127 | return col; |
||
128 | } |
||
129 | public Col addColTextRight(1.5.0/docs/api/java/lang/String.html">String value) |
||
130 | { Col col = new Col(value); |
||
131 | col.setTypeText(); |
||
132 | col.setAlignRight(); |
||
133 | cols.add(col); |
||
134 | return col; |
||
135 | } |
||
1571 | jmachado | 136 | |
1553 | jmachado | 137 | public Col addColTextCenter(1.5.0/docs/api/java/lang/String.html">String value) |
138 | { Col col = new Col(value); |
||
139 | col.setTypeText(); |
||
140 | col.setAlignCenter(); |
||
141 | cols.add(col); |
||
142 | return col; |
||
143 | } |
||
144 | |||
1571 | jmachado | 145 | public Col addColInvisible() |
146 | { Col col = new Col(); |
||
147 | col.setTypeInvisible(); |
||
148 | cols.add(col); |
||
149 | return col; |
||
150 | } |
||
151 | |||
1553 | jmachado | 152 | public Col addColPercentageLeft(1.5.0/docs/api/java/lang/String.html">String value) |
153 | { Col col = new Col(value); |
||
154 | col.setTypePercentage(); |
||
155 | col.setAlignLeft(); |
||
156 | cols.add(col); |
||
157 | return col; |
||
158 | } |
||
159 | public Col addColPercentageRight(1.5.0/docs/api/java/lang/String.html">String value) |
||
160 | { Col col = new Col(value); |
||
161 | col.setTypePercentage(); |
||
162 | col.setAlignRight(); |
||
163 | cols.add(col); |
||
164 | return col; |
||
165 | } |
||
166 | public Col addColPercentageCenter(1.5.0/docs/api/java/lang/String.html">String value) |
||
167 | { Col col = new Col(value); |
||
168 | col.setTypePercentage(); |
||
169 | col.setAlignCenter(); |
||
170 | cols.add(col); |
||
171 | return col; |
||
172 | } |
||
1554 | jmachado | 173 | |
174 | public Col addColPercentageLeft(1.5.0/docs/api/java/lang/String.html">String value,boolean usePercentageColors) |
||
175 | { Col col = new Col(value); |
||
176 | col.setTypePercentage(); |
||
177 | col.setAlignLeft(); |
||
178 | col.setUsePercentageColor(usePercentageColors); |
||
179 | cols.add(col); |
||
180 | return col; |
||
181 | } |
||
182 | public Col addColPercentageRight(1.5.0/docs/api/java/lang/String.html">String value,boolean usePercentageColors) |
||
183 | { Col col = new Col(value); |
||
184 | col.setTypePercentage(); |
||
185 | col.setAlignRight(); |
||
186 | col.setUsePercentageColor(usePercentageColors); |
||
187 | cols.add(col); |
||
188 | return col; |
||
189 | } |
||
190 | public Col addColPercentageCenter(1.5.0/docs/api/java/lang/String.html">String value,boolean usePercentageColors) |
||
191 | { Col col = new Col(value); |
||
192 | col.setTypePercentage(); |
||
193 | col.setAlignCenter(); |
||
194 | col.setUsePercentageColor(usePercentageColors); |
||
195 | cols.add(col); |
||
196 | return col; |
||
197 | } |
||
198 | |||
199 | |||
200 | public Col addColPercentageDefinedLeft(1.5.0/docs/api/java/lang/String.html">String value,1.5.0/docs/api/java/lang/String.html">String percent,boolean usePercentageColors) |
||
201 | { Col col = new Col(value); |
||
202 | col.setPercentDefined(percent); |
||
203 | col.setTypePercentageDefined(); |
||
204 | col.setAlignLeft(); |
||
205 | col.setUsePercentageColor(usePercentageColors); |
||
206 | cols.add(col); |
||
207 | return col; |
||
208 | } |
||
209 | public Col addColPercentageDefinedRight(1.5.0/docs/api/java/lang/String.html">String value,1.5.0/docs/api/java/lang/String.html">String percent,boolean usePercentageColors) |
||
210 | { Col col = new Col(value); |
||
211 | col.setPercentDefined(percent); |
||
212 | col.setTypePercentageDefined(); |
||
213 | col.setAlignRight(); |
||
214 | col.setUsePercentageColor(usePercentageColors); |
||
215 | cols.add(col); |
||
216 | return col; |
||
217 | } |
||
218 | public Col addColPercentageDefinedCenter(1.5.0/docs/api/java/lang/String.html">String value,1.5.0/docs/api/java/lang/String.html">String percent,boolean usePercentageColors) |
||
219 | { Col col = new Col(value); |
||
220 | col.setPercentDefined(percent); |
||
221 | col.setTypePercentageDefined(); |
||
222 | col.setAlignCenter(); |
||
223 | col.setUsePercentageColor(usePercentageColors); |
||
224 | cols.add(col); |
||
225 | return col; |
||
226 | } |
||
227 | |||
1570 | jmachado | 228 | public Col addColPercentageDefinedProgressCenter(1.5.0/docs/api/java/lang/String.html">String value,1.5.0/docs/api/java/lang/String.html">String percent) |
229 | { Col col = new Col(value); |
||
230 | col.setPercentDefined(percent); |
||
231 | col.setTypePercentageDefinedProgress(); |
||
232 | col.setAlignCenter(); |
||
233 | cols.add(col); |
||
234 | return col; |
||
235 | } |
||
236 | public Col addColPercentageProgressCenter(1.5.0/docs/api/java/lang/String.html">String value) |
||
237 | { Col col = new Col(value); |
||
238 | col.setTypePercentageProgress(); |
||
239 | col.setAlignCenter(); |
||
240 | cols.add(col); |
||
241 | return col; |
||
242 | } |
||
1554 | jmachado | 243 | |
1570 | jmachado | 244 | |
1553 | jmachado | 245 | public Col addColLabelLeft(1.5.0/docs/api/java/lang/String.html">String value) |
246 | { Col col = new Col(value); |
||
247 | col.setTypeLabel(); |
||
248 | col.setAlignLeft(); |
||
249 | cols.add(col); |
||
250 | return col; |
||
251 | } |
||
252 | public Col addColLabelRight(1.5.0/docs/api/java/lang/String.html">String value) |
||
253 | { Col col = new Col(value); |
||
254 | col.setTypeLabel(); |
||
255 | col.setAlignRight(); |
||
256 | cols.add(col); |
||
257 | return col; |
||
258 | } |
||
259 | public Col addColLabelCenter(1.5.0/docs/api/java/lang/String.html">String value) |
||
260 | { Col col = new Col(value); |
||
261 | col.setTypeLabel(); |
||
262 | col.setAlignCenter(); |
||
263 | cols.add(col); |
||
264 | return col; |
||
265 | } |
||
266 | |||
267 | public 1.5.0/docs/api/java/lang/String.html">String getType() { return type; } |
||
268 | public ArrayList<Col> getCols() { return cols; } |
||
269 | |||
270 | public void setType(1.5.0/docs/api/java/lang/String.html">String type) { |
||
271 | this.type = type; |
||
272 | } |
||
273 | |||
274 | |||
275 | public static class Col implements 1.5.0/docs/api/java/io/Serializable.html">Serializable |
||
276 | { |
||
277 | public Col(1.5.0/docs/api/java/lang/String.html">String value) { |
||
278 | this.value = value; |
||
279 | } |
||
280 | public Col() { |
||
281 | } |
||
282 | |||
1569 | jmachado | 283 | |
1553 | jmachado | 284 | //center, left, right |
1568 | jmachado | 285 | 1.5.0/docs/api/java/lang/String.html">String width = ""; |
1553 | jmachado | 286 | 1.5.0/docs/api/java/lang/String.html">String align = null; |
287 | 1.5.0/docs/api/java/lang/String.html">String value = null; |
||
1554 | jmachado | 288 | 1.5.0/docs/api/java/lang/String.html">String percentDefined = null; |
289 | //number, percentage, percentageDefined, text, label |
||
1553 | jmachado | 290 | 1.5.0/docs/api/java/lang/String.html">String type = null; |
1554 | jmachado | 291 | boolean usePercentageColor = false; |
292 | 1.5.0/docs/api/java/lang/String.html">String backgroundColor = ""; |
||
1565 | jmachado | 293 | 1.5.0/docs/api/java/lang/String.html">String backgroundColorPercentage = ""; |
1567 | jmachado | 294 | 1.5.0/docs/api/java/lang/String.html">String fontWeight = ""; |
295 | int colspan = 0; |
||
1553 | jmachado | 296 | |
1568 | jmachado | 297 | public 1.5.0/docs/api/java/lang/String.html">String getWidth() { |
298 | return width; |
||
299 | } |
||
300 | |||
301 | public void setWidth(1.5.0/docs/api/java/lang/String.html">String width) { |
||
302 | this.width = width; |
||
303 | } |
||
304 | |||
1567 | jmachado | 305 | public 1.5.0/docs/api/java/lang/String.html">String getFontWeight() { |
306 | return fontWeight; |
||
307 | } |
||
1554 | jmachado | 308 | |
1567 | jmachado | 309 | public void setFontWeight(1.5.0/docs/api/java/lang/String.html">String fontWeight) { |
310 | this.fontWeight = fontWeight; |
||
311 | } |
||
312 | |||
313 | public int getColspan() { |
||
314 | return colspan; |
||
315 | } |
||
316 | |||
317 | public void setColspan(int colspan) { |
||
318 | this.colspan = colspan; |
||
319 | } |
||
320 | |||
1554 | jmachado | 321 | public 1.5.0/docs/api/java/lang/String.html">String getBackgroundColor() { |
322 | return backgroundColor; |
||
323 | } |
||
324 | |||
325 | public void setBackgroundColor(1.5.0/docs/api/java/lang/String.html">String backgroundColor) { |
||
326 | this.backgroundColor = backgroundColor; |
||
327 | } |
||
328 | |||
1565 | jmachado | 329 | public 1.5.0/docs/api/java/lang/String.html">String getBackgroundColorPercentage() { |
330 | return backgroundColorPercentage; |
||
331 | } |
||
332 | |||
333 | public void setBackgroundColorPercentage(1.5.0/docs/api/java/lang/String.html">String backgroundColorPercentage) { |
||
334 | this.backgroundColorPercentage = backgroundColorPercentage; |
||
335 | } |
||
336 | |||
1553 | jmachado | 337 | public void setAlignLeft() { align = "left"; } |
338 | public void setAlignRight() { align = "right"; } |
||
339 | public void setAlignCenter() { align = "center"; } |
||
340 | public void setTypeNumber() { type = "number"; } |
||
341 | public void setTypeText() { type = "text"; } |
||
1571 | jmachado | 342 | public void setTypeInvisible() { type = "invisible"; } |
1553 | jmachado | 343 | public void setTypePercentage() { type = "percentage"; } |
1554 | jmachado | 344 | public void setTypePercentageDefined() { type = "percentageDefined"; } |
1570 | jmachado | 345 | public void setTypePercentageDefinedProgress() { type = "percentageDefinedProgress"; } |
346 | public void setTypePercentageProgress() { type = "percentageProgress"; } |
||
1553 | jmachado | 347 | public void setTypeLabel() { type = "label"; } |
348 | |||
1554 | jmachado | 349 | public boolean isUsePercentageColor() { |
350 | return usePercentageColor; |
||
351 | } |
||
352 | |||
1565 | jmachado | 353 | public void setUsePercentageColor(boolean usePercentageColor) |
354 | { |
||
1554 | jmachado | 355 | this.usePercentageColor = usePercentageColor; |
1565 | jmachado | 356 | //new Approach for percentage color using degrade |
357 | if(usePercentageColor) |
||
358 | { |
||
359 | double percentage = type.equals("percentageDefined") ? 1.5.0/docs/api/java/lang/Double.html">Double.parseDouble(percentDefined.replace(",",".")) : 1.5.0/docs/api/java/lang/Double.html">Double.parseDouble(value.replace(",",".")); |
||
360 | percentage = percentage / 100.0; |
||
361 | |||
1567 | jmachado | 362 | setBackgroundColorPercentage(getColorGradientForPercentage(percentage)); |
1565 | jmachado | 363 | } |
364 | |||
1554 | jmachado | 365 | } |
366 | |||
1553 | jmachado | 367 | public 1.5.0/docs/api/java/lang/String.html">String getValue() { return value; } |
368 | public void setValue(1.5.0/docs/api/java/lang/String.html">String value) { this.value = value; } |
||
1554 | jmachado | 369 | |
370 | public 1.5.0/docs/api/java/lang/String.html">String getPercentDefined() { |
||
371 | return percentDefined; |
||
372 | } |
||
373 | |||
1565 | jmachado | 374 | public void setPercentDefined(1.5.0/docs/api/java/lang/String.html">String percentDefined) { |
375 | if(percentDefined.contains(".")) |
||
376 | this.percentDefined = percentDefined.substring(0,percentDefined.indexOf(".")); |
||
377 | else if(percentDefined.contains(",")) |
||
378 | this.percentDefined = percentDefined.substring(0,percentDefined.indexOf(",")); |
||
1554 | jmachado | 379 | this.percentDefined = percentDefined; |
380 | } |
||
1553 | jmachado | 381 | } |
382 | } |
||
383 | |||
1567 | jmachado | 384 | /** |
385 | * |
||
386 | * @param percentageDecimal between 0 and 1 |
||
387 | * @return |
||
388 | */ |
||
389 | public static 1.5.0/docs/api/java/lang/String.html">String getColorGradientForPercentage(double percentageDecimal) |
||
390 | { |
||
391 | if(percentageDecimal < 0.5) |
||
392 | { |
||
393 | int green = ChartBuilderUtil.getGreenComponentGradient(percentageDecimal); |
||
394 | return "rgb(255," + green + ",0)"; |
||
395 | } |
||
396 | else |
||
397 | { |
||
398 | |||
399 | int red = ChartBuilderUtil.getRedComponentGradient(percentageDecimal); |
||
400 | //int red = (int) (255.0*((1.0-percentageDecimal)*2)); |
||
401 | return "rgb(" + red + ",255,0)"; |
||
402 | } |
||
403 | } |
||
404 | |||
405 | |||
406 | |||
1553 | jmachado | 407 | public 5+0%2Fdocs%2Fapi+Document">Document serialize() throws DocumentException, 1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException, 1.5.0/docs/api/java/io/IOException.html">IOException { |
408 | 1.5.0/docs/api/java/io/ByteArrayOutputStream.html">ByteArrayOutputStream out = new 1.5.0/docs/api/java/io/ByteArrayOutputStream.html">ByteArrayOutputStream(); |
||
409 | //fos1 = new FileOutputStream("/Volumes/Home/jorgemachado/Desktop/docenteReport.xml"); |
||
410 | java.beans.1.5.0/docs/api/java/beans/XMLEncoder.html">XMLEncoder xe1 = new java.beans.1.5.0/docs/api/java/beans/XMLEncoder.html">XMLEncoder(out); |
||
411 | |||
412 | |||
413 | xe1.writeObject(this); |
||
414 | xe1.flush(); |
||
415 | xe1.close(); |
||
416 | //Dom4jUtil.writeSout(Dom4jUtil.parse(out.toString())); |
||
417 | return Dom4jUtil.toW3c(Dom4jUtil.parse(out.toString())); |
||
418 | |||
419 | } |
||
420 | |||
421 | } |