svn-gvsig-desktop / branches / v05 / extensions / extWMS / src / com / iver / cit / gvsig / gui / beans / Pager.java @ 4187
History | View | Annotate | Download (13.1 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 4187 2006-02-23 10:36:30Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.2.2.6 2006-02-23 10:36:30 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.2.2.5 2006/02/16 10:36:41 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.1 2006/02/16 09:09:05 caballero
|
53 |
* PAger de Jaume
|
54 |
*
|
55 |
* Revision 1.2.2.4 2006/02/10 13:23:18 jaume
|
56 |
* page value can now be set externally
|
57 |
*
|
58 |
* Revision 1.2.2.3 2006/01/31 16:25:24 jaume
|
59 |
* correcciones de bugs
|
60 |
*
|
61 |
* Revision 1.3 2006/01/26 16:07:14 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.2.2.1 2006/01/26 12:59:32 jaume
|
65 |
* 0.5
|
66 |
*
|
67 |
* Revision 1.2 2006/01/24 14:36:33 jaume
|
68 |
* This is the new version
|
69 |
*
|
70 |
* Revision 1.1.2.5 2006/01/19 16:09:30 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
* Revision 1.1.2.4 2006/01/17 17:05:39 jaume
|
74 |
* fixed crazy buttons behavior :-P
|
75 |
*
|
76 |
* Revision 1.1.2.3 2006/01/17 17:01:55 jaume
|
77 |
* fixed crazy buttons behavior :-P
|
78 |
*
|
79 |
* Revision 1.1.2.2 2006/01/11 12:20:30 jaume
|
80 |
* *** empty log message ***
|
81 |
*
|
82 |
* Revision 1.1.2.1 2006/01/10 13:11:38 jaume
|
83 |
* *** empty log message ***
|
84 |
*
|
85 |
* Revision 1.1.2.1 2006/01/10 11:33:31 jaume
|
86 |
* Time dimension working against Jet Propulsion Laboratory's WMS server
|
87 |
*
|
88 |
* Revision 1.1.2.3 2006/01/09 18:10:38 jaume
|
89 |
* casi con el time dimension
|
90 |
*
|
91 |
* Revision 1.1.2.2 2006/01/02 18:08:01 jaume
|
92 |
* Tree de estilos
|
93 |
*
|
94 |
* Revision 1.1.2.1 2005/12/30 08:56:19 jaume
|
95 |
* *** empty log message ***
|
96 |
*
|
97 |
*
|
98 |
*/
|
99 |
/**
|
100 |
*
|
101 |
*/
|
102 |
package com.iver.cit.gvsig.gui.beans; |
103 |
|
104 |
import java.awt.Dimension; |
105 |
import java.awt.event.ActionEvent; |
106 |
import java.awt.event.ActionListener; |
107 |
|
108 |
import javax.swing.ImageIcon; |
109 |
import javax.swing.JButton; |
110 |
import javax.swing.JPanel; |
111 |
import javax.swing.JSlider; |
112 |
import javax.swing.JTextField; |
113 |
|
114 |
|
115 |
|
116 |
/**
|
117 |
* Bean that is useful to browse a very large list of data. It
|
118 |
* includes a set of navigation buttons to step ahead or behind
|
119 |
* by one or going to the first and last element of the list as
|
120 |
* well as an slider and a text field for directly focus on a
|
121 |
* list item.
|
122 |
*
|
123 |
* @author jaume dominguez faus
|
124 |
*
|
125 |
*/
|
126 |
public class Pager extends DefaultBean { |
127 |
private JPanel buttonsPanel = null; |
128 |
private JButton btnFastBackward = null; |
129 |
private JButton btnBackward = null; |
130 |
private JTextField txtItemCountDisplay = null; |
131 |
private JButton btnForward = null; |
132 |
private JButton btnFastForward = null; |
133 |
private JPanel sliderPanel = null; |
134 |
private JSlider slider = null; |
135 |
private int itemCount; |
136 |
private int lowLimit; |
137 |
private int currentValue = -1; |
138 |
private int orientation; |
139 |
private boolean refreshing = false; |
140 |
public static int HORIZONTAL=0; |
141 |
public static int VERTICAL=1; |
142 |
/**
|
143 |
* This is the default constructor. Creates a new instance of ItemBrowser with
|
144 |
* zero items.
|
145 |
*/
|
146 |
public Pager(int orientation){ |
147 |
super();
|
148 |
this.orientation=orientation;
|
149 |
initialize(0, 0); |
150 |
} |
151 |
|
152 |
/**
|
153 |
* Creates a new instance of ItemBrowser defining its edges
|
154 |
* @param lowIndex, the lowest edge.
|
155 |
* @param itemCount, the highest edge.
|
156 |
*/
|
157 |
public Pager(int lowIndex, int itemCount,int orientation) { |
158 |
super();
|
159 |
this.orientation=orientation;
|
160 |
initialize(lowIndex, itemCount); |
161 |
} |
162 |
|
163 |
/**
|
164 |
* This method initializes this
|
165 |
*
|
166 |
* @return void
|
167 |
*/
|
168 |
private void initialize(int lowIndex, int itemCount) { |
169 |
setItemCount(itemCount); |
170 |
this.lowLimit = lowIndex;
|
171 |
this.setLayout(null); |
172 |
if (orientation==VERTICAL){
|
173 |
this.setSize(45,305); |
174 |
this.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.lightGray,1)); |
175 |
this.setPreferredSize(new Dimension(40,300)); |
176 |
}else{
|
177 |
this.setSize(240, 50); |
178 |
this.setPreferredSize(new Dimension(190,50)); |
179 |
} |
180 |
|
181 |
this.add(getSliderPanel(), null); |
182 |
this.add(getButtonsPanel(), null); |
183 |
} |
184 |
|
185 |
/**
|
186 |
* This method initializes buttonsPanel
|
187 |
*
|
188 |
* @return javax.swing.JPanel
|
189 |
*/
|
190 |
private JPanel getButtonsPanel() { |
191 |
if (buttonsPanel == null) { |
192 |
buttonsPanel = new JPanel(); |
193 |
buttonsPanel.setLayout(null);
|
194 |
buttonsPanel.setName("buttonsPanel");
|
195 |
buttonsPanel.setPreferredSize(new java.awt.Dimension(173,50)); |
196 |
if (orientation==VERTICAL){
|
197 |
buttonsPanel.setBounds(3, 182, 35,115); |
198 |
}else{
|
199 |
buttonsPanel.setBounds(5, 25, 240, 25); |
200 |
} |
201 |
|
202 |
buttonsPanel.add(getBtnFastBackward(), null);
|
203 |
buttonsPanel.add(getBtnBackward(), null);
|
204 |
buttonsPanel.add(getTxtItemCountDisplay(), null);
|
205 |
buttonsPanel.add(getBtnForward(), null);
|
206 |
buttonsPanel.add(getBtnFastForward(), null);
|
207 |
} |
208 |
return buttonsPanel;
|
209 |
} |
210 |
|
211 |
/**
|
212 |
* This method initializes btnFastBackWard
|
213 |
*
|
214 |
* @return javax.swing.JButton
|
215 |
*/
|
216 |
private JButton getBtnFastBackward() { |
217 |
if (btnFastBackward == null) { |
218 |
btnFastBackward = new JButton(); |
219 |
if (orientation==VERTICAL){
|
220 |
btnFastBackward.setBounds(7, 1, 20, 24); |
221 |
}else{
|
222 |
btnFastBackward.setBounds(2, 1, 20, 24); |
223 |
} |
224 |
|
225 |
btnFastBackward.setEnabled(itemCount!=0);
|
226 |
btnFastBackward.addActionListener(new ActionListener() { |
227 |
public void actionPerformed(ActionEvent e) { |
228 |
if (currentValue != lowLimit){
|
229 |
setValue(lowLimit, true);
|
230 |
} |
231 |
}}); |
232 |
btnFastBackward.setIcon(new ImageIcon(getClass().getResource("images/fastbackward.png"))); |
233 |
} |
234 |
return btnFastBackward;
|
235 |
} |
236 |
|
237 |
/**
|
238 |
* This method initializes btnBackward
|
239 |
*
|
240 |
* @return javax.swing.JButton
|
241 |
*/
|
242 |
private JButton getBtnBackward() { |
243 |
if (btnBackward == null) { |
244 |
btnBackward = new JButton(); |
245 |
if (orientation==VERTICAL){
|
246 |
btnBackward.setBounds(7, 21, 20, 24); |
247 |
}else{
|
248 |
btnBackward.setBounds(21, 1, 20, 24); |
249 |
} |
250 |
|
251 |
btnBackward.setEnabled(itemCount!=0);
|
252 |
btnBackward.addActionListener(new ActionListener() { |
253 |
public void actionPerformed(ActionEvent e) { |
254 |
if (currentValue > lowLimit ){
|
255 |
setValue(currentValue-1, true); |
256 |
} |
257 |
}}); |
258 |
btnBackward.setIcon(new ImageIcon(getClass().getResource("images/backward.png"))); |
259 |
} |
260 |
return btnBackward;
|
261 |
} |
262 |
|
263 |
/**
|
264 |
* This method initializes txtItemCountDisplay
|
265 |
*
|
266 |
* @return javax.swing.JTextField
|
267 |
*/
|
268 |
private JTextField getTxtItemCountDisplay() { |
269 |
if (txtItemCountDisplay == null) { |
270 |
txtItemCountDisplay = new JTextField(); |
271 |
txtItemCountDisplay.setEnabled(itemCount!=0);
|
272 |
txtItemCountDisplay.setHorizontalAlignment(javax.swing.JTextField.CENTER); |
273 |
if (orientation==VERTICAL){
|
274 |
txtItemCountDisplay.setBounds(2,43, 33, 23); |
275 |
} else {
|
276 |
txtItemCountDisplay.setBounds(43, 2, 144, 23); |
277 |
} |
278 |
|
279 |
txtItemCountDisplay.setText(lowLimit+" / "+itemCount);
|
280 |
txtItemCountDisplay.addMouseListener(new java.awt.event.MouseAdapter() {
|
281 |
public void mouseClicked(java.awt.event.MouseEvent e) { |
282 |
txtItemCountDisplay.setText(currentValue+"");
|
283 |
txtItemCountDisplay.setSelectionStart(0);
|
284 |
txtItemCountDisplay.setSelectionEnd(txtItemCountDisplay.getText().length()); |
285 |
} |
286 |
}); |
287 |
txtItemCountDisplay.addActionListener(new java.awt.event.ActionListener() {
|
288 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
289 |
try {
|
290 |
int v = Integer.parseInt(txtItemCountDisplay.getText()); |
291 |
v = (v>itemCount) ? itemCount : v; |
292 |
setValue(v, true);
|
293 |
} catch (Exception ex){ |
294 |
refreshText(currentValue); |
295 |
} |
296 |
txtItemCountDisplay.transferFocusDownCycle(); |
297 |
} |
298 |
}); |
299 |
txtItemCountDisplay.setEnabled(false);
|
300 |
} |
301 |
return txtItemCountDisplay;
|
302 |
} |
303 |
|
304 |
/**
|
305 |
* This, sets the bean value and triggers an event that can be captured
|
306 |
* by a listener.
|
307 |
* @param number
|
308 |
* @param fireEvent, if true then this method will fire the event. If false,
|
309 |
* then the value will be changed silently.
|
310 |
*
|
311 |
*/
|
312 |
public void setValue(int number, boolean fireEvent) { |
313 |
if (number < lowLimit)
|
314 |
number = lowLimit; |
315 |
if (number > itemCount-1) |
316 |
number = itemCount; |
317 |
if (number != currentValue) {
|
318 |
currentValue = number; |
319 |
refreshControls(); |
320 |
if (fireEvent)
|
321 |
callValueChanged(new Integer(currentValue)); |
322 |
} |
323 |
} |
324 |
|
325 |
/**
|
326 |
* Refreshes all the mutable controls in this component.
|
327 |
*/
|
328 |
private void refreshControls() { |
329 |
int normalizedValue = (int) ((currentValue / (float) itemCount)*100); |
330 |
refreshSlider(normalizedValue); |
331 |
refreshText(currentValue); |
332 |
} |
333 |
|
334 |
/**
|
335 |
* Sets the slider to the correct (scaled) position.
|
336 |
* @param normalizedValue
|
337 |
*/
|
338 |
private void refreshSlider(int normalizedValue) { |
339 |
refreshing = true;
|
340 |
getSlider().setValue(normalizedValue); |
341 |
refreshing = false;
|
342 |
} |
343 |
|
344 |
/**
|
345 |
* @param string
|
346 |
*/
|
347 |
private void refreshText(int value) { |
348 |
String newText = (value+1) +" / "+itemCount; |
349 |
|
350 |
if (!getTxtItemCountDisplay().getText().equals(newText))
|
351 |
getTxtItemCountDisplay().setText(newText); |
352 |
} |
353 |
|
354 |
/**
|
355 |
* This method initializes btnForward
|
356 |
*
|
357 |
* @return javax.swing.JButton
|
358 |
*/
|
359 |
private JButton getBtnForward() { |
360 |
if (btnForward == null) { |
361 |
btnForward = new JButton(); |
362 |
if (orientation==VERTICAL){
|
363 |
btnForward.setBounds(7, 67, 20, 24); |
364 |
}else{
|
365 |
btnForward.setBounds(189, 1, 20, 24); |
366 |
} |
367 |
|
368 |
btnForward.setEnabled(itemCount!=0);
|
369 |
btnForward.addActionListener(new ActionListener() { |
370 |
public void actionPerformed(ActionEvent e) { |
371 |
if (currentValue < itemCount-1){ |
372 |
setValue(currentValue+1, true); |
373 |
} |
374 |
}}); |
375 |
btnForward.setIcon(new ImageIcon(getClass().getResource("images/forward.png"))); |
376 |
} |
377 |
return btnForward;
|
378 |
} |
379 |
|
380 |
/**
|
381 |
* This method initializes btnFastForward
|
382 |
*
|
383 |
* @return javax.swing.JButton
|
384 |
*/
|
385 |
private JButton getBtnFastForward() { |
386 |
if (btnFastForward == null) { |
387 |
btnFastForward = new JButton(); |
388 |
if (orientation==VERTICAL){
|
389 |
btnFastForward.setBounds(7, 91, 20, 24); |
390 |
}else{
|
391 |
btnFastForward.setBounds(208, 1, 20, 24); |
392 |
} |
393 |
|
394 |
btnFastForward.setEnabled(itemCount!=0);
|
395 |
btnFastForward.addActionListener(new ActionListener() { |
396 |
public void actionPerformed(ActionEvent e) { |
397 |
if (currentValue < itemCount-1){ |
398 |
setValue(itemCount-1, true); |
399 |
} |
400 |
}}); |
401 |
btnFastForward.setIcon(new ImageIcon(getClass().getResource("images/fastforward.png"))); |
402 |
} |
403 |
return btnFastForward;
|
404 |
} |
405 |
|
406 |
/**
|
407 |
* This method initializes sliderPanel
|
408 |
*
|
409 |
* @return javax.swing.JPanel
|
410 |
*/
|
411 |
private JPanel getSliderPanel() { |
412 |
if (sliderPanel == null) { |
413 |
sliderPanel = new JPanel(); |
414 |
sliderPanel.setLayout(null);
|
415 |
sliderPanel.setName("sliderPanel");
|
416 |
if (orientation==VERTICAL){
|
417 |
sliderPanel.setBounds(3, 0, 35, 181); |
418 |
}else{
|
419 |
sliderPanel.setBounds(5, 0, 300, 26); |
420 |
} |
421 |
sliderPanel.setEnabled(false);
|
422 |
sliderPanel.add(getSlider(), null);
|
423 |
} |
424 |
return sliderPanel;
|
425 |
} |
426 |
|
427 |
/**
|
428 |
* This method initializes slider
|
429 |
*
|
430 |
* @return javax.swing.JSlider
|
431 |
*/
|
432 |
private JSlider getSlider() { |
433 |
if (slider == null) { |
434 |
slider = new JSlider(); |
435 |
slider.setValue(0);
|
436 |
if (orientation==VERTICAL){
|
437 |
slider.setOrientation(JSlider.VERTICAL);
|
438 |
slider.setSize(24, 230); |
439 |
}else{
|
440 |
slider.setOrientation(JSlider.HORIZONTAL);
|
441 |
slider.setSize(230, 24); |
442 |
} |
443 |
|
444 |
slider.setLocation(0, 1); |
445 |
slider.setEnabled(itemCount!=0);
|
446 |
slider.addMouseListener(new java.awt.event.MouseAdapter() {
|
447 |
public void mouseReleased(java.awt.event.MouseEvent e) { |
448 |
int value = (int) (getSlider().getValue() * itemCount * 0.01); |
449 |
if (value >= itemCount)
|
450 |
value = itemCount - 1;
|
451 |
refreshText(value); |
452 |
setValue(value, false);
|
453 |
} |
454 |
}); |
455 |
slider.addChangeListener(new javax.swing.event.ChangeListener() {
|
456 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
457 |
int value = (int) (getSlider().getValue() * itemCount * 0.01); |
458 |
if (value >= itemCount)
|
459 |
value = itemCount - 1;
|
460 |
refreshText(value); |
461 |
if (!refreshing)
|
462 |
callValueChanged(new Integer(value)); |
463 |
} |
464 |
}); |
465 |
} |
466 |
return slider;
|
467 |
} |
468 |
|
469 |
/**
|
470 |
* Sets the amount of items that this component will handle.
|
471 |
* @param count
|
472 |
*/
|
473 |
public void setItemCount(int count){ |
474 |
itemCount = count; |
475 |
getSlider().setEnabled(count != 0);
|
476 |
getBtnFastBackward().setEnabled(count != 0);
|
477 |
getBtnBackward().setEnabled(count != 0);
|
478 |
getTxtItemCountDisplay().setEnabled(count != 0);
|
479 |
getBtnForward().setEnabled(count != 0);
|
480 |
getBtnFastForward().setEnabled(count != 0);
|
481 |
} |
482 |
|
483 |
/**
|
484 |
* Sets the starting point if none is defined the pager will start from 0.
|
485 |
* @param initial position
|
486 |
*/
|
487 |
public void setStartingPosition(int initialPosition) { |
488 |
lowLimit = initialPosition; |
489 |
} |
490 |
|
491 |
public void setCurrentPosition(int pos) { |
492 |
setValue(pos, true);
|
493 |
} |
494 |
} // @jve:decl-index=0:visual-constraint="10,15"
|