| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| GenericColumn |
|
| 1.125;1.125 |
| 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: GenericColumn.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.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 | 0 | private final List values = new ArrayList(); |
| 41 | 0 | 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 | 0 | public GenericColumn(final String title) { |
| 48 | 0 | this.title = title; |
| 49 | 0 | } |
| 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 | 0 | this.total = value; |
| 57 | 0 | } |
| 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 | 0 | values.add(value); |
| 65 | 0 | } |
| 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 | 0 | return values.get(rowIndex); |
| 74 | } | |
| 75 | ||
| 76 | /** | |
| 77 | * @see net.sf.statcvs.reportmodel.Column#getRows() | |
| 78 | */ | |
| 79 | public int getRows() { | |
| 80 | 0 | 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 | 0 | renderer.renderCell(title); |
| 88 | 0 | } |
| 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 | 0 | if (total == null) { |
| 100 | 0 | renderer.renderEmptyCell(); |
| 101 | } else { | |
| 102 | 0 | renderer.renderCell(total); |
| 103 | } | |
| 104 | 0 | } |
| 105 | } |