svn-gvsig-desktop / branches / gvSIG_WMSv2 / extensions / extWMS / src / com / iver / cit / gvsig / gui / beans / Pager.java @ 3658
History | View | Annotate | Download (12 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: Pager.java 3658 2006-01-17 17:01:55Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.1.2.3 2006-01-17 17:01:55 jaume
|
47 |
* fixed crazy buttons behavior :-P
|
48 |
*
|
49 |
* Revision 1.1.2.2 2006/01/11 12:20:30 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.1.2.1 2006/01/10 13:11:38 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.1.2.1 2006/01/10 11:33:31 jaume
|
56 |
* Time dimension working against Jet Propulsion Laboratory's WMS server
|
57 |
*
|
58 |
* Revision 1.1.2.3 2006/01/09 18:10:38 jaume
|
59 |
* casi con el time dimension
|
60 |
*
|
61 |
* Revision 1.1.2.2 2006/01/02 18:08:01 jaume
|
62 |
* Tree de estilos
|
63 |
*
|
64 |
* Revision 1.1.2.1 2005/12/30 08:56:19 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
*
|
68 |
*/
|
69 |
/**
|
70 |
*
|
71 |
*/
|
72 |
package com.iver.cit.gvsig.gui.beans; |
73 |
|
74 |
import java.awt.event.ActionEvent; |
75 |
import java.awt.event.ActionListener; |
76 |
|
77 |
import javax.swing.ImageIcon; |
78 |
import javax.swing.JButton; |
79 |
import javax.swing.JPanel; |
80 |
import javax.swing.JSlider; |
81 |
import javax.swing.JTextField; |
82 |
|
83 |
/**
|
84 |
* Bean useful to browse a very large list of data. It includes
|
85 |
* a set of navigation buttons to step ahead or behind by one or
|
86 |
* going to the first and last element of the list as well as an
|
87 |
* slider and a text field for directly focus on a list item.
|
88 |
|
89 |
* @author jaume dominguez faus
|
90 |
*
|
91 |
*/
|
92 |
public class Pager extends DefaultBean { |
93 |
private JPanel buttonsPanel = null; |
94 |
private JButton btnFastBackward = null; |
95 |
private JButton btnBackward = null; |
96 |
private JTextField txtItemCountDisplay = null; |
97 |
private JButton btnForward = null; |
98 |
private JButton btnFastForward = null; |
99 |
private JPanel sliderPanel = null; |
100 |
private JSlider slider = null; |
101 |
private int itemCount; |
102 |
private int lowLimit; |
103 |
private int currentValue; |
104 |
private boolean editing = true; |
105 |
/**
|
106 |
* This is the default constructor. Creates a new instance of ItemBrowser with
|
107 |
* zero items.
|
108 |
*/
|
109 |
public Pager(){
|
110 |
super();
|
111 |
initialize(0, 0); |
112 |
} |
113 |
|
114 |
/**
|
115 |
* Creates a new instance of ItemBrowser defining its edges
|
116 |
* @param lowIndex, the lowest edge.
|
117 |
* @param itemCount, the highest edge.
|
118 |
*/
|
119 |
public Pager(int lowIndex, int itemCount) { |
120 |
super();
|
121 |
initialize(lowIndex, itemCount); |
122 |
} |
123 |
|
124 |
/**
|
125 |
* This method initializes this
|
126 |
*
|
127 |
* @return void
|
128 |
*/
|
129 |
private void initialize(int lowIndex, int itemCount) { |
130 |
setItemCount(itemCount); |
131 |
this.lowLimit = lowIndex;
|
132 |
this.currentValue = lowLimit;
|
133 |
this.setLayout(null); |
134 |
this.setSize(190, 50); |
135 |
this.add(getSliderPanel(), null); |
136 |
this.add(getButtonsPanel(), null); |
137 |
} |
138 |
|
139 |
/**
|
140 |
* This method initializes buttonsPanel
|
141 |
*
|
142 |
* @return javax.swing.JPanel
|
143 |
*/
|
144 |
private JPanel getButtonsPanel() { |
145 |
if (buttonsPanel == null) { |
146 |
buttonsPanel = new JPanel(); |
147 |
buttonsPanel.setLayout(null);
|
148 |
buttonsPanel.setName("buttonsPanel");
|
149 |
buttonsPanel.setPreferredSize(new java.awt.Dimension(173,50)); |
150 |
buttonsPanel.setBounds(5, 25, 180, 25); |
151 |
buttonsPanel.add(getBtnFastBackward(), null);
|
152 |
buttonsPanel.add(getBtnBackward(), null);
|
153 |
buttonsPanel.add(getTxtItemCountDisplay(), null);
|
154 |
buttonsPanel.add(getBtnForward(), null);
|
155 |
buttonsPanel.add(getBtnFastForward(), null);
|
156 |
} |
157 |
return buttonsPanel;
|
158 |
} |
159 |
|
160 |
/**
|
161 |
* This method initializes btnFastBackWard
|
162 |
*
|
163 |
* @return javax.swing.JButton
|
164 |
*/
|
165 |
private JButton getBtnFastBackward() { |
166 |
if (btnFastBackward == null) { |
167 |
btnFastBackward = new JButton(); |
168 |
btnFastBackward.setBounds(2, 1, 20, 24); |
169 |
btnFastBackward.setEnabled(itemCount!=0);
|
170 |
btnFastBackward.addActionListener(new ActionListener() { |
171 |
public void actionPerformed(ActionEvent e) { |
172 |
if (currentValue != lowLimit){
|
173 |
setValue(lowLimit, true);
|
174 |
} |
175 |
}}); |
176 |
btnFastBackward.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/fastbackward.png"))); |
177 |
} |
178 |
return btnFastBackward;
|
179 |
} |
180 |
|
181 |
/**
|
182 |
* This method initializes btnBackward
|
183 |
*
|
184 |
* @return javax.swing.JButton
|
185 |
*/
|
186 |
private JButton getBtnBackward() { |
187 |
if (btnBackward == null) { |
188 |
btnBackward = new JButton(); |
189 |
btnBackward.setBounds(21, 1, 20, 24); |
190 |
btnBackward.setEnabled(itemCount!=0);
|
191 |
btnBackward.addActionListener(new ActionListener() { |
192 |
public void actionPerformed(ActionEvent e) { |
193 |
if (currentValue > lowLimit ){
|
194 |
setValue(currentValue-1, true); |
195 |
} |
196 |
}}); |
197 |
btnBackward.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/backward.png"))); |
198 |
} |
199 |
return btnBackward;
|
200 |
} |
201 |
|
202 |
/**
|
203 |
* This method initializes txtItemCountDisplay
|
204 |
*
|
205 |
* @return javax.swing.JTextField
|
206 |
*/
|
207 |
private JTextField getTxtItemCountDisplay() { |
208 |
if (txtItemCountDisplay == null) { |
209 |
txtItemCountDisplay = new JTextField(); |
210 |
txtItemCountDisplay.setEnabled(itemCount!=0);
|
211 |
txtItemCountDisplay.setHorizontalAlignment(javax.swing.JTextField.CENTER); |
212 |
txtItemCountDisplay.setBounds(43, 2, 94, 23); |
213 |
txtItemCountDisplay.setText(lowLimit+" / "+itemCount);
|
214 |
txtItemCountDisplay.addMouseListener(new java.awt.event.MouseAdapter() {
|
215 |
public void mouseClicked(java.awt.event.MouseEvent e) { |
216 |
txtItemCountDisplay.setText(currentValue+"");
|
217 |
txtItemCountDisplay.setSelectionStart(0);
|
218 |
txtItemCountDisplay.setSelectionEnd(txtItemCountDisplay.getText().length()); |
219 |
} |
220 |
}); |
221 |
txtItemCountDisplay.addActionListener(new java.awt.event.ActionListener() {
|
222 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
223 |
try {
|
224 |
int v = Integer.parseInt(txtItemCountDisplay.getText()); |
225 |
v = (v>itemCount) ? itemCount : v; |
226 |
setValue(v, true);
|
227 |
} catch (Exception ex){ |
228 |
refreshText(currentValue); |
229 |
} |
230 |
txtItemCountDisplay.transferFocusDownCycle(); |
231 |
} |
232 |
}); |
233 |
txtItemCountDisplay.setEnabled(false);
|
234 |
} |
235 |
return txtItemCountDisplay;
|
236 |
} |
237 |
|
238 |
/**
|
239 |
* This, sets the bean value and triggers an event that can be captured
|
240 |
* by a listener.
|
241 |
* @param number
|
242 |
* @param fireEvent, if true then this method will fire the event. If false,
|
243 |
* then the value will be changed silently.
|
244 |
*
|
245 |
*/
|
246 |
public void setValue(int number, boolean fireEvent) { |
247 |
if (number < lowLimit)
|
248 |
number = lowLimit; |
249 |
if (number > itemCount)
|
250 |
number = itemCount; |
251 |
if (number != currentValue) {
|
252 |
currentValue = number; |
253 |
refreshControls(); |
254 |
if (fireEvent)
|
255 |
callValueChanged(new Integer(currentValue)); |
256 |
} |
257 |
} |
258 |
|
259 |
private void refreshControls() { |
260 |
int normalizedValue = (int) ((currentValue / (float) itemCount)*100); |
261 |
refreshSlider(normalizedValue); |
262 |
refreshText(currentValue); |
263 |
} |
264 |
|
265 |
/**
|
266 |
* @param normalizedValue
|
267 |
*/
|
268 |
private void refreshSlider(int normalizedValue) { |
269 |
getSlider().setValue(normalizedValue); |
270 |
} |
271 |
|
272 |
/**
|
273 |
* @param string
|
274 |
*/
|
275 |
private void refreshText(int value) { |
276 |
String newText = value+" / "+itemCount; |
277 |
if (!getTxtItemCountDisplay().getText().equals(newText))
|
278 |
getTxtItemCountDisplay().setText(newText); |
279 |
} |
280 |
|
281 |
/**
|
282 |
* This method initializes btnForward
|
283 |
*
|
284 |
* @return javax.swing.JButton
|
285 |
*/
|
286 |
private JButton getBtnForward() { |
287 |
if (btnForward == null) { |
288 |
btnForward = new JButton(); |
289 |
btnForward.setBounds(139, 1, 20, 24); |
290 |
btnForward.setEnabled(itemCount!=0);
|
291 |
btnForward.addActionListener(new ActionListener() { |
292 |
public void actionPerformed(ActionEvent e) { |
293 |
if (currentValue < itemCount){
|
294 |
setValue(currentValue+1, true); |
295 |
} |
296 |
}}); |
297 |
btnForward.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/forward.png"))); |
298 |
} |
299 |
return btnForward;
|
300 |
} |
301 |
|
302 |
/**
|
303 |
* This method initializes btnFastForward
|
304 |
*
|
305 |
* @return javax.swing.JButton
|
306 |
*/
|
307 |
private JButton getBtnFastForward() { |
308 |
if (btnFastForward == null) { |
309 |
btnFastForward = new JButton(); |
310 |
btnFastForward.setBounds(158, 1, 20, 24); |
311 |
btnFastForward.setEnabled(itemCount!=0);
|
312 |
btnFastForward.addActionListener(new ActionListener() { |
313 |
public void actionPerformed(ActionEvent e) { |
314 |
if (currentValue < itemCount){
|
315 |
setValue(itemCount, true);
|
316 |
} |
317 |
}}); |
318 |
btnFastForward.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/fastforward.png"))); |
319 |
} |
320 |
return btnFastForward;
|
321 |
} |
322 |
|
323 |
/**
|
324 |
* This method initializes sliderPanel
|
325 |
*
|
326 |
* @return javax.swing.JPanel
|
327 |
*/
|
328 |
private JPanel getSliderPanel() { |
329 |
if (sliderPanel == null) { |
330 |
sliderPanel = new JPanel(); |
331 |
sliderPanel.setLayout(null);
|
332 |
sliderPanel.setName("sliderPanel");
|
333 |
sliderPanel.setBounds(5, 0, 181, 26); |
334 |
sliderPanel.setEnabled(false);
|
335 |
sliderPanel.add(getSlider(), null);
|
336 |
} |
337 |
return sliderPanel;
|
338 |
} |
339 |
|
340 |
/**
|
341 |
* This method initializes slider
|
342 |
*
|
343 |
* @return javax.swing.JSlider
|
344 |
*/
|
345 |
private JSlider getSlider() { |
346 |
if (slider == null) { |
347 |
slider = new JSlider(); |
348 |
slider.setValue(0);
|
349 |
slider.setSize(180, 24); |
350 |
slider.setLocation(0, 1); |
351 |
slider.setEnabled(itemCount!=0);
|
352 |
slider.addMouseListener(new java.awt.event.MouseAdapter() {
|
353 |
public void mouseReleased(java.awt.event.MouseEvent e) { |
354 |
int value = (int) (getSlider().getValue() * itemCount * 0.01); |
355 |
setValue(value, false);
|
356 |
} |
357 |
}); |
358 |
slider.addChangeListener(new javax.swing.event.ChangeListener() {
|
359 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
360 |
int value = (int) (getSlider().getValue() * itemCount * 0.01); |
361 |
refreshText(value); |
362 |
callValueChanged(new Integer(value)); |
363 |
} |
364 |
}); |
365 |
} |
366 |
return slider;
|
367 |
} |
368 |
|
369 |
|
370 |
public void setItemCount(int count){ |
371 |
itemCount = count; |
372 |
getSlider().setEnabled(count != 0);
|
373 |
getBtnFastBackward().setEnabled(count != 0);
|
374 |
getBtnBackward().setEnabled(count != 0);
|
375 |
getTxtItemCountDisplay().setEnabled(count != 0);
|
376 |
getBtnForward().setEnabled(count != 0);
|
377 |
getBtnFastForward().setEnabled(count != 0);
|
378 |
} |
379 |
} // @jve:decl-index=0:visual-constraint="10,15"
|