svn-gvsig-desktop / tags / v1_0_2_Build_898 / extensions / extGeoreferencing / src / org / gvsig / georeferencing / gui / selectPoints / SelectPointsPanel.java @ 10513
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.project.documents.view.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 |
try{
|
228 |
bInsertPoint.setIcon(new ImageIcon(getClass().getClassLoader().getResource(pathToImages + "selectfromview.png"))); |
229 |
}catch(NullPointerException e){ |
230 |
//Sin icono
|
231 |
} |
232 |
bInsertPoint.setToolTipText(PluginServices.getText(this, "selectfromview")); |
233 |
bInsertPoint.setEnabled(false);
|
234 |
bInsertPoint.setSelected(true);
|
235 |
bInsertPoint.addActionListener(this);
|
236 |
} |
237 |
return bInsertPoint;
|
238 |
} |
239 |
|
240 |
/**
|
241 |
* Control de eventos de TableControlerPanel
|
242 |
*/
|
243 |
public void actionPerformed(ActionEvent e) { |
244 |
|
245 |
//Bot?n de ir al punto inicial
|
246 |
if(e.getSource() == tableControlerPanel.getBFirst()){
|
247 |
if(tableControlerPanel.getItemCount() >= 1) |
248 |
changePoint(true, 0); |
249 |
} |
250 |
|
251 |
//Bot?n de ir al punto anterior
|
252 |
if(e.getSource() == tableControlerPanel.getBPrev()){
|
253 |
if(tableControlerPanel.getSelectedIndex() != 0) |
254 |
changePoint(true, tableControlerPanel.getSelectedIndex() - 1); |
255 |
} |
256 |
|
257 |
//Bot?n de ir al punto siguiente
|
258 |
if(e.getSource() == tableControlerPanel.getBNext()){
|
259 |
if(tableControlerPanel.getSelectedIndex() != (tableControlerPanel.getItemCount() - 1)) |
260 |
changePoint(true, tableControlerPanel.getSelectedIndex() + 1); |
261 |
|
262 |
} |
263 |
|
264 |
//Bot?n de ir al punto final
|
265 |
if(e.getSource() == tableControlerPanel.getBLast()){
|
266 |
if(tableControlerPanel.getItemCount() >= 1) |
267 |
changePoint(true, tableControlerPanel.getItemCount() - 1); |
268 |
} |
269 |
|
270 |
//Combo de selecci?n de punto
|
271 |
if(e.getSource() == tableControlerPanel.getCPoint()){
|
272 |
if(tableControlerPanel.getSelectedIndex() != -1){ |
273 |
try{
|
274 |
loadLyrPoint(); |
275 |
}catch(InstantiationException exc){ |
276 |
return;
|
277 |
} |
278 |
lyrPoints.getPointManager().selectPoint(tableControlerPanel.getSelectedIndex(), dialog); |
279 |
tableControlerPanel.checkArrows(); |
280 |
} |
281 |
} |
282 |
|
283 |
//Bot?n de activar/desactivar la inserci?n de un punto
|
284 |
if((e.getSource() == getBInsertPoint()) || (e.getSource() == dialog.getBInsertPointOfTablePoints())){
|
285 |
View theView = (View) PluginServices.getMDIManager().getActiveWindow(); |
286 |
if(!bInsertPoint.isSelected()){
|
287 |
String toolSelected = theView.getMapControl().getCurrentTool();
|
288 |
if(toolSelected.equals("pointLyrSelection")) |
289 |
theView.getMapControl().setTool(lyrPoints.getLastTool()); |
290 |
else
|
291 |
theView.getMapControl().setTool("pointLyrSelection");
|
292 |
}else
|
293 |
theView.getMapControl().setTool("pointLyrSelection");
|
294 |
} |
295 |
|
296 |
//Bot?n de nuevo punto
|
297 |
if((e.getSource() == tableControlerPanel.getBNew()) || (e.getSource() == dialog.getBNewPointOfTablePoints())){
|
298 |
//Comprobamos si est? activa la inserci?n de punto o no. Si no est? activa no hacemos nada
|
299 |
if(bInsertPoint.isSelected()){
|
300 |
dialog.getPointManager().newEmptyPoint(); |
301 |
|
302 |
//Desactivamos todos los controles para centrar la visi?n del usuario
|
303 |
//sobre la introducci?n de puntos
|
304 |
dialog.getPointManager().disableAllControls(); |
305 |
|
306 |
View theView = null; |
307 |
try{
|
308 |
theView = (View) PluginServices.getMDIManager().getActiveWindow();
|
309 |
}catch(ClassCastException ex){ |
310 |
//Controlamos que cuado se produzca esta excepci?n cerremos el cuadro con un aviso.
|
311 |
System.err.println("**Vista asociada al dialogo no encontrada"); |
312 |
try{
|
313 |
String string1 = PluginServices.getText(this, "yes"); |
314 |
Object[] options = {string1}; |
315 |
JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(), |
316 |
PluginServices.getText(this, "cuadro_no_asociado"), |
317 |
PluginServices.getText(this, "confirmacion"), |
318 |
JOptionPane.YES_OPTION,
|
319 |
JOptionPane.QUESTION_MESSAGE,
|
320 |
null,
|
321 |
options, |
322 |
string1); |
323 |
dialog.getFrame().setClosed(true);
|
324 |
return;
|
325 |
}catch(PropertyVetoException exc){} |
326 |
} |
327 |
|
328 |
//Salvamos la tool actualmente seleccionada, asignamos el punto y cargamos la herramienta de selecci?n de pto.
|
329 |
try{
|
330 |
loadLyrPoint(); |
331 |
lyrPoints.setLastTool(theView.getMapControl().getCurrentTool()); |
332 |
GeorefPointSelectorListener.posPoint = tableControlerPanel.getSelectedIndex(); |
333 |
GeorefPointSelectorListener.firstPoint = true;
|
334 |
theView.getMapControl().setTool("pointLyrSelection");
|
335 |
}catch(InstantiationException exc){ |
336 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
337 |
PluginServices.getText(this, "error_capa_puntos")); |
338 |
} |
339 |
} |
340 |
} |
341 |
|
342 |
TableControlerPanel ctrlPanel = dialog.getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().getTableControlerPanel(); |
343 |
|
344 |
//Bot?n de eliminado de todos los puntos
|
345 |
if( e.getSource() == getTableControlerPanel().getBClear() ||
|
346 |
e.getSource() == ctrlPanel.getBClear()){ |
347 |
dialog.getPointManager().deleteAllPoints(); |
348 |
} |
349 |
|
350 |
//Bot?n de eliminado de un punto
|
351 |
if(e.getSource() == getTableControlerPanel().getBDelPoint() ||
|
352 |
e.getSource() == ctrlPanel.getBDelPoint()){ |
353 |
dialog.getPointManager().deletePoint(); |
354 |
} |
355 |
|
356 |
//Bot?n de extensi?n del cuadro de dialogo
|
357 |
if(e.getSource() == this.getBExtended()) |
358 |
this.setEnlarge(dialog.isEnlarge());
|
359 |
|
360 |
} |
361 |
|
362 |
/* (non-Javadoc)
|
363 |
* @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
|
364 |
*/
|
365 |
public void keyPressed(KeyEvent e) { |
366 |
|
367 |
} |
368 |
|
369 |
/**
|
370 |
* Checkea un textField para que contenga caracteres validos. Consideramos validos
|
371 |
* los caracteres del 0 al 9, punto, menos, DEL, Supr, flechas, Inicio, Fin, y Enter teniendo en cuenta que el
|
372 |
* c?digo ascii del teclado numerico es distinto.
|
373 |
*/
|
374 |
public boolean checkTextField(int code){ |
375 |
if( (code >= 0 && code <= 7) || |
376 |
code == 9 ||
|
377 |
(code >= 11 && code < 36) || |
378 |
(code >= 41 && code < 45) || |
379 |
code == 47 ||
|
380 |
(code >= 58 && code <= 85) || |
381 |
(code >= 87 && code <= 95) || |
382 |
(code >= 106 && code < 109) || |
383 |
(code >= 111 && code <= 126) || |
384 |
code >= 128 ){
|
385 |
return false; |
386 |
} |
387 |
|
388 |
return true; |
389 |
} |
390 |
|
391 |
/**
|
392 |
* Control de eventos de las entradas de texto de los puntos
|
393 |
*/
|
394 |
public void keyReleased(KeyEvent e) { |
395 |
String tx = dataPointPanel.getTX().getText();
|
396 |
String ty = dataPointPanel.getTY().getText();
|
397 |
String lon = dataPointPanel.getLongitud().getText();
|
398 |
String lat = dataPointPanel.getLatitud().getText();
|
399 |
|
400 |
//Campo de texto de la coordenada X en pixeles
|
401 |
Point2D pixel = null; |
402 |
Point2D map = null; |
403 |
|
404 |
//Si el evento es sobre TX
|
405 |
if(e.getSource() == dataPointPanel.getTX()){
|
406 |
if(e.getKeyCode() == 10){ |
407 |
txEvent(); |
408 |
return;
|
409 |
} |
410 |
|
411 |
if(checkTextField(e.getKeyCode()))
|
412 |
lastBlockTx = tx; |
413 |
else
|
414 |
dataPointPanel.getTX().setText(lastBlockTx); |
415 |
} |
416 |
|
417 |
//Si el evento es sobre TY
|
418 |
if(e.getSource() == dataPointPanel.getTY()){
|
419 |
if(e.getKeyCode() == 10){ |
420 |
tyEvent(); |
421 |
return;
|
422 |
} |
423 |
|
424 |
if(checkTextField(e.getKeyCode()))
|
425 |
lastBlockTy = ty; |
426 |
else
|
427 |
dataPointPanel.getTY().setText(lastBlockTy); |
428 |
} |
429 |
|
430 |
//Si el evento es sobre Longitud
|
431 |
if(e.getSource() == dataPointPanel.getLongitud()){
|
432 |
if(e.getKeyCode() == 10){ |
433 |
lonEvent(); |
434 |
return;
|
435 |
} |
436 |
|
437 |
if(checkTextField(e.getKeyCode()))
|
438 |
lastBlockLong = lon; |
439 |
else
|
440 |
dataPointPanel.getLongitud().setText(lastBlockLong); |
441 |
} |
442 |
|
443 |
//Si el evento es sobre Latitud
|
444 |
if(e.getSource() == dataPointPanel.getLatitud()){
|
445 |
if(e.getKeyCode() == 10){ |
446 |
latEvent(); |
447 |
return;
|
448 |
} |
449 |
|
450 |
if(checkTextField(e.getKeyCode()))
|
451 |
lastBlockLat = lat; |
452 |
else
|
453 |
dataPointPanel.getLatitud().setText(lastBlockLat); |
454 |
} |
455 |
|
456 |
} |
457 |
|
458 |
/* (non-Javadoc)
|
459 |
* @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
|
460 |
*/
|
461 |
public void keyTyped(KeyEvent e) { |
462 |
|
463 |
} |
464 |
|
465 |
/* (non-Javadoc)
|
466 |
* @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
|
467 |
*/
|
468 |
public void focusGained(FocusEvent arg0) { |
469 |
|
470 |
} |
471 |
|
472 |
/**
|
473 |
* Cancela la selecci?n de puntos sobre la vista de forma gr?fica. Esta acci?n
|
474 |
* conllevar? seleccionar la ?ltima herramienta del mapCtrl
|
475 |
*/
|
476 |
private void abortSelectPoints(){ |
477 |
//Si todos los puntos est?n rellenos deseleccionamos la herramienta de selecci?n de puntos
|
478 |
GeorefPointSelectorListener.firstPoint = true;
|
479 |
|
480 |
//Activamos los controles de esta ya que habr? sido desactivados al llamar a newEmptyPoint
|
481 |
GeoreferencingToolsModule.setEnabled(true);
|
482 |
|
483 |
com.iver.cit.gvsig.project.documents.view.gui.View theView = null;
|
484 |
try{
|
485 |
theView = (com.iver.cit.gvsig.project.documents.view.gui.View)PluginServices.getMDIManager().getActiveWindow(); |
486 |
theView.getMapControl().setTool(dialog.getLyrPoints().getLastTool()); |
487 |
}catch(ClassCastException exc){ |
488 |
//No se selecciona la herramienta
|
489 |
} |
490 |
} |
491 |
|
492 |
/**
|
493 |
* Validaci?n de que el par?metro tenga formato numerico y de si
|
494 |
* este valor est? dentro de los l?mites de la imagen
|
495 |
* @param tx Campo TX
|
496 |
* @return true si es valido y false si no lo es
|
497 |
*/
|
498 |
private boolean validateTX(String tx){ |
499 |
double x = 0D; |
500 |
try{
|
501 |
x = Double.valueOf(tx).doubleValue();
|
502 |
if(x > dialog.getLyrGeoRaster().getImageWidth() || x < 0) |
503 |
throw new NumberFormatException(); |
504 |
}catch(NumberFormatException exc){ |
505 |
//Si no es valido reponemos lastValue
|
506 |
dataPointPanel.getTX().setText(lastTx); |
507 |
return false; |
508 |
} |
509 |
|
510 |
lastTx = tx; |
511 |
return true; |
512 |
} |
513 |
|
514 |
|
515 |
/**
|
516 |
* Validaci?n de que el par?metro tenga formato numerico y de si
|
517 |
* este valor est? dentro de los l?mites de la imagen
|
518 |
* @param ty Campo TY
|
519 |
* @return true si es valido y false si no lo es
|
520 |
*/
|
521 |
private boolean validateTY(String ty){ |
522 |
double y = 0D; |
523 |
try{
|
524 |
y = Double.valueOf(ty).doubleValue();
|
525 |
if(y > dialog.getLyrGeoRaster().getImageHeight() || y < 0) |
526 |
throw new NumberFormatException(); |
527 |
}catch(NumberFormatException exc){ |
528 |
//Si no es valido reponemos lastValue
|
529 |
dataPointPanel.getTY().setText(lastTy); |
530 |
return false; |
531 |
} |
532 |
|
533 |
lastTy = ty; |
534 |
return true; |
535 |
} |
536 |
|
537 |
/**
|
538 |
* Validaci?n de que el par?metro tenga formato numerico
|
539 |
* @param t Valor del campo
|
540 |
* @return true si es valido y false si no lo es
|
541 |
*/
|
542 |
private boolean validateNumericFormat(String field){ |
543 |
double d = 0D; |
544 |
try{
|
545 |
d = Double.valueOf(field).doubleValue();
|
546 |
}catch(NumberFormatException exc){ |
547 |
return false; |
548 |
} |
549 |
return true; |
550 |
} |
551 |
|
552 |
/**
|
553 |
* Funci?n que se ejecuta cuando TX pierde el foco o se pulsa enter sobre
|
554 |
* el JTextField
|
555 |
*/
|
556 |
private void txEvent(){ |
557 |
String tx = dataPointPanel.getTX().getText();
|
558 |
String ty = dataPointPanel.getTY().getText();
|
559 |
|
560 |
if(!validateTX(tx)) return; |
561 |
|
562 |
if(!ty.equals("")){ |
563 |
if(!validateTY(ty)) return; |
564 |
else{
|
565 |
lastBlockTx = "";
|
566 |
//Llamamos a la funci?n que gestiona la entrada del primer punto
|
567 |
dialog.getPointManager().selectFirstPoint(tx, ty); |
568 |
} |
569 |
} |
570 |
} |
571 |
|
572 |
/**
|
573 |
* Funci?n que se ejecuta cuando TY pierde el foco o se pulsa enter sobre
|
574 |
* el JTextField
|
575 |
*/
|
576 |
private void tyEvent(){ |
577 |
String tx = dataPointPanel.getTX().getText();
|
578 |
String ty = dataPointPanel.getTY().getText();
|
579 |
|
580 |
if(!validateTY(ty)) return; |
581 |
|
582 |
if(!tx.equals("")){ |
583 |
if(!validateTX(tx)) return; |
584 |
else{
|
585 |
lastBlockTy = "";
|
586 |
//Llamamos a la funci?n que gestiona la entrada del primer punto
|
587 |
dialog.getPointManager().selectFirstPoint(tx, ty); |
588 |
} |
589 |
} |
590 |
} |
591 |
|
592 |
/**
|
593 |
* Funci?n que se ejecuta cuando el campo de texto Longitud pierde el foco o se
|
594 |
* pulsa enter sobre el JTextField
|
595 |
*/
|
596 |
private void lonEvent(){ |
597 |
String lon = dataPointPanel.getLongitud().getText();
|
598 |
String lat = dataPointPanel.getLatitud().getText();
|
599 |
|
600 |
if(!validateNumericFormat(lon))
|
601 |
return;
|
602 |
|
603 |
lastLong = lon; |
604 |
if(!lat.equals("")){ |
605 |
lastLat = lat; |
606 |
lastBlockLat = "";
|
607 |
//Llamamos a la funci?n que gestiona la entrada del segundo punto
|
608 |
dialog.getPointManager().selectSecondPoint(lon, lat); |
609 |
} |
610 |
} |
611 |
|
612 |
/**
|
613 |
* Funci?n que se ejecuta cuando el campo de texto Latitud pierde el foco o se
|
614 |
* pulsa enter sobre el JTextField
|
615 |
*/
|
616 |
private void latEvent(){ |
617 |
String lon = dataPointPanel.getLongitud().getText();
|
618 |
String lat = dataPointPanel.getLatitud().getText();
|
619 |
|
620 |
if(!validateNumericFormat(lon))
|
621 |
return;
|
622 |
|
623 |
lastLat = lat; |
624 |
if(!lon.equals("")){ |
625 |
lastLong = lon; |
626 |
lastBlockLong = "";
|
627 |
//Llamamos a la funci?n que gestiona la entrada del segundo punto
|
628 |
dialog.getPointManager().selectSecondPoint(lon, lat); |
629 |
} |
630 |
} |
631 |
|
632 |
/**
|
633 |
* Los campos de texto de las coordenadas cuando pierden el foco actualizan el valor del pixel
|
634 |
* en la cap, vista, mini imagen y tabla
|
635 |
*/
|
636 |
public void focusLost(FocusEvent e) { |
637 |
String tx = dataPointPanel.getTX().getText();
|
638 |
String ty = dataPointPanel.getTY().getText();
|
639 |
String lon = dataPointPanel.getLongitud().getText();
|
640 |
String lat = dataPointPanel.getLatitud().getText();
|
641 |
|
642 |
//Si el elemento que pierde el foco es TX
|
643 |
if(e.getSource() == dataPointPanel.getTX())
|
644 |
txEvent(); |
645 |
|
646 |
//Si el elemento que pierde el foco es TY
|
647 |
if(e.getSource() == dataPointPanel.getTY())
|
648 |
tyEvent(); |
649 |
|
650 |
//Si el elemento que pierde el foco es Longitud
|
651 |
if(e.getSource() == dataPointPanel.getLongitud())
|
652 |
lonEvent(); |
653 |
|
654 |
//Si el elemento que pierde el foco es Latitud
|
655 |
if(e.getSource() == dataPointPanel.getLatitud())
|
656 |
latEvent(); |
657 |
|
658 |
//Si est?n rellenos todos los campos restauramos los controles
|
659 |
if( !dataPointPanel.getTX().getText().equals("") && |
660 |
!dataPointPanel.getTY().getText().equals("") &&
|
661 |
!dataPointPanel.getLongitud().getText().equals("") &&
|
662 |
!dataPointPanel.getLatitud().getText().equals("")){
|
663 |
dialog.getPointManager().restoreControlsValue(); |
664 |
this.abortSelectPoints();
|
665 |
} |
666 |
|
667 |
} |
668 |
|
669 |
//**********************End Methods*******************************
|
670 |
|
671 |
//**********************Setters & Getters*************************
|
672 |
/**
|
673 |
* Extiende o pliega el panel inferior controlando el icono del bot?n. Si se
|
674 |
* asigna true quiere decir que el panel est? desplegado, en este caso lo plegar?.
|
675 |
* Si se asigna false quiere decir que el panel est? plegado, en este caso lo
|
676 |
* desplegar?.
|
677 |
* @param enlarge True para recogerlo y false para desplegarlo
|
678 |
*/
|
679 |
public void setEnlarge(boolean enlarge){ |
680 |
if(enlarge){
|
681 |
dialog.setEnlarge(!enlarge); |
682 |
bExtended.setIcon(new ImageIcon(getClass().getClassLoader().getResource(pathToImages + "down.png"))); |
683 |
}else{
|
684 |
dialog.setEnlarge(!enlarge); |
685 |
bExtended.setIcon(new ImageIcon(getClass().getClassLoader().getResource(pathToImages + "up.png"))); |
686 |
if(lyrPoints != null){ |
687 |
//lyrPoints.getPointManager().selectPoint(tableControlerPanel.getSelectedIndex(), this.grd);
|
688 |
if(lyrPoints.isNewPoint(dialog.getSelectedPoint())){
|
689 |
dialog.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().setEnabled(false);
|
690 |
dialog.getConectorPanel().getAdjustGeorefPanel().getZoomRight().setEnabled(false);
|
691 |
} |
692 |
dialog.getZoomControlRight().draw(); |
693 |
dialog.getZoomControlLeft().draw(); |
694 |
} |
695 |
} |
696 |
} |
697 |
|
698 |
/**
|
699 |
* @return Returns the errorPointPanel.
|
700 |
*/
|
701 |
public ErrorPointPanel getErrorPointPanel() {
|
702 |
if(this.errorPointPanel == null) |
703 |
errorPointPanel = new ErrorPointPanel();
|
704 |
errorPointPanel.setPreferredSize(new java.awt.Dimension(175,130)); |
705 |
return errorPointPanel;
|
706 |
} |
707 |
/**
|
708 |
* @return Returns the lyrPoints.
|
709 |
*/
|
710 |
public FLyrPoints getLyrPoints() {
|
711 |
if(lyrPoints == null){ |
712 |
try{
|
713 |
loadLyrPoint(); |
714 |
}catch(InstantiationException exc){ |
715 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
716 |
PluginServices.getText(this, "error_capa_puntos")); |
717 |
} |
718 |
} |
719 |
return lyrPoints;
|
720 |
} |
721 |
|
722 |
/**
|
723 |
* This method initializes jButton
|
724 |
*
|
725 |
* @return javax.swing.JButton
|
726 |
*/
|
727 |
public JButton getBExtended() { |
728 |
if (bExtended == null) { |
729 |
bExtended = new JButton(); |
730 |
bExtended.setPreferredSize(new java.awt.Dimension(22,22)); |
731 |
bExtended.setIcon(new ImageIcon(getClass().getClassLoader().getResource(pathToImages + "down.png"))); |
732 |
bExtended.setToolTipText(PluginServices.getText(this, "plegar_despl")); |
733 |
bExtended.addActionListener(this);
|
734 |
} |
735 |
return bExtended;
|
736 |
} |
737 |
|
738 |
/**
|
739 |
* This method initializes jPanel
|
740 |
*
|
741 |
* @return javax.swing.JPanel
|
742 |
*/
|
743 |
private JPanel getPExtend() { |
744 |
if (pExtend == null) { |
745 |
FlowLayout flowLayout21 = new FlowLayout(); |
746 |
pExtend = new JPanel(); |
747 |
pExtend.setLayout(flowLayout21); |
748 |
flowLayout21.setHgap(0);
|
749 |
flowLayout21.setVgap(1);
|
750 |
flowLayout21.setAlignment(java.awt.FlowLayout.LEFT); |
751 |
pExtend.setPreferredSize(new java.awt.Dimension(50,22)); |
752 |
pExtend.add(getBInsertPoint(), null);
|
753 |
pExtend.add(getBExtended(), null);
|
754 |
} |
755 |
return pExtend;
|
756 |
} |
757 |
|
758 |
/**
|
759 |
* @return Returns the dataPointPanel.
|
760 |
*/
|
761 |
public DataPointPanel getDataPointPanel() {
|
762 |
return dataPointPanel;
|
763 |
} |
764 |
|
765 |
/**
|
766 |
* @param dataPointPanel The dataPointPanel to set.
|
767 |
*/
|
768 |
public void setDataPointPanel(DataPointPanel dataPointPanel) { |
769 |
this.dataPointPanel = dataPointPanel;
|
770 |
} |
771 |
|
772 |
/**
|
773 |
* @return Returns the tableControlerPanel.
|
774 |
*/
|
775 |
public TableControlerPanel getTableControlerPanel() {
|
776 |
return tableControlerPanel;
|
777 |
} |
778 |
|
779 |
/**
|
780 |
* @param tableControlerPanel The tableControlerPanel to set.
|
781 |
*/
|
782 |
public void setTableControlerPanel(TableControlerPanel tableControlerPanel) { |
783 |
this.tableControlerPanel = tableControlerPanel;
|
784 |
} |
785 |
|
786 |
/**
|
787 |
* This method initializes pGeneral
|
788 |
*
|
789 |
* @return javax.swing.JPanel
|
790 |
*/
|
791 |
private JPanel getPGeneral() { |
792 |
if (pGeneral == null) { |
793 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
794 |
gridBagConstraints1.insets = new java.awt.Insets(0,0,0,0); |
795 |
gridBagConstraints1.gridy = 0;
|
796 |
gridBagConstraints1.gridx = 0;
|
797 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
798 |
gridBagConstraints.insets = new java.awt.Insets(5,0,5,0); |
799 |
gridBagConstraints.gridy = 1;
|
800 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; |
801 |
gridBagConstraints.gridheight = 1;
|
802 |
gridBagConstraints.gridx = 0;
|
803 |
pGeneral = new JPanel(); |
804 |
pGeneral.setLayout(new GridBagLayout()); |
805 |
pGeneral.setPreferredSize(new java.awt.Dimension(390,175)); |
806 |
gridBagConstraints.gridwidth = 1;
|
807 |
pGeneral.add(getPPointSelection(), gridBagConstraints); |
808 |
pGeneral.add(getPControlPoint(), gridBagConstraints1); |
809 |
} |
810 |
return pGeneral;
|
811 |
} |
812 |
|
813 |
/**
|
814 |
* This method initializes pFileSelection
|
815 |
*
|
816 |
* @return javax.swing.JPanel
|
817 |
*/
|
818 |
private JPanel getPPointSelection() { |
819 |
if (pPointSelection == null) { |
820 |
//jLabel = new JLabel();
|
821 |
FlowLayout flowLayout1 = new FlowLayout(); |
822 |
FlowLayout flowLayout = new FlowLayout(); |
823 |
flowLayout.setHgap(0);
|
824 |
flowLayout.setVgap(1);
|
825 |
flowLayout.setAlignment(java.awt.FlowLayout.LEFT); |
826 |
pPointSelection = new JPanel(); |
827 |
pPointSelection.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.LOWERED)); |
828 |
pPointSelection.setName("");
|
829 |
pPointSelection.setLayout(flowLayout); |
830 |
pPointSelection.setPreferredSize(new java.awt.Dimension(375,27)); |
831 |
if(this.tableControlerPanel == null){ |
832 |
tableControlerPanel = new TableControlerPanel();
|
833 |
tableControlerPanel.setLayout(flowLayout1); |
834 |
flowLayout1.setVgap(0);
|
835 |
flowLayout1.setHgap(0);
|
836 |
|
837 |
tableControlerPanel.getBFirst().addActionListener(this);
|
838 |
tableControlerPanel.getBLast().addActionListener(this);
|
839 |
tableControlerPanel.getBNext().addActionListener(this);
|
840 |
tableControlerPanel.getBPrev().addActionListener(this);
|
841 |
tableControlerPanel.getBNew().addActionListener(this);
|
842 |
tableControlerPanel.getCPoint().addActionListener(this);
|
843 |
tableControlerPanel.getBClear().addActionListener(this);
|
844 |
tableControlerPanel.getBDelPoint().addActionListener(this);
|
845 |
} |
846 |
|
847 |
pPointSelection.add(tableControlerPanel, null);
|
848 |
pPointSelection.add(getPExtend(), null);
|
849 |
} |
850 |
return pPointSelection;
|
851 |
} |
852 |
|
853 |
/**
|
854 |
* This method initializes pControls
|
855 |
*
|
856 |
*/
|
857 |
private JPanel getPControlPoint() { |
858 |
if (pControlPoint == null) { |
859 |
GridBagConstraints gridBagConstraints11 = new GridBagConstraints(); |
860 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
861 |
gridBagConstraints2.gridx = 0;
|
862 |
gridBagConstraints2.insets = new java.awt.Insets(0,0,0,0); |
863 |
gridBagConstraints2.gridy = 0;
|
864 |
pControlPoint = new JPanel(); |
865 |
pControlPoint.setLayout(new GridBagLayout()); |
866 |
pControlPoint.setPreferredSize(new java.awt.Dimension(380,130)); |
867 |
pControlPoint.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,0,0,0)); |
868 |
gridBagConstraints11.gridy = 0;
|
869 |
gridBagConstraints11.gridx = 1;
|
870 |
if(this.dataPointPanel == null){ |
871 |
dataPointPanel = new DataPointPanel();
|
872 |
dataPointPanel.setPreferredSize(new java.awt.Dimension(200,130)); |
873 |
dataPointPanel.getTX().addKeyListener(this);
|
874 |
dataPointPanel.getTY().addKeyListener(this);
|
875 |
dataPointPanel.getLatitud().addKeyListener(this);
|
876 |
dataPointPanel.getLongitud().addKeyListener(this);
|
877 |
dataPointPanel.getTX().addFocusListener(this);
|
878 |
dataPointPanel.getTY().addFocusListener(this);
|
879 |
dataPointPanel.getLatitud().addFocusListener(this);
|
880 |
dataPointPanel.getLongitud().addFocusListener(this);
|
881 |
} |
882 |
pControlPoint.add(dataPointPanel, gridBagConstraints2); |
883 |
|
884 |
getErrorPointPanel(); |
885 |
pControlPoint.add(errorPointPanel, gridBagConstraints11); |
886 |
} |
887 |
return pControlPoint;
|
888 |
} |
889 |
|
890 |
/**
|
891 |
* Asigna la ruta donde est?n las imagenes
|
892 |
* @param pathToImages
|
893 |
*/
|
894 |
public void setPathToImages(String pathToImages) { |
895 |
this.pathToImages = pathToImages;
|
896 |
} |
897 |
|
898 |
/**
|
899 |
* Obtiene el ?ltimo indice seleccionado de la lista de puntos
|
900 |
* @return entero con el ?ltimo indice seleccionado de la lista de puntos
|
901 |
*/
|
902 |
public int getLastIndexSelection() { |
903 |
return lastIndexSelection;
|
904 |
} |
905 |
|
906 |
/**
|
907 |
* Asigna el ?ltimo indice seleccionado de la lista de puntos
|
908 |
* @param entero con el ?ltimo indice seleccionado de la lista de puntos
|
909 |
*/
|
910 |
public void setLastIndexSelection(int lastIndexSelection) { |
911 |
this.lastIndexSelection = lastIndexSelection;
|
912 |
} |
913 |
|
914 |
/**
|
915 |
* Activa o desactiva este panel y todos los que lo componen
|
916 |
* @param enabled variable booleana para la activaci?n y/o desactivaci?n
|
917 |
*/
|
918 |
public void setEnabled(boolean enabled){ |
919 |
this.dataPointPanel.setEnabled(enabled);
|
920 |
this.errorPointPanel.setEnabled(enabled);
|
921 |
this.tableControlerPanel.setEnabled(enabled);
|
922 |
this.getBInsertPoint().setEnabled(enabled);
|
923 |
} |
924 |
//**********************End Setters & Getters*********************
|
925 |
} |