1 package org.ozoneDB.adminGui.widget; 9 10 11 import javax.swing.event.TableModelEvent ; 12 import javax.swing.event.TableModelListener ; 13 import javax.swing.table.AbstractTableModel ; 14 import javax.swing.table.TableModel ; 15 import java.util.Vector ; 16 17 33 public class TableMap extends AbstractTableModel implements TableModelListener { 34 35 protected TableModel model; 36 37 protected int columnCount; 38 39 protected int rowCount; 40 41 protected Vector columnNames = new Vector (); 42 43 protected Vector data = new Vector (); 44 45 46 51 public TableModel getModel() { 52 return this.model; 54 } 55 56 61 public void setModel(TableModel model) { 62 this.model = model; 63 this.model.addTableModelListener(this); 64 } 66 67 75 public Object getValueAt(int row, int column) { 76 return ((Object []) data.elementAt(row))[column]; 77 } 78 79 87 public void setValueAt(Object aValue, int aRow, int aColumn) { 88 String value; 89 try { 90 value = (String ) aValue; 91 } catch (Exception e) { 92 System.out.println("wrong format"); 93 e.printStackTrace(); 94 return; 95 } 96 97 ((Object []) data.elementAt(aRow))[aColumn] = value; 98 fireTableCellUpdated(aRow, aColumn); 99 } 100 101 106 public int getRowCount() { 107 return this.data.size(); 108 } 109 110 115 public int getColumnCount() { 116 return this.columnNames.size(); 117 } 118 119 125 public String getColumnName(int index) { 126 return (String ) columnNames.elementAt(index); 127 } 128 129 135 public Class getColumnClass(int index) { 136 return ((Object []) data.elementAt(0))[index].getClass(); 137 } 138 139 142 public void clear() { 143 this.data.clear(); 145 this.rowCount = 0; 146 } 148 155 158 159 164 public void tableChanged(TableModelEvent e) { 165 fireTableChanged(e); 166 } 167 } 168 | Popular Tags |