root / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / Panels / SelectPointsPanel.java @ 3142
History | View | Annotate | Download (23.6 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 |
getErrorPointPanel(); |
201 |
pControlPoint.add(errorPointPanel, gridBagConstraints11); |
202 |
} |
203 |
return pControlPoint;
|
204 |
} |
205 |
|
206 |
/**
|
207 |
* Actualiza el n?mero de puntos del combo a partir de los contenidos en
|
208 |
* la capa de puntos. Esta funci?n es usada desde otros paneles que cambien
|
209 |
* el punto seleccionado para comunicar al control la nueva selecci?n.
|
210 |
*/
|
211 |
public void updateComboPoint(int pointSelected){ |
212 |
disableEvent = true;
|
213 |
try{
|
214 |
loadLyrPoint(); |
215 |
}catch(InstantiationException exc){ |
216 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
217 |
PluginServices.getText(this, "error_capa_puntos")); |
218 |
return;
|
219 |
} |
220 |
|
221 |
tableControlerPanel.setNItems(lyrPoints.getCountPoints()); |
222 |
tableControlerPanel.getCPoint().setSelectedIndex(pointSelected); |
223 |
tableControlerPanel.checkArrows(); |
224 |
lyrPoints.loadVisualPoint(pointSelected, this.grd);
|
225 |
disableEvent = false;
|
226 |
} |
227 |
|
228 |
/**
|
229 |
* Comprueba si los valores de un punto en los campos de texto est?n
|
230 |
* vacios y lanza una excepci?n si hay alguno sin informaci?n.
|
231 |
* @throws NoSuchFieldException
|
232 |
*/
|
233 |
public void checkInfoPointText()throws NoSuchFieldException{ |
234 |
if( dataPointPanel.getTX().getText().equals("") || |
235 |
dataPointPanel.getTY().getText().equals("") ||
|
236 |
dataPointPanel.getLatitud().getText().equals("") ||
|
237 |
dataPointPanel.getLongitud().getText().equals("")){
|
238 |
disableEvent = true;
|
239 |
try{
|
240 |
tableControlerPanel.getCPoint().setSelectedIndex(lastIndexSelection); |
241 |
disableEvent = false;
|
242 |
}catch(IllegalArgumentException ex){ |
243 |
//Si el lastIndex tiene un valor erroneo no hacemos ninguna selecci?n
|
244 |
} |
245 |
throw new NoSuchFieldException(); |
246 |
} |
247 |
} |
248 |
|
249 |
/**
|
250 |
* Esta funci?n resetea los controles del panel de info de un punto.
|
251 |
*/
|
252 |
public void resetControls(boolean active){ |
253 |
dataPointPanel.getTX().setText("");
|
254 |
dataPointPanel.getTY().setText("");
|
255 |
dataPointPanel.getLatitud().setText("");
|
256 |
dataPointPanel.getLongitud().setText("");
|
257 |
getBSelectFromView().setEnabled(active); |
258 |
getTableControlerPanel().getBClear().setEnabled(active); |
259 |
getTableControlerPanel().getBDelPoint().setEnabled(active); |
260 |
} |
261 |
|
262 |
/**
|
263 |
* Cuando pasamos de un punto a otro o se va a crear uno nuevo
|
264 |
* <UL>
|
265 |
* <LI>Cargamos la capa FLyrPoint si no est? ya cargada.</LI>
|
266 |
* <LI>Comprobamos que los campos no esten vacios y lanzamos una excepci?n si hay alg?n campo vacio si lo est?n.</LI>
|
267 |
* <LI>Insertamos el nuevo punto seleccionado en los campos de informaci?n.</LI>
|
268 |
* <LI>Checkeamos las flechas para ver si tenemos que activarlas o desactivarlas.</LI>
|
269 |
* </UL>
|
270 |
* @param changeSelection Cambia la posici?n seleccionada del combo si es true
|
271 |
* @param pos Posici?n a la que cambia el combo si el parametro chageSelection es true
|
272 |
*/
|
273 |
public void changePoint(boolean changeSelection, int pos){ |
274 |
disableEvent = true;
|
275 |
try{
|
276 |
loadLyrPoint(); |
277 |
checkInfoPointText(); |
278 |
if(changeSelection){
|
279 |
lastIndexSelection = pos; |
280 |
tableControlerPanel.setSelectedIndex(pos); |
281 |
} |
282 |
lyrPoints.loadVisualPoint(tableControlerPanel.getSelectedIndex(), this.grd);
|
283 |
tableControlerPanel.checkArrows(); |
284 |
}catch(NoSuchFieldException exc){ |
285 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
286 |
PluginServices.getText(this, "coordenadas_vacias")); |
287 |
}catch(InstantiationException e){ |
288 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
289 |
PluginServices.getText(this, "error_capa_puntos")); |
290 |
} |
291 |
disableEvent = false;
|
292 |
} |
293 |
|
294 |
/**
|
295 |
* Limpia la lista de puntos y borra el dialogo.
|
296 |
*/
|
297 |
public void clearList(){ |
298 |
try{
|
299 |
loadLyrPoint(); |
300 |
if(lyrPoints != null) |
301 |
lyrPoints.clearVisualList(this,
|
302 |
grd.getConectorPanel().getDataPointsTabPanel().getTablePointsPanel(), |
303 |
grd.getConectorPanel().getAdjustGeorefPanel()); |
304 |
}catch(InstantiationException e){ |
305 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
306 |
PluginServices.getText(this, "error_capa_puntos")); |
307 |
} |
308 |
} |
309 |
|
310 |
/**
|
311 |
* Obtiene una capa de puntos. Si no existe crea una.
|
312 |
* @return
|
313 |
*/
|
314 |
private void loadLyrPoint() throws InstantiationException{ |
315 |
//Buscamos una capa FlyrPoint en la vista y si no la hay la creamos
|
316 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
317 |
|
318 |
if(lyrPoints == null){ |
319 |
for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
320 |
FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i); |
321 |
if( lyr instanceof FLyrGeoRaster && |
322 |
lyr.getName().startsWith("*") &&
|
323 |
lyr.isActive()){ |
324 |
try{
|
325 |
lyrPoints = ((FLyrGeoRaster)lyr).getFLyrPoints(); |
326 |
}catch(ClassCastException exc){ |
327 |
throw new InstantiationException("No se ha podido obtener una capa de puntos"); |
328 |
} |
329 |
|
330 |
} |
331 |
} |
332 |
} |
333 |
|
334 |
} |
335 |
|
336 |
|
337 |
|
338 |
/**
|
339 |
* Este m?todo inicializa el bot?n seleccionar desde la vista. Cuando lo
|
340 |
* activamos se carga la herramienta de selecci?n de puntos desde la vista.
|
341 |
*
|
342 |
* @return javax.swing.JButton
|
343 |
*/
|
344 |
public JButton getBSelectFromView() { |
345 |
if (bSelectFromView == null) { |
346 |
bSelectFromView = new JButton(); |
347 |
bSelectFromView.setText("");
|
348 |
bSelectFromView.setPreferredSize(new java.awt.Dimension(22,22)); |
349 |
bSelectFromView.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/selectfromview.png"))); |
350 |
bSelectFromView.setEnabled(false);
|
351 |
bSelectFromView.addActionListener(new java.awt.event.ActionListener() {
|
352 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
353 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
354 |
try{
|
355 |
loadLyrPoint(); |
356 |
lyrPoints.setLastTool(theView.getMapControl().getTool()); |
357 |
GeorefPointSelectorListener.posPoint = tableControlerPanel.getSelectedIndex(); |
358 |
GeorefPointSelectorListener.firstPoint = true;
|
359 |
theView.getMapControl().setTool("pointLyrSelection");
|
360 |
}catch(InstantiationException exc){ |
361 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
362 |
PluginServices.getText(this, "error_capa_puntos")); |
363 |
} |
364 |
} |
365 |
}); |
366 |
} |
367 |
return bSelectFromView;
|
368 |
} |
369 |
|
370 |
/**
|
371 |
* Checkea un textField para que contenga caracteres validos. Consideramos validos
|
372 |
* los caracteres del 0 al 9, el punto, DEL, Supr, flechas y Enter teniendo en cuenta que el
|
373 |
* c?digo ascii del teclado numerico es distinto.
|
374 |
*/
|
375 |
public boolean checkTextField(JTextField tf, int code, String lastText){ |
376 |
System.out.println(code);
|
377 |
//Si el caracter es erroneo pasamos de el y reponemos el texto que habia
|
378 |
if( (code >= 0 && code <= 7) || |
379 |
code == 9 ||
|
380 |
(code >= 11 && code <= 36) || |
381 |
(code >= 41 && code <= 45) || |
382 |
code == 47 ||
|
383 |
(code >= 58 && code <= 95) || |
384 |
(code >= 106 && code <= 109) || |
385 |
(code >= 111 && code <= 126) || |
386 |
code >= 128){
|
387 |
tf.setText(lastText); |
388 |
return false; |
389 |
} |
390 |
|
391 |
return true; |
392 |
} |
393 |
|
394 |
/**
|
395 |
* @return Returns the lyrPoints.
|
396 |
*/
|
397 |
public FLyrPoints getLyrPoints() {
|
398 |
if(lyrPoints == null){ |
399 |
try{
|
400 |
loadLyrPoint(); |
401 |
}catch(InstantiationException exc){ |
402 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
403 |
PluginServices.getText(this, "error_capa_puntos")); |
404 |
} |
405 |
} |
406 |
return lyrPoints;
|
407 |
} |
408 |
|
409 |
/**
|
410 |
* This method initializes jButton
|
411 |
*
|
412 |
* @return javax.swing.JButton
|
413 |
*/
|
414 |
private JButton getBExtended() { |
415 |
if (bExtended == null) { |
416 |
bExtended = new JButton(); |
417 |
bExtended.setPreferredSize(new java.awt.Dimension(22,22)); |
418 |
bExtended.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/down.png"))); |
419 |
bExtended.addActionListener(this);
|
420 |
} |
421 |
return bExtended;
|
422 |
} |
423 |
/**
|
424 |
* This method initializes jPanel
|
425 |
*
|
426 |
* @return javax.swing.JPanel
|
427 |
*/
|
428 |
private JPanel getPExtend() { |
429 |
if (pExtend == null) { |
430 |
FlowLayout flowLayout21 = new FlowLayout(); |
431 |
pExtend = new JPanel(); |
432 |
pExtend.setLayout(flowLayout21); |
433 |
flowLayout21.setHgap(0);
|
434 |
flowLayout21.setVgap(0);
|
435 |
flowLayout21.setAlignment(java.awt.FlowLayout.RIGHT); |
436 |
pExtend.setPreferredSize(new java.awt.Dimension(35,22)); |
437 |
pExtend.add(getBExtended(), null);
|
438 |
} |
439 |
return pExtend;
|
440 |
} |
441 |
|
442 |
/**
|
443 |
* @return Returns the dataPointPanel.
|
444 |
*/
|
445 |
public DataPointPanel getDataPointPanel() {
|
446 |
return dataPointPanel;
|
447 |
} |
448 |
|
449 |
/**
|
450 |
* @param dataPointPanel The dataPointPanel to set.
|
451 |
*/
|
452 |
public void setDataPointPanel(DataPointPanel dataPointPanel) { |
453 |
this.dataPointPanel = dataPointPanel;
|
454 |
} |
455 |
|
456 |
/**
|
457 |
* @return Returns the tableControlerPanel.
|
458 |
*/
|
459 |
public TableControlerPanel getTableControlerPanel() {
|
460 |
return tableControlerPanel;
|
461 |
} |
462 |
|
463 |
/**
|
464 |
* @param tableControlerPanel The tableControlerPanel to set.
|
465 |
*/
|
466 |
public void setTableControlerPanel(TableControlerPanel tableControlerPanel) { |
467 |
this.tableControlerPanel = tableControlerPanel;
|
468 |
} |
469 |
|
470 |
/**
|
471 |
* Control de eventos de TableControlerPanel
|
472 |
*/
|
473 |
public void actionPerformed(ActionEvent e) { |
474 |
|
475 |
//Bot?n de ir al punto inicial
|
476 |
if(e.getSource() == tableControlerPanel.getBFirst()){
|
477 |
if(tableControlerPanel.getItemCount() >= 1) |
478 |
changePoint(true, 0); |
479 |
} |
480 |
|
481 |
//Bot?n de ir al punto anterior
|
482 |
if(e.getSource() == tableControlerPanel.getBPrev()){
|
483 |
if(tableControlerPanel.getSelectedIndex() != 0) |
484 |
changePoint(true, tableControlerPanel.getSelectedIndex() - 1); |
485 |
} |
486 |
|
487 |
//Bot?n de ir al punto siguiente
|
488 |
if(e.getSource() == tableControlerPanel.getBNext()){
|
489 |
if(tableControlerPanel.getSelectedIndex() != (tableControlerPanel.getItemCount() - 1)) |
490 |
changePoint(true, tableControlerPanel.getSelectedIndex() + 1); |
491 |
|
492 |
} |
493 |
|
494 |
//Bot?n de ir al punto final
|
495 |
if(e.getSource() == tableControlerPanel.getBLast()){
|
496 |
if(tableControlerPanel.getItemCount() >= 1) |
497 |
changePoint(true, tableControlerPanel.getItemCount() - 1); |
498 |
} |
499 |
|
500 |
//Combo de selecci?n de punto
|
501 |
if(e.getSource() == tableControlerPanel.getCPoint()){
|
502 |
if(tableControlerPanel.getSelectedIndex() != -1){ |
503 |
if(!disableEvent){
|
504 |
try{
|
505 |
loadLyrPoint(); |
506 |
}catch(InstantiationException exc){ |
507 |
return;
|
508 |
} |
509 |
lyrPoints.loadVisualPoint(tableControlerPanel.getSelectedIndex(), grd); |
510 |
tableControlerPanel.checkArrows(); |
511 |
} |
512 |
} |
513 |
} |
514 |
|
515 |
//Bot?n de nuevo punto
|
516 |
if(e.getSource() == tableControlerPanel.getBNew()){
|
517 |
try{
|
518 |
disableEvent = true;
|
519 |
loadLyrPoint(); |
520 |
if(this.getTableControlerPanel().getItemCount() > 0) |
521 |
checkInfoPointText(); |
522 |
lyrPoints.addPoint(null, null); |
523 |
tableControlerPanel.getCPoint().addItem("" + lyrPoints.getCountPoints());
|
524 |
tableControlerPanel.getLNumberOfPoints().setText(PluginServices.getText(this, "de ") + " " + lyrPoints.getCountPoints()); |
525 |
lastIndexSelection = lyrPoints.getCountPoints() - 1;
|
526 |
tableControlerPanel.setSelectedIndex(tableControlerPanel.getItemCount() - 1);
|
527 |
grd.resetControls(true);
|
528 |
tableControlerPanel.checkArrows(); |
529 |
}catch(NoSuchFieldException exc){ |
530 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
531 |
PluginServices.getText(this, "coordenadas_vacias")); |
532 |
}catch(InstantiationException exc){ |
533 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
534 |
PluginServices.getText(this, "error_capa_puntos")); |
535 |
} |
536 |
disableEvent = false;
|
537 |
} |
538 |
|
539 |
//Bot?n de eliminado de todos los puntos
|
540 |
if(e.getSource() == getTableControlerPanel().getBClear()){
|
541 |
clearList(); |
542 |
} |
543 |
|
544 |
//Bot?n de eliminado de un punto
|
545 |
if(e.getSource() == getTableControlerPanel().getBDelPoint()){
|
546 |
if(lyrPoints.length() == 1) //Si solo hay un punto reseteamos |
547 |
clearList(); |
548 |
else{
|
549 |
disableEvent = true;
|
550 |
int posSelect = tableControlerPanel.getSelectedIndex();
|
551 |
if(posSelect == -1) |
552 |
return;
|
553 |
lyrPoints.deleteVisualPoint(posSelect, grd); |
554 |
|
555 |
if(posSelect == 0){ |
556 |
lastIndexSelection = posSelect; |
557 |
}else{
|
558 |
lastIndexSelection = posSelect -1 ;
|
559 |
} |
560 |
disableEvent = false;
|
561 |
} |
562 |
} |
563 |
|
564 |
//Bot?n de extensi?n del cuadro de dialogo
|
565 |
if(e.getSource() == this.getBExtended()){ |
566 |
if(grd.isEnlarge()){
|
567 |
grd.setEnlarge(false);
|
568 |
bExtended.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/down.png"))); |
569 |
}else{
|
570 |
grd.setEnlarge(true);
|
571 |
bExtended.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/up.png"))); |
572 |
if(lyrPoints != null) |
573 |
lyrPoints.loadVisualPoint(tableControlerPanel.getSelectedIndex(), this.grd);
|
574 |
} |
575 |
} |
576 |
|
577 |
} |
578 |
|
579 |
/* (non-Javadoc)
|
580 |
* @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
|
581 |
*/
|
582 |
public void keyPressed(KeyEvent e) { |
583 |
// TODO Auto-generated method stu
|
584 |
} |
585 |
|
586 |
/**
|
587 |
* Actualiza los valores del punto nuevo introducido desde el teclado llamando a la funci?n
|
588 |
* de la capa updataData que actualizar? los controles necesarios para que se refresquen la vista
|
589 |
* mini imagenes, textfields, tabla y capa de puntos.
|
590 |
* @param pixel Pixel de la imagen
|
591 |
* @param map Coordenadas de la vista.
|
592 |
*/
|
593 |
private void updatePointsValue(Point2D pixel, Point2D map){ |
594 |
//Actualizamos los controles con los nuevos valores
|
595 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
596 |
for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
597 |
FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i); |
598 |
if( lyr instanceof FLyrGeoRaster && |
599 |
lyr.getName().startsWith("*") &&
|
600 |
lyr.isActive()){ |
601 |
((FLyrGeoRaster)lyr).updateData(Integer.valueOf(this.grd.getSelectPointsPanel().getTableControlerPanel().getSelectedItem()).intValue(), |
602 |
pixel, |
603 |
map, |
604 |
this.grd,
|
605 |
theView, |
606 |
lyrPoints); |
607 |
} |
608 |
} |
609 |
} |
610 |
|
611 |
/**
|
612 |
* Control de eventos de las entradas de texto de los puntos
|
613 |
*/
|
614 |
public void keyReleased(KeyEvent e) { |
615 |
//Campo de texto de la coordenada X en pixeles
|
616 |
Point2D pixel = null; |
617 |
Point2D map = null; |
618 |
boolean update = false; |
619 |
|
620 |
try{
|
621 |
if(e.getSource() == dataPointPanel.getTX()){
|
622 |
if(checkTextField(dataPointPanel.getTX(), e.getKeyCode(), lastTx)){
|
623 |
pixel = new Point2D.Double(); |
624 |
pixel.setLocation( Double.valueOf(dataPointPanel.getTX().getText()).doubleValue(),
|
625 |
Double.valueOf(dataPointPanel.getTY().getText()).doubleValue());
|
626 |
if(e.getKeyCode() == 10) |
627 |
update = true;
|
628 |
lastTx = dataPointPanel.getTX().getText(); |
629 |
} |
630 |
} |
631 |
|
632 |
//Campo de texto de la coordenada Y en pixeles
|
633 |
if(e.getSource() == dataPointPanel.getTY()){
|
634 |
if(checkTextField(dataPointPanel.getTY(), e.getKeyCode(), lastTy)){
|
635 |
pixel = new Point2D.Double(); |
636 |
pixel.setLocation( Double.valueOf(dataPointPanel.getTX().getText()).doubleValue(),
|
637 |
Double.valueOf(dataPointPanel.getTY().getText()).doubleValue());
|
638 |
if(e.getKeyCode() == 10) |
639 |
update = true;
|
640 |
lastTy = dataPointPanel.getTY().getText(); |
641 |
} |
642 |
} |
643 |
|
644 |
//Campo de texto de la coordenada X en coordenadas del mundo
|
645 |
if(e.getSource() == dataPointPanel.getLatitud()){
|
646 |
if(checkTextField(dataPointPanel.getLatitud(), e.getKeyCode(), lastLat)){
|
647 |
map = new Point2D.Double(); |
648 |
map.setLocation( Double.valueOf(dataPointPanel.getLongitud().getText()).doubleValue(),
|
649 |
Double.valueOf(dataPointPanel.getLatitud().getText()).doubleValue());
|
650 |
if(e.getKeyCode() == 10) |
651 |
update = true;
|
652 |
lastLat = dataPointPanel.getLatitud().getText(); |
653 |
} |
654 |
} |
655 |
|
656 |
//Campo de texto de la coordenada Y en coordenadas del mundo
|
657 |
if(e.getSource() == dataPointPanel.getLongitud()){
|
658 |
if(checkTextField(dataPointPanel.getLongitud(), e.getKeyCode(), lastLong)){
|
659 |
map = new Point2D.Double(); |
660 |
map.setLocation( Double.valueOf(dataPointPanel.getLongitud().getText()).doubleValue(),
|
661 |
Double.valueOf(dataPointPanel.getLatitud().getText()).doubleValue());
|
662 |
if(e.getKeyCode() == 10) |
663 |
update = true;
|
664 |
lastLong = dataPointPanel.getLongitud().getText(); |
665 |
} |
666 |
} |
667 |
|
668 |
if(update)
|
669 |
this.updatePointsValue(pixel, map);
|
670 |
|
671 |
}catch(NumberFormatException exc){ |
672 |
System.out.println("Formato numerico erroneo"); |
673 |
} |
674 |
|
675 |
} |
676 |
|
677 |
/* (non-Javadoc)
|
678 |
* @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
|
679 |
*/
|
680 |
public void keyTyped(KeyEvent e) { |
681 |
// TODO Auto-generated method stub
|
682 |
|
683 |
} |
684 |
|
685 |
/* (non-Javadoc)
|
686 |
* @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
|
687 |
*/
|
688 |
public void focusGained(FocusEvent arg0) { |
689 |
// TODO Auto-generated method stub
|
690 |
|
691 |
} |
692 |
|
693 |
/**
|
694 |
* Los campos de texto de las coordenadas cuando pierden el foco actualizan el valor del pixel
|
695 |
* en la cap, vista, mini imagen y tabla
|
696 |
*/
|
697 |
public void focusLost(FocusEvent arg0) { |
698 |
Point2D pixel = new Point2D.Double(); |
699 |
Point2D map = new Point2D.Double(); |
700 |
pixel.setLocation(Double.valueOf(dataPointPanel.getTX().getText()).doubleValue(),
|
701 |
Double.valueOf(dataPointPanel.getTY().getText()).doubleValue());
|
702 |
map.setLocation(Double.valueOf(dataPointPanel.getLongitud().getText()).doubleValue(),
|
703 |
Double.valueOf(dataPointPanel.getLatitud().getText()).doubleValue());
|
704 |
this.updatePointsValue(pixel, map);
|
705 |
|
706 |
} |
707 |
|
708 |
/**
|
709 |
* @return Returns the errorPointPanel.
|
710 |
*/
|
711 |
public ErrorPointPanel getErrorPointPanel() {
|
712 |
if(this.errorPointPanel == null) |
713 |
errorPointPanel = new ErrorPointPanel();
|
714 |
return errorPointPanel;
|
715 |
} |
716 |
} |