svn-gvsig-desktop / tags / v2_0_0_Build_2057 / libraries / libUIComponent / src / org / gvsig / gui / beans / table / TableControlerPanel.java @ 39177
History | View | Annotate | Download (11.8 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 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 |
package org.gvsig.gui.beans.table; |
20 |
|
21 |
import java.awt.Dimension; |
22 |
import java.awt.FlowLayout; |
23 |
import java.net.URL; |
24 |
|
25 |
import javax.swing.ImageIcon; |
26 |
import javax.swing.JButton; |
27 |
import javax.swing.JComboBox; |
28 |
import javax.swing.JLabel; |
29 |
import javax.swing.JPanel; |
30 |
|
31 |
import org.gvsig.gui.beans.Messages; |
32 |
import org.gvsig.gui.beans.table.listeners.TableListener; |
33 |
import org.gvsig.gui.util.StatusComponent; |
34 |
|
35 |
/**
|
36 |
* Control para el manejo de tablas. No contiene eventos, estos deben ser
|
37 |
* manejados desde la clase que lo llame.
|
38 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
39 |
*/
|
40 |
public class TableControlerPanel extends JPanel { |
41 |
private static final long serialVersionUID = -6442685244347917638L; |
42 |
private int HEIGHT_BUTTONS = 19; // 16 |
43 |
// estaria
|
44 |
// bien
|
45 |
// **********************Vars**********************************
|
46 |
private JButton bPrev = null; |
47 |
private JComboBox cPoint = null; |
48 |
private JButton bNext = null; |
49 |
private JButton bFirst = null; |
50 |
private JButton bLast = null; |
51 |
private JLabel lPoints = null; |
52 |
private JLabel lNumberOfPoints = null; |
53 |
private JButton bNew = null; |
54 |
private JButton bDelPoint = null; |
55 |
private JButton bClear = null; |
56 |
|
57 |
private String pathToImages = "images/"; // "/com/iver/cit/gvsig/gui/panels/images/"; |
58 |
|
59 |
/**
|
60 |
* Objeto para controlar el estado de los componentes visuales
|
61 |
*/
|
62 |
private StatusComponent statusComponent = null; |
63 |
|
64 |
// **********************End Vars******************************
|
65 |
|
66 |
// **********************Methods*******************************
|
67 |
/**
|
68 |
* This is the default constructor
|
69 |
*/
|
70 |
public TableControlerPanel(TableListener tableListener) {
|
71 |
initialize(tableListener); |
72 |
} |
73 |
|
74 |
/**
|
75 |
* This method initializes this
|
76 |
* @return void
|
77 |
*/
|
78 |
private void initialize(TableListener tableListener) { |
79 |
statusComponent = new StatusComponent(this); |
80 |
|
81 |
this.setLayout(new FlowLayout(FlowLayout.CENTER, 1, 0)); |
82 |
this.setAlignmentX(0); |
83 |
|
84 |
lPoints = new JLabel(); |
85 |
lPoints.setText(Messages.getText("registro") + " "); |
86 |
this.add(lPoints);
|
87 |
|
88 |
this.add(getBFirst());
|
89 |
this.add(getBPrev());
|
90 |
this.add(getCPoint());
|
91 |
this.add(getBNext());
|
92 |
this.add(getBLast());
|
93 |
this.add(getBNew());
|
94 |
this.add(getLNumberOfPoints());
|
95 |
this.add(getBDelPoint());
|
96 |
this.add(getBClear());
|
97 |
|
98 |
getBFirst().addActionListener(tableListener); |
99 |
getBPrev().addActionListener(tableListener); |
100 |
getCPoint().addActionListener(tableListener); |
101 |
getBNext().addActionListener(tableListener); |
102 |
getBLast().addActionListener(tableListener); |
103 |
getBNew().addActionListener(tableListener); |
104 |
getBDelPoint().addActionListener(tableListener); |
105 |
getBClear().addActionListener(tableListener); |
106 |
} |
107 |
|
108 |
/**
|
109 |
* Esta funci?n deshabilita todos los controles y guarda sus valores de
|
110 |
* habilitado o deshabilitado para que cuando se ejecute restoreControlsValue
|
111 |
* se vuelvan a quedar como estaba
|
112 |
*/
|
113 |
public void disableAllControls() { |
114 |
statusComponent.setEnabled(false);
|
115 |
} |
116 |
|
117 |
/**
|
118 |
* Esta funci?n deja los controles como estaban al ejecutar la funci?n
|
119 |
* disableAllControls
|
120 |
*/
|
121 |
public void restoreControlsValue() { |
122 |
statusComponent.setEnabled(true);
|
123 |
} |
124 |
|
125 |
// **********************Methods*******************************
|
126 |
/**
|
127 |
* This method initializes jButton
|
128 |
* @return javax.swing.JButton
|
129 |
*/
|
130 |
public JButton getBFirst() { |
131 |
if (bFirst == null) { |
132 |
bFirst = new JButton(); |
133 |
bFirst.setPreferredSize(new Dimension(22, HEIGHT_BUTTONS)); |
134 |
bFirst.setEnabled(false);
|
135 |
URL url = getClass().getResource(pathToImages + "first.png"); |
136 |
if(url != null) { |
137 |
bFirst.setIcon(new ImageIcon(url)); |
138 |
} |
139 |
bFirst.setToolTipText(Messages.getText("primero"));
|
140 |
} |
141 |
return bFirst;
|
142 |
} |
143 |
|
144 |
/**
|
145 |
* This method initializes jButton
|
146 |
* @return javax.swing.JButton
|
147 |
*/
|
148 |
public JButton getBLast() { |
149 |
if (bLast == null) { |
150 |
bLast = new JButton(); |
151 |
bLast.setPreferredSize(new Dimension(22, HEIGHT_BUTTONS)); |
152 |
bLast.setEnabled(false);
|
153 |
URL url = getClass().getResource(pathToImages + "last.png"); |
154 |
if(url != null) |
155 |
bLast.setIcon(new ImageIcon(url)); |
156 |
bLast.setToolTipText(Messages.getText("ultimo"));
|
157 |
} |
158 |
return bLast;
|
159 |
} |
160 |
|
161 |
/**
|
162 |
* This method initializes bBefore
|
163 |
* @return javax.swing.JButton
|
164 |
*/
|
165 |
public JButton getBPrev() { |
166 |
if (bPrev == null) { |
167 |
bPrev = new JButton(); |
168 |
bPrev.setText("");
|
169 |
bPrev.setEnabled(false);
|
170 |
bPrev.setPreferredSize(new Dimension(22, HEIGHT_BUTTONS)); |
171 |
URL url = getClass().getResource(pathToImages + "prev.png"); |
172 |
if(url != null) |
173 |
bPrev.setIcon(new ImageIcon(url)); |
174 |
bPrev.setActionCommand("");
|
175 |
bPrev.setToolTipText(Messages.getText("anterior"));
|
176 |
} |
177 |
return bPrev;
|
178 |
} |
179 |
|
180 |
/**
|
181 |
* This method initializes bNext
|
182 |
* @return javax.swing.JButton
|
183 |
*/
|
184 |
public JButton getBNext() { |
185 |
if (bNext == null) { |
186 |
bNext = new JButton(""); |
187 |
bNext.setEnabled(false);
|
188 |
bNext.setPreferredSize(new Dimension(22, HEIGHT_BUTTONS)); |
189 |
URL url = getClass().getResource(pathToImages + "next.png"); |
190 |
if(url != null) |
191 |
bNext.setIcon(new ImageIcon(url)); |
192 |
bNext.setActionCommand("");
|
193 |
bNext.setToolTipText(Messages.getText("siguiente"));
|
194 |
} |
195 |
return bNext;
|
196 |
} |
197 |
|
198 |
/**
|
199 |
* Este m?todo inicializa el combo que contiene el n?mero de puntos.
|
200 |
* @return javax.swing.JComboBox
|
201 |
*/
|
202 |
public JComboBox getCPoint() { |
203 |
if (cPoint == null) { |
204 |
cPoint = new JComboBox(); |
205 |
cPoint.setPreferredSize(new Dimension(64, HEIGHT_BUTTONS)); |
206 |
} |
207 |
return cPoint;
|
208 |
} |
209 |
|
210 |
/**
|
211 |
* @return Returns the lNumberOfPoints.
|
212 |
*/
|
213 |
public JLabel getLNumberOfPoints() { |
214 |
if (lNumberOfPoints == null) { |
215 |
lNumberOfPoints = new JLabel(); |
216 |
lNumberOfPoints.setText(Messages.getText("de") + " 0"); |
217 |
// lNumberOfPoints.setPreferredSize(new java.awt.Dimension(35,15));
|
218 |
} |
219 |
return lNumberOfPoints;
|
220 |
} |
221 |
|
222 |
/**
|
223 |
* This method initializes jButton
|
224 |
* @return javax.swing.JButton
|
225 |
*/
|
226 |
public JButton getBNew() { |
227 |
if (bNew == null) { |
228 |
bNew = new JButton(); |
229 |
bNew.setPreferredSize(new Dimension(22, HEIGHT_BUTTONS)); |
230 |
URL url = getClass().getResource(pathToImages + "newpoint.png"); |
231 |
if(url != null) |
232 |
bNew.setIcon(new ImageIcon(url)); |
233 |
bNew.setToolTipText(Messages.getText("nuevo"));
|
234 |
} |
235 |
return bNew;
|
236 |
} |
237 |
|
238 |
/**
|
239 |
* Este m?todo inicializa el bot?n del eliminar punto que har? que se elimine
|
240 |
* el punto seleccionado.
|
241 |
* @return javax.swing.JButton
|
242 |
*/
|
243 |
public JButton getBDelPoint() { |
244 |
if (bDelPoint == null) { |
245 |
bDelPoint = new JButton(); |
246 |
bDelPoint.setText("");
|
247 |
bDelPoint.setEnabled(false);
|
248 |
bDelPoint.setPreferredSize(new Dimension(22, HEIGHT_BUTTONS)); |
249 |
URL url = getClass().getResource(pathToImages + "delone.png"); |
250 |
if(url != null) |
251 |
bDelPoint.setIcon(new ImageIcon(url)); |
252 |
bDelPoint.setToolTipText(Messages.getText("borrar_uno"));
|
253 |
} |
254 |
return bDelPoint;
|
255 |
} |
256 |
|
257 |
/**
|
258 |
* Este m?todo inicializa el bot?n del clear que har? que se eliminen todos
|
259 |
* los puntos seleccionados.
|
260 |
* @return javax.swing.JButton
|
261 |
*/
|
262 |
public JButton getBClear() { |
263 |
if (bClear == null) { |
264 |
bClear = new JButton(); |
265 |
bClear.setText("");
|
266 |
bClear.setPreferredSize(new Dimension(22, HEIGHT_BUTTONS)); |
267 |
bClear.setEnabled(false);
|
268 |
URL url = getClass().getResource(pathToImages + "delall.png"); |
269 |
if(url != null) |
270 |
bClear.setIcon(new ImageIcon(url)); |
271 |
bClear.setActionCommand("");
|
272 |
bClear.setToolTipText(Messages.getText("borrar_todos"));
|
273 |
} |
274 |
return bClear;
|
275 |
} |
276 |
|
277 |
/**
|
278 |
* Resetea el control al estado inicial. Limpia el combo, pone el n?mero de
|
279 |
* elementos a 0 y desactiva las flechas.
|
280 |
*/
|
281 |
public void resetControls() { |
282 |
getCPoint().removeAllItems(); |
283 |
getLNumberOfPoints().setText(Messages.getText("de 0"));
|
284 |
checkArrows(); |
285 |
} |
286 |
|
287 |
/**
|
288 |
* Elimina del control un elemento de una posici?n.
|
289 |
* <UL>
|
290 |
* <LI>Actualiza el combo</LI>
|
291 |
* <LI>Actualiza el texto que dice el n?mero de elementos</LI>
|
292 |
* <LI>Actualiza las flechas</LI>
|
293 |
* </UL>
|
294 |
* @param pos Posici?n del elemento a eliminar.
|
295 |
*/
|
296 |
public void setNItems(int n) { |
297 |
// if(n < 1)
|
298 |
// return;
|
299 |
getCPoint().removeAllItems(); |
300 |
for (int i = 1; i <= n; i++) { |
301 |
try {
|
302 |
getCPoint().addItem(String.valueOf(i));
|
303 |
} catch (ArrayIndexOutOfBoundsException ex) { |
304 |
// No a?adimos nada
|
305 |
} |
306 |
} |
307 |
getLNumberOfPoints().setText(Messages.getText("de") + " " + n); |
308 |
checkArrows(); |
309 |
} |
310 |
|
311 |
/**
|
312 |
* Selecciona un elemento del control
|
313 |
* @param index
|
314 |
*/
|
315 |
public void setSelectedIndex(int index) { |
316 |
try {
|
317 |
getCPoint().setSelectedIndex(index); |
318 |
} catch (IllegalArgumentException ex) { |
319 |
|
320 |
} |
321 |
checkArrows(); |
322 |
} |
323 |
|
324 |
/**
|
325 |
* Devuelve el punto seleccionado
|
326 |
* @return Punto seleccionado.
|
327 |
*/
|
328 |
public int getSelectedIndex() { |
329 |
return getCPoint().getSelectedIndex();
|
330 |
} |
331 |
|
332 |
/**
|
333 |
* Obtiene el n?mero de elementos en la lista.
|
334 |
* @return N?mero de elementos
|
335 |
*/
|
336 |
public int getItemCount() { |
337 |
return getCPoint().getItemCount();
|
338 |
} |
339 |
|
340 |
/**
|
341 |
* Obtiene el Objeto seleccionado como cadena de texto.
|
342 |
* @return N?mero seleccionado
|
343 |
*/
|
344 |
public String getSelectedItem() { |
345 |
return getCPoint().getSelectedItem().toString();
|
346 |
} |
347 |
|
348 |
/**
|
349 |
* Comprueba la posici?n del combo para ver si tiene que habilitar o
|
350 |
* deshabilitar las flechas de delante y detr?s.
|
351 |
*/
|
352 |
public void checkArrows() { |
353 |
if (!statusComponent.isEnabled())
|
354 |
return;
|
355 |
|
356 |
if (getCPoint().getItemCount() <= 0) { |
357 |
getBClear().setEnabled(false);
|
358 |
getBDelPoint().setEnabled(false);
|
359 |
} else {
|
360 |
getBClear().setEnabled(true);
|
361 |
getBDelPoint().setEnabled(true);
|
362 |
} |
363 |
|
364 |
if (getCPoint().getSelectedIndex() == -1) { |
365 |
getBPrev().setEnabled(false);
|
366 |
getBNext().setEnabled(false);
|
367 |
getBLast().setEnabled(false);
|
368 |
getBFirst().setEnabled(false);
|
369 |
|
370 |
return;
|
371 |
} |
372 |
if (getCPoint().getSelectedIndex() == 0) { |
373 |
getBPrev().setEnabled(false);
|
374 |
getBFirst().setEnabled(false);
|
375 |
} else {
|
376 |
getBPrev().setEnabled(true);
|
377 |
getBFirst().setEnabled(true);
|
378 |
} |
379 |
|
380 |
if (getCPoint().getSelectedIndex() == (getCPoint().getItemCount() - 1)) { |
381 |
getBNext().setEnabled(false);
|
382 |
getBLast().setEnabled(false);
|
383 |
} else {
|
384 |
getBNext().setEnabled(true);
|
385 |
getBLast().setEnabled(true);
|
386 |
} |
387 |
} |
388 |
|
389 |
/**
|
390 |
* A?ade un punto al combo y checkea los controles colocandolos en los valores
|
391 |
* correctos.
|
392 |
* @param countPoints N?mero de punto a a?adir al final del combo
|
393 |
*/
|
394 |
public void addPointToTable(int countPoints) { |
395 |
getCPoint().addItem("" + countPoints);
|
396 |
getLNumberOfPoints().setText(Messages.getText("de") + " " + countPoints); |
397 |
setSelectedIndex(getItemCount() - 1);
|
398 |
checkArrows(); |
399 |
} |
400 |
|
401 |
/**
|
402 |
* Asigna la ruta donde est?n las imagenes
|
403 |
* @param pathToImages
|
404 |
*/
|
405 |
public void setPathToImages(String pathToImages) { |
406 |
this.pathToImages = pathToImages;
|
407 |
} |
408 |
|
409 |
/**
|
410 |
* Activa o desactiva este panel y todos los que lo componen
|
411 |
* @param enabled variable booleana para la activaci?n y/o desactivaci?n
|
412 |
*/
|
413 |
public void setEnabled(boolean enabled) { |
414 |
this.getBDelPoint().setEnabled(enabled);
|
415 |
this.getBClear().setEnabled(enabled);
|
416 |
} |
417 |
|
418 |
/**
|
419 |
* Dice si los controles est?n deshabilitados o no
|
420 |
* @return true si est? habilitado y false si no lo est?
|
421 |
*/
|
422 |
public boolean isDisableAllControls() { |
423 |
return !statusComponent.isEnabled();
|
424 |
} |
425 |
} |