1
|
|
/*
|
2
|
|
* Angkor Web Framework
|
3
|
|
*
|
4
|
|
* Distributable under LGPL license.
|
5
|
|
* See terms of license at gnu.org.
|
6
|
|
*/
|
7
|
|
|
8
|
|
package com.tirsen.angkor.table;
|
9
|
|
|
10
|
|
import com.tirsen.angkor.widget.BasicValueModel;
|
11
|
|
import com.tirsen.angkor.widget.ValueModel;
|
12
|
|
|
13
|
|
import java.util.Arrays;
|
14
|
|
import java.util.LinkedList;
|
15
|
|
import java.util.List;
|
16
|
|
|
17
|
|
/**
|
18
|
|
* @author $Author: tirsen $
|
19
|
|
* @version $Revision: 1.5 $
|
20
|
|
* <BR>
|
21
|
|
* $Id: DefaultTableModel.java,v 1.5 2002/10/09 21:37:37 tirsen Exp $
|
22
|
|
*/
|
23
|
|
public class DefaultTableModel extends AbstractTableModel
|
24
|
|
{
|
25
|
|
/**
|
26
|
|
* The <code>List</code> of <code>List</code>s of <code>Object</code> values.
|
27
|
|
*/
|
28
|
|
private List dataList = new LinkedList();
|
29
|
|
|
30
|
|
/**
|
31
|
|
* The <code>List</code> of <code>Object</code> column names.
|
32
|
|
*/
|
33
|
|
private List columnNames = new LinkedList();
|
34
|
|
|
35
|
3
|
public void addColumn(String name)
|
36
|
|
{
|
37
|
3
|
columnNames.add(name);
|
38
|
3
|
signalChanged();
|
39
|
|
}
|
40
|
|
|
41
|
|
/**
|
42
|
|
* Adds a row to the end of this table.
|
43
|
|
*/
|
44
|
1
|
public void addRow(Object[] columnValues)
|
45
|
|
{
|
46
|
1
|
dataList.add(Arrays.asList(columnValues));
|
47
|
1
|
signalChanged();
|
48
|
|
}
|
49
|
|
|
50
|
29
|
public void setRow(int row, Object[] columnValues)
|
51
|
|
{
|
52
|
29
|
int size = dataList.size();
|
53
|
29
|
for (int i = size - row; i < size + 1; i++)
|
54
|
|
{
|
55
|
147
|
dataList.add(null);
|
56
|
|
}
|
57
|
29
|
dataList.set(row, Arrays.asList(columnValues));
|
58
|
29
|
signalChanged();
|
59
|
|
}
|
60
|
|
|
61
|
0
|
public String getColumnName(int column)
|
62
|
|
{
|
63
|
0
|
Object name = columnNames.get(column);
|
64
|
0
|
return name != null ? name.toString() : "";
|
65
|
|
}
|
66
|
|
|
67
|
17
|
public ValueModel getValueAt(final int row, final int column)
|
68
|
|
{
|
69
|
17
|
return new BasicValueModel()
|
70
|
|
{
|
71
|
6
|
public Object getValue()
|
72
|
|
{
|
73
|
6
|
return ((List) dataList.get(row)).get(column);
|
74
|
|
}
|
75
|
|
|
76
|
0
|
public void setValue(Object value)
|
77
|
|
{
|
78
|
0
|
((List) dataList.get(row)).set(column, value);
|
79
|
|
}
|
80
|
|
};
|
81
|
|
}
|
82
|
|
|
83
|
2
|
public int getColumnCount()
|
84
|
|
{
|
85
|
2
|
return columnNames.size();
|
86
|
|
}
|
87
|
|
|
88
|
128
|
public int getRowCount()
|
89
|
|
{
|
90
|
128
|
return super.getRowCount() == -1 ? dataList.size() : super.getRowCount();
|
91
|
|
}
|
92
|
|
|
93
|
0
|
public void empty()
|
94
|
|
{
|
95
|
0
|
super.empty();
|
96
|
0
|
dataList.removeAll(dataList);
|
97
|
0
|
signalChanged();
|
98
|
|
}
|
99
|
|
}
|
100
|
|
|