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