001    package util.swing;
002    
003    import javax.swing.event.TableModelListener;
004    import javax.swing.event.TableModelEvent;
005    
006    /**
007     * In a chain of data manipulators some behaviour is common. TableMap
008     * provides most of this behavour and can be subclassed by filters
009     * that only need to override a handful of specific methods. TableMap
010     * implements TableModel by routing all requests to its model, and
011     * TableModelListener by routing all events to its listeners. Inserting
012     * a TableMap which has not been subclassed into a chain of table filters
013     * should have no effect.
014     *
015     *
016     * @version 1.4 12/17/97
017     * @author Philip Milne
018     * @author Thomas Medack
019     */
020    public class TableMap extends AbstractTableModel implements TableModelListener {
021    
022        /**
023             * ID for serialization.
024             */
025            private static final long serialVersionUID = 334802292852356320L;
026            
027            /**
028         * The original TableModel
029         */
030        protected AbstractTableModel model;
031        
032        /**
033         * Set the table's data. This actually has no effect here. 
034         */
035            public void setData(Object n_lModel) {
036            }
037    
038        /**
039         * Constructor
040         */
041        public TableMap() {
042            super(null);
043    
044        }
045    
046        /**
047         * Returns the TableModel.
048         *
049         * @return the TableModel.
050         */
051        public AbstractTableModel getModel() {
052            return model;
053        }
054    
055        /**
056         * Sets the TableModel.
057         *
058         * @param model the TableModel.
059         */
060        public void setModel(AbstractTableModel model) {
061            this.model = model;
062            model.addTableModelListener(this);
063        }
064    
065        // By default, implement TableModel by forwarding all messages
066        // to the model.
067    
068        /**
069         * Gets the value of a table cell.
070         *
071         * @param aRow row to get the value from.
072         * @param aColumn column to get the value from.
073         * @return the value at (aRow, aColumn).
074         */
075        public Object getValueAt(int aRow, int aColumn) {
076            return model.getValueAt(aRow, aColumn);
077        }
078    
079        /**
080         * Changes the value of a table cell.
081         *
082         * @param aValue the value to set.
083         * @param aRow the row of the TableCell to be changed.
084         * @param aColumn the column of the table cell to be changed.
085         */
086        public void setValueAt(Object aValue, int aRow, int aColumn) {
087            model.setValueAt(aValue, aRow, aColumn);
088        }
089    
090        /**
091         * Returns the number of rows.
092         *
093         * @return the number of rows.
094         */
095        public int getRowCount() {
096            return (model == null) ? 0 : model.getRowCount();
097        }
098    
099        /**
100         * Returns the number of columns.
101         *
102         * @return the number of columns.
103         */
104        public int getColumnCount() {
105            return (model == null) ? 0 : model.getColumnCount();
106        }
107    
108        /**
109         * Returns the column's names.
110         *
111         * @param aColumn the affected column.
112         * @return columns' names.
113         */
114        public String getColumnName(int aColumn) {
115            return model.getColumnName(aColumn);
116        }
117    
118        /**
119         * @param nIndex the affected column.
120         * @return columns' classes. They indicate how column's values should be aligned.
121         */
122        public Class<?> getColumnClass(int aColumn) {
123            return model.getColumnClass(aColumn);
124        }
125    
126        /**
127         * Returns if cell is editable or not.
128         *
129         * @param row the affected table row.
130         * @param column the affected column.
131         * @return <ul><li>true: cell is editable</li>
132         *              <li>false: cell is not editable</li></ul>
133         */
134        public boolean isCellEditable(int row, int column) {
135            return model.isCellEditable(row, column);
136        }
137    
138        /**
139         * Gets the record.
140         *
141         * @param row the affected table row.
142         * @return the appropriate record.
143         */
144        public Object getRecord(int row) {
145            return model.getRecord(row);
146        }
147    
148        /**
149         * Reacts on TableChangeEvents.
150         * @param e the event.
151         */
152        public void tableChanged(TableModelEvent e) {
153            fireTableChanged(e);
154        }
155    }