// file:  TableMap.java

import javax.swing.table.*; 
import javax.swing.event.TableModelListener; 
import javax.swing.event.TableModelEvent; 


/** 
 * In a chain of data manipulators some behaviour is common. TableMap
 * provides most of this behavour and can be subclassed by filters
 * that only need to override a handful of specific methods. TableMap 
 * implements TableModel by routing all requests to its model, and
 * TableModelListener by routing all events to its listeners. Inserting 
 * a TableMap which has not been subclassed into a chain of table filters 
 * should have no effect.
 *
 * @version 1.4 12/17/97
 * @author Philip Milne */
public class TableMap extends AbstractTableModel 
                      implements TableModelListener {
  
    /**
     * TabelModel object of class
     */
    protected TableModel model; 

    /**
     * Gets model
     * @return TabelModel object of clasd
     */
    public TableModel getModel() {
        return model;
    }

    /**
     * Sets the model variable and adds the table model listener
     * @param model TabelModel to set
     */
    public void setModel(TableModel model) {
        this.model = model; 
        model.addTableModelListener(this); 
    }

    // By default, implement TableModel by forwarding all messages 
    // to the model. 

    /**
     * Gets the value for the cell at columnIndex and rowIndex.
     *
     * @param aRow the row whose value is to be queried
     * @param aColumn the column whose value is to be queried 
     * @return the value Object at the specified cell
     */
    public Object getValueAt(int aRow, int aColumn) {
        return model.getValueAt(aRow, aColumn); 
    }
    /**
     * Sets the value in the cell at columnIndex and rowIndex to aValue.
     *
     * @param aValue  the new value
     * @param aRow    the row whose value is to be changed
     * @param aColumn the column whose value is to be changed
     */
    public void setValueAt(Object aValue, int aRow, int aColumn) {
        model.setValueAt(aValue, aRow, aColumn); 
    }

    /**
     * Returns the number of rows in the model
     * @return the number of rows in the model
     */
    public int getRowCount() {
        return (model == null) ? 0 : model.getRowCount(); 
    }

    /**
     * Returns the number of columns in the model
     * @return the number of columns in the model
     */
    public int getColumnCount() {
        return (model == null) ? 0 : model.getColumnCount(); 
    }
    /**
     * Returns the column name in the model with an index
     * @param aColumn column number to be accessed
     * @return the column name in the model with an index
     */
    public String getColumnName(int aColumn) {
        return model.getColumnName(aColumn); 
    }
    /**
     * Returns the column class name in the model with an index
     * @param aColumn column number to be accessed
     * @return the column class name in the model with an index
     */
    public Class getColumnClass(int aColumn) {
        return model.getColumnClass(aColumn); 
    }
    /**
     * Sees if the cell is editable
     * @param row row number to be checked
     * @param column column number to be checked
     * @return true if the cell is editable
     */
    public boolean isCellEditable(int row, int column) { 
         return model.isCellEditable(row, column); 
    }
//
// Implementation of the TableModelListener interface, 
//
    /**
     * By default forward all events to all the listeners. 
     * @param e TabelModelEvent that occured
     */
    public void tableChanged(TableModelEvent e) {
        fireTableChanged(e);
    }
}
