1 package ist.coach.coachEmfClientComponents.gui; 2 3 import javax.swing.table.AbstractTableModel ; 4 5 class ParamTableModel extends AbstractTableModel { 6 7 final String [] columnNames = {"Attribute", "Value"}; 8 Object [][] data = null; 9 boolean[] param_options = null; 10 11 ParamTableModel(String []params) { 12 13 data = new Object [params.length][2]; 14 for(int i = 0; i < params.length; i++) { 15 data[i][0] = params[i]; 17 data[i][1] = new String (); 18 } 19 } 20 21 ParamTableModel(String []params, Object [] values, boolean[] param_options) { 22 23 data = new Object [params.length][2]; 24 this.param_options = param_options; 25 for(int i = 0; i < params.length; i++) { 26 data[i][0] = params[i]; 28 data[i][1] = values[i]; 29 } 30 } 31 32 33 public int getColumnCount() { 34 return columnNames.length; 35 } 36 37 public int getRowCount() { 38 return data.length; 39 } 40 41 public String getColumnName(int col) { 42 return columnNames[col]; 43 } 44 45 public Object getValueAt(int row, int col) { 46 return data[row][col]; 47 48 } 49 50 56 public Class getColumnClass(int c) { 57 return getValueAt(0, c).getClass(); 58 } 59 60 64 public boolean isCellEditable(int row, int col) { 65 if (col <1) { 68 return false; 69 } else { 70 71 if (param_options != null && param_options.length > row) 72 return param_options[row]; 73 else 74 return true; 75 } 76 } 77 78 public void setValueAt(Object value, int row, int col) { 79 80 data[row][col] = value; 86 fireTableCellUpdated(row, col); 87 } 90 91 public void printDebugData() { 92 int numRows = getRowCount(); 93 int numCols = getColumnCount(); 94 95 for (int i=0; i < numRows; i++) { 96 GuiClient.print(" row " + i + ":"); 97 for (int j=0; j < numCols; j++) { 98 GuiClient.print(" " + data[i][j]); 99 } 100 GuiClient.println(""); 101 } 102 GuiClient.println("--------------------------"); 103 } 104 } 105 106 | Popular Tags |