root / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / gui / selectPoints / SelectPointsPanel.java @ 6214
History | View | Annotate | Download (29.2 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.georeferencing.gui.selectPoints; |
20 |
|
21 |
import java.awt.Component; |
22 |
import java.awt.FlowLayout; |
23 |
import java.awt.GridBagConstraints; |
24 |
import java.awt.GridBagLayout; |
25 |
import java.awt.event.ActionEvent; |
26 |
import java.awt.event.ActionListener; |
27 |
import java.awt.event.FocusEvent; |
28 |
import java.awt.event.FocusListener; |
29 |
import java.awt.event.KeyEvent; |
30 |
import java.awt.event.KeyListener; |
31 |
import java.awt.geom.Point2D; |
32 |
import java.beans.PropertyVetoException; |
33 |
|
34 |
import javax.swing.ImageIcon; |
35 |
import javax.swing.JButton; |
36 |
import javax.swing.JOptionPane; |
37 |
import javax.swing.JPanel; |
38 |
import javax.swing.JToggleButton; |
39 |
|
40 |
import org.gvsig.georeferencing.GeoreferencingToolsModule; |
41 |
import org.gvsig.georeferencing.gui.dialog.GeoreferencingDialog; |
42 |
import org.gvsig.georeferencing.gui.listeners.GeorefPointSelectorListener; |
43 |
import org.gvsig.georeferencing.gui.pointsTable.TableControlerPanel; |
44 |
|
45 |
import com.iver.andami.PluginServices; |
46 |
import com.iver.cit.gvsig.fmap.layers.FLyrPoints; |
47 |
import com.iver.cit.gvsig.gui.View; |
48 |
|
49 |
public class SelectPointsPanel extends JPanel implements ActionListener, KeyListener, FocusListener{ |
50 |
|
51 |
//**********************Vars**********************************
|
52 |
private String pathToImages = "images/"; //"/com/iver/cit/gvsig/gui/panels/images/"; |
53 |
private JPanel pGeneral = null; |
54 |
private JPanel pPointSelection = null; |
55 |
private JPanel pControlPoint = null; |
56 |
private JToggleButton bInsertPoint = null; |
57 |
private FLyrPoints lyrPoints = null; |
58 |
//private boolean disableEvent = false;
|
59 |
private int lastIndexSelection = -1; |
60 |
private JButton bExtended = null; |
61 |
private JPanel pExtend = null; |
62 |
private TableControlerPanel tableControlerPanel = null; |
63 |
private DataPointPanel dataPointPanel = null; |
64 |
private ErrorPointPanel errorPointPanel = null; |
65 |
private GeoreferencingDialog dialog = null; |
66 |
private boolean update = false; |
67 |
/**
|
68 |
* Valores ?ltimos que se han introducido en los JTextField para poder reponerlos.
|
69 |
*/
|
70 |
public String lastTx = "", lastTy = "", lastLong = "", lastLat = ""; |
71 |
/**
|
72 |
* Valores ?ltimos que se han introducido parcialmente en los JTextField para poder reponerlos si
|
73 |
* al pulsar una tecla se introduce un valor erroneo.
|
74 |
*/
|
75 |
public String lastBlockTx = "", lastBlockTy = "", lastBlockLong = "", lastBlockLat = ""; |
76 |
//**********************End Vars********************************
|
77 |
|
78 |
//**********************Methods*********************************
|
79 |
/**
|
80 |
* Contructor. Inicializa el panel.
|
81 |
*/
|
82 |
public SelectPointsPanel() {
|
83 |
super();
|
84 |
initialize(); |
85 |
} |
86 |
|
87 |
/**
|
88 |
* This is the default constructor
|
89 |
*/
|
90 |
public SelectPointsPanel(GeoreferencingDialog grd) {
|
91 |
super();
|
92 |
initialize(); |
93 |
this.dialog = grd;
|
94 |
} |
95 |
|
96 |
/**
|
97 |
* This method initializes this
|
98 |
*
|
99 |
* @return void
|
100 |
*/
|
101 |
private void initialize() { |
102 |
FlowLayout flowLayout2 = new FlowLayout(); |
103 |
flowLayout2.setHgap(5);
|
104 |
this.setLayout(flowLayout2);
|
105 |
this.setPreferredSize(new java.awt.Dimension(390,175)); |
106 |
this.setSize(new java.awt.Dimension(390,175)); |
107 |
this.setLocation(new java.awt.Point(0,0)); |
108 |
this.add(getPGeneral(), null); |
109 |
} |
110 |
|
111 |
/**
|
112 |
* Actualiza el n?mero de puntos del combo a partir de los contenidos en
|
113 |
* la capa de puntos. Esta funci?n es usada desde otros paneles que cambien
|
114 |
* el punto seleccionado para comunicar al control la nueva selecci?n.
|
115 |
*/
|
116 |
public void updateComboPoint(int pointSelected){ |
117 |
//disableEvent = true;
|
118 |
try{
|
119 |
loadLyrPoint(); |
120 |
}catch(InstantiationException exc){ |
121 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
122 |
PluginServices.getText(this, "error_capa_puntos")); |
123 |
return;
|
124 |
} |
125 |
|
126 |
tableControlerPanel.setNItems(lyrPoints.getCountPoints()); |
127 |
try{
|
128 |
tableControlerPanel.getCPoint().setSelectedIndex(pointSelected); |
129 |
}catch(IllegalArgumentException ex){ |
130 |
|
131 |
} |
132 |
tableControlerPanel.checkArrows(); |
133 |
lyrPoints.getPointManager().selectPoint(pointSelected, this.dialog);
|
134 |
//disableEvent = false;
|
135 |
} |
136 |
|
137 |
/**
|
138 |
* Comprueba si los valores de un punto en los campos de texto est?n
|
139 |
* vacios y lanza una excepci?n si hay alguno sin informaci?n.
|
140 |
* @throws NoSuchFieldException
|
141 |
*/
|
142 |
public void checkInfoPointText()throws NoSuchFieldException{ |
143 |
if( dataPointPanel.getTX().getText().equals("") || |
144 |
dataPointPanel.getTY().getText().equals("") ||
|
145 |
dataPointPanel.getLatitud().getText().equals("") ||
|
146 |
dataPointPanel.getLongitud().getText().equals("")){
|
147 |
//disableEvent = true;
|
148 |
try{
|
149 |
tableControlerPanel.getCPoint().setSelectedIndex(lastIndexSelection); |
150 |
//disableEvent = false;
|
151 |
}catch(IllegalArgumentException ex){ |
152 |
//Si el lastIndex tiene un valor erroneo no hacemos ninguna selecci?n
|
153 |
} |
154 |
throw new NoSuchFieldException(); |
155 |
} |
156 |
} |
157 |
|
158 |
/**
|
159 |
* Esta funci?n resetea los controles del panel de info de un punto.
|
160 |
*/
|
161 |
public void resetControls(boolean active){ |
162 |
dataPointPanel.resetControls(null);
|
163 |
errorPointPanel.resetControls(null);
|
164 |
getBInsertPoint().setEnabled(active); |
165 |
getTableControlerPanel().getBClear().setEnabled(active); |
166 |
getTableControlerPanel().getBDelPoint().setEnabled(active); |
167 |
if(!active)
|
168 |
getTableControlerPanel().resetControls(); |
169 |
} |
170 |
|
171 |
/**
|
172 |
* Cuando pasamos de un punto a otro o se va a crear uno nuevo
|
173 |
* <UL>
|
174 |
* <LI>Cargamos la capa FLyrPoint si no est? ya cargada.</LI>
|
175 |
* <LI>Comprobamos que los campos no esten vacios y lanzamos una excepci?n si hay alg?n campo vacio si lo est?n.</LI>
|
176 |
* <LI>Insertamos el nuevo punto seleccionado en los campos de informaci?n.</LI>
|
177 |
* <LI>Checkeamos las flechas para ver si tenemos que activarlas o desactivarlas.</LI>
|
178 |
* </UL>
|
179 |
* @param changeSelection Cambia la posici?n seleccionada del combo si es true
|
180 |
* @param pos Posici?n a la que cambia el combo si el parametro chageSelection es true
|
181 |
*/
|
182 |
public void changePoint(boolean changeSelection, int pos){ |
183 |
try{
|
184 |
loadLyrPoint(); |
185 |
checkInfoPointText(); |
186 |
if(changeSelection){
|
187 |
lastIndexSelection = pos; |
188 |
tableControlerPanel.setSelectedIndex(pos); |
189 |
} |
190 |
lyrPoints.getPointManager().selectPoint(tableControlerPanel.getSelectedIndex(), dialog); |
191 |
tableControlerPanel.checkArrows(); |
192 |
}catch(NoSuchFieldException exc){ |
193 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
194 |
PluginServices.getText(this, "coordenadas_vacias")); |
195 |
}catch(InstantiationException e){ |
196 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
197 |
PluginServices.getText(this, "error_capa_puntos")); |
198 |
} |
199 |
} |
200 |
|
201 |
/**
|
202 |
* Obtiene una capa de puntos. Si no existe crea una.
|
203 |
* @return
|
204 |
*/
|
205 |
private void loadLyrPoint() throws InstantiationException{ |
206 |
if(lyrPoints == null){ |
207 |
lyrPoints = dialog.getLyrPoints(); |
208 |
if(lyrPoints == null) |
209 |
throw new InstantiationException(); |
210 |
} |
211 |
} |
212 |
|
213 |
private void dialogWithoutImageError(){ |
214 |
|
215 |
} |
216 |
/**
|
217 |
* Este m?todo inicializa el bot?n seleccionar desde la vista. Cuando lo
|
218 |
* activamos se carga la herramienta de selecci?n de puntos desde la vista.
|
219 |
*
|
220 |
* @return javax.swing.JButton
|
221 |
*/
|
222 |
public JToggleButton getBInsertPoint() { |
223 |
if (bInsertPoint == null) { |
224 |
bInsertPoint = new JToggleButton(); |
225 |
bInsertPoint.setText("");
|
226 |
bInsertPoint.setPreferredSize(new java.awt.Dimension(22,22)); |
227 |
bInsertPoint.setIcon(new ImageIcon(getClass().getClassLoader().getResource(pathToImages + "selectfromview.png"))); |
228 |
bInsertPoint.setToolTipText(PluginServices.getText(this, "selectfromview")); |
229 |
bInsertPoint.setEnabled(false);
|
230 |
bInsertPoint.setSelected(true);
|
231 |
bInsertPoint.addActionListener(this);
|
232 |
} |
233 |
return bInsertPoint;
|
234 |
} |
235 |
|
236 |
/**
|
237 |
* Control de eventos de TableControlerPanel
|
238 |
*/
|
239 |
public void actionPerformed(ActionEvent e) { |
240 |
|
241 |
//Bot?n de ir al punto inicial
|
242 |
if(e.getSource() == tableControlerPanel.getBFirst()){
|
243 |
if(tableControlerPanel.getItemCount() >= 1) |
244 |
changePoint(true, 0); |
245 |
} |
246 |
|
247 |
//Bot?n de ir al punto anterior
|
248 |
if(e.getSource() == tableControlerPanel.getBPrev()){
|
249 |
if(tableControlerPanel.getSelectedIndex() != 0) |
250 |
changePoint(true, tableControlerPanel.getSelectedIndex() - 1); |
251 |
} |
252 |
|
253 |
//Bot?n de ir al punto siguiente
|
254 |
if(e.getSource() == tableControlerPanel.getBNext()){
|
255 |
if(tableControlerPanel.getSelectedIndex() != (tableControlerPanel.getItemCount() - 1)) |
256 |
changePoint(true, tableControlerPanel.getSelectedIndex() + 1); |
257 |
|
258 |
} |
259 |
|
260 |
//Bot?n de ir al punto final
|
261 |
if(e.getSource() == tableControlerPanel.getBLast()){
|
262 |
if(tableControlerPanel.getItemCount() >= 1) |
263 |
changePoint(true, tableControlerPanel.getItemCount() - 1); |
264 |
} |
265 |
|
266 |
//Combo de selecci?n de punto
|
267 |
if(e.getSource() == tableControlerPanel.getCPoint()){
|
268 |
if(tableControlerPanel.getSelectedIndex() != -1){ |
269 |
try{
|
270 |
loadLyrPoint(); |
271 |
}catch(InstantiationException exc){ |
272 |
return;
|
273 |
} |
274 |
lyrPoints.getPointManager().selectPoint(tableControlerPanel.getSelectedIndex(), dialog); |
275 |
tableControlerPanel.checkArrows(); |
276 |
} |
277 |
} |
278 |
|
279 |
//Bot?n de activar/desactivar la inserci?n de un punto
|
280 |
if((e.getSource() == getBInsertPoint()) || (e.getSource() == dialog.getBInsertPointOfTablePoints())){
|
281 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
282 |
if(!bInsertPoint.isSelected()){
|
283 |
String toolSelected = theView.getMapControl().getTool();
|
284 |
if(toolSelected.equals("pointLyrSelection")) |
285 |
theView.getMapControl().setTool(lyrPoints.getLastTool()); |
286 |
else
|
287 |
theView.getMapControl().setTool("pointLyrSelection");
|
288 |
}else
|
289 |
theView.getMapControl().setTool("pointLyrSelection");
|
290 |
} |
291 |
|
292 |
//Bot?n de nuevo punto
|
293 |
if((e.getSource() == tableControlerPanel.getBNew()) || (e.getSource() == dialog.getBNewPointOfTablePoints())){
|
294 |
//Comprobamos si est? activa la inserci?n de punto o no. Si no est? activa no hacemos nada
|
295 |
if(bInsertPoint.isSelected()){
|
296 |
dialog.getPointManager().newEmptyPoint(); |
297 |
|
298 |
//Desactivamos todos los controles para centrar la visi?n del usuario
|
299 |
//sobre la introducci?n de puntos
|
300 |
dialog.getPointManager().disableAllControls(); |
301 |
|
302 |
View theView = null; |
303 |
try{
|
304 |
theView = (View) PluginServices.getMDIManager().getActiveView();
|
305 |
}catch(ClassCastException ex){ |
306 |
//Controlamos que cuado se produzca esta excepci?n cerremos el cuadro con un aviso.
|
307 |
System.err.println("**Vista asociada al dialogo no encontrada"); |
308 |
try{
|
309 |
String string1 = PluginServices.getText(this, "yes"); |
310 |
Object[] options = {string1}; |
311 |
JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(), |
312 |
PluginServices.getText(this, "cuadro_no_asociado"), |
313 |
PluginServices.getText(this, "confirmacion"), |
314 |
JOptionPane.YES_OPTION,
|
315 |
JOptionPane.QUESTION_MESSAGE,
|
316 |
null,
|
317 |
options, |
318 |
string1); |
319 |
dialog.getFrame().setClosed(true);
|
320 |
return;
|
321 |
}catch(PropertyVetoException exc){} |
322 |
} |
323 |
|
324 |
//Salvamos la tool actualmente seleccionada, asignamos el punto y cargamos la herramienta de selecci?n de pto.
|
325 |
try{
|
326 |
loadLyrPoint(); |
327 |
lyrPoints.setLastTool(theView.getMapControl().getTool()); |
328 |
GeorefPointSelectorListener.posPoint = tableControlerPanel.getSelectedIndex(); |
329 |
GeorefPointSelectorListener.firstPoint = true;
|
330 |
theView.getMapControl().setTool("pointLyrSelection");
|
331 |
}catch(InstantiationException exc){ |
332 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
333 |
PluginServices.getText(this, "error_capa_puntos")); |
334 |
} |
335 |
} |
336 |
} |
337 |
|
338 |
TableControlerPanel ctrlPanel = dialog.getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().getTableControlerPanel(); |
339 |
|
340 |
//Bot?n de eliminado de todos los puntos
|
341 |
if( e.getSource() == getTableControlerPanel().getBClear() ||
|
342 |
e.getSource() == ctrlPanel.getBClear()){ |
343 |
dialog.getPointManager().deleteAllPoints(); |
344 |
} |
345 |
|
346 |
//Bot?n de eliminado de un punto
|
347 |
if(e.getSource() == getTableControlerPanel().getBDelPoint() ||
|
348 |
e.getSource() == ctrlPanel.getBDelPoint()){ |
349 |
dialog.getPointManager().deletePoint(); |
350 |
} |
351 |
|
352 |
//Bot?n de extensi?n del cuadro de dialogo
|
353 |
if(e.getSource() == this.getBExtended()) |
354 |
this.setEnlarge(dialog.isEnlarge());
|
355 |
|
356 |
} |
357 |
|
358 |
/* (non-Javadoc)
|
359 |
* @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
|
360 |
*/
|
361 |
public void keyPressed(KeyEvent e) { |
362 |
// TODO Auto-generated method stu
|
363 |
} |
364 |
|
365 |
/**
|
366 |
* Checkea un textField para que contenga caracteres validos. Consideramos validos
|
367 |
* los caracteres del 0 al 9, el punto, DEL, Supr, flechas y Enter teniendo en cuenta que el
|
368 |
* c?digo ascii del teclado numerico es distinto.
|
369 |
*/
|
370 |
public boolean checkTextField(int code){ |
371 |
|
372 |
//Si el caracter es erroneo pasamos de el y reponemos el texto que habia
|
373 |
if( (code >= 0 && code <= 7) || |
374 |
code == 9 ||
|
375 |
(code >= 11 && code <= 36) || |
376 |
(code >= 41 && code <= 45) || |
377 |
code == 47 ||
|
378 |
(code >= 58 && code <= 95) || |
379 |
(code >= 106 && code <= 109) || |
380 |
(code >= 111 && code <= 126) || |
381 |
code >= 128){
|
382 |
return false; |
383 |
} |
384 |
|
385 |
return true; |
386 |
} |
387 |
|
388 |
/**
|
389 |
* Control de eventos de las entradas de texto de los puntos
|
390 |
*/
|
391 |
public void keyReleased(KeyEvent e) { |
392 |
String tx = dataPointPanel.getTX().getText();
|
393 |
String ty = dataPointPanel.getTY().getText();
|
394 |
String lon = dataPointPanel.getLongitud().getText();
|
395 |
String lat = dataPointPanel.getLatitud().getText();
|
396 |
|
397 |
//Campo de texto de la coordenada X en pixeles
|
398 |
Point2D pixel = null; |
399 |
Point2D map = null; |
400 |
|
401 |
//Si el evento es sobre TX
|
402 |
if(e.getSource() == dataPointPanel.getTX()){
|
403 |
if(e.getKeyCode() == 10){ |
404 |
txEvent(); |
405 |
return;
|
406 |
} |
407 |
|
408 |
if(checkTextField(e.getKeyCode()))
|
409 |
lastBlockTx = tx; |
410 |
else
|
411 |
dataPointPanel.getTX().setText(lastBlockTx); |
412 |
} |
413 |
|
414 |
//Si el evento es sobre TY
|
415 |
if(e.getSource() == dataPointPanel.getTY()){
|
416 |
if(e.getKeyCode() == 10){ |
417 |
tyEvent(); |
418 |
return;
|
419 |
} |
420 |
|
421 |
if(checkTextField(e.getKeyCode()))
|
422 |
lastBlockTy = ty; |
423 |
else
|
424 |
dataPointPanel.getTY().setText(lastBlockTy); |
425 |
} |
426 |
|
427 |
//Si el evento es sobre Longitud
|
428 |
if(e.getSource() == dataPointPanel.getLongitud()){
|
429 |
if(e.getKeyCode() == 10){ |
430 |
lonEvent(); |
431 |
return;
|
432 |
} |
433 |
|
434 |
if(checkTextField(e.getKeyCode()))
|
435 |
lastBlockLong = lon; |
436 |
else
|
437 |
dataPointPanel.getLongitud().setText(lastBlockLong); |
438 |
} |
439 |
|
440 |
//Si el evento es sobre Latitud
|
441 |
if(e.getSource() == dataPointPanel.getLatitud()){
|
442 |
if(e.getKeyCode() == 10){ |
443 |
latEvent(); |
444 |
return;
|
445 |
} |
446 |
|
447 |
if(checkTextField(e.getKeyCode()))
|
448 |
lastBlockLat = lat; |
449 |
else
|
450 |
dataPointPanel.getLatitud().setText(lastBlockLat); |
451 |
} |
452 |
|
453 |
} |
454 |
|
455 |
/* (non-Javadoc)
|
456 |
* @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
|
457 |
*/
|
458 |
public void keyTyped(KeyEvent e) { |
459 |
// TODO Auto-generated method stub
|
460 |
|
461 |
} |
462 |
|
463 |
/* (non-Javadoc)
|
464 |
* @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
|
465 |
*/
|
466 |
public void focusGained(FocusEvent arg0) { |
467 |
// TODO Auto-generated method stub
|
468 |
|
469 |
} |
470 |
|
471 |
/**
|
472 |
* Cancela la selecci?n de puntos sobre la vista de forma gr?fica. Esta acci?n
|
473 |
* conllevar? seleccionar la ?ltima herramienta del mapCtrl
|
474 |
*/
|
475 |
private void abortSelectPoints(){ |
476 |
//Si todos los puntos est?n rellenos deseleccionamos la herramienta de selecci?n de puntos
|
477 |
GeorefPointSelectorListener.firstPoint = true;
|
478 |
|
479 |
//Activamos los controles de esta ya que habr? sido desactivados al llamar a newEmptyPoint
|
480 |
GeoreferencingToolsModule.setEnabled(true);
|
481 |
|
482 |
com.iver.cit.gvsig.gui.View theView = null;
|
483 |
try{
|
484 |
theView = (com.iver.cit.gvsig.gui.View)PluginServices.getMDIManager().getActiveView(); |
485 |
theView.getMapControl().setTool(dialog.getLyrPoints().getLastTool()); |
486 |
}catch(ClassCastException exc){ |
487 |
//No se selecciona la herramienta
|
488 |
} |
489 |
} |
490 |
|
491 |
/**
|
492 |
* Validaci?n de que el par?metro tenga formato numerico y de si
|
493 |
* este valor est? dentro de los l?mites de la imagen
|
494 |
* @param tx Campo TX
|
495 |
* @return true si es valido y false si no lo es
|
496 |
*/
|
497 |
private boolean validateTX(String tx){ |
498 |
double x = 0D; |
499 |
try{
|
500 |
x = Double.valueOf(tx).doubleValue();
|
501 |
if(x > dialog.getLyrGeoRaster().getImageWidth() || x < 0) |
502 |
throw new NumberFormatException(); |
503 |
}catch(NumberFormatException exc){ |
504 |
//Si no es valido reponemos lastValue
|
505 |
dataPointPanel.getTX().setText(lastTx); |
506 |
return false; |
507 |
} |
508 |
|
509 |
lastTx = tx; |
510 |
return true; |
511 |
} |
512 |
|
513 |
|
514 |
/**
|
515 |
* Validaci?n de que el par?metro tenga formato numerico y de si
|
516 |
* este valor est? dentro de los l?mites de la imagen
|
517 |
* @param ty Campo TY
|
518 |
* @return true si es valido y false si no lo es
|
519 |
*/
|
520 |
private boolean validateTY(String ty){ |
521 |
double y = 0D; |
522 |
try{
|
523 |
y = Double.valueOf(ty).doubleValue();
|
524 |
if(y > dialog.getLyrGeoRaster().getImageHeight() || y < 0) |
525 |
throw new NumberFormatException(); |
526 |
}catch(NumberFormatException exc){ |
527 |
//Si no es valido reponemos lastValue
|
528 |
dataPointPanel.getTY().setText(lastTy); |
529 |
return false; |
530 |
} |
531 |
|
532 |
lastTy = ty; |
533 |
return true; |
534 |
} |
535 |
|
536 |
/**
|
537 |
* Validaci?n de que el par?metro tenga formato numerico
|
538 |
* @param t Valor del campo
|
539 |
* @return true si es valido y false si no lo es
|
540 |
*/
|
541 |
private boolean validateNumericFormat(String field){ |
542 |
double d = 0D; |
543 |
try{
|
544 |
d = Double.valueOf(field).doubleValue();
|
545 |
}catch(NumberFormatException exc){ |
546 |
return false; |
547 |
} |
548 |
return true; |
549 |
} |
550 |
|
551 |
/**
|
552 |
* Funci?n que se ejecuta cuando TX pierde el foco o se pulsa enter sobre
|
553 |
* el JTextField
|
554 |
*/
|
555 |
private void txEvent(){ |
556 |
String tx = dataPointPanel.getTX().getText();
|
557 |
String ty = dataPointPanel.getTY().getText();
|
558 |
|
559 |
if(!validateTX(tx)) return; |
560 |
|
561 |
if(!ty.equals("")){ |
562 |
if(!validateTY(ty)) return; |
563 |
else{
|
564 |
lastBlockTx = "";
|
565 |
//Llamamos a la funci?n que gestiona la entrada del primer punto
|
566 |
dialog.getPointManager().selectFirstPoint(tx, ty); |
567 |
} |
568 |
} |
569 |
} |
570 |
|
571 |
/**
|
572 |
* Funci?n que se ejecuta cuando TY pierde el foco o se pulsa enter sobre
|
573 |
* el JTextField
|
574 |
*/
|
575 |
private void tyEvent(){ |
576 |
String tx = dataPointPanel.getTX().getText();
|
577 |
String ty = dataPointPanel.getTY().getText();
|
578 |
|
579 |
if(!validateTY(ty)) return; |
580 |
|
581 |
if(!tx.equals("")){ |
582 |
if(!validateTX(tx)) return; |
583 |
else{
|
584 |
lastBlockTy = "";
|
585 |
//Llamamos a la funci?n que gestiona la entrada del primer punto
|
586 |
dialog.getPointManager().selectFirstPoint(tx, ty); |
587 |
} |
588 |
} |
589 |
} |
590 |
|
591 |
/**
|
592 |
* Funci?n que se ejecuta cuando el campo de texto Longitud pierde el foco o se
|
593 |
* pulsa enter sobre el JTextField
|
594 |
*/
|
595 |
private void lonEvent(){ |
596 |
String lon = dataPointPanel.getLongitud().getText();
|
597 |
String lat = dataPointPanel.getLatitud().getText();
|
598 |
|
599 |
if(!validateNumericFormat(lon))
|
600 |
return;
|
601 |
|
602 |
lastLong = lon; |
603 |
if(!lat.equals("")){ |
604 |
lastLat = lat; |
605 |
lastBlockLat = "";
|
606 |
//Llamamos a la funci?n que gestiona la entrada del segundo punto
|
607 |
dialog.getPointManager().selectSecondPoint(lon, lat); |
608 |
} |
609 |
} |
610 |
|
611 |
/**
|
612 |
* Funci?n que se ejecuta cuando el campo de texto Latitud pierde el foco o se
|
613 |
* pulsa enter sobre el JTextField
|
614 |
*/
|
615 |
private void latEvent(){ |
616 |
String lon = dataPointPanel.getLongitud().getText();
|
617 |
String lat = dataPointPanel.getLatitud().getText();
|
618 |
|
619 |
if(!validateNumericFormat(lon))
|
620 |
return;
|
621 |
|
622 |
lastLat = lat; |
623 |
if(!lon.equals("")){ |
624 |
lastLong = lon; |
625 |
lastBlockLong = "";
|
626 |
//Llamamos a la funci?n que gestiona la entrada del segundo punto
|
627 |
dialog.getPointManager().selectSecondPoint(lon, lat); |
628 |
} |
629 |
} |
630 |
|
631 |
/**
|
632 |
* Los campos de texto de las coordenadas cuando pierden el foco actualizan el valor del pixel
|
633 |
* en la cap, vista, mini imagen y tabla
|
634 |
*/
|
635 |
public void focusLost(FocusEvent e) { |
636 |
String tx = dataPointPanel.getTX().getText();
|
637 |
String ty = dataPointPanel.getTY().getText();
|
638 |
String lon = dataPointPanel.getLongitud().getText();
|
639 |
String lat = dataPointPanel.getLatitud().getText();
|
640 |
|
641 |
//Si el elemento que pierde el foco es TX
|
642 |
if(e.getSource() == dataPointPanel.getTX())
|
643 |
txEvent(); |
644 |
|
645 |
//Si el elemento que pierde el foco es TY
|
646 |
if(e.getSource() == dataPointPanel.getTY())
|
647 |
tyEvent(); |
648 |
|
649 |
//Si el elemento que pierde el foco es Longitud
|
650 |
if(e.getSource() == dataPointPanel.getLongitud())
|
651 |
lonEvent(); |
652 |
|
653 |
//Si el elemento que pierde el foco es Latitud
|
654 |
if(e.getSource() == dataPointPanel.getLatitud())
|
655 |
latEvent(); |
656 |
|
657 |
//Si est?n rellenos todos los campos restauramos los controles
|
658 |
if( !dataPointPanel.getTX().getText().equals("") && |
659 |
!dataPointPanel.getTY().getText().equals("") &&
|
660 |
!dataPointPanel.getLongitud().getText().equals("") &&
|
661 |
!dataPointPanel.getLatitud().getText().equals("")){
|
662 |
dialog.getPointManager().restoreControlsValue(); |
663 |
this.abortSelectPoints();
|
664 |
} |
665 |
|
666 |
} |
667 |
|
668 |
//**********************End Methods*******************************
|
669 |
|
670 |
//**********************Setters & Getters*************************
|
671 |
/**
|
672 |
* Extiende o pliega el panel inferior controlando el icono del bot?n. Si se
|
673 |
* asigna true quiere decir que el panel est? desplegado, en este caso lo plegar?.
|
674 |
* Si se asigna false quiere decir que el panel est? plegado, en este caso lo
|
675 |
* desplegar?.
|
676 |
* @param enlarge True para recogerlo y false para desplegarlo
|
677 |
*/
|
678 |
public void setEnlarge(boolean enlarge){ |
679 |
if(enlarge){
|
680 |
dialog.setEnlarge(!enlarge); |
681 |
bExtended.setIcon(new ImageIcon(getClass().getClassLoader().getResource(pathToImages + "down.png"))); |
682 |
}else{
|
683 |
dialog.setEnlarge(!enlarge); |
684 |
bExtended.setIcon(new ImageIcon(getClass().getClassLoader().getResource(pathToImages + "up.png"))); |
685 |
if(lyrPoints != null){ |
686 |
//lyrPoints.getPointManager().selectPoint(tableControlerPanel.getSelectedIndex(), this.grd);
|
687 |
if(lyrPoints.isNewPoint(dialog.getSelectedPoint())){
|
688 |
dialog.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().setEnabled(false);
|
689 |
dialog.getConectorPanel().getAdjustGeorefPanel().getZoomRight().setEnabled(false);
|
690 |
} |
691 |
dialog.getZoomControlRight().draw(); |
692 |
dialog.getZoomControlLeft().draw(); |
693 |
} |
694 |
} |
695 |
} |
696 |
|
697 |
/**
|
698 |
* @return Returns the errorPointPanel.
|
699 |
*/
|
700 |
public ErrorPointPanel getErrorPointPanel() {
|
701 |
if(this.errorPointPanel == null) |
702 |
errorPointPanel = new ErrorPointPanel();
|
703 |
errorPointPanel.setPreferredSize(new java.awt.Dimension(175,130)); |
704 |
return errorPointPanel;
|
705 |
} |
706 |
/**
|
707 |
* @return Returns the lyrPoints.
|
708 |
*/
|
709 |
public FLyrPoints getLyrPoints() {
|
710 |
if(lyrPoints == null){ |
711 |
try{
|
712 |
loadLyrPoint(); |
713 |
}catch(InstantiationException exc){ |
714 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
715 |
PluginServices.getText(this, "error_capa_puntos")); |
716 |
} |
717 |
} |
718 |
return lyrPoints;
|
719 |
} |
720 |
|
721 |
/**
|
722 |
* This method initializes jButton
|
723 |
*
|
724 |
* @return javax.swing.JButton
|
725 |
*/
|
726 |
public JButton getBExtended() { |
727 |
if (bExtended == null) { |
728 |
bExtended = new JButton(); |
729 |
bExtended.setPreferredSize(new java.awt.Dimension(22,22)); |
730 |
bExtended.setIcon(new ImageIcon(getClass().getClassLoader().getResource(pathToImages + "down.png"))); |
731 |
bExtended.setToolTipText(PluginServices.getText(this, "plegar_despl")); |
732 |
bExtended.addActionListener(this);
|
733 |
} |
734 |
return bExtended;
|
735 |
} |
736 |
|
737 |
/**
|
738 |
* This method initializes jPanel
|
739 |
*
|
740 |
* @return javax.swing.JPanel
|
741 |
*/
|
742 |
private JPanel getPExtend() { |
743 |
if (pExtend == null) { |
744 |
FlowLayout flowLayout21 = new FlowLayout(); |
745 |
pExtend = new JPanel(); |
746 |
pExtend.setLayout(flowLayout21); |
747 |
flowLayout21.setHgap(0);
|
748 |
flowLayout21.setVgap(1);
|
749 |
flowLayout21.setAlignment(java.awt.FlowLayout.LEFT); |
750 |
pExtend.setPreferredSize(new java.awt.Dimension(50,22)); |
751 |
pExtend.add(getBInsertPoint(), null);
|
752 |
pExtend.add(getBExtended(), null);
|
753 |
} |
754 |
return pExtend;
|
755 |
} |
756 |
|
757 |
/**
|
758 |
* @return Returns the dataPointPanel.
|
759 |
*/
|
760 |
public DataPointPanel getDataPointPanel() {
|
761 |
return dataPointPanel;
|
762 |
} |
763 |
|
764 |
/**
|
765 |
* @param dataPointPanel The dataPointPanel to set.
|
766 |
*/
|
767 |
public void setDataPointPanel(DataPointPanel dataPointPanel) { |
768 |
this.dataPointPanel = dataPointPanel;
|
769 |
} |
770 |
|
771 |
/**
|
772 |
* @return Returns the tableControlerPanel.
|
773 |
*/
|
774 |
public TableControlerPanel getTableControlerPanel() {
|
775 |
return tableControlerPanel;
|
776 |
} |
777 |
|
778 |
/**
|
779 |
* @param tableControlerPanel The tableControlerPanel to set.
|
780 |
*/
|
781 |
public void setTableControlerPanel(TableControlerPanel tableControlerPanel) { |
782 |
this.tableControlerPanel = tableControlerPanel;
|
783 |
} |
784 |
|
785 |
/**
|
786 |
* This method initializes pGeneral
|
787 |
*
|
788 |
* @return javax.swing.JPanel
|
789 |
*/
|
790 |
private JPanel getPGeneral() { |
791 |
if (pGeneral == null) { |
792 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
793 |
gridBagConstraints1.insets = new java.awt.Insets(0,0,0,0); |
794 |
gridBagConstraints1.gridy = 0;
|
795 |
gridBagConstraints1.gridx = 0;
|
796 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
797 |
gridBagConstraints.insets = new java.awt.Insets(5,0,5,0); |
798 |
gridBagConstraints.gridy = 1;
|
799 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; |
800 |
gridBagConstraints.gridheight = 1;
|
801 |
gridBagConstraints.gridx = 0;
|
802 |
pGeneral = new JPanel(); |
803 |
pGeneral.setLayout(new GridBagLayout()); |
804 |
pGeneral.setPreferredSize(new java.awt.Dimension(390,175)); |
805 |
gridBagConstraints.gridwidth = 1;
|
806 |
pGeneral.add(getPPointSelection(), gridBagConstraints); |
807 |
pGeneral.add(getPControlPoint(), gridBagConstraints1); |
808 |
} |
809 |
return pGeneral;
|
810 |
} |
811 |
|
812 |
/**
|
813 |
* This method initializes pFileSelection
|
814 |
*
|
815 |
* @return javax.swing.JPanel
|
816 |
*/
|
817 |
private JPanel getPPointSelection() { |
818 |
if (pPointSelection == null) { |
819 |
//jLabel = new JLabel();
|
820 |
FlowLayout flowLayout1 = new FlowLayout(); |
821 |
FlowLayout flowLayout = new FlowLayout(); |
822 |
flowLayout.setHgap(0);
|
823 |
flowLayout.setVgap(1);
|
824 |
flowLayout.setAlignment(java.awt.FlowLayout.LEFT); |
825 |
pPointSelection = new JPanel(); |
826 |
pPointSelection.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.LOWERED)); |
827 |
pPointSelection.setName("");
|
828 |
pPointSelection.setLayout(flowLayout); |
829 |
pPointSelection.setPreferredSize(new java.awt.Dimension(375,27)); |
830 |
if(this.tableControlerPanel == null){ |
831 |
tableControlerPanel = new TableControlerPanel();
|
832 |
tableControlerPanel.setLayout(flowLayout1); |
833 |
flowLayout1.setVgap(0);
|
834 |
flowLayout1.setHgap(0);
|
835 |
|
836 |
tableControlerPanel.getBFirst().addActionListener(this);
|
837 |
tableControlerPanel.getBLast().addActionListener(this);
|
838 |
tableControlerPanel.getBNext().addActionListener(this);
|
839 |
tableControlerPanel.getBPrev().addActionListener(this);
|
840 |
tableControlerPanel.getBNew().addActionListener(this);
|
841 |
tableControlerPanel.getCPoint().addActionListener(this);
|
842 |
tableControlerPanel.getBClear().addActionListener(this);
|
843 |
tableControlerPanel.getBDelPoint().addActionListener(this);
|
844 |
} |
845 |
|
846 |
pPointSelection.add(tableControlerPanel, null);
|
847 |
pPointSelection.add(getPExtend(), null);
|
848 |
} |
849 |
return pPointSelection;
|
850 |
} |
851 |
|
852 |
/**
|
853 |
* This method initializes pControls
|
854 |
*
|
855 |
*/
|
856 |
private JPanel getPControlPoint() { |
857 |
if (pControlPoint == null) { |
858 |
GridBagConstraints gridBagConstraints11 = new GridBagConstraints(); |
859 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
860 |
gridBagConstraints2.gridx = 0;
|
861 |
gridBagConstraints2.insets = new java.awt.Insets(0,0,0,0); |
862 |
gridBagConstraints2.gridy = 0;
|
863 |
pControlPoint = new JPanel(); |
864 |
pControlPoint.setLayout(new GridBagLayout()); |
865 |
pControlPoint.setPreferredSize(new java.awt.Dimension(380,130)); |
866 |
pControlPoint.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,0,0,0)); |
867 |
gridBagConstraints11.gridy = 0;
|
868 |
gridBagConstraints11.gridx = 1;
|
869 |
if(this.dataPointPanel == null){ |
870 |
dataPointPanel = new DataPointPanel();
|
871 |
dataPointPanel.setPreferredSize(new java.awt.Dimension(200,130)); |
872 |
dataPointPanel.getTX().addKeyListener(this);
|
873 |
dataPointPanel.getTY().addKeyListener(this);
|
874 |
dataPointPanel.getLatitud().addKeyListener(this);
|
875 |
dataPointPanel.getLongitud().addKeyListener(this);
|
876 |
dataPointPanel.getTX().addFocusListener(this);
|
877 |
dataPointPanel.getTY().addFocusListener(this);
|
878 |
dataPointPanel.getLatitud().addFocusListener(this);
|
879 |
dataPointPanel.getLongitud().addFocusListener(this);
|
880 |
} |
881 |
pControlPoint.add(dataPointPanel, gridBagConstraints2); |
882 |
|
883 |
getErrorPointPanel(); |
884 |
pControlPoint.add(errorPointPanel, gridBagConstraints11); |
885 |
} |
886 |
return pControlPoint;
|
887 |
} |
888 |
|
889 |
/**
|
890 |
* Asigna la ruta donde est?n las imagenes
|
891 |
* @param pathToImages
|
892 |
*/
|
893 |
public void setPathToImages(String pathToImages) { |
894 |
this.pathToImages = pathToImages;
|
895 |
} |
896 |
|
897 |
/**
|
898 |
* Obtiene el ?ltimo indice seleccionado de la lista de puntos
|
899 |
* @return entero con el ?ltimo indice seleccionado de la lista de puntos
|
900 |
*/
|
901 |
public int getLastIndexSelection() { |
902 |
return lastIndexSelection;
|
903 |
} |
904 |
|
905 |
/**
|
906 |
* Asigna el ?ltimo indice seleccionado de la lista de puntos
|
907 |
* @param entero con el ?ltimo indice seleccionado de la lista de puntos
|
908 |
*/
|
909 |
public void setLastIndexSelection(int lastIndexSelection) { |
910 |
this.lastIndexSelection = lastIndexSelection;
|
911 |
} |
912 |
|
913 |
/**
|
914 |
* Activa o desactiva este panel y todos los que lo componen
|
915 |
* @param enabled variable booleana para la activaci?n y/o desactivaci?n
|
916 |
*/
|
917 |
public void setEnabled(boolean enabled){ |
918 |
this.dataPointPanel.setEnabled(enabled);
|
919 |
this.errorPointPanel.setEnabled(enabled);
|
920 |
this.tableControlerPanel.setEnabled(enabled);
|
921 |
this.getBInsertPoint().setEnabled(enabled);
|
922 |
} |
923 |
//**********************End Setters & Getters*********************
|
924 |
} |