001    package groovy.inspect.swingui;
002    
003    /*
004     * Copyright (c) 2003 Sun Microsystems, Inc. All  Rights Reserved.
005     *
006     * Redistribution and use in source and binary forms, with or without
007     * modification, are permitted provided that the following conditions
008     * are met:
009     *
010     * -Redistributions of source code must retain the above copyright
011     *  notice, this list of conditions and the following disclaimer.
012     *
013     * -Redistribution in binary form must reproduct the above copyright
014     *  notice, this list of conditions and the following disclaimer in
015     *  the documentation and/or other materials provided with the distribution.
016     *
017     * Neither the name of Sun Microsystems, Inc. or the names of contributors
018     * may be used to endorse or promote products derived from this software
019     * without specific prior written permission.
020     *
021     * This software is provided "AS IS," without a warranty of any kind. ALL
022     * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
023     * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
024     * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT
025     * BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT
026     * OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS
027     * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
028     * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
029     * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
030     * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN
031     * IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
032     *
033     * You acknowledge that Software is not designed, licensed or intended for
034     * use in the design, construction, operation or maintenance of any nuclear
035     * facility.
036     */
037    
038    /*
039     * @(#)TableMap.java    1.11 03/01/23
040     */
041    
042    /**
043     * In a chain of data manipulators some behaviour is common. TableMap
044     * provides most of this behavour and can be subclassed by filters
045     * that only need to override a handful of specific methods. TableMap
046     * implements TableModel by routing all requests to its model, and
047     * TableModelListener by routing all events to its listeners. Inserting
048     * a TableMap which has not been subclassed into a chain of table filters
049     * should have no effect.
050     *
051     * @version 1.11 01/23/03
052     * @author Philip Milne */
053    
054    import javax.swing.table.*;
055    import javax.swing.event.TableModelListener;
056    import javax.swing.event.TableModelEvent;
057    
058    public class TableMap extends AbstractTableModel implements TableModelListener
059    {
060        protected TableModel model;
061    
062        public TableModel  getModel() {
063            return model;
064        }
065    
066        public void  setModel(TableModel model) {
067            this.model = model;
068            model.addTableModelListener(this);
069        }
070    
071        // By default, Implement TableModel by forwarding all messages
072        // to the model.
073    
074        public Object getValueAt(int aRow, int aColumn) {
075            return model.getValueAt(aRow, aColumn);
076        }
077    
078        public void setValueAt(Object aValue, int aRow, int aColumn) {
079            model.setValueAt(aValue, aRow, aColumn);
080        }
081    
082        public int getRowCount() {
083            return (model == null) ? 0 : model.getRowCount();
084        }
085    
086        public int getColumnCount() {
087            return (model == null) ? 0 : model.getColumnCount();
088        }
089    
090        public String getColumnName(int aColumn) {
091            return model.getColumnName(aColumn);
092        }
093    
094        public Class getColumnClass(int aColumn) {
095            return model.getColumnClass(aColumn);
096        }
097    
098        public boolean isCellEditable(int row, int column) {
099             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