View Javadoc

1   /*
2   	StatCvs - CVS statistics generation 
3   	Copyright (C) 2002  Lukasz Pekacki <lukasz@pekacki.de>
4   	http://statcvs.sf.net/
5       
6   	This library is free software; you can redistribute it and/or
7   	modify it under the terms of the GNU Lesser General Public
8   	License as published by the Free Software Foundation; either
9   	version 2.1 of the License, or (at your option) any later version.
10  
11  	This library is distributed in the hope that it will be useful,
12  	but WITHOUT ANY WARRANTY; without even the implied warranty of
13  	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  	Lesser General Public License for more details.
15  
16  	You should have received a copy of the GNU Lesser General Public
17  	License along with this library; if not, write to the Free Software
18  	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19      
20  	$RCSfile: Table.java,v $
21  	$Date: 2008/04/02 11:22:14 $
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 }