svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / Panels / SelectPointsPanel.java @ 3102
History | View | Annotate | Download (24.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 |
* Carga el panel desde los datos contenidos en una capa de puntos
|
397 |
* @param lyr
|
398 |
*/
|
399 |
public void loadFromLyrPoints(FLyrPoints lyr){ |
400 |
if(lyr != null){ |
401 |
lyr.clean(); |
402 |
lyrPoints = new FLyrPoints();
|
403 |
lyrPoints.setListPoint(lyr.getListPoint()); |
404 |
|
405 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
406 |
theView.getMapControl().getMapContext().beginAtomicEvent(); |
407 |
theView.getMapControl().getMapContext().getLayers().addLayer(lyr); |
408 |
theView.getMapControl().getMapContext().endAtomicEvent(); |
409 |
|
410 |
tableControlerPanel.getCPoint().removeAllItems(); |
411 |
for(int i=0;i<lyr.getCountPoints();i++) |
412 |
tableControlerPanel.getCPoint().addItem("" + (i + 1)); |
413 |
tableControlerPanel.getLNumberOfPoints().setText(PluginServices.getText(this, "de") + " " + lyrPoints.getCountPoints()); |
414 |
if(lyr.getCountPoints() >= 1){ |
415 |
changePoint(true, 0); |
416 |
getBSelectFromView().setEnabled(true);
|
417 |
getTableControlerPanel().getBClear().setEnabled(true);
|
418 |
getTableControlerPanel().getBDelPoint().setEnabled(true);
|
419 |
} |
420 |
} |
421 |
} |
422 |
|
423 |
/**
|
424 |
* @return Returns the lyrPoints.
|
425 |
*/
|
426 |
public FLyrPoints getLyrPoints() {
|
427 |
if(lyrPoints == null){ |
428 |
try{
|
429 |
loadLyrPoint(); |
430 |
}catch(InstantiationException exc){ |
431 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
432 |
PluginServices.getText(this, "error_capa_puntos")); |
433 |
} |
434 |
} |
435 |
return lyrPoints;
|
436 |
} |
437 |
|
438 |
/**
|
439 |
* This method initializes jButton
|
440 |
*
|
441 |
* @return javax.swing.JButton
|
442 |
*/
|
443 |
private JButton getBExtended() { |
444 |
if (bExtended == null) { |
445 |
bExtended = new JButton(); |
446 |
bExtended.setPreferredSize(new java.awt.Dimension(22,22)); |
447 |
bExtended.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/down.png"))); |
448 |
bExtended.addActionListener(this);
|
449 |
} |
450 |
return bExtended;
|
451 |
} |
452 |
/**
|
453 |
* This method initializes jPanel
|
454 |
*
|
455 |
* @return javax.swing.JPanel
|
456 |
*/
|
457 |
private JPanel getPExtend() { |
458 |
if (pExtend == null) { |
459 |
FlowLayout flowLayout21 = new FlowLayout(); |
460 |
pExtend = new JPanel(); |
461 |
pExtend.setLayout(flowLayout21); |
462 |
flowLayout21.setHgap(0);
|
463 |
flowLayout21.setVgap(0);
|
464 |
flowLayout21.setAlignment(java.awt.FlowLayout.RIGHT); |
465 |
pExtend.setPreferredSize(new java.awt.Dimension(35,22)); |
466 |
pExtend.add(getBExtended(), null);
|
467 |
} |
468 |
return pExtend;
|
469 |
} |
470 |
|
471 |
/**
|
472 |
* @return Returns the dataPointPanel.
|
473 |
*/
|
474 |
public DataPointPanel getDataPointPanel() {
|
475 |
return dataPointPanel;
|
476 |
} |
477 |
|
478 |
/**
|
479 |
* @param dataPointPanel The dataPointPanel to set.
|
480 |
*/
|
481 |
public void setDataPointPanel(DataPointPanel dataPointPanel) { |
482 |
this.dataPointPanel = dataPointPanel;
|
483 |
} |
484 |
|
485 |
/**
|
486 |
* @return Returns the tableControlerPanel.
|
487 |
*/
|
488 |
public TableControlerPanel getTableControlerPanel() {
|
489 |
return tableControlerPanel;
|
490 |
} |
491 |
|
492 |
/**
|
493 |
* @param tableControlerPanel The tableControlerPanel to set.
|
494 |
*/
|
495 |
public void setTableControlerPanel(TableControlerPanel tableControlerPanel) { |
496 |
this.tableControlerPanel = tableControlerPanel;
|
497 |
} |
498 |
|
499 |
/**
|
500 |
* Control de eventos de TableControlerPanel
|
501 |
*/
|
502 |
public void actionPerformed(ActionEvent e) { |
503 |
|
504 |
//Bot?n de ir al punto inicial
|
505 |
if(e.getSource() == tableControlerPanel.getBFirst()){
|
506 |
if(tableControlerPanel.getItemCount() >= 1) |
507 |
changePoint(true, 0); |
508 |
} |
509 |
|
510 |
//Bot?n de ir al punto anterior
|
511 |
if(e.getSource() == tableControlerPanel.getBPrev()){
|
512 |
if(tableControlerPanel.getSelectedIndex() != 0) |
513 |
changePoint(true, tableControlerPanel.getSelectedIndex() - 1); |
514 |
} |
515 |
|
516 |
//Bot?n de ir al punto siguiente
|
517 |
if(e.getSource() == tableControlerPanel.getBNext()){
|
518 |
if(tableControlerPanel.getSelectedIndex() != (tableControlerPanel.getItemCount() - 1)) |
519 |
changePoint(true, tableControlerPanel.getSelectedIndex() + 1); |
520 |
|
521 |
} |
522 |
|
523 |
//Bot?n de ir al punto final
|
524 |
if(e.getSource() == tableControlerPanel.getBLast()){
|
525 |
if(tableControlerPanel.getItemCount() >= 1) |
526 |
changePoint(true, tableControlerPanel.getItemCount() - 1); |
527 |
} |
528 |
|
529 |
//Combo de selecci?n de punto
|
530 |
if(e.getSource() == tableControlerPanel.getCPoint()){
|
531 |
if(tableControlerPanel.getSelectedIndex() != -1){ |
532 |
if(!disableEvent){
|
533 |
lyrPoints.loadVisualPoint(tableControlerPanel.getSelectedIndex(), grd); |
534 |
tableControlerPanel.checkArrows(); |
535 |
} |
536 |
} |
537 |
} |
538 |
|
539 |
//Bot?n de nuevo punto
|
540 |
if(e.getSource() == tableControlerPanel.getBNew()){
|
541 |
try{
|
542 |
disableEvent = true;
|
543 |
loadLyrPoint(); |
544 |
if(this.getTableControlerPanel().getItemCount() > 0) |
545 |
checkInfoPointText(); |
546 |
lyrPoints.addPoint(null, null); |
547 |
tableControlerPanel.getCPoint().addItem("" + lyrPoints.getCountPoints());
|
548 |
tableControlerPanel.getLNumberOfPoints().setText(PluginServices.getText(this, "de ") + " " + lyrPoints.getCountPoints()); |
549 |
lastIndexSelection = lyrPoints.getCountPoints() - 1;
|
550 |
tableControlerPanel.setSelectedIndex(tableControlerPanel.getItemCount() - 1);
|
551 |
resetControls(true);
|
552 |
tableControlerPanel.checkArrows(); |
553 |
}catch(NoSuchFieldException exc){ |
554 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
555 |
PluginServices.getText(this, "coordenadas_vacias")); |
556 |
}catch(InstantiationException exc){ |
557 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
558 |
PluginServices.getText(this, "error_capa_puntos")); |
559 |
} |
560 |
disableEvent = false;
|
561 |
} |
562 |
|
563 |
//Bot?n de eliminado de todos los puntos
|
564 |
if(e.getSource() == getTableControlerPanel().getBClear()){
|
565 |
clearList(); |
566 |
} |
567 |
|
568 |
//Bot?n de eliminado de un punto
|
569 |
if(e.getSource() == getTableControlerPanel().getBDelPoint()){
|
570 |
if(lyrPoints.length() == 1) //Si solo hay un punto reseteamos |
571 |
clearList(); |
572 |
else{
|
573 |
disableEvent = true;
|
574 |
int posSelect = tableControlerPanel.getSelectedIndex();
|
575 |
if(posSelect == -1) |
576 |
return;
|
577 |
lyrPoints.deleteVisualPoint(posSelect, grd); |
578 |
|
579 |
if(posSelect == 0){ |
580 |
lastIndexSelection = posSelect; |
581 |
}else{
|
582 |
lastIndexSelection = posSelect -1 ;
|
583 |
} |
584 |
disableEvent = false;
|
585 |
} |
586 |
} |
587 |
|
588 |
//Bot?n de extensi?n del cuadro de dialogo
|
589 |
if(e.getSource() == this.getBExtended()){ |
590 |
if(grd.isEnlarge()){
|
591 |
grd.setEnlarge(false);
|
592 |
bExtended.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/down.png"))); |
593 |
}else{
|
594 |
grd.setEnlarge(true);
|
595 |
bExtended.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/up.png"))); |
596 |
if(lyrPoints != null) |
597 |
lyrPoints.loadVisualPoint(tableControlerPanel.getSelectedIndex(), this.grd);
|
598 |
} |
599 |
} |
600 |
|
601 |
} |
602 |
|
603 |
/* (non-Javadoc)
|
604 |
* @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
|
605 |
*/
|
606 |
public void keyPressed(KeyEvent e) { |
607 |
// TODO Auto-generated method stu
|
608 |
} |
609 |
|
610 |
/**
|
611 |
* Actualiza los valores del punto nuevo introducido desde el teclado llamando a la funci?n
|
612 |
* de la capa updataData que actualizar? los controles necesarios para que se refresquen la vista
|
613 |
* mini imagenes, textfields, tabla y capa de puntos.
|
614 |
* @param pixel Pixel de la imagen
|
615 |
* @param map Coordenadas de la vista.
|
616 |
*/
|
617 |
private void updatePointsValue(Point2D pixel, Point2D map){ |
618 |
//Actualizamos los controles con los nuevos valores
|
619 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
620 |
for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
621 |
FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i); |
622 |
if( lyr instanceof FLyrGeoRaster && |
623 |
lyr.getName().startsWith("*") &&
|
624 |
lyr.isActive()){ |
625 |
((FLyrGeoRaster)lyr).updateData(Integer.valueOf(this.grd.getSelectPointsPanel().getTableControlerPanel().getSelectedItem()).intValue(), |
626 |
pixel, |
627 |
map, |
628 |
this.grd,
|
629 |
theView, |
630 |
lyrPoints); |
631 |
} |
632 |
} |
633 |
} |
634 |
|
635 |
/**
|
636 |
* Control de eventos de las entradas de texto de los puntos
|
637 |
*/
|
638 |
public void keyReleased(KeyEvent e) { |
639 |
//Campo de texto de la coordenada X en pixeles
|
640 |
Point2D pixel = null; |
641 |
Point2D map = null; |
642 |
boolean update = false; |
643 |
|
644 |
try{
|
645 |
if(e.getSource() == dataPointPanel.getTX()){
|
646 |
if(checkTextField(dataPointPanel.getTX(), e.getKeyCode(), lastTx)){
|
647 |
pixel = new Point2D.Double(); |
648 |
pixel.setLocation( Double.valueOf(dataPointPanel.getTX().getText()).doubleValue(),
|
649 |
Double.valueOf(dataPointPanel.getTY().getText()).doubleValue());
|
650 |
if(e.getKeyCode() == 10) |
651 |
update = true;
|
652 |
lastTx = dataPointPanel.getTX().getText(); |
653 |
} |
654 |
} |
655 |
|
656 |
//Campo de texto de la coordenada Y en pixeles
|
657 |
if(e.getSource() == dataPointPanel.getTY()){
|
658 |
if(checkTextField(dataPointPanel.getTY(), e.getKeyCode(), lastTy)){
|
659 |
pixel = new Point2D.Double(); |
660 |
pixel.setLocation( Double.valueOf(dataPointPanel.getTX().getText()).doubleValue(),
|
661 |
Double.valueOf(dataPointPanel.getTY().getText()).doubleValue());
|
662 |
if(e.getKeyCode() == 10) |
663 |
update = true;
|
664 |
lastTy = dataPointPanel.getTY().getText(); |
665 |
} |
666 |
} |
667 |
|
668 |
//Campo de texto de la coordenada X en coordenadas del mundo
|
669 |
if(e.getSource() == dataPointPanel.getLatitud()){
|
670 |
if(checkTextField(dataPointPanel.getLatitud(), e.getKeyCode(), lastLat)){
|
671 |
map = new Point2D.Double(); |
672 |
map.setLocation( Double.valueOf(dataPointPanel.getLongitud().getText()).doubleValue(),
|
673 |
Double.valueOf(dataPointPanel.getLatitud().getText()).doubleValue());
|
674 |
if(e.getKeyCode() == 10) |
675 |
update = true;
|
676 |
lastLat = dataPointPanel.getLatitud().getText(); |
677 |
} |
678 |
} |
679 |
|
680 |
//Campo de texto de la coordenada Y en coordenadas del mundo
|
681 |
if(e.getSource() == dataPointPanel.getLongitud()){
|
682 |
if(checkTextField(dataPointPanel.getLongitud(), e.getKeyCode(), lastLong)){
|
683 |
map = new Point2D.Double(); |
684 |
map.setLocation( Double.valueOf(dataPointPanel.getLongitud().getText()).doubleValue(),
|
685 |
Double.valueOf(dataPointPanel.getLatitud().getText()).doubleValue());
|
686 |
if(e.getKeyCode() == 10) |
687 |
update = true;
|
688 |
lastLong = dataPointPanel.getLongitud().getText(); |
689 |
} |
690 |
} |
691 |
|
692 |
if(update)
|
693 |
this.updatePointsValue(pixel, map);
|
694 |
|
695 |
}catch(NumberFormatException exc){ |
696 |
System.out.println("Formato numerico erroneo"); |
697 |
} |
698 |
|
699 |
} |
700 |
|
701 |
/* (non-Javadoc)
|
702 |
* @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
|
703 |
*/
|
704 |
public void keyTyped(KeyEvent e) { |
705 |
// TODO Auto-generated method stub
|
706 |
|
707 |
} |
708 |
|
709 |
/* (non-Javadoc)
|
710 |
* @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
|
711 |
*/
|
712 |
public void focusGained(FocusEvent arg0) { |
713 |
// TODO Auto-generated method stub
|
714 |
|
715 |
} |
716 |
|
717 |
/**
|
718 |
* Los campos de texto de las coordenadas cuando pierden el foco actualizan el valor del pixel
|
719 |
* en la cap, vista, mini imagen y tabla
|
720 |
*/
|
721 |
public void focusLost(FocusEvent arg0) { |
722 |
Point2D pixel = new Point2D.Double(); |
723 |
Point2D map = new Point2D.Double(); |
724 |
pixel.setLocation(Double.valueOf(dataPointPanel.getTX().getText()).doubleValue(),
|
725 |
Double.valueOf(dataPointPanel.getTY().getText()).doubleValue());
|
726 |
map.setLocation(Double.valueOf(dataPointPanel.getLongitud().getText()).doubleValue(),
|
727 |
Double.valueOf(dataPointPanel.getLatitud().getText()).doubleValue());
|
728 |
this.updatePointsValue(pixel, map);
|
729 |
|
730 |
} |
731 |
|
732 |
} |