Rev 1553 | Rev 1563 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1553 | jmachado | 1 | package pt.estgp.estgweb.services.questionarios.pedagogico; |
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 | |||
69 | public Row() { |
||
70 | setCols(new ArrayList<Col>()); |
||
71 | } |
||
72 | |||
73 | public void setCols(ArrayList<Col> cols) { |
||
74 | this.cols = cols; |
||
75 | } |
||
76 | |||
77 | public void setTypeNormal() { type = "normal"; } |
||
78 | public void setTypeHeader() { type = "header"; } |
||
79 | public void setTypeFooter() { type = "footer"; } |
||
80 | |||
81 | public Col addCol() |
||
82 | { |
||
83 | Col col = new Col(); |
||
84 | cols.add(col); |
||
85 | return col; |
||
86 | } |
||
87 | |||
88 | public Col addColNumberLeft(1.5.0/docs/api/java/lang/String.html">String value) |
||
89 | { Col col = new Col(value); |
||
90 | col.setTypeNumber(); |
||
91 | col.setAlignLeft(); |
||
92 | cols.add(col); |
||
93 | return col; |
||
94 | } |
||
95 | public Col addColNumberRight(1.5.0/docs/api/java/lang/String.html">String value) |
||
96 | { Col col = new Col(); |
||
97 | col.setTypeNumber(); |
||
98 | col.setAlignRight(); |
||
99 | cols.add(col); |
||
100 | return col; |
||
101 | } |
||
102 | public Col addColNumberCenter(1.5.0/docs/api/java/lang/String.html">String value) |
||
103 | { Col col = new Col(value); |
||
104 | col.setTypeNumber(); |
||
105 | col.setAlignCenter(); |
||
106 | cols.add(col); |
||
107 | return col; |
||
108 | } |
||
109 | |||
110 | public Col addColTextLeft(1.5.0/docs/api/java/lang/String.html">String value) |
||
111 | { Col col = new Col(value); |
||
112 | col.setTypeText(); |
||
113 | col.setAlignLeft(); |
||
114 | cols.add(col); |
||
115 | return col; |
||
116 | } |
||
117 | public Col addColTextRight(1.5.0/docs/api/java/lang/String.html">String value) |
||
118 | { Col col = new Col(value); |
||
119 | col.setTypeText(); |
||
120 | col.setAlignRight(); |
||
121 | cols.add(col); |
||
122 | return col; |
||
123 | } |
||
124 | public Col addColTextCenter(1.5.0/docs/api/java/lang/String.html">String value) |
||
125 | { Col col = new Col(value); |
||
126 | col.setTypeText(); |
||
127 | col.setAlignCenter(); |
||
128 | cols.add(col); |
||
129 | return col; |
||
130 | } |
||
131 | |||
132 | public Col addColPercentageLeft(1.5.0/docs/api/java/lang/String.html">String value) |
||
133 | { Col col = new Col(value); |
||
134 | col.setTypePercentage(); |
||
135 | col.setAlignLeft(); |
||
136 | cols.add(col); |
||
137 | return col; |
||
138 | } |
||
139 | public Col addColPercentageRight(1.5.0/docs/api/java/lang/String.html">String value) |
||
140 | { Col col = new Col(value); |
||
141 | col.setTypePercentage(); |
||
142 | col.setAlignRight(); |
||
143 | cols.add(col); |
||
144 | return col; |
||
145 | } |
||
146 | public Col addColPercentageCenter(1.5.0/docs/api/java/lang/String.html">String value) |
||
147 | { Col col = new Col(value); |
||
148 | col.setTypePercentage(); |
||
149 | col.setAlignCenter(); |
||
150 | cols.add(col); |
||
151 | return col; |
||
152 | } |
||
1554 | jmachado | 153 | |
154 | public Col addColPercentageLeft(1.5.0/docs/api/java/lang/String.html">String value,boolean usePercentageColors) |
||
155 | { Col col = new Col(value); |
||
156 | col.setTypePercentage(); |
||
157 | col.setAlignLeft(); |
||
158 | col.setUsePercentageColor(usePercentageColors); |
||
159 | cols.add(col); |
||
160 | return col; |
||
161 | } |
||
162 | public Col addColPercentageRight(1.5.0/docs/api/java/lang/String.html">String value,boolean usePercentageColors) |
||
163 | { Col col = new Col(value); |
||
164 | col.setTypePercentage(); |
||
165 | col.setAlignRight(); |
||
166 | col.setUsePercentageColor(usePercentageColors); |
||
167 | cols.add(col); |
||
168 | return col; |
||
169 | } |
||
170 | public Col addColPercentageCenter(1.5.0/docs/api/java/lang/String.html">String value,boolean usePercentageColors) |
||
171 | { Col col = new Col(value); |
||
172 | col.setTypePercentage(); |
||
173 | col.setAlignCenter(); |
||
174 | col.setUsePercentageColor(usePercentageColors); |
||
175 | cols.add(col); |
||
176 | return col; |
||
177 | } |
||
178 | |||
179 | |||
180 | 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) |
||
181 | { Col col = new Col(value); |
||
182 | col.setPercentDefined(percent); |
||
183 | col.setTypePercentageDefined(); |
||
184 | col.setAlignLeft(); |
||
185 | col.setUsePercentageColor(usePercentageColors); |
||
186 | cols.add(col); |
||
187 | return col; |
||
188 | } |
||
189 | 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) |
||
190 | { Col col = new Col(value); |
||
191 | col.setPercentDefined(percent); |
||
192 | col.setTypePercentageDefined(); |
||
193 | col.setAlignRight(); |
||
194 | col.setUsePercentageColor(usePercentageColors); |
||
195 | cols.add(col); |
||
196 | return col; |
||
197 | } |
||
198 | 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) |
||
199 | { Col col = new Col(value); |
||
200 | col.setPercentDefined(percent); |
||
201 | col.setTypePercentageDefined(); |
||
202 | col.setAlignCenter(); |
||
203 | col.setUsePercentageColor(usePercentageColors); |
||
204 | cols.add(col); |
||
205 | return col; |
||
206 | } |
||
207 | |||
208 | |||
1553 | jmachado | 209 | public Col addColLabelLeft(1.5.0/docs/api/java/lang/String.html">String value) |
210 | { Col col = new Col(value); |
||
211 | col.setTypeLabel(); |
||
212 | col.setAlignLeft(); |
||
213 | cols.add(col); |
||
214 | return col; |
||
215 | } |
||
216 | public Col addColLabelRight(1.5.0/docs/api/java/lang/String.html">String value) |
||
217 | { Col col = new Col(value); |
||
218 | col.setTypeLabel(); |
||
219 | col.setAlignRight(); |
||
220 | cols.add(col); |
||
221 | return col; |
||
222 | } |
||
223 | public Col addColLabelCenter(1.5.0/docs/api/java/lang/String.html">String value) |
||
224 | { Col col = new Col(value); |
||
225 | col.setTypeLabel(); |
||
226 | col.setAlignCenter(); |
||
227 | cols.add(col); |
||
228 | return col; |
||
229 | } |
||
230 | |||
231 | public 1.5.0/docs/api/java/lang/String.html">String getType() { return type; } |
||
232 | public ArrayList<Col> getCols() { return cols; } |
||
233 | |||
234 | public void setType(1.5.0/docs/api/java/lang/String.html">String type) { |
||
235 | this.type = type; |
||
236 | } |
||
237 | |||
238 | |||
239 | public static class Col implements 1.5.0/docs/api/java/io/Serializable.html">Serializable |
||
240 | { |
||
241 | public Col(1.5.0/docs/api/java/lang/String.html">String value) { |
||
242 | this.value = value; |
||
243 | } |
||
244 | public Col() { |
||
245 | } |
||
246 | |||
247 | //center, left, right |
||
248 | 1.5.0/docs/api/java/lang/String.html">String align = null; |
||
249 | 1.5.0/docs/api/java/lang/String.html">String value = null; |
||
1554 | jmachado | 250 | 1.5.0/docs/api/java/lang/String.html">String percentDefined = null; |
251 | //number, percentage, percentageDefined, text, label |
||
1553 | jmachado | 252 | 1.5.0/docs/api/java/lang/String.html">String type = null; |
1554 | jmachado | 253 | boolean usePercentageColor = false; |
254 | 1.5.0/docs/api/java/lang/String.html">String backgroundColor = ""; |
||
1553 | jmachado | 255 | |
1554 | jmachado | 256 | |
257 | public 1.5.0/docs/api/java/lang/String.html">String getBackgroundColor() { |
||
258 | return backgroundColor; |
||
259 | } |
||
260 | |||
261 | public void setBackgroundColor(1.5.0/docs/api/java/lang/String.html">String backgroundColor) { |
||
262 | this.backgroundColor = backgroundColor; |
||
263 | } |
||
264 | |||
1553 | jmachado | 265 | public void setAlignLeft() { align = "left"; } |
266 | public void setAlignRight() { align = "right"; } |
||
267 | public void setAlignCenter() { align = "center"; } |
||
268 | public void setTypeNumber() { type = "number"; } |
||
269 | public void setTypeText() { type = "text"; } |
||
270 | public void setTypePercentage() { type = "percentage"; } |
||
1554 | jmachado | 271 | public void setTypePercentageDefined() { type = "percentageDefined"; } |
1553 | jmachado | 272 | public void setTypeLabel() { type = "label"; } |
273 | |||
1554 | jmachado | 274 | public boolean isUsePercentageColor() { |
275 | return usePercentageColor; |
||
276 | } |
||
277 | |||
278 | public void setUsePercentageColor(boolean usePercentageColor) { |
||
279 | this.usePercentageColor = usePercentageColor; |
||
280 | } |
||
281 | |||
1553 | jmachado | 282 | public 1.5.0/docs/api/java/lang/String.html">String getValue() { return value; } |
283 | public void setValue(1.5.0/docs/api/java/lang/String.html">String value) { this.value = value; } |
||
1554 | jmachado | 284 | |
285 | public 1.5.0/docs/api/java/lang/String.html">String getPercentDefined() { |
||
286 | return percentDefined; |
||
287 | } |
||
288 | |||
289 | public void setPercentDefined(1.5.0/docs/api/java/lang/String.html">String percentDefined) { |
||
290 | this.percentDefined = percentDefined; |
||
291 | } |
||
1553 | jmachado | 292 | } |
293 | } |
||
294 | |||
295 | 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 { |
||
296 | 1.5.0/docs/api/java/io/ByteArrayOutputStream.html">ByteArrayOutputStream out = new 1.5.0/docs/api/java/io/ByteArrayOutputStream.html">ByteArrayOutputStream(); |
||
297 | //fos1 = new FileOutputStream("/Volumes/Home/jorgemachado/Desktop/docenteReport.xml"); |
||
298 | 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); |
||
299 | |||
300 | |||
301 | xe1.writeObject(this); |
||
302 | xe1.flush(); |
||
303 | xe1.close(); |
||
304 | //Dom4jUtil.writeSout(Dom4jUtil.parse(out.toString())); |
||
305 | return Dom4jUtil.toW3c(Dom4jUtil.parse(out.toString())); |
||
306 | |||
307 | } |
||
308 | |||
309 | } |