2
2
3
3
import java .util .HashMap ;
4
4
import java .util .Map ;
5
+ import java .util .Objects ;
5
6
6
7
/**
7
8
* This a class which represents the formatting of a cell (background color, font size, font style, etc...)
@@ -16,7 +17,8 @@ public final class Style implements Cloneable {
16
17
private int fontSize = -1 ;
17
18
private Borders borders = null ;
18
19
private boolean wrap = false ;
19
- private TEXT_ALIGMENT alignment = null ;
20
+ private TEXT_ALIGMENT horizontal_alignment = null ;
21
+ private VERTICAL_TEXT_ALIGMENT vertical_alignment = null ;
20
22
private boolean isDate = false ;
21
23
22
24
/** Defines the text position of a Cell
@@ -25,6 +27,10 @@ public enum TEXT_ALIGMENT {
25
27
Left , Center , Right
26
28
}
27
29
30
+ public enum VERTICAL_TEXT_ALIGMENT {
31
+ Top , Middle , Bottom
32
+ }
33
+
28
34
/**
29
35
* Constructs an empty-default Style.
30
36
*/
@@ -219,7 +225,7 @@ public void setWrap(boolean wrap) {
219
225
* @return true if the style has table cell properties, false otherwise.
220
226
*/
221
227
public boolean hasTableCellProperties () {
222
- return backgroundColor != null || hasBorders () || wrap ;
228
+ return backgroundColor != null || hasBorders () || wrap || vertical_alignment != null ;
223
229
}
224
230
225
231
/**
@@ -236,17 +242,24 @@ public boolean hasBorders() {
236
242
* @param p {@link TEXT_ALIGMENT} Left, Center, Right
237
243
*/
238
244
public void setTextAligment (TEXT_ALIGMENT p ) {
239
- alignment = p ;
245
+ horizontal_alignment = p ;
240
246
}
241
247
242
248
/**
243
249
* Get text aligment of the cell
244
250
* @return p {@link TEXT_ALIGMENT} Left, Center, Right
245
251
*/
246
252
public TEXT_ALIGMENT getTextAligment () {
247
- return alignment ;
253
+ return horizontal_alignment ;
254
+ }
255
+
256
+
257
+ public void setVerticalTextAligment (VERTICAL_TEXT_ALIGMENT p ) {
258
+ vertical_alignment = p ;
248
259
}
249
260
261
+ public VERTICAL_TEXT_ALIGMENT getVerticalTextAligment () { return vertical_alignment ;}
262
+
250
263
public Object clone () throws CloneNotSupportedException {
251
264
return super .clone ();
252
265
}
@@ -272,14 +285,17 @@ public boolean equals(Object o) {
272
285
if (italic != style .italic ) return false ;
273
286
if (underline != style .underline ) return false ;
274
287
if (fontSize != style .fontSize ) return false ;
275
- if (borders != null ? ! borders .equals (style . borders ) : style .borders != null ) return false ;
288
+ if (! Objects .equals (borders , style .borders ) ) return false ;
276
289
if (wrap != style .wrap ) return false ;
277
- if (fontColor != null ? ! fontColor .equals (style . fontColor ) : style .fontColor != null ) return false ;
278
- if (backgroundColor != null ? ! backgroundColor .equals (style . backgroundColor ) : style .backgroundColor != null )
290
+ if (! Objects .equals (fontColor , style .fontColor ) ) return false ;
291
+ if (! Objects .equals (backgroundColor , style .backgroundColor ) )
279
292
return false ;
280
293
if (isDate != style .isDate )
281
294
return false ;
282
- return alignment == style .alignment ;
295
+ if (horizontal_alignment != style .horizontal_alignment )
296
+ return false ;
297
+
298
+ return vertical_alignment == style .vertical_alignment ;
283
299
}
284
300
285
301
@ Override
@@ -293,7 +309,8 @@ public int hashCode() {
293
309
result = 31 * result + (borders != null ? borders .hashCode () : 0 );
294
310
result = 31 * result + (wrap ? 1 : 0 );
295
311
result = 31 * result + (isDate ? 1 : 0 );
296
- result = 31 * result + (alignment != null ? alignment .hashCode () : 0 );
312
+ result = 31 * result + (horizontal_alignment != null ? horizontal_alignment .hashCode () : 0 );
313
+ result = 31 * result + (vertical_alignment != null ? vertical_alignment .hashCode () : 0 );
297
314
return result ;
298
315
}
299
316
@@ -341,9 +358,12 @@ public Map<String, String> getCssStyles()
341
358
result .put ("white-space" , "normal" );
342
359
}
343
360
344
- if (alignment != null )
361
+ if (horizontal_alignment != null )
345
362
result .put ("text-align" , getTextAligment ().toString ());
346
363
364
+ if (vertical_alignment != null )
365
+ result .put ("vertical-align" , getVerticalTextAligment ().toString ().toLowerCase ());
366
+
347
367
return result ;
348
368
}
349
369
0 commit comments