1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts2.components.table.renderer;
19
20 import org.apache.struts2.components.table.WebTable;
21
22
23 /***
24 * this is the base class that most renderers will be derived from.
25 * It allows setting the alignment. Subclasses should set there actuall
26 * content by implementing getCellValue
27 */
28 abstract public class AbstractCellRenderer implements CellRenderer {
29
30 /***
31 * used for horizontal cell alignmnet
32 */
33 protected String _alignment = null;
34
35
36 public void setAlignment(String alignment) {
37 _alignment = alignment;
38 }
39
40 public String getAlignment() {
41 return _alignment;
42 }
43
44 /***
45 * implememnts CellRenderer renderCell. It sets the alignment. gets the actual
46 * data from getCellValue
47 */
48 public String renderCell(WebTable table, Object data, int row, int col) {
49 if (isAligned()) {
50 StringBuffer buf = new StringBuffer(256);
51 buf.append("<div align='").append(_alignment).append("'>");
52 buf.append(getCellValue(table, data, row, col));
53 buf.append("</div>");
54
55 return buf.toString();
56 }
57
58 return getCellValue(table, data, row, col);
59 }
60
61 protected boolean isAligned() {
62 return _alignment != null;
63 }
64
65 /***
66 * this is the method that subclasses need to implement to set their value.
67 * they should not override renderCell unless they want to change the alignmnent
68 * renderering
69 */
70 abstract protected String getCellValue(WebTable table, Object data, int row, int col);
71 }