KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > TableMap


1 package org.objectweb.jac.aspects.gui;
2
3 import javax.swing.event.TableModelEvent JavaDoc;
4 import javax.swing.event.TableModelListener JavaDoc;
5 import javax.swing.table.AbstractTableModel JavaDoc;
6 import org.apache.log4j.Logger;
7 import org.objectweb.jac.core.rtti.CollectionItem;
8 import org.objectweb.jac.core.rtti.FieldItem;
9 import org.objectweb.jac.core.rtti.MemberItem;
10
11 /**
12  * In a chain of data manipulators some behaviour is common. TableMap
13  * provides most of this behavour and can be subclassed by filters
14  * that only need to override a handful of specific methods. TableMap
15  * implements TableModel by routing all requests to its model, and
16  * TableModelListener by routing all events to its listeners. Inserting
17  * a TableMap which has not been subclassed into a chain of table filters
18  * should have no effect.
19  *
20  * @version 1.4 12/17/97
21  * @author Philip Milne */

22
23 class TableMap extends AbstractTableModel JavaDoc
24     implements TableModelListener JavaDoc, ExtendedTableModel
25 {
26     static Logger logger = Logger.getLogger("gui.model");
27
28     protected ExtendedTableModel model;
29
30     public ExtendedTableModel getModel() {
31         return model;
32     }
33
34     public void setModel(ExtendedTableModel model) {
35         if (this.model!=null)
36             this.model.removeTableModelListener(this);
37         this.model = model;
38         model.addTableModelListener(this);
39     }
40
41     // By default, implement TableModel by forwarding all messages
42
// to the model.
43

44     public CollectionItem getCollection() {
45         return model.getCollection();
46     }
47
48     public Object JavaDoc getValueAt(int aRow, int aColumn) {
49         return model.getValueAt(aRow, aColumn);
50     }
51
52     public Object JavaDoc getObject(int row) {
53         return model.getObject(row);
54     }
55         
56     public Object JavaDoc getObject(int row, int column) {
57         return getObject(row,column);
58     }
59
60     public int indexOf(Object JavaDoc object) {
61         return model.indexOf(object);
62     }
63         
64     public void setValueAt(Object JavaDoc aValue, int aRow, int aColumn) {
65         model.setValueAt(aValue, aRow, aColumn);
66     }
67
68     public int getRowCount() {
69         return (model == null) ? 0 : model.getRowCount();
70     }
71
72     public int getColumnCount() {
73         return (model == null) ? 0 : model.getColumnCount();
74     }
75         
76     public String JavaDoc getColumnName(int aColumn) {
77         return model.getColumnName(aColumn);
78     }
79
80     public Class JavaDoc getColumnClass(int aColumn) {
81         return model.getColumnClass(aColumn);
82     }
83         
84     public boolean isCellEditable(int row, int column) {
85         return model.isCellEditable(row, column);
86     }
87
88     public Object JavaDoc getCellRenderer(View tableView, int column,
89                                   ViewFactory factory, DisplayContext context) {
90         return model.getCellRenderer(tableView, column,factory,context);
91     }
92
93     public MemberItem[] getMembers() {
94         return model.getMembers();
95     }
96
97     public String JavaDoc[] getHeaders() {
98         return model.getHeaders();
99     }
100
101     public int getColumnIndex(FieldItem field) {
102         return model.getColumnIndex(field);
103     }
104
105     //
106
// Implementation of the TableModelListener interface,
107
//
108
// By default forward all events to all the listeners.
109
public void tableChanged(TableModelEvent JavaDoc e) {
110         fireTableChanged(e);
111     }
112
113     // Model interface
114

115     public void close() {
116         ((Model)model).close();
117     }
118
119     public TableFilter getFilter() {
120         if (this instanceof TableFilter)
121             return (TableFilter)this;
122         else
123             return model.getFilter();
124     }
125
126     public TableSorter getSorter() {
127         logger.debug(this+".getSorter");
128         if (this instanceof TableSorter)
129             return (TableSorter)this;
130         else
131             return model.getSorter();
132     }
133 }
134
Popular Tags