Rev 1567 | Rev 1569 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1563 | jmachado | 1 | package pt.estgp.estgweb.services.questionarios.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; |
||
67 | private ArrayList<Col> cols; |
||
68 | |||
1567 | jmachado | 69 | |
1553 | jmachado | 70 | public Row() { |
71 | setCols(new ArrayList<Col>()); |
||
72 | } |
||
73 | |||
74 | public void setCols(ArrayList<Col> cols) { |
||
75 | this.cols = cols; |
||
76 | } |
||
77 | |||
78 | public void setTypeNormal() { type = "normal"; } |
||
79 | public void setTypeHeader() { type = "header"; } |
||
80 | public void setTypeFooter() { type = "footer"; } |
||
81 | |||
1567 | jmachado | 82 | |
83 | |||
1553 | jmachado | 84 | public Col addCol() |
85 | { |
||
86 | Col col = new Col(); |
||
87 | cols.add(col); |
||
88 | return col; |
||
89 | } |
||
90 | |||
91 | public Col addColNumberLeft(1.5.0/docs/api/java/lang/String.html">String value) |
||
92 | { Col col = new Col(value); |
||
93 | col.setTypeNumber(); |
||
94 | col.setAlignLeft(); |
||
95 | cols.add(col); |
||
96 | return col; |
||
97 | } |
||
98 | public Col addColNumberRight(1.5.0/docs/api/java/lang/String.html">String value) |
||
1567 | jmachado | 99 | { Col col = new Col(value); |
1553 | jmachado | 100 | col.setTypeNumber(); |
101 | col.setAlignRight(); |
||
102 | cols.add(col); |
||
103 | return col; |
||
104 | } |
||
105 | public Col addColNumberCenter(1.5.0/docs/api/java/lang/String.html">String value) |
||
106 | { Col col = new Col(value); |
||
107 | col.setTypeNumber(); |
||
108 | col.setAlignCenter(); |
||
109 | cols.add(col); |
||
110 | return col; |
||
111 | } |
||
112 | |||
113 | public Col addColTextLeft(1.5.0/docs/api/java/lang/String.html">String value) |
||
114 | { Col col = new Col(value); |
||
115 | col.setTypeText(); |
||
116 | col.setAlignLeft(); |
||
117 | cols.add(col); |
||
118 | return col; |
||
119 | } |
||
120 | public Col addColTextRight(1.5.0/docs/api/java/lang/String.html">String value) |
||
121 | { Col col = new Col(value); |
||
122 | col.setTypeText(); |
||
123 | col.setAlignRight(); |
||
124 | cols.add(col); |
||
125 | return col; |
||
126 | } |
||
127 | public Col addColTextCenter(1.5.0/docs/api/java/lang/String.html">String value) |
||
128 | { Col col = new Col(value); |
||
129 | col.setTypeText(); |
||
130 | col.setAlignCenter(); |
||
131 | cols.add(col); |
||
132 | return col; |
||
133 | } |
||
134 | |||
135 | public Col addColPercentageLeft(1.5.0/docs/api/java/lang/String.html">String value) |
||
136 | { Col col = new Col(value); |
||
137 | col.setTypePercentage(); |
||
138 | col.setAlignLeft(); |
||
139 | cols.add(col); |
||
140 | return col; |
||
141 | } |
||
142 | public Col addColPercentageRight(1.5.0/docs/api/java/lang/String.html">String value) |
||
143 | { Col col = new Col(value); |
||
144 | col.setTypePercentage(); |
||
145 | col.setAlignRight(); |
||
146 | cols.add(col); |
||
147 | return col; |
||
148 | } |
||
149 | public Col addColPercentageCenter(1.5.0/docs/api/java/lang/String.html">String value) |
||
150 | { Col col = new Col(value); |
||
151 | col.setTypePercentage(); |
||
152 | col.setAlignCenter(); |
||
153 | cols.add(col); |
||
154 | return col; |
||
155 | } |
||
1554 | jmachado | 156 | |
157 | public Col addColPercentageLeft(1.5.0/docs/api/java/lang/String.html">String value,boolean usePercentageColors) |
||
158 | { Col col = new Col(value); |
||
159 | col.setTypePercentage(); |
||
160 | col.setAlignLeft(); |
||
161 | col.setUsePercentageColor(usePercentageColors); |
||
162 | cols.add(col); |
||
163 | return col; |
||
164 | } |
||
165 | public Col addColPercentageRight(1.5.0/docs/api/java/lang/String.html">String value,boolean usePercentageColors) |
||
166 | { Col col = new Col(value); |
||
167 | col.setTypePercentage(); |
||
168 | col.setAlignRight(); |
||
169 | col.setUsePercentageColor(usePercentageColors); |
||
170 | cols.add(col); |
||
171 | return col; |
||
172 | } |
||
173 | public Col addColPercentageCenter(1.5.0/docs/api/java/lang/String.html">String value,boolean usePercentageColors) |
||
174 | { Col col = new Col(value); |
||
175 | col.setTypePercentage(); |
||
176 | col.setAlignCenter(); |
||
177 | col.setUsePercentageColor(usePercentageColors); |
||
178 | cols.add(col); |
||
179 | return col; |
||
180 | } |
||
181 | |||
182 | |||
183 | 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) |
||
184 | { Col col = new Col(value); |
||
185 | col.setPercentDefined(percent); |
||
186 | col.setTypePercentageDefined(); |
||
187 | col.setAlignLeft(); |
||
188 | col.setUsePercentageColor(usePercentageColors); |
||
189 | cols.add(col); |
||
190 | return col; |
||
191 | } |
||
192 | 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) |
||
193 | { Col col = new Col(value); |
||
194 | col.setPercentDefined(percent); |
||
195 | col.setTypePercentageDefined(); |
||
196 | col.setAlignRight(); |
||
197 | col.setUsePercentageColor(usePercentageColors); |
||
198 | cols.add(col); |
||
199 | return col; |
||
200 | } |
||
201 | 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) |
||
202 | { Col col = new Col(value); |
||
203 | col.setPercentDefined(percent); |
||
204 | col.setTypePercentageDefined(); |
||
205 | col.setAlignCenter(); |
||
206 | col.setUsePercentageColor(usePercentageColors); |
||
207 | cols.add(col); |
||
208 | return col; |
||
209 | } |
||
210 | |||
211 | |||
1553 | jmachado | 212 | public Col addColLabelLeft(1.5.0/docs/api/java/lang/String.html">String value) |
213 | { Col col = new Col(value); |
||
214 | col.setTypeLabel(); |
||
215 | col.setAlignLeft(); |
||
216 | cols.add(col); |
||
217 | return col; |
||
218 | } |
||
219 | public Col addColLabelRight(1.5.0/docs/api/java/lang/String.html">String value) |
||
220 | { Col col = new Col(value); |
||
221 | col.setTypeLabel(); |
||
222 | col.setAlignRight(); |
||
223 | cols.add(col); |
||
224 | return col; |
||
225 | } |
||
226 | public Col addColLabelCenter(1.5.0/docs/api/java/lang/String.html">String value) |
||
227 | { Col col = new Col(value); |
||
228 | col.setTypeLabel(); |
||
229 | col.setAlignCenter(); |
||
230 | cols.add(col); |
||
231 | return col; |
||
232 | } |
||
233 | |||
234 | public 1.5.0/docs/api/java/lang/String.html">String getType() { return type; } |
||
235 | public ArrayList<Col> getCols() { return cols; } |
||
236 | |||
237 | public void setType(1.5.0/docs/api/java/lang/String.html">String type) { |
||
238 | this.type = type; |
||
239 | } |
||
240 | |||
241 | |||
242 | public static class Col implements 1.5.0/docs/api/java/io/Serializable.html">Serializable |
||
243 | { |
||
244 | public Col(1.5.0/docs/api/java/lang/String.html">String value) { |
||
245 | this.value = value; |
||
246 | } |
||
247 | public Col() { |
||
248 | } |
||
249 | |||
250 | //center, left, right |
||
1568 | jmachado | 251 | 1.5.0/docs/api/java/lang/String.html">String width = ""; |
1553 | jmachado | 252 | 1.5.0/docs/api/java/lang/String.html">String align = null; |
253 | 1.5.0/docs/api/java/lang/String.html">String value = null; |
||
1554 | jmachado | 254 | 1.5.0/docs/api/java/lang/String.html">String percentDefined = null; |
255 | //number, percentage, percentageDefined, text, label |
||
1553 | jmachado | 256 | 1.5.0/docs/api/java/lang/String.html">String type = null; |
1554 | jmachado | 257 | boolean usePercentageColor = false; |
258 | 1.5.0/docs/api/java/lang/String.html">String backgroundColor = ""; |
||
1565 | jmachado | 259 | 1.5.0/docs/api/java/lang/String.html">String backgroundColorPercentage = ""; |
1567 | jmachado | 260 | 1.5.0/docs/api/java/lang/String.html">String fontWeight = ""; |
261 | int colspan = 0; |
||
1553 | jmachado | 262 | |
1568 | jmachado | 263 | public 1.5.0/docs/api/java/lang/String.html">String getWidth() { |
264 | return width; |
||
265 | } |
||
266 | |||
267 | public void setWidth(1.5.0/docs/api/java/lang/String.html">String width) { |
||
268 | this.width = width; |
||
269 | } |
||
270 | |||
1567 | jmachado | 271 | public 1.5.0/docs/api/java/lang/String.html">String getFontWeight() { |
272 | return fontWeight; |
||
273 | } |
||
1554 | jmachado | 274 | |
1567 | jmachado | 275 | public void setFontWeight(1.5.0/docs/api/java/lang/String.html">String fontWeight) { |
276 | this.fontWeight = fontWeight; |
||
277 | } |
||
278 | |||
279 | public int getColspan() { |
||
280 | return colspan; |
||
281 | } |
||
282 | |||
283 | public void setColspan(int colspan) { |
||
284 | this.colspan = colspan; |
||
285 | } |
||
286 | |||
1554 | jmachado | 287 | public 1.5.0/docs/api/java/lang/String.html">String getBackgroundColor() { |
288 | return backgroundColor; |
||
289 | } |
||
290 | |||
291 | public void setBackgroundColor(1.5.0/docs/api/java/lang/String.html">String backgroundColor) { |
||
292 | this.backgroundColor = backgroundColor; |
||
293 | } |
||
294 | |||
1565 | jmachado | 295 | public 1.5.0/docs/api/java/lang/String.html">String getBackgroundColorPercentage() { |
296 | return backgroundColorPercentage; |
||
297 | } |
||
298 | |||
299 | public void setBackgroundColorPercentage(1.5.0/docs/api/java/lang/String.html">String backgroundColorPercentage) { |
||
300 | this.backgroundColorPercentage = backgroundColorPercentage; |
||
301 | } |
||
302 | |||
1553 | jmachado | 303 | public void setAlignLeft() { align = "left"; } |
304 | public void setAlignRight() { align = "right"; } |
||
305 | public void setAlignCenter() { align = "center"; } |
||
306 | public void setTypeNumber() { type = "number"; } |
||
307 | public void setTypeText() { type = "text"; } |
||
308 | public void setTypePercentage() { type = "percentage"; } |
||
1554 | jmachado | 309 | public void setTypePercentageDefined() { type = "percentageDefined"; } |
1553 | jmachado | 310 | public void setTypeLabel() { type = "label"; } |
311 | |||
1554 | jmachado | 312 | public boolean isUsePercentageColor() { |
313 | return usePercentageColor; |
||
314 | } |
||
315 | |||
1565 | jmachado | 316 | public void setUsePercentageColor(boolean usePercentageColor) |
317 | { |
||
1554 | jmachado | 318 | this.usePercentageColor = usePercentageColor; |
1565 | jmachado | 319 | //new Approach for percentage color using degrade |
320 | if(usePercentageColor) |
||
321 | { |
||
322 | 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(",",".")); |
||
323 | percentage = percentage / 100.0; |
||
324 | |||
1567 | jmachado | 325 | setBackgroundColorPercentage(getColorGradientForPercentage(percentage)); |
1565 | jmachado | 326 | } |
327 | |||
1554 | jmachado | 328 | } |
329 | |||
1553 | jmachado | 330 | public 1.5.0/docs/api/java/lang/String.html">String getValue() { return value; } |
331 | public void setValue(1.5.0/docs/api/java/lang/String.html">String value) { this.value = value; } |
||
1554 | jmachado | 332 | |
333 | public 1.5.0/docs/api/java/lang/String.html">String getPercentDefined() { |
||
334 | return percentDefined; |
||
335 | } |
||
336 | |||
1565 | jmachado | 337 | public void setPercentDefined(1.5.0/docs/api/java/lang/String.html">String percentDefined) { |
338 | if(percentDefined.contains(".")) |
||
339 | this.percentDefined = percentDefined.substring(0,percentDefined.indexOf(".")); |
||
340 | else if(percentDefined.contains(",")) |
||
341 | this.percentDefined = percentDefined.substring(0,percentDefined.indexOf(",")); |
||
1554 | jmachado | 342 | this.percentDefined = percentDefined; |
343 | } |
||
1553 | jmachado | 344 | } |
345 | } |
||
346 | |||
1567 | jmachado | 347 | /** |
348 | * |
||
349 | * @param percentageDecimal between 0 and 1 |
||
350 | * @return |
||
351 | */ |
||
352 | public static 1.5.0/docs/api/java/lang/String.html">String getColorGradientForPercentage(double percentageDecimal) |
||
353 | { |
||
354 | if(percentageDecimal < 0.5) |
||
355 | { |
||
356 | int green = ChartBuilderUtil.getGreenComponentGradient(percentageDecimal); |
||
357 | return "rgb(255," + green + ",0)"; |
||
358 | } |
||
359 | else |
||
360 | { |
||
361 | |||
362 | int red = ChartBuilderUtil.getRedComponentGradient(percentageDecimal); |
||
363 | //int red = (int) (255.0*((1.0-percentageDecimal)*2)); |
||
364 | return "rgb(" + red + ",255,0)"; |
||
365 | } |
||
366 | } |
||
367 | |||
368 | |||
369 | |||
1553 | jmachado | 370 | 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 { |
371 | 1.5.0/docs/api/java/io/ByteArrayOutputStream.html">ByteArrayOutputStream out = new 1.5.0/docs/api/java/io/ByteArrayOutputStream.html">ByteArrayOutputStream(); |
||
372 | //fos1 = new FileOutputStream("/Volumes/Home/jorgemachado/Desktop/docenteReport.xml"); |
||
373 | 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); |
||
374 | |||
375 | |||
376 | xe1.writeObject(this); |
||
377 | xe1.flush(); |
||
378 | xe1.close(); |
||
379 | //Dom4jUtil.writeSout(Dom4jUtil.parse(out.toString())); |
||
380 | return Dom4jUtil.toW3c(Dom4jUtil.parse(out.toString())); |
||
381 | |||
382 | } |
||
383 | |||
384 | } |