001 package util.swing; 002 003 import javax.swing.event.TableModelListener; 004 import javax.swing.event.TableModelEvent; 005 006 /** 007 * In a chain of data manipulators some behaviour is common. TableMap 008 * provides most of this behavour and can be subclassed by filters 009 * that only need to override a handful of specific methods. TableMap 010 * implements TableModel by routing all requests to its model, and 011 * TableModelListener by routing all events to its listeners. Inserting 012 * a TableMap which has not been subclassed into a chain of table filters 013 * should have no effect. 014 * 015 * 016 * @version 1.4 12/17/97 017 * @author Philip Milne 018 * @author Thomas Medack 019 */ 020 public class TableMap extends AbstractTableModel implements TableModelListener { 021 022 /** 023 * The original TableModel 024 */ 025 protected AbstractTableModel model; 026 027 /** 028 * Set the table's data. This actually has no effect here. 029 */ 030 public void setData(Object n_lModel) { 031 } 032 033 /** 034 * Constructor 035 */ 036 public TableMap() { 037 super(null); 038 039 } 040 041 /** 042 * Returns the TableModel. 043 * 044 * @return the TableModel. 045 */ 046 public AbstractTableModel getModel() { 047 return model; 048 } 049 050 /** 051 * Sets the TableModel. 052 * 053 * @param model the TableModel. 054 */ 055 public void setModel(AbstractTableModel model) { 056 this.model = model; 057 model.addTableModelListener(this); 058 } 059 060 // By default, implement TableModel by forwarding all messages 061 // to the model. 062 063 /** 064 * Gets the value of a table cell. 065 * 066 * @param aRow row to get the value from. 067 * @param aColumn column to get the value from. 068 * @return the value at (aRow, aColumn). 069 */ 070 public Object getValueAt(int aRow, int aColumn) { 071 return model.getValueAt(aRow, aColumn); 072 } 073 074 /** 075 * Changes the value of a table cell. 076 * 077 * @param aValue the value to set. 078 * @param aRow the row of the TableCell to be changed. 079 * @param aColumn the column of the table cell to be changed. 080 */ 081 public void setValueAt(Object aValue, int aRow, int aColumn) { 082 model.setValueAt(aValue, aRow, aColumn); 083 } 084 085 /** 086 * Returns the number of rows. 087 * 088 * @return the number of rows. 089 */ 090 public int getRowCount() { 091 return (model == null) ? 0 : model.getRowCount(); 092 } 093 094 /** 095 * Returns the number of columns. 096 * 097 * @return the number of columns. 098 */ 099 public int getColumnCount() { 100 return (model == null) ? 0 : model.getColumnCount(); 101 } 102 103 /** 104 * Returns the column's names. 105 * 106 * @param aColumn the affected column. 107 * @return columns' names. 108 */ 109 public String getColumnName(int aColumn) { 110 return model.getColumnName(aColumn); 111 } 112 113 /** 114 * @param nIndex the affected column. 115 * @return columns' classes. They indicate how column's values should be aligned. 116 */ 117 public Class getColumnClass(int aColumn) { 118 return model.getColumnClass(aColumn); 119 } 120 121 /** 122 * Returns if cell is editable or not. 123 * 124 * @param row the affected table row. 125 * @param column the affected column. 126 * @return <ul><li>true: cell is editable</li> 127 * <li>false: cell is not editable</li></ul> 128 */ 129 public boolean isCellEditable(int row, int column) { 130 return model.isCellEditable(row, column); 131 } 132 133 /** 134 * Gets the record. 135 * 136 * @param row the affected table row. 137 * @return the appropriate record. 138 */ 139 public Object getRecord(int row) { 140 return model.getRecord(row); 141 } 142 143 /** 144 * Reacts on TableChangeEvents. 145 * @param e the event. 146 */ 147 public void tableChanged(TableModelEvent e) { 148 fireTableChanged(e); 149 } 150 }