View Javadoc

    1   package groovy.inspect.swingui;
    2
    3   /*
    4    * Copyright (c) 2003 Sun Microsystems, Inc. All  Rights Reserved.
    5    *
    6    * Redistribution and use in source and binary forms, with or without
    7    * modification, are permitted provided that the following conditions
    8    * are met:
    9    *
    10   * -Redistributions of source code must retain the above copyright
    11   *  notice, this list of conditions and the following disclaimer.
    12   *
    13   * -Redistribution in binary form must reproduct the above copyright
    14   *  notice, this list of conditions and the following disclaimer in
    15   *  the documentation and/or other materials provided with the distribution.
    16   *
    17   * Neither the name of Sun Microsystems, Inc. or the names of contributors
    18   * may be used to endorse or promote products derived from this software
    19   * without specific prior written permission.
    20   *
    21   * This software is provided "AS IS," without a warranty of any kind. ALL
    22   * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
    23   * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
    24   * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT
    25   * BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT
    26   * OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS
    27   * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
    28   * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
    29   * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
    30   * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN
    31   * IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
    32   *
    33   * You acknowledge that Software is not designed, licensed or intended for
    34   * use in the design, construction, operation or maintenance of any nuclear
    35   * facility.
    36   */
    37
    38  /*
    39   * @(#)TableMap.java	1.11 03/01/23
    40   */
    41
    42  /***
    43   * In a chain of data manipulators some behaviour is common. TableMap
    44   * provides most of this behavour and can be subclassed by filters
    45   * that only need to override a handful of specific methods. TableMap
    46   * implements TableModel by routing all requests to its model, and
    47   * TableModelListener by routing all events to its listeners. Inserting
    48   * a TableMap which has not been subclassed into a chain of table filters
    49   * should have no effect.
    50   *
    51   * @version 1.11 01/23/03
    52   * @author Philip Milne */
    53
    54  import javax.swing.table.*;
    55  import javax.swing.event.TableModelListener;
    56  import javax.swing.event.TableModelEvent;
    57
    58  public class TableMap extends AbstractTableModel implements TableModelListener
    59  {
    60      protected TableModel model;
    61
    62      public TableModel  getModel() {
    63          return model;
    64      }
    65
    66      public void  setModel(TableModel model) {
    67          this.model = model;
    68          model.addTableModelListener(this);
    69      }
    70
    71      // By default, Implement TableModel by forwarding all messages
    72      // to the model.
    73
    74      public Object getValueAt(int aRow, int aColumn) {
    75          return model.getValueAt(aRow, aColumn);
    76      }
    77
    78      public void setValueAt(Object aValue, int aRow, int aColumn) {
    79          model.setValueAt(aValue, aRow, aColumn);
    80      }
    81
    82      public int getRowCount() {
    83          return (model == null) ? 0 : model.getRowCount();
    84      }
    85
    86      public int getColumnCount() {
    87          return (model == null) ? 0 : model.getColumnCount();
    88      }
    89
    90      public String getColumnName(int aColumn) {
    91          return model.getColumnName(aColumn);
    92      }
    93
    94      public Class getColumnClass(int aColumn) {
    95          return model.getColumnClass(aColumn);
    96      }
    97
    98      public boolean isCellEditable(int row, int column) {
    99           return model.isCellEditable(row, column);
    100     }
    101 //
    102 // Implementation of the TableModelListener interface,
    103 //
    104
    105     // By default forward all events to all the listeners.
    106     public void tableChanged(TableModelEvent e) {
    107         fireTableChanged(e);
    108     }
    109 }
    110