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.Iterator;
27 import java.util.List;
28
29 /**
30 * Represents a data table for a report. Columns may be added to the table.
31 * Values can be added to the columns. Finally, the table can be rendered
32 * as HTML.
33 *
34 * @author Richard Cyganiak <rcyg@gmx.de>
35 * @version $Id: Table.java,v 1.2 2008/04/02 11:22:14 benoitx Exp $
36 */
37 public class Table {
38
39 private final String summary;
40 private boolean keysInFirstColumn = false;
41 private boolean showTotals = false;
42 private final List columns = new ArrayList();
43
44 /**
45 * Creates a new table model
46 * @param summary a short summary of the table data, intended for
47 * non-visual web browsers
48 */
49 public Table(final String summary) {
50 this.summary = summary;
51 }
52
53 /**
54 * set if the first column contains keys that identify each row
55 * @param enabled <tt>true</tt> if first column contains keys
56 */
57 public void setKeysInFirstColumn(final boolean enabled) {
58 keysInFirstColumn = enabled;
59 }
60
61 /**
62 * Returns if the first column contains keys that identify each row
63 * @return <tt>true</tt> if first column contains keys
64 */
65 public boolean hasKeysInFirstColumn() {
66 return keysInFirstColumn;
67 }
68
69 /**
70 * set if totals of each column should be shown
71 * @param enabled <tt>true</tt> if totals should be shown
72 */
73 public void setShowTotals(final boolean enabled) {
74 showTotals = enabled;
75 }
76
77 /**
78 * Returns if totals of each column should be shown
79 * @return <tt>true</tt> if so
80 */
81 public boolean showTotals() {
82 return showTotals;
83 }
84
85 /**
86 * Returns the summary text of the table. This is intended for non-visual
87 * web browsers.
88 * @return the table summary
89 */
90 public String getSummary() {
91 return summary;
92 }
93
94 /**
95 * Returns the number of data rows in the table.
96 * @return number of data rows in the table
97 */
98 public int getRowCount() {
99 int result = 0;
100 final Iterator it = columns.iterator();
101 while (it.hasNext()) {
102 final Column column = (Column) it.next();
103 if (column.getRows() > result) {
104 result = column.getRows();
105 }
106 }
107 return result;
108 }
109
110 /**
111 * Adds a column to the table
112 * @param column the column
113 */
114 public void addColumn(final Column column) {
115 columns.add(column);
116 }
117
118 /**
119 * Returns an iterator of all {@link Column} objects of the table
120 * @return an iterator of Columns
121 */
122 public Iterator getColumnIterator() {
123 return columns.iterator();
124 }
125 }