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.event.ChangeListener;
|
11
|
|
import com.tirsen.angkor.event.ChangeSourceHelper;
|
12
|
|
|
13
|
|
|
14
|
|
/**
|
15
|
|
* @author $Author: tirsen $
|
16
|
|
* @version $Revision: 1.5 $
|
17
|
|
* <BR>
|
18
|
|
* $Id: AbstractTableModel.java,v 1.5 2002/10/09 21:37:37 tirsen Exp $
|
19
|
|
*/
|
20
|
|
public abstract class AbstractTableModel implements TableModel
|
21
|
|
{
|
22
|
|
private int start = 0;
|
23
|
|
private int end = -1;
|
24
|
|
private int rowCount = -1;
|
25
|
|
private ChangeSourceHelper changeSourceHelper = new ChangeSourceHelper(this);
|
26
|
|
|
27
|
|
/**
|
28
|
|
* Sets the actual row count of this model. Values needs to be fetched beforehand for rows actually used by
|
29
|
|
* the user of the model. If set to -1 the size of actual data is used instead.
|
30
|
|
*/
|
31
|
7
|
public void setRowCount(int rowCount)
|
32
|
|
{
|
33
|
7
|
this.rowCount = rowCount;
|
34
|
|
}
|
35
|
|
|
36
|
0
|
public int getRowCountInRange()
|
37
|
|
{
|
38
|
0
|
return getEnd() - getStart() + 1;
|
39
|
|
}
|
40
|
|
|
41
|
301
|
public int getRowCount()
|
42
|
|
{
|
43
|
301
|
return rowCount;
|
44
|
|
}
|
45
|
|
|
46
|
|
/**
|
47
|
|
* If any number is set to a negative number it is subtracted from the number of rows.
|
48
|
|
* As a special case of this setting end to -1 sets the range to the last row.
|
49
|
|
*/
|
50
|
5
|
public void setRange(int start, int end)
|
51
|
|
{
|
52
|
5
|
this.start = start;
|
53
|
5
|
this.end = end;
|
54
|
|
}
|
55
|
|
|
56
|
50
|
public int getStart()
|
57
|
|
{
|
58
|
50
|
System.out.println("start = " + start);
|
59
|
50
|
System.out.println("normalize(start) = " + normalize(start));
|
60
|
50
|
return normalize(start);
|
61
|
|
}
|
62
|
|
|
63
|
69
|
public int getEnd()
|
64
|
|
{
|
65
|
69
|
return normalize(end);
|
66
|
|
}
|
67
|
|
|
68
|
169
|
private int normalize(int row)
|
69
|
|
{
|
70
|
169
|
int rows = getRowCount();
|
71
|
169
|
if (rows == 0)
|
72
|
0
|
row = 0;
|
73
|
|
else
|
74
|
|
{
|
75
|
31
|
if (row < 0) row = rows + row;
|
76
|
7
|
if (row >= rows) row = rows - 1;
|
77
|
|
}
|
78
|
169
|
return row;
|
79
|
|
}
|
80
|
|
|
81
|
0
|
public void empty()
|
82
|
|
{
|
83
|
0
|
setRowCount(-1);
|
84
|
0
|
setRange(0, -1);
|
85
|
|
}
|
86
|
|
|
87
|
2
|
public void addChangeListener(ChangeListener listener)
|
88
|
|
{
|
89
|
2
|
changeSourceHelper.addChangeListener(listener);
|
90
|
|
}
|
91
|
|
|
92
|
1
|
public void removeChangeListener(ChangeListener listener)
|
93
|
|
{
|
94
|
1
|
changeSourceHelper.removeChangeListener(listener);
|
95
|
|
}
|
96
|
|
|
97
|
|
/**
|
98
|
|
* Call this method when values of the model has changed, will fire a change event.
|
99
|
|
*/
|
100
|
33
|
protected void signalChanged()
|
101
|
|
{
|
102
|
33
|
changeSourceHelper.signalChangeEvent();
|
103
|
|
}
|
104
|
|
}
|
105
|
|
|