root / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / Panels / SelectPointsPanel.java @ 3134
History | View | Annotate | Download (23.4 KB)
1 |
package com.iver.cit.gvsig.gui.Panels; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.awt.FlowLayout; |
5 |
import java.awt.GridBagConstraints; |
6 |
import java.awt.GridBagLayout; |
7 |
import java.awt.event.ActionEvent; |
8 |
import java.awt.event.ActionListener; |
9 |
import java.awt.event.FocusEvent; |
10 |
import java.awt.event.FocusListener; |
11 |
import java.awt.event.KeyEvent; |
12 |
import java.awt.event.KeyListener; |
13 |
import java.awt.geom.Point2D; |
14 |
|
15 |
import javax.swing.ImageIcon; |
16 |
import javax.swing.JButton; |
17 |
import javax.swing.JLabel; |
18 |
import javax.swing.JOptionPane; |
19 |
import javax.swing.JPanel; |
20 |
import javax.swing.JTextField; |
21 |
|
22 |
import com.iver.andami.PluginServices; |
23 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
24 |
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster; |
25 |
import com.iver.cit.gvsig.fmap.layers.FLyrPoints; |
26 |
import com.iver.cit.gvsig.gui.View; |
27 |
import com.iver.cit.gvsig.gui.Dialogs.GeoreferencingDialog; |
28 |
import com.iver.cit.gvsig.gui.toolListeners.GeorefPointSelectorListener; |
29 |
|
30 |
public class SelectPointsPanel extends JPanel implements ActionListener, KeyListener, FocusListener{ |
31 |
|
32 |
private JPanel pGeneral = null; |
33 |
private JPanel pPointSelection = null; |
34 |
private JPanel pControlPoint = null; |
35 |
private JPanel pInfoPoint = null; |
36 |
private JPanel pX = null; |
37 |
private JPanel pY = null; |
38 |
private JPanel pLatitud = null; |
39 |
private JPanel pLongitud = null; |
40 |
private JTextField tX = null; |
41 |
private JLabel lX = null; |
42 |
private JLabel lY = null; |
43 |
private JTextField tY = null; |
44 |
private JLabel lLongitud = null; |
45 |
private JLabel lLatitud = null; |
46 |
private JTextField tLatitud = null; |
47 |
private JTextField tLongitud = null; |
48 |
|
49 |
private JPanel pControls = null; |
50 |
private JPanel pSelectFromView = null; |
51 |
private JButton bSelectFromView = null; |
52 |
private FLyrPoints lyrPoints = null; |
53 |
private boolean disableEvent = false; |
54 |
private JButton bClear = null; |
55 |
private JButton bDelPoint = null; |
56 |
private int lastIndexSelection = -1; |
57 |
|
58 |
private JPanel pManagerPoint = null; |
59 |
private JButton bExtended = null; |
60 |
private JPanel pExtend = null; |
61 |
|
62 |
private TableControlerPanel tableControlerPanel = null; |
63 |
private DataPointPanel dataPointPanel = null; |
64 |
private ErrorPointPanel errorPointPanel = null; |
65 |
|
66 |
private GeoreferencingDialog grd = null; |
67 |
|
68 |
/**
|
69 |
* Valores ?ltimos que se han introducido en los JTextField para poder reponerlos.
|
70 |
*/
|
71 |
public String lastTx = "", lastTy = "", lastLong = "", lastLat = ""; |
72 |
|
73 |
public SelectPointsPanel() {
|
74 |
super();
|
75 |
initialize(); |
76 |
} |
77 |
|
78 |
/**
|
79 |
* This is the default constructor
|
80 |
*/
|
81 |
public SelectPointsPanel(GeoreferencingDialog grd) {
|
82 |
super();
|
83 |
initialize(); |
84 |
this.grd = grd;
|
85 |
} |
86 |
|
87 |
private void init(){} |
88 |
|
89 |
/**
|
90 |
* This method initializes this
|
91 |
*
|
92 |
* @return void
|
93 |
*/
|
94 |
private void initialize() { |
95 |
this.setPreferredSize(new java.awt.Dimension(380,160)); |
96 |
this.setSize(new java.awt.Dimension(380,160)); |
97 |
this.setLocation(new java.awt.Point(0,0)); |
98 |
this.add(getPGeneral(), null); |
99 |
} |
100 |
|
101 |
/**
|
102 |
* This method initializes pGeneral
|
103 |
*
|
104 |
* @return javax.swing.JPanel
|
105 |
*/
|
106 |
private JPanel getPGeneral() { |
107 |
if (pGeneral == null) { |
108 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
109 |
gridBagConstraints1.insets = new java.awt.Insets(0,0,0,0); |
110 |
gridBagConstraints1.gridy = 0;
|
111 |
gridBagConstraints1.gridx = 0;
|
112 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
113 |
gridBagConstraints.insets = new java.awt.Insets(5,0,5,0); |
114 |
gridBagConstraints.gridy = 1;
|
115 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; |
116 |
gridBagConstraints.gridheight = 1;
|
117 |
gridBagConstraints.gridx = 0;
|
118 |
pGeneral = new JPanel(); |
119 |
pGeneral.setLayout(new GridBagLayout()); |
120 |
pGeneral.setPreferredSize(new java.awt.Dimension(390,158)); |
121 |
gridBagConstraints.gridwidth = 1;
|
122 |
pGeneral.add(getPPointSelection(), gridBagConstraints); |
123 |
pGeneral.add(getPControlPoint(), gridBagConstraints1); |
124 |
} |
125 |
return pGeneral;
|
126 |
} |
127 |
|
128 |
/**
|
129 |
* This method initializes pFileSelection
|
130 |
*
|
131 |
* @return javax.swing.JPanel
|
132 |
*/
|
133 |
private JPanel getPPointSelection() { |
134 |
if (pPointSelection == null) { |
135 |
//jLabel = new JLabel();
|
136 |
FlowLayout flowLayout1 = new FlowLayout(); |
137 |
FlowLayout flowLayout = new FlowLayout(); |
138 |
flowLayout.setVgap(-3);
|
139 |
flowLayout.setAlignment(java.awt.FlowLayout.LEFT); |
140 |
pPointSelection = new JPanel(); |
141 |
pPointSelection.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", java.awt.Font.BOLD, 12), java.awt.Color.black)); |
142 |
pPointSelection.setName("");
|
143 |
pPointSelection.setLayout(flowLayout); |
144 |
pPointSelection.setPreferredSize(new java.awt.Dimension(375,27)); |
145 |
flowLayout.setHgap(0);
|
146 |
if(this.tableControlerPanel == null){ |
147 |
tableControlerPanel = new TableControlerPanel();
|
148 |
tableControlerPanel.setLayout(flowLayout1); |
149 |
flowLayout1.setVgap(1);
|
150 |
flowLayout1.setHgap(0);
|
151 |
//jLabel.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
|
152 |
//tableControlerPanel.setLNumberOfPoints(jLabel);
|
153 |
tableControlerPanel.getBFirst().addActionListener(this);
|
154 |
tableControlerPanel.getBLast().addActionListener(this);
|
155 |
tableControlerPanel.getBNext().addActionListener(this);
|
156 |
tableControlerPanel.getBPrev().addActionListener(this);
|
157 |
tableControlerPanel.getBNew().addActionListener(this);
|
158 |
tableControlerPanel.getCPoint().addActionListener(this);
|
159 |
tableControlerPanel.getBClear().addActionListener(this);
|
160 |
tableControlerPanel.getBDelPoint().addActionListener(this);
|
161 |
} |
162 |
//pPointSelection.add(getPTableControl(), null);
|
163 |
pPointSelection.add(tableControlerPanel, null);
|
164 |
pPointSelection.add(getBSelectFromView(), null);
|
165 |
pPointSelection.add(getPExtend(), null);
|
166 |
} |
167 |
return pPointSelection;
|
168 |
} |
169 |
|
170 |
/**
|
171 |
* This method initializes pControls
|
172 |
*
|
173 |
*/
|
174 |
private JPanel getPControlPoint() { |
175 |
if (pControlPoint == null) { |
176 |
GridBagConstraints gridBagConstraints11 = new GridBagConstraints(); |
177 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
178 |
gridBagConstraints2.gridx = 0;
|
179 |
gridBagConstraints2.insets = new java.awt.Insets(0,0,0,0); |
180 |
gridBagConstraints2.gridy = 0;
|
181 |
pControlPoint = new JPanel(); |
182 |
pControlPoint.setLayout(new GridBagLayout()); |
183 |
pControlPoint.setPreferredSize(new java.awt.Dimension(382,120)); |
184 |
pControlPoint.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,0,0,0)); |
185 |
gridBagConstraints11.gridy = 0;
|
186 |
gridBagConstraints11.gridx = 1;
|
187 |
if(this.dataPointPanel == null){ |
188 |
dataPointPanel = new DataPointPanel();
|
189 |
dataPointPanel.getTX().addKeyListener(this);
|
190 |
dataPointPanel.getTY().addKeyListener(this);
|
191 |
dataPointPanel.getLatitud().addKeyListener(this);
|
192 |
dataPointPanel.getLongitud().addKeyListener(this);
|
193 |
dataPointPanel.getTX().addFocusListener(this);
|
194 |
dataPointPanel.getTY().addFocusListener(this);
|
195 |
dataPointPanel.getLatitud().addFocusListener(this);
|
196 |
dataPointPanel.getLongitud().addFocusListener(this);
|
197 |
} |
198 |
pControlPoint.add(dataPointPanel, gridBagConstraints2); |
199 |
|
200 |
if(this.errorPointPanel == null) |
201 |
errorPointPanel = new ErrorPointPanel();
|
202 |
pControlPoint.add(errorPointPanel, gridBagConstraints11); |
203 |
} |
204 |
return pControlPoint;
|
205 |
} |
206 |
|
207 |
/**
|
208 |
* Actualiza el n?mero de puntos del combo a partir de los contenidos en
|
209 |
* la capa de puntos. Esta funci?n es usada desde otros paneles que cambien
|
210 |
* el punto seleccionado para comunicar al control la nueva selecci?n.
|
211 |
*/
|
212 |
public void updateComboPoint(int pointSelected){ |
213 |
disableEvent = true;
|
214 |
try{
|
215 |
loadLyrPoint(); |
216 |
}catch(InstantiationException exc){ |
217 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
218 |
PluginServices.getText(this, "error_capa_puntos")); |
219 |
return;
|
220 |
} |
221 |
|
222 |
tableControlerPanel.setNItems(lyrPoints.getCountPoints()); |
223 |
tableControlerPanel.getCPoint().setSelectedIndex(pointSelected); |
224 |
tableControlerPanel.checkArrows(); |
225 |
lyrPoints.loadVisualPoint(pointSelected, this.grd);
|
226 |
disableEvent = false;
|
227 |
} |
228 |
|
229 |
/**
|
230 |
* Comprueba si los valores de un punto en los campos de texto est?n
|
231 |
* vacios y lanza una excepci?n si hay alguno sin informaci?n.
|
232 |
* @throws NoSuchFieldException
|
233 |
*/
|
234 |
public void checkInfoPointText()throws NoSuchFieldException{ |
235 |
if( dataPointPanel.getTX().getText().equals("") || |
236 |
dataPointPanel.getTY().getText().equals("") ||
|
237 |
dataPointPanel.getLatitud().getText().equals("") ||
|
238 |
dataPointPanel.getLongitud().getText().equals("")){
|
239 |
disableEvent = true;
|
240 |
try{
|
241 |
tableControlerPanel.getCPoint().setSelectedIndex(lastIndexSelection); |
242 |
disableEvent = false;
|
243 |
}catch(IllegalArgumentException ex){ |
244 |
//Si el lastIndex tiene un valor erroneo no hacemos ninguna selecci?n
|
245 |
} |
246 |
throw new NoSuchFieldException(); |
247 |
} |
248 |
} |
249 |
|
250 |
/**
|
251 |
* Esta funci?n resetea los controles del panel de info de un punto.
|
252 |
*/
|
253 |
public void resetControls(boolean active){ |
254 |
dataPointPanel.getTX().setText("");
|
255 |
dataPointPanel.getTY().setText("");
|
256 |
dataPointPanel.getLatitud().setText("");
|
257 |
dataPointPanel.getLongitud().setText("");
|
258 |
getBSelectFromView().setEnabled(active); |
259 |
getTableControlerPanel().getBClear().setEnabled(active); |
260 |
getTableControlerPanel().getBDelPoint().setEnabled(active); |
261 |
} |
262 |
|
263 |
/**
|
264 |
* Cuando pasamos de un punto a otro o se va a crear uno nuevo
|
265 |
* <UL>
|
266 |
* <LI>Cargamos la capa FLyrPoint si no est? ya cargada.</LI>
|
267 |
* <LI>Comprobamos que los campos no esten vacios y lanzamos una excepci?n si hay alg?n campo vacio si lo est?n.</LI>
|
268 |
* <LI>Insertamos el nuevo punto seleccionado en los campos de informaci?n.</LI>
|
269 |
* <LI>Checkeamos las flechas para ver si tenemos que activarlas o desactivarlas.</LI>
|
270 |
* </UL>
|
271 |
* @param changeSelection Cambia la posici?n seleccionada del combo si es true
|
272 |
* @param pos Posici?n a la que cambia el combo si el parametro chageSelection es true
|
273 |
*/
|
274 |
public void changePoint(boolean changeSelection, int pos){ |
275 |
disableEvent = true;
|
276 |
try{
|
277 |
loadLyrPoint(); |
278 |
checkInfoPointText(); |
279 |
if(changeSelection){
|
280 |
lastIndexSelection = pos; |
281 |
tableControlerPanel.setSelectedIndex(pos); |
282 |
} |
283 |
lyrPoints.loadVisualPoint(tableControlerPanel.getSelectedIndex(), this.grd);
|
284 |
tableControlerPanel.checkArrows(); |
285 |
}catch(NoSuchFieldException exc){ |
286 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
287 |
PluginServices.getText(this, "coordenadas_vacias")); |
288 |
}catch(InstantiationException e){ |
289 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
290 |
PluginServices.getText(this, "error_capa_puntos")); |
291 |
} |
292 |
disableEvent = false;
|
293 |
} |
294 |
|
295 |
/**
|
296 |
* Limpia la lista de puntos y borra el dialogo.
|
297 |
*/
|
298 |
public void clearList(){ |
299 |
try{
|
300 |
loadLyrPoint(); |
301 |
if(lyrPoints != null) |
302 |
lyrPoints.clearVisualList(this,
|
303 |
grd.getConectorPanel().getDataPointsTabPanel().getTablePointsPanel(), |
304 |
grd.getConectorPanel().getAdjustGeorefPanel()); |
305 |
}catch(InstantiationException e){ |
306 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
307 |
PluginServices.getText(this, "error_capa_puntos")); |
308 |
} |
309 |
} |
310 |
|
311 |
/**
|
312 |
* Obtiene una capa de puntos. Si no existe crea una.
|
313 |
* @return
|
314 |
*/
|
315 |
private void loadLyrPoint() throws InstantiationException{ |
316 |
//Buscamos una capa FlyrPoint en la vista y si no la hay la creamos
|
317 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
318 |
|
319 |
if(lyrPoints == null){ |
320 |
for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
321 |
FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i); |
322 |
if( lyr instanceof FLyrGeoRaster && |
323 |
lyr.getName().startsWith("*") &&
|
324 |
lyr.isActive()){ |
325 |
try{
|
326 |
lyrPoints = ((FLyrGeoRaster)lyr).getFLyrPoints(); |
327 |
}catch(ClassCastException exc){ |
328 |
throw new InstantiationException("No se ha podido obtener una capa de puntos"); |
329 |
} |
330 |
|
331 |
} |
332 |
} |
333 |
} |
334 |
|
335 |
} |
336 |
|
337 |
|
338 |
|
339 |
/**
|
340 |
* Este m?todo inicializa el bot?n seleccionar desde la vista. Cuando lo
|
341 |
* activamos se carga la herramienta de selecci?n de puntos desde la vista.
|
342 |
*
|
343 |
* @return javax.swing.JButton
|
344 |
*/
|
345 |
public JButton getBSelectFromView() { |
346 |
if (bSelectFromView == null) { |
347 |
bSelectFromView = new JButton(); |
348 |
bSelectFromView.setText("");
|
349 |
bSelectFromView.setPreferredSize(new java.awt.Dimension(22,22)); |
350 |
bSelectFromView.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/selectfromview.png"))); |
351 |
bSelectFromView.setEnabled(false);
|
352 |
bSelectFromView.addActionListener(new java.awt.event.ActionListener() {
|
353 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
354 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
355 |
try{
|
356 |
loadLyrPoint(); |
357 |
lyrPoints.setLastTool(theView.getMapControl().getTool()); |
358 |
GeorefPointSelectorListener.posPoint = tableControlerPanel.getSelectedIndex(); |
359 |
GeorefPointSelectorListener.firstPoint = true;
|
360 |
theView.getMapControl().setTool("pointLyrSelection");
|
361 |
}catch(InstantiationException exc){ |
362 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
363 |
PluginServices.getText(this, "error_capa_puntos")); |
364 |
} |
365 |
} |
366 |
}); |
367 |
} |
368 |
return bSelectFromView;
|
369 |
} |
370 |
|
371 |
/**
|
372 |
* Checkea un textField para que contenga caracteres validos. Consideramos validos
|
373 |
* los caracteres del 0 al 9, el punto, DEL, Supr, flechas y Enter teniendo en cuenta que el
|
374 |
* c?digo ascii del teclado numerico es distinto.
|
375 |
*/
|
376 |
public boolean checkTextField(JTextField tf, int code, String lastText){ |
377 |
System.out.println(code);
|
378 |
//Si el caracter es erroneo pasamos de el y reponemos el texto que habia
|
379 |
if( (code >= 0 && code <= 7) || |
380 |
code == 9 ||
|
381 |
(code >= 11 && code <= 36) || |
382 |
(code >= 41 && code <= 45) || |
383 |
code == 47 ||
|
384 |
(code >= 58 && code <= 95) || |
385 |
(code >= 106 && code <= 109) || |
386 |
(code >= 111 && code <= 126) || |
387 |
code >= 128){
|
388 |
tf.setText(lastText); |
389 |
return false; |
390 |
} |
391 |
|
392 |
return true; |
393 |
} |
394 |
|
395 |
/**
|
396 |
* @return Returns the lyrPoints.
|
397 |
*/
|
398 |
public FLyrPoints getLyrPoints() {
|
399 |
if(lyrPoints == null){ |
400 |
try{
|
401 |
loadLyrPoint(); |
402 |
}catch(InstantiationException exc){ |
403 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
404 |
PluginServices.getText(this, "error_capa_puntos")); |
405 |
} |
406 |
} |
407 |
return lyrPoints;
|
408 |
} |
409 |
|
410 |
/**
|
411 |
* This method initializes jButton
|
412 |
*
|
413 |
* @return javax.swing.JButton
|
414 |
*/
|
415 |
private JButton getBExtended() { |
416 |
if (bExtended == null) { |
417 |
bExtended = new JButton(); |
418 |
bExtended.setPreferredSize(new java.awt.Dimension(22,22)); |
419 |
bExtended.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/down.png"))); |
420 |
bExtended.addActionListener(this);
|
421 |
} |
422 |
return bExtended;
|
423 |
} |
424 |
/**
|
425 |
* This method initializes jPanel
|
426 |
*
|
427 |
* @return javax.swing.JPanel
|
428 |
*/
|
429 |
private JPanel getPExtend() { |
430 |
if (pExtend == null) { |
431 |
FlowLayout flowLayout21 = new FlowLayout(); |
432 |
pExtend = new JPanel(); |
433 |
pExtend.setLayout(flowLayout21); |
434 |
flowLayout21.setHgap(0);
|
435 |
flowLayout21.setVgap(0);
|
436 |
flowLayout21.setAlignment(java.awt.FlowLayout.RIGHT); |
437 |
pExtend.setPreferredSize(new java.awt.Dimension(35,22)); |
438 |
pExtend.add(getBExtended(), null);
|
439 |
} |
440 |
return pExtend;
|
441 |
} |
442 |
|
443 |
/**
|
444 |
* @return Returns the dataPointPanel.
|
445 |
*/
|
446 |
public DataPointPanel getDataPointPanel() {
|
447 |
return dataPointPanel;
|
448 |
} |
449 |
|
450 |
/**
|
451 |
* @param dataPointPanel The dataPointPanel to set.
|
452 |
*/
|
453 |
public void setDataPointPanel(DataPointPanel dataPointPanel) { |
454 |
this.dataPointPanel = dataPointPanel;
|
455 |
} |
456 |
|
457 |
/**
|
458 |
* @return Returns the tableControlerPanel.
|
459 |
*/
|
460 |
public TableControlerPanel getTableControlerPanel() {
|
461 |
return tableControlerPanel;
|
462 |
} |
463 |
|
464 |
/**
|
465 |
* @param tableControlerPanel The tableControlerPanel to set.
|
466 |
*/
|
467 |
public void setTableControlerPanel(TableControlerPanel tableControlerPanel) { |
468 |
this.tableControlerPanel = tableControlerPanel;
|
469 |
} |
470 |
|
471 |
/**
|
472 |
* Control de eventos de TableControlerPanel
|
473 |
*/
|
474 |
public void actionPerformed(ActionEvent e) { |
475 |
|
476 |
//Bot?n de ir al punto inicial
|
477 |
if(e.getSource() == tableControlerPanel.getBFirst()){
|
478 |
if(tableControlerPanel.getItemCount() >= 1) |
479 |
changePoint(true, 0); |
480 |
} |
481 |
|
482 |
//Bot?n de ir al punto anterior
|
483 |
if(e.getSource() == tableControlerPanel.getBPrev()){
|
484 |
if(tableControlerPanel.getSelectedIndex() != 0) |
485 |
changePoint(true, tableControlerPanel.getSelectedIndex() - 1); |
486 |
} |
487 |
|
488 |
//Bot?n de ir al punto siguiente
|
489 |
if(e.getSource() == tableControlerPanel.getBNext()){
|
490 |
if(tableControlerPanel.getSelectedIndex() != (tableControlerPanel.getItemCount() - 1)) |
491 |
changePoint(true, tableControlerPanel.getSelectedIndex() + 1); |
492 |
|
493 |
} |
494 |
|
495 |
//Bot?n de ir al punto final
|
496 |
if(e.getSource() == tableControlerPanel.getBLast()){
|
497 |
if(tableControlerPanel.getItemCount() >= 1) |
498 |
changePoint(true, tableControlerPanel.getItemCount() - 1); |
499 |
} |
500 |
|
501 |
//Combo de selecci?n de punto
|
502 |
if(e.getSource() == tableControlerPanel.getCPoint()){
|
503 |
if(tableControlerPanel.getSelectedIndex() != -1){ |
504 |
if(!disableEvent){
|
505 |
try{
|
506 |
loadLyrPoint(); |
507 |
}catch(InstantiationException exc){ |
508 |
return;
|
509 |
} |
510 |
lyrPoints.loadVisualPoint(tableControlerPanel.getSelectedIndex(), grd); |
511 |
tableControlerPanel.checkArrows(); |
512 |
} |
513 |
} |
514 |
} |
515 |
|
516 |
//Bot?n de nuevo punto
|
517 |
if(e.getSource() == tableControlerPanel.getBNew()){
|
518 |
try{
|
519 |
disableEvent = true;
|
520 |
loadLyrPoint(); |
521 |
if(this.getTableControlerPanel().getItemCount() > 0) |
522 |
checkInfoPointText(); |
523 |
lyrPoints.addPoint(null, null); |
524 |
tableControlerPanel.getCPoint().addItem("" + lyrPoints.getCountPoints());
|
525 |
tableControlerPanel.getLNumberOfPoints().setText(PluginServices.getText(this, "de ") + " " + lyrPoints.getCountPoints()); |
526 |
lastIndexSelection = lyrPoints.getCountPoints() - 1;
|
527 |
tableControlerPanel.setSelectedIndex(tableControlerPanel.getItemCount() - 1);
|
528 |
grd.resetControls(true);
|
529 |
tableControlerPanel.checkArrows(); |
530 |
}catch(NoSuchFieldException exc){ |
531 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
532 |
PluginServices.getText(this, "coordenadas_vacias")); |
533 |
}catch(InstantiationException exc){ |
534 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
535 |
PluginServices.getText(this, "error_capa_puntos")); |
536 |
} |
537 |
disableEvent = false;
|
538 |
} |
539 |
|
540 |
//Bot?n de eliminado de todos los puntos
|
541 |
if(e.getSource() == getTableControlerPanel().getBClear()){
|
542 |
clearList(); |
543 |
} |
544 |
|
545 |
//Bot?n de eliminado de un punto
|
546 |
if(e.getSource() == getTableControlerPanel().getBDelPoint()){
|
547 |
if(lyrPoints.length() == 1) //Si solo hay un punto reseteamos |
548 |
clearList(); |
549 |
else{
|
550 |
disableEvent = true;
|
551 |
int posSelect = tableControlerPanel.getSelectedIndex();
|
552 |
if(posSelect == -1) |
553 |
return;
|
554 |
lyrPoints.deleteVisualPoint(posSelect, grd); |
555 |
|
556 |
if(posSelect == 0){ |
557 |
lastIndexSelection = posSelect; |
558 |
}else{
|
559 |
lastIndexSelection = posSelect -1 ;
|
560 |
} |
561 |
disableEvent = false;
|
562 |
} |
563 |
} |
564 |
|
565 |
//Bot?n de extensi?n del cuadro de dialogo
|
566 |
if(e.getSource() == this.getBExtended()){ |
567 |
if(grd.isEnlarge()){
|
568 |
grd.setEnlarge(false);
|
569 |
bExtended.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/down.png"))); |
570 |
}else{
|
571 |
grd.setEnlarge(true);
|
572 |
bExtended.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/up.png"))); |
573 |
if(lyrPoints != null) |
574 |
lyrPoints.loadVisualPoint(tableControlerPanel.getSelectedIndex(), this.grd);
|
575 |
} |
576 |
} |
577 |
|
578 |
} |
579 |
|
580 |
/* (non-Javadoc)
|
581 |
* @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
|
582 |
*/
|
583 |
public void keyPressed(KeyEvent e) { |
584 |
// TODO Auto-generated method stu
|
585 |
} |
586 |
|
587 |
/**
|
588 |
* Actualiza los valores del punto nuevo introducido desde el teclado llamando a la funci?n
|
589 |
* de la capa updataData que actualizar? los controles necesarios para que se refresquen la vista
|
590 |
* mini imagenes, textfields, tabla y capa de puntos.
|
591 |
* @param pixel Pixel de la imagen
|
592 |
* @param map Coordenadas de la vista.
|
593 |
*/
|
594 |
private void updatePointsValue(Point2D pixel, Point2D map){ |
595 |
//Actualizamos los controles con los nuevos valores
|
596 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
597 |
for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
598 |
FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i); |
599 |
if( lyr instanceof FLyrGeoRaster && |
600 |
lyr.getName().startsWith("*") &&
|
601 |
lyr.isActive()){ |
602 |
((FLyrGeoRaster)lyr).updateData(Integer.valueOf(this.grd.getSelectPointsPanel().getTableControlerPanel().getSelectedItem()).intValue(), |
603 |
pixel, |
604 |
map, |
605 |
this.grd,
|
606 |
theView, |
607 |
lyrPoints); |
608 |
} |
609 |
} |
610 |
} |
611 |
|
612 |
/**
|
613 |
* Control de eventos de las entradas de texto de los puntos
|
614 |
*/
|
615 |
public void keyReleased(KeyEvent e) { |
616 |
//Campo de texto de la coordenada X en pixeles
|
617 |
Point2D pixel = null; |
618 |
Point2D map = null; |
619 |
boolean update = false; |
620 |
|
621 |
try{
|
622 |
if(e.getSource() == dataPointPanel.getTX()){
|
623 |
if(checkTextField(dataPointPanel.getTX(), e.getKeyCode(), lastTx)){
|
624 |
pixel = new Point2D.Double(); |
625 |
pixel.setLocation( Double.valueOf(dataPointPanel.getTX().getText()).doubleValue(),
|
626 |
Double.valueOf(dataPointPanel.getTY().getText()).doubleValue());
|
627 |
if(e.getKeyCode() == 10) |
628 |
update = true;
|
629 |
lastTx = dataPointPanel.getTX().getText(); |
630 |
} |
631 |
} |
632 |
|
633 |
//Campo de texto de la coordenada Y en pixeles
|
634 |
if(e.getSource() == dataPointPanel.getTY()){
|
635 |
if(checkTextField(dataPointPanel.getTY(), e.getKeyCode(), lastTy)){
|
636 |
pixel = new Point2D.Double(); |
637 |
pixel.setLocation( Double.valueOf(dataPointPanel.getTX().getText()).doubleValue(),
|
638 |
Double.valueOf(dataPointPanel.getTY().getText()).doubleValue());
|
639 |
if(e.getKeyCode() == 10) |
640 |
update = true;
|
641 |
lastTy = dataPointPanel.getTY().getText(); |
642 |
} |
643 |
} |
644 |
|
645 |
//Campo de texto de la coordenada X en coordenadas del mundo
|
646 |
if(e.getSource() == dataPointPanel.getLatitud()){
|
647 |
if(checkTextField(dataPointPanel.getLatitud(), e.getKeyCode(), lastLat)){
|
648 |
map = new Point2D.Double(); |
649 |
map.setLocation( Double.valueOf(dataPointPanel.getLongitud().getText()).doubleValue(),
|
650 |
Double.valueOf(dataPointPanel.getLatitud().getText()).doubleValue());
|
651 |
if(e.getKeyCode() == 10) |
652 |
update = true;
|
653 |
lastLat = dataPointPanel.getLatitud().getText(); |
654 |
} |
655 |
} |
656 |
|
657 |
//Campo de texto de la coordenada Y en coordenadas del mundo
|
658 |
if(e.getSource() == dataPointPanel.getLongitud()){
|
659 |
if(checkTextField(dataPointPanel.getLongitud(), e.getKeyCode(), lastLong)){
|
660 |
map = new Point2D.Double(); |
661 |
map.setLocation( Double.valueOf(dataPointPanel.getLongitud().getText()).doubleValue(),
|
662 |
Double.valueOf(dataPointPanel.getLatitud().getText()).doubleValue());
|
663 |
if(e.getKeyCode() == 10) |
664 |
update = true;
|
665 |
lastLong = dataPointPanel.getLongitud().getText(); |
666 |
} |
667 |
} |
668 |
|
669 |
if(update)
|
670 |
this.updatePointsValue(pixel, map);
|
671 |
|
672 |
}catch(NumberFormatException exc){ |
673 |
System.out.println("Formato numerico erroneo"); |
674 |
} |
675 |
|
676 |
} |
677 |
|
678 |
/* (non-Javadoc)
|
679 |
* @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
|
680 |
*/
|
681 |
public void keyTyped(KeyEvent e) { |
682 |
// TODO Auto-generated method stub
|
683 |
|
684 |
} |
685 |
|
686 |
/* (non-Javadoc)
|
687 |
* @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
|
688 |
*/
|
689 |
public void focusGained(FocusEvent arg0) { |
690 |
// TODO Auto-generated method stub
|
691 |
|
692 |
} |
693 |
|
694 |
/**
|
695 |
* Los campos de texto de las coordenadas cuando pierden el foco actualizan el valor del pixel
|
696 |
* en la cap, vista, mini imagen y tabla
|
697 |
*/
|
698 |
public void focusLost(FocusEvent arg0) { |
699 |
Point2D pixel = new Point2D.Double(); |
700 |
Point2D map = new Point2D.Double(); |
701 |
pixel.setLocation(Double.valueOf(dataPointPanel.getTX().getText()).doubleValue(),
|
702 |
Double.valueOf(dataPointPanel.getTY().getText()).doubleValue());
|
703 |
map.setLocation(Double.valueOf(dataPointPanel.getLongitud().getText()).doubleValue(),
|
704 |
Double.valueOf(dataPointPanel.getLatitud().getText()).doubleValue());
|
705 |
this.updatePointsValue(pixel, map);
|
706 |
|
707 |
} |
708 |
|
709 |
} |