| TableMap |

    1   /*
    2    *  Copyright (c) 1998-2001, The University of Sheffield.
    3    *
    4    *  This file is part of GATE (see http://gate.ac.uk/), and is free
    5    *  software, licenced under the GNU Library General Public License,
    6    *  Version 2, June 1991 (in the distribution as file licence.html,
    7    *  and also available at http://gate.ac.uk/gate/licence.html).
    8    *
    9    *  Valentin Tablan 14/12/2000
    10   *
    11   *  $Id: TableMap.java,v 1.1 2001/03/30 17:51:01 valyt Exp $
    12   *
    13   */
    14  package gate.swing;
    15
    16  import javax.swing.table.*;
    17  import javax.swing.event.TableModelListener;
    18  import javax.swing.event.TableModelEvent;
    19
    20  /**
    21   * In a chain of data manipulators some behaviour is common. TableMap
    22   * provides most of this behavour and can be subclassed by filters
    23   * that only need to override a handful of specific methods. TableMap
    24   * implements TableModel by routing all requests to its model, and
    25   * TableModelListener by routing all events to its listeners. Inserting
    26   * a TableMap which has not been subclassed into a chain of table filters
    27   * should have no effect.
    28   *
    29   * @version 1.4 12/17/97
    30   * @author Philip Milne */
    31  public class TableMap extends AbstractTableModel
    32                        implements TableModelListener {
    33      protected TableModel model;
    34
    35      public TableModel getModel() {
    36          return model;
    37      }
    38
    39      public void setModel(TableModel model) {
    40          this.model = model;
    41          model.addTableModelListener(this);
    42          tableChanged(null);
    43      }
    44
    45      // By default, implement TableModel by forwarding all messages
    46      // to the model.
    47
    48      public Object getValueAt(int aRow, int aColumn) {
    49          return model.getValueAt(aRow, aColumn);
    50      }
    51
    52      public void setValueAt(Object aValue, int aRow, int aColumn) {
    53          model.setValueAt(aValue, aRow, aColumn);
    54      }
    55
    56      public int getRowCount() {
    57          return (model == null) ? 0 : model.getRowCount();
    58      }
    59
    60      public int getColumnCount() {
    61          return (model == null) ? 0 : model.getColumnCount();
    62      }
    63
    64      public String getColumnName(int aColumn) {
    65          return model.getColumnName(aColumn);
    66      }
    67
    68      public Class getColumnClass(int aColumn) {
    69          return model.getColumnClass(aColumn);
    70      }
    71
    72      public boolean isCellEditable(int row, int column) {
    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 e) {
    80          fireTableChanged(e);
    81      }
    82  }
    83

| TableMap |