Source code: cor/gui/JspmTableMap.java
1 /*-----------------------------------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (C) */
4 /* */
5 /* This program is free software; you can redistribute it and/or modify it under the terms of the GNU */
6 /* General Public License as published by the Free Software Foundation; either version 2 of the */
7 /* License, or (at your option) any later version. */
8 /* */
9 /* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; */
10 /* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR */
11 /* PURPOSE. See the GNU General Public License for more details. */
12 /* */
13 /* You should have received a copy of the GNU General Public License along with this program; if */
14 /* not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA */
15 /* 02111-1307 USA */
16 /* */
17 /*-----------------------------------------------------------------------------------------------------*/
18 /* */
19 /* $Author: strand01 $ $Revision: 1.3 $ $Date: 2001/12/20 14:23:02 $ */
20 /* */
21 /*-----------------------------------------------------------------------------------------------------*/
22
23 package cor.gui;
24
25 // Swing components
26 import javax.swing.table.*;
27 import javax.swing.event.TableModelListener;
28 import javax.swing.event.TableModelEvent;
29
30 /**
31 * In a chain of data manipulators some behaviour is common. TableMap
32 * provides most of this behavour and can be subclassed by filters
33 * that only need to override a handful of specific methods. TableMap
34 * implements TableModel by routing all requests to its model, and
35 * TableModelListener by routing all events to its listeners. Inserting
36 * a TableMap which has not been subclassed into a chain of table filters
37 * should have no effect.
38 *
39 * @author Steve Randall (strand012001@yahoo.com)
40 * @version 0.0.11
41 * @date 01/12/2001
42 */
43 public class JspmTableMap extends AbstractTableModel implements TableModelListener
44 {
45 protected TableModel model;
46
47 /**
48 * Returns the table model
49 */
50 public TableModel getModel() { return model; }
51
52 /**
53 * Sets the table model
54 */
55 public void setModel(TableModel model) {
56 this.model = model;
57 model.addTableModelListener(this);
58 }
59
60 /**
61 * The value at a specific row/column
62 *
63 * By default, implement TableModel by forwarding all messages to the model.
64 */
65 public Object getValueAt(int aRow, int aColumn) { return model.getValueAt(aRow, aColumn); }
66
67 /**
68 * Sets value at a specific row/column
69 *
70 * By default, implement TableModel by forwarding all messages to the model.
71 */
72 public void setValueAt(Object aValue, int aRow, int aColumn) { model.setValueAt(aValue, aRow, aColumn); }
73
74 /**
75 * Returns the total number of rows
76 */
77 public int getRowCount() { return (model == null) ? 0 : model.getRowCount(); }
78
79 /**
80 * Returns the total number of columns
81 */
82 public int getColumnCount() { return (model == null) ? 0 : model.getColumnCount(); }
83
84 /**
85 * Return the columns name
86 */
87 public String getColumnName(int aColumn) { return model.getColumnName(aColumn); }
88
89 /**
90 * Returns the columns name
91 */
92 public Class getColumnClass(int aColumn) { return model.getColumnClass(aColumn); }
93
94 /**
95 * Return the editable flag
96 */
97 public boolean isCellEditable(int row, int column) { return model.isCellEditable(row, column); }
98
99 /**
100 * Table changed notification.
101 *
102 * By default forward all events to all the listeners.
103 */
104 public void tableChanged(TableModelEvent e) {
105 fireTableChanged(e);
106 }
107 }