001/* ---------------------------------------------------------------------------- 002 The Kiwi Toolkit - A Java Class Library 003 Copyright (C) 1998-2004 Mark A. Lindner 004 005 This library is free software; you can redistribute it and/or 006 modify it under the terms of the GNU General Public License as 007 published by the Free Software Foundation; either version 2 of the 008 License, or (at your option) any later version. 009 010 This library is distributed in the hope that it will be useful, 011 but WITHOUT ANY WARRANTY; without even the implied warranty of 012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 General Public License for more details. 014 015 You should have received a copy of the GNU General Public License 016 along with this library; if not, write to the Free Software 017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 018 02111-1307, USA. 019 020 The author may be contacted at: mark_a_lindner@yahoo.com 021 ---------------------------------------------------------------------------- 022 $Log: ProxyTableModel.java,v $ 023 Revision 1.1 2004/05/13 21:39:33 markl 024 new class 025 026 ---------------------------------------------------------------------------- 027*/ 028 029package kiwi.ui.model; 030 031import javax.swing.table.*; 032import javax.swing.event.TableModelListener; 033import javax.swing.event.TableModelEvent; 034 035/** A mapping object for <code>TableModel</code>s. In a chain of data 036 * manipulators some behavior is common. 037 * <code>ProxyTableModel</code> provides most of this behavior and 038 * can be subclassed by filters that only need to override a handful 039 * of specific methods. <code>ProxyTableModel</code> implements 040 * <code>javax.swing.table.TableModel</code> by routing all requests 041 * to its model, and 042 * <code>javax.swing.event.TableModelListener</code> by routing all 043 * events to its listeners. Inserting a <code>ProxyTableModel</code> 044 * which has not been subclassed into a chain of table filters should 045 * have no effect. 046 * 047 * @see javax.swing.table.TableModel 048 * @see kiwi.ui.model.TableSorter 049 * 050 * @author Mark Lindner 051 * @since Kiwi 2.0 052 */ 053 054public class ProxyTableModel extends AbstractTableModel 055 implements TableModelListener 056 { 057 /** The <code>TableModel</code> that this model proxies for. */ 058 protected TableModel model; 059 060 /** Construct a new <code>ProxyTableModel</code>. */ 061 062 public ProxyTableModel() 063 { 064 } 065 066 /** Get the <code>TableModel</code> used by this map. */ 067 068 public TableModel getModel() 069 { 070 return model; 071 } 072 073 /** Set the <code>TableModel</code> to use with this map. 074 * 075 * @param model The <code>TableModel</code> to use. 076 */ 077 078 public void setModel(TableModel model) 079 { 080 this.model = model; 081 model.addTableModelListener(this); 082 } 083 084 /* By default, Implement TableModel by forwarding all messages to the 085 inner model. */ 086 087 public Object getValueAt(int row, int col) 088 { 089 return(model.getValueAt(row, col)); 090 } 091 092 public void setValueAt(Object value, int row, int col) 093 { 094 model.setValueAt(value, row, col); 095 } 096 097 public int getRowCount() 098 { 099 return((model == null) ? 0 : model.getRowCount()); 100 } 101 102 public int getColumnCount() 103 { 104 return((model == null) ? 0 : model.getColumnCount()); 105 } 106 107 public String getColumnName(int col) 108 { 109 return model.getColumnName(col); 110 } 111 112 public Class getColumnClass(int col) 113 { 114 return model.getColumnClass(col); 115 } 116 117 public boolean isCellEditable(int row, int col) 118 { 119 return model.isCellEditable(row, col); 120 } 121 122 /* Implementation of the TableModelListener interface. By default 123 * forward all events to all the listeners. 124 */ 125 126 public void tableChanged(TableModelEvent e) 127 { 128 fireTableChanged(e); 129 } 130 131 } 132 133/* end of source file */