KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ca > commons > cbutil > CBTableMap


1 package com.ca.commons.cbutil;
2
3 /**
4  * In a chain of data manipulators some behaviour is common. TableMap
5  * provides most of this behavour and can be subclassed by filters
6  * that only need to override a handful of specific methods. TableMap
7  * implements TableModel by routing all requests to its model, and
8  * TableModelListener by routing all events to its listeners. Inserting
9  * a TableMap which has not been subclassed into a chain of table filters
10  * should have no effect.
11  *
12  * @version 1.4 12/17/97
13  * @author Philip Milne http:
14  * //java.sun.com/docs/books/tutorial/uiswing/components/table.html#eg
15  */

16
17 import javax.swing.event.TableModelEvent JavaDoc;
18 import javax.swing.event.TableModelListener JavaDoc;
19 import javax.swing.table.AbstractTableModel JavaDoc;
20 import javax.swing.table.TableModel JavaDoc;
21
22 public class CBTableMap extends AbstractTableModel JavaDoc
23         implements TableModelListener JavaDoc
24 {
25     protected TableModel JavaDoc model;
26
27     public TableModel JavaDoc getModel()
28     {
29         return model;
30     }
31
32     public void setModel(TableModel JavaDoc model)
33     {
34         this.model = model;
35         model.addTableModelListener(this);
36     }
37
38     // By default, implement TableModel by forwarding all messages
39
// to the model.
40

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