Source code: javatools/swing/table/IndexedTableMap.java
1 /*
2 * IndexedTableMap.java
3 *
4 * Created on 11 maggio 2002, 11.52
5 Javatools (modified version) - Some useful general classes.
6 Copyright (C) 2002-2003 Chris Bitmead (original) Antonio Petrelli (modified)
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22 Contact me at: brenmcguire@users.sourceforge.net
23 */
24
25 package javatools.swing.table;
26
27 /**
28 *
29 * @author Antonio Petrelli
30 * @version 0.1.7
31 */
32 import javax.swing.table.*;
33 import javax.swing.event.TableModelListener;
34 import javax.swing.event.TableModelEvent;
35
36 /** A base table for IndexedTableSorter. The constructor does nothing but the
37 * default actions.
38 */
39 public class IndexedTableMap extends AbstractTableModel
40 implements TableModelListener {
41
42 /** Returns the model inside.
43 * @return The used model.
44 */
45 public TableModel getModel() {
46 return model;
47 }
48
49 /** Sets the model to use.
50 * @param model The model to use.
51 */
52 public void setModel(IndexedTableModel model) {
53 this.model = model;
54 model.addTableModelListener(this);
55 }
56
57 // By default, implement TableModel by forwarding all messages
58 // to the model.
59
60 /** Returns the value in the table.
61 * @param aRow The row index.
62 * @param aColumn The column index.
63 * @return The value.
64 */
65 public Object getValueAt(int aRow, int aColumn) {
66 return model.getValueAt(aRow, aColumn);
67 }
68
69 /** Returns an index.
70 * @param row The row index.
71 * @throws ArrayIndexOutOfBoundsException If <CODE>row</CODE> is not correct.
72 * @return The index.
73 */
74 public Object getIndex(int row) throws ArrayIndexOutOfBoundsException {
75 return model.getIndex(row);
76 }
77
78 /** Sets a value in the table.
79 * @param aValue The value.
80 * @param aRow The row index.
81 * @param aColumn The column index.
82 */
83 public void setValueAt(Object aValue, int aRow, int aColumn) {
84 model.setValueAt(aValue, aRow, aColumn);
85 }
86
87 /** Sets an index.
88 * @param row The row index.
89 * @param index The index to put.
90 * @throws ArrayIndexOutOfBoundsException If <CODE>row</CODE> is not correct.
91 */
92 public void setIndex(int row, Object index) throws ArrayIndexOutOfBoundsException {
93 model.setIndex(row, index);
94 }
95
96 /** Returns the number of contained rows.
97 * @return The row count.
98 */
99 public int getRowCount() {
100 return (model == null) ? 0 : model.getRowCount();
101 }
102
103 /** Returns the number of contained columns.
104 * @return The column count.
105 */
106 public int getColumnCount() {
107 return (model == null) ? 0 : model.getColumnCount();
108 }
109
110 /** Returns a column name.
111 * @param aColumn The column index.
112 * @return The name.
113 */
114 public String getColumnName(int aColumn) {
115 return model.getColumnName(aColumn);
116 }
117
118 /** Returns a column class.
119 * @param aColumn The column index.
120 * @return The class.
121 */
122 public Class getColumnClass(int aColumn) {
123 return model.getColumnClass(aColumn);
124 }
125
126 /** Checks if a cell is editable.
127 * @param row The row index.
128 * @param column The column index.
129 * @return <CODE>true</CODE>: the cell is editable;
130 * <CODE>false</CODE>: the cell is NOT editable.
131 */
132 public boolean isCellEditable(int row, int column) {
133 return model.isCellEditable(row, column);
134 }
135 //
136 // Implementation of the TableModelListener interface,
137 //
138 // By default forward all events to all the listeners.
139 /** Method called whenever table changes.
140 * @param e The event.
141 */
142 public void tableChanged(TableModelEvent e) {
143 fireTableChanged(e);
144 }
145
146 /** The model to use.
147 */
148 protected IndexedTableModel model;
149
150 }