1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sf.statcvs.reportmodel;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import net.sf.statcvs.renderer.TableCellRenderer;
29
30 /**
31 * A generic column with a text header and a text total. Each cell contains
32 * an <tt>Object</tt>. The renderCell method must be implemented by subclasses.
33 *
34 * @author Richard Cyganiak <rcyg@gmx.de>
35 * @version $Id: GenericColumn.java,v 1.2 2008/04/02 11:22:14 benoitx Exp $
36 */
37 public abstract class GenericColumn extends Column {
38
39 private final String title;
40 private final List values = new ArrayList();
41 private String total = null;
42
43 /**
44 * Creates a new <tt>GenericColumn</tt> with the given head
45 * @param title the head of the column
46 */
47 public GenericColumn(final String title) {
48 this.title = title;
49 }
50
51 /**
52 * Sets the total for this column
53 * @param value the total for this column
54 */
55 public void setTotal(final String value) {
56 this.total = value;
57 }
58
59 /**
60 * Adds a value to this column (in a new row)
61 * @param value the new value
62 */
63 public void addValue(final Object value) {
64 values.add(value);
65 }
66
67 /**
68 * Returns a value of the column
69 * @param rowIndex the row, starting at 0
70 * @return the value
71 */
72 public Object getValue(final int rowIndex) {
73 return values.get(rowIndex);
74 }
75
76 /**
77 * @see net.sf.statcvs.reportmodel.Column#getRows()
78 */
79 public int getRows() {
80 return values.size();
81 }
82
83 /**
84 * @see net.sf.statcvs.reportmodel.Column#renderHead(net.sf.statcvs.renderer.TableCellRenderer)
85 */
86 public void renderHead(final TableCellRenderer renderer) {
87 renderer.renderCell(title);
88 }
89
90 /**
91 * @see net.sf.statcvs.reportmodel.Column#renderCell
92 */
93 public abstract void renderCell(int rowIndex, TableCellRenderer renderer);
94
95 /**
96 * @see net.sf.statcvs.reportmodel.Column#renderTotal
97 */
98 public void renderTotal(final TableCellRenderer renderer) {
99 if (total == null) {
100 renderer.renderEmptyCell();
101 } else {
102 renderer.renderCell(total);
103 }
104 }
105 }