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.Debug;
|
11
|
|
import com.tirsen.angkor.RenderContext;
|
12
|
|
import com.tirsen.angkor.event.AbstractAction;
|
13
|
|
import com.tirsen.angkor.event.Action;
|
14
|
|
import com.tirsen.angkor.event.ActionEvent;
|
15
|
|
import com.tirsen.angkor.Component;
|
16
|
|
import com.tirsen.angkor.widget.Link;
|
17
|
|
import org.apache.log4j.Category;
|
18
|
|
|
19
|
|
import java.io.IOException;
|
20
|
|
|
21
|
|
/**
|
22
|
|
* @author $Author: tirsen $
|
23
|
|
* @version $Revision: 1.6 $
|
24
|
|
* <BR>
|
25
|
|
* $Id: TableScroller.java,v 1.6 2002/10/13 19:59:22 tirsen Exp $
|
26
|
|
*/
|
27
|
|
public class TableScroller extends Component
|
28
|
|
{
|
29
|
|
private static final Category logger = Category.getInstance(Debug.LOGGER_NAME);
|
30
|
|
|
31
|
|
private Table table;
|
32
|
|
|
33
|
1
|
public void setTable(Table table)
|
34
|
|
{
|
35
|
1
|
this.table = table;
|
36
|
|
}
|
37
|
|
|
38
|
6
|
private boolean isForwardEnabled()
|
39
|
|
{
|
40
|
6
|
boolean result;
|
41
|
|
|
42
|
6
|
if (table == null)
|
43
|
|
{
|
44
|
0
|
result = false;
|
45
|
|
}
|
46
|
|
else
|
47
|
|
{
|
48
|
6
|
if (getEnd() >= getRowCount() - 1)
|
49
|
1
|
result = false;
|
50
|
|
else
|
51
|
5
|
result = true;
|
52
|
|
}
|
53
|
|
|
54
|
6
|
return result;
|
55
|
|
}
|
56
|
|
|
57
|
6
|
private boolean isBackwardEnabled()
|
58
|
|
{
|
59
|
6
|
boolean result;
|
60
|
|
|
61
|
6
|
if (table == null)
|
62
|
|
{
|
63
|
0
|
result = false;
|
64
|
|
}
|
65
|
|
else
|
66
|
|
{
|
67
|
6
|
if (getStart() == 0)
|
68
|
2
|
result = false;
|
69
|
|
else
|
70
|
4
|
result = true;
|
71
|
|
}
|
72
|
|
|
73
|
6
|
return result;
|
74
|
|
}
|
75
|
|
|
76
|
6
|
private int getEnd()
|
77
|
|
{
|
78
|
6
|
return table.getTableModel().getEnd();
|
79
|
|
}
|
80
|
|
|
81
|
6
|
private int getStart()
|
82
|
|
{
|
83
|
6
|
return table.getTableModel().getStart();
|
84
|
|
}
|
85
|
|
|
86
|
6
|
private int getRowCount()
|
87
|
|
{
|
88
|
6
|
return table.getRowCount();
|
89
|
|
}
|
90
|
|
|
91
|
0
|
public void render(RenderContext context) throws IOException
|
92
|
|
{
|
93
|
0
|
getPrevious().render(context);
|
94
|
0
|
context.println(" ");
|
95
|
0
|
getNext().render(context);
|
96
|
|
}
|
97
|
|
|
98
|
1
|
public Action getPreviousAction()
|
99
|
|
{
|
100
|
1
|
return new BackwardAction();
|
101
|
|
}
|
102
|
|
|
103
|
1
|
public Action getNextAction()
|
104
|
|
{
|
105
|
1
|
return new ForwardAction();
|
106
|
|
}
|
107
|
|
|
108
|
0
|
private Link getPrevious()
|
109
|
|
{
|
110
|
0
|
return Link.createActionLink(getPreviousAction());
|
111
|
|
}
|
112
|
|
|
113
|
0
|
private Link getNext()
|
114
|
|
{
|
115
|
0
|
return Link.createActionLink(getNextAction());
|
116
|
|
}
|
117
|
|
|
118
|
|
private class ForwardAction extends AbstractAction
|
119
|
|
{
|
120
|
1
|
public ForwardAction()
|
121
|
|
{
|
122
|
1
|
super("Next");
|
123
|
|
}
|
124
|
|
|
125
|
2
|
public void actionPerformed(ActionEvent evt)
|
126
|
|
{
|
127
|
2
|
table.scrollForward();
|
128
|
|
}
|
129
|
|
|
130
|
6
|
public boolean isEnabled()
|
131
|
|
{
|
132
|
6
|
return super.isEnabled() && isForwardEnabled();
|
133
|
|
}
|
134
|
|
}
|
135
|
|
|
136
|
|
private class BackwardAction extends AbstractAction
|
137
|
|
{
|
138
|
1
|
public BackwardAction()
|
139
|
|
{
|
140
|
1
|
super("Previous");
|
141
|
|
}
|
142
|
|
|
143
|
2
|
public void actionPerformed(ActionEvent evt)
|
144
|
|
{
|
145
|
2
|
table.scrollBackward();
|
146
|
|
}
|
147
|
|
|
148
|
6
|
public boolean isEnabled()
|
149
|
|
{
|
150
|
6
|
return super.isEnabled() && isBackwardEnabled();
|
151
|
|
}
|
152
|
|
}
|
153
|
|
}
|
154
|
|
|