001: /*
002: * SingleColumnTableModel.java
003: *
004: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021:
022: package org.underworldlabs.swing.table;
023:
024: import java.util.List;
025: import java.util.Vector;
026: import javax.swing.table.AbstractTableModel;
027:
028: /* ----------------------------------------------------------
029: * CVS NOTE: Changes to the CVS repository prior to the
030: * release of version 3.0.0beta1 has meant a
031: * resetting of CVS revision numbers.
032: * ----------------------------------------------------------
033: */
034:
035: /**
036: * Basic updateable table model with a single column.
037: *
038: * @author Takis Diakoumis
039: * @version $Revision: 1.4 $
040: * @date $Date: 2006/05/14 06:56:07 $
041: */
042: public class SingleColumnTableModel extends AbstractTableModel {
043:
044: /** the column header */
045: private String header;
046:
047: /** the data values */
048: private String[] values;
049:
050: /** Creates a new instance of SingleColumnTableModel */
051: public SingleColumnTableModel() {
052: }
053:
054: public SingleColumnTableModel(String header) {
055: this .header = header;
056: }
057:
058: public SingleColumnTableModel(String header, String[] values) {
059: this .header = header;
060: this .values = values;
061: }
062:
063: public SingleColumnTableModel(String header, Vector<String> values) {
064: this .header = header;
065: setValues(values);
066: }
067:
068: public SingleColumnTableModel(String header, List<String> values) {
069: this .header = header;
070: setValues(values);
071: }
072:
073: public void setValues(List<String> _values) {
074: values = new String[_values.size()];
075: for (int i = 0; i < values.length; i++) {
076: values[i] = _values.get(i);
077: }
078: fireTableDataChanged();
079: }
080:
081: public void setValues(Vector<String> _values) {
082: values = new String[_values.size()];
083: for (int i = 0; i < values.length; i++) {
084: values[i] = _values.elementAt(i);
085: }
086: fireTableDataChanged();
087: }
088:
089: public void setValues(String[] values) {
090: this .values = values;
091: fireTableDataChanged();
092: }
093:
094: public int getColumnCount() {
095: return 1;
096: }
097:
098: public int getRowCount() {
099: if (values == null) {
100: return 0;
101: }
102: return values.length;
103: }
104:
105: public Object getValueAt(int row, int col) {
106: if (values == null) {
107: return null;
108: }
109: return values[row];
110: }
111:
112: public String getColumnName(int col) {
113: return header;
114: }
115:
116: }
|