001: /*
002: ** $Id: VectorTableModel.java,v 1.4 2000/10/26 08:34:15 mrw Exp $
003: **
004: ** Mike Wilson, July 2000, mrw@whisperingwind.co.uk
005: **
006: ** (C) Copyright 2000, Mike Wilson, Reading, Berkshire, UK
007: **
008: ** This program is free software; you can redistribute it and/or modify
009: ** it under the terms of the GNU General Public License as published by
010: ** the Free Software Foundation; either version 2 of the License, or
011: ** (at your option) any later version.
012: **
013: ** This program is distributed in the hope that it will be useful,
014: ** but WITHOUT ANY WARRANTY; without even the implied warranty of
015: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: ** GNU General Public License for more details.
017: **
018: ** You should have received a copy of the GNU Library General
019: ** Public License along with this library; if not, write to the
020: ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
021: ** Boston, MA 02111-1307 USA.
022: */
023:
024: package uk.co.whisperingwind.framework;
025:
026: import javax.swing.table.AbstractTableModel;
027: import java.util.Vector;
028: import javax.swing.event.TableModelListener;
029:
030: /**
031: ** Base class for models that are used to populate a JTable. Uses a
032: ** Vector to hold the data for the table. Also handles a list of
033: ** column names and optionally a list of widths.
034: */
035:
036: public class VectorTableModel extends AbstractTableModel {
037: protected Vector names = null;
038: protected Vector widths = null;
039: protected Vector rows = null;
040:
041: public VectorTableModel() {
042: names = new Vector();
043: widths = new Vector();
044: rows = new Vector();
045: }
046:
047: public Class getColumnClass(int columnIndex) {
048: return String.class;
049: }
050:
051: public int getColumnCount() {
052: return names.size();
053: }
054:
055: public String getColumnName(int columnIndex) {
056: return (String) names.get(columnIndex);
057: }
058:
059: public int getColumnWidth(int columnIndex) {
060: return ((Integer) widths.get(columnIndex)).intValue();
061: }
062:
063: public int getTitleWidth(int columnIndex) {
064: return ((String) names.get(columnIndex)).length();
065: }
066:
067: public int getRowCount() {
068: return rows.size();
069: }
070:
071: public Object getValueAt(int rowIndex, int columnIndex) {
072: return ((Vector) rows.get(rowIndex)).get(columnIndex);
073: }
074:
075: public boolean isCellEditable(int rowIndex, int columnIndex) {
076: return false;
077: }
078:
079: public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
080: }
081:
082: public void addName(String name, int width) {
083: names.add(name);
084: widths.add(new Integer(width));
085: }
086:
087: public Vector addRow() {
088: Vector row = new Vector();
089: rows.add(row);
090:
091: return row;
092: }
093:
094: public void clear() {
095: names.clear();
096: widths.clear();
097: rows.clear();
098: fireTableDataChanged();
099: }
100: }
|