1 package net.sourceforge.xmlfit.fit.stepper.gui;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import javax.swing.table.AbstractTableModel;
7
8 public class DebuggerViewModel extends AbstractTableModel
9 {
10
11 private Object[][] data;
12
13 private int maxCellCount;
14
15 public DebuggerViewModel(ArrayList<List<String>> tabel, int maxCellCount)
16 {
17 this.maxCellCount = maxCellCount;
18 this.data = initData(tabel);
19 }
20
21 private Object[][] initData(ArrayList<List<String>> tabel)
22 {
23 Object[][] result = new Object[tabel.size()][maxCellCount+1];
24 clean(result);
25 for (int i = 0; i < tabel.size(); i++)
26 {
27 Object[] cellsObjects = result[i];
28 List<String> cells = tabel.get(i);
29 if(cells.size() > 0)
30 {
31 cellsObjects[0] = new Boolean(false);
32 }
33 for (int j = 0; j < cells.size(); j++)
34 {
35 cellsObjects[j+1] = cells.get(j);
36 }
37 }
38 return result;
39 }
40
41 private void clean(Object[][] result)
42 {
43 for (Object[] objects : result)
44 {
45 for (Object object : objects)
46 {
47 object = "";
48 }
49 }
50 }
51
52 public Class getColumnClass(int c) {
53 if(c == 0)
54 {
55 return Boolean.class;
56 }
57 return super.getColumnClass(c);
58 }
59
60 public boolean isCellEditable(int row, int col) {
61 if (col == 0) {
62 Object object = data[row][col];
63 if (object instanceof Boolean)
64 {
65 return true;
66 }
67 }
68 return false;
69 }
70
71 public void setValueAt(Object value, int row, int col) {
72 data[row][col] = value;
73 fireTableCellUpdated(row, col);
74 }
75
76 public int getColumnCount()
77 {
78 return maxCellCount;
79 }
80
81 public int getRowCount()
82 {
83 return data.length;
84 }
85
86 public Object getValueAt(int rowIndex, int columnIndex)
87 {
88 return data[rowIndex][columnIndex];
89 }
90
91 }