1 7 8 package javax.swing.table; 9 10 import javax.swing.*; 11 import javax.swing.event.*; 12 import java.io.Serializable ; 13 import java.util.EventListener ; 14 15 43 public abstract class AbstractTableModel implements TableModel , Serializable 44 { 45 49 50 protected EventListenerList listenerList = new EventListenerList(); 51 52 56 64 public String getColumnName(int column) { 65 String result = ""; 66 for (; column >= 0; column = column / 26 - 1) { 67 result = (char)((char)(column%26)+'A') + result; 68 } 69 return result; 70 } 71 72 82 public int findColumn(String columnName) { 83 for (int i = 0; i < getColumnCount(); i++) { 84 if (columnName.equals(getColumnName(i))) { 85 return i; 86 } 87 } 88 return -1; 89 } 90 91 97 public Class <?> getColumnClass(int columnIndex) { 98 return Object .class; 99 } 100 101 108 public boolean isCellEditable(int rowIndex, int columnIndex) { 109 return false; 110 } 111 112 120 public void setValueAt(Object aValue, int rowIndex, int columnIndex) { 121 } 122 123 124 128 134 public void addTableModelListener(TableModelListener l) { 135 listenerList.add(TableModelListener.class, l); 136 } 137 138 144 public void removeTableModelListener(TableModelListener l) { 145 listenerList.remove(TableModelListener.class, l); 146 } 147 148 161 public TableModelListener[] getTableModelListeners() { 162 return (TableModelListener[])listenerList.getListeners( 163 TableModelListener.class); 164 } 165 166 170 181 public void fireTableDataChanged() { 182 fireTableChanged(new TableModelEvent(this)); 183 } 184 185 199 public void fireTableStructureChanged() { 200 fireTableChanged(new TableModelEvent(this, TableModelEvent.HEADER_ROW)); 201 } 202 203 214 public void fireTableRowsInserted(int firstRow, int lastRow) { 215 fireTableChanged(new TableModelEvent(this, firstRow, lastRow, 216 TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); 217 } 218 219 229 public void fireTableRowsUpdated(int firstRow, int lastRow) { 230 fireTableChanged(new TableModelEvent(this, firstRow, lastRow, 231 TableModelEvent.ALL_COLUMNS, TableModelEvent.UPDATE)); 232 } 233 234 244 public void fireTableRowsDeleted(int firstRow, int lastRow) { 245 fireTableChanged(new TableModelEvent(this, firstRow, lastRow, 246 TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE)); 247 } 248 249 258 public void fireTableCellUpdated(int row, int column) { 259 fireTableChanged(new TableModelEvent(this, row, row, column)); 260 } 261 262 273 public void fireTableChanged(TableModelEvent e) { 274 Object [] listeners = listenerList.getListenerList(); 276 for (int i = listeners.length-2; i>=0; i-=2) { 279 if (listeners[i]==TableModelListener.class) { 280 ((TableModelListener)listeners[i+1]).tableChanged(e); 281 } 282 } 283 } 284 285 321 public <T extends EventListener > T[] getListeners(Class <T> listenerType) { 322 return listenerList.getListeners(listenerType); 323 } 324 } | Popular Tags |