KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mc4j > console > swing > table > TableMap


1 /*
2  * Copyright 2002-2004 Greg Hinkle
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.mc4j.console.swing.table;
18
19 import javax.swing.event.TableModelEvent JavaDoc;
20 import javax.swing.event.TableModelListener JavaDoc;
21 import javax.swing.table.AbstractTableModel JavaDoc;
22 import javax.swing.table.TableModel JavaDoc;
23
24
25 /**
26  * In a chain of data manipulators some behaviour is common. TableMap
27  * provides most of this behaviour and can be subclassed by filters
28  * that only need to override a handful of specific methods. TableMap
29  * implements TableModel by routing all requests to its model, and
30  * TableModelListener by routing all events to its listeners. Inserting
31  * a TableMap which has not been subclassed into a chain of table filters
32  * should have no effect.
33  *
34  * @version 1.4 12/17/97
35  * @author Philip Milne
36  */

37 public class TableMap extends AbstractTableModel JavaDoc
38                       implements TableModelListener JavaDoc {
39     protected TableModel JavaDoc model;
40
41     public TableModel JavaDoc getModel() {
42         return model;
43     }
44
45     public void setModel(TableModel JavaDoc model) {
46         this.model = model;
47         model.addTableModelListener(this);
48     }
49
50     // By default, implement TableModel by forwarding all messages
51
// to the model.
52

53     public Object JavaDoc getValueAt(int aRow, int aColumn) {
54         return model.getValueAt(aRow, aColumn);
55     }
56
57     public void setValueAt(Object JavaDoc aValue, int aRow, int aColumn) {
58         model.setValueAt(aValue, aRow, aColumn);
59     }
60
61     public int getRowCount() {
62         return (model == null) ? 0 : model.getRowCount();
63     }
64
65     public int getColumnCount() {
66         return (model == null) ? 0 : model.getColumnCount();
67     }
68
69     public String JavaDoc getColumnName(int aColumn) {
70         return model.getColumnName(aColumn);
71     }
72
73     public Class JavaDoc getColumnClass(int aColumn) {
74         return model.getColumnClass(aColumn);
75     }
76
77     public boolean isCellEditable(int row, int column) {
78          return model.isCellEditable(row, column);
79     }
80 //
81
// Implementation of the TableModelListener interface,
82
//
83
// By default forward all events to all the listeners.
84
public void tableChanged(TableModelEvent JavaDoc e) {
85         fireTableChanged(e);
86     }
87 }
88
Popular Tags