KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ist > coach > coachEmfClientComponents > gui > ParamTableModel


1 package ist.coach.coachEmfClientComponents.gui;
2
3 import javax.swing.table.AbstractTableModel JavaDoc;
4
5 class ParamTableModel extends AbstractTableModel JavaDoc {
6
7         final String JavaDoc[] columnNames = {"Attribute", "Value"};
8         Object JavaDoc[][] data = null;
9         boolean[] param_options = null;
10
11         ParamTableModel(String JavaDoc []params) {
12
13             data = new Object JavaDoc[params.length][2];
14             for(int i = 0; i < params.length; i++) {
15                  //GuiClient.println("params[i] = " + params[i]);
16
data[i][0] = params[i];
17                 data[i][1] = new String JavaDoc();
18             }
19         }
20
21         ParamTableModel(String JavaDoc []params, Object JavaDoc[] values, boolean[] param_options) {
22
23             data = new Object JavaDoc[params.length][2];
24             this.param_options = param_options;
25             for(int i = 0; i < params.length; i++) {
26                  //GuiClient.println("params[i] = " + params[i]);
27
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 JavaDoc getColumnName(int col) {
42             return columnNames[col];
43         }
44
45         public Object JavaDoc getValueAt(int row, int col) {
46             return data[row][col];
47
48         }
49
50         /*
51          * JTable uses this method to determine the default renderer/
52          * editor for each cell. If we didn't implement this method,
53          * then the last column would contain text ("true"/"false"),
54          * rather than a check box.
55          */

56         public Class JavaDoc getColumnClass(int c) {
57             return getValueAt(0, c).getClass();
58         }
59
60         /*
61          * Don't need to implement this method unless your table's
62          * editable.
63          */

64         public boolean isCellEditable(int row, int col) {
65             //Note that the data/cell address is constant,
66
//no matter where the cell appears onscreen.
67
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 JavaDoc value, int row, int col) {
79
80          // GuiClient.println("Setting value at " + row + "," + col
81
// + " to " + value
82
// + " (an instance of "
83
// + value.getClass() + ")");
84
//
85
data[row][col] = value;
86             fireTableCellUpdated(row, col);
87           // GuiClient.println("New value of data:");
88
// printDebugData();
89
}
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