root / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / Panels / SelectPointsPanel.java @ 3014
History | View | Annotate | Download (24.8 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.KeyEvent; |
10 |
import java.awt.event.KeyListener; |
11 |
import java.awt.geom.Point2D; |
12 |
|
13 |
import javax.swing.ImageIcon; |
14 |
import javax.swing.JButton; |
15 |
import javax.swing.JLabel; |
16 |
import javax.swing.JOptionPane; |
17 |
import javax.swing.JPanel; |
18 |
import javax.swing.JTextField; |
19 |
|
20 |
import com.iver.andami.PluginServices; |
21 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
22 |
import com.iver.cit.gvsig.fmap.layers.FLyrPoints; |
23 |
import com.iver.cit.gvsig.fmap.layers.FLyrPoints.GeoPoint; |
24 |
import com.iver.cit.gvsig.gui.View; |
25 |
import com.iver.cit.gvsig.gui.Dialogs.GeoreferencingDialog; |
26 |
import com.iver.cit.gvsig.gui.toolListeners.GeorefPointerListener; |
27 |
|
28 |
public class SelectPointsPanel extends JPanel implements ActionListener, KeyListener{ |
29 |
|
30 |
private JPanel pGeneral = null; |
31 |
private JPanel pPointSelection = null; |
32 |
private JPanel pControlPoint = null; |
33 |
private JButton bNew = null; |
34 |
private JPanel pInfoPoint = null; |
35 |
private JPanel pX = null; |
36 |
private JPanel pY = null; |
37 |
private JPanel pLatitud = null; |
38 |
private JPanel pLongitud = null; |
39 |
private JTextField tX = null; |
40 |
private JLabel lX = null; |
41 |
private JLabel lY = null; |
42 |
private JTextField tY = null; |
43 |
private JLabel lLongitud = null; |
44 |
private JLabel lLatitud = null; |
45 |
private JTextField tLatitud = null; |
46 |
private JTextField tLongitud = null; |
47 |
|
48 |
private JPanel pControls = null; |
49 |
private JPanel pSelectFromView = null; |
50 |
private JButton bSelectFromView = null; |
51 |
private FLyrPoints lyrPoints = null; |
52 |
private boolean isNew = false; |
53 |
private JButton bClear = null; |
54 |
private JButton bDelPoint = null; |
55 |
private int lastIndexSelection = -1; |
56 |
|
57 |
private JPanel pManagerPoint = null; |
58 |
private JButton bExtended = null; |
59 |
private JPanel pExtend = null; |
60 |
|
61 |
private TableControlerPanel tableControlerPanel = null; |
62 |
private DataPointPanel dataPointPanel = null; |
63 |
private ErrorPointPanel errorPointPanel = null; |
64 |
|
65 |
private GeoreferencingDialog grd = null; |
66 |
|
67 |
public SelectPointsPanel() {
|
68 |
super();
|
69 |
initialize(); |
70 |
} |
71 |
|
72 |
/**
|
73 |
* This is the default constructor
|
74 |
*/
|
75 |
public SelectPointsPanel(GeoreferencingDialog grd) {
|
76 |
super();
|
77 |
initialize(); |
78 |
this.grd = grd;
|
79 |
} |
80 |
|
81 |
private void init(){} |
82 |
|
83 |
/**
|
84 |
* This method initializes this
|
85 |
*
|
86 |
* @return void
|
87 |
*/
|
88 |
private void initialize() { |
89 |
this.setPreferredSize(new java.awt.Dimension(400,240)); |
90 |
this.setSize(new java.awt.Dimension(400,240)); |
91 |
this.setLocation(new java.awt.Point(0,0)); |
92 |
this.add(getPGeneral(), null); |
93 |
} |
94 |
|
95 |
/**
|
96 |
* This method initializes pGeneral
|
97 |
*
|
98 |
* @return javax.swing.JPanel
|
99 |
*/
|
100 |
private JPanel getPGeneral() { |
101 |
if (pGeneral == null) { |
102 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
103 |
gridBagConstraints1.insets = new java.awt.Insets(5,0,0,0); |
104 |
gridBagConstraints1.gridy = 0;
|
105 |
gridBagConstraints1.gridx = 0;
|
106 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
107 |
gridBagConstraints.insets = new java.awt.Insets(5,0,5,0); |
108 |
gridBagConstraints.gridy = 1;
|
109 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; |
110 |
gridBagConstraints.gridheight = 1;
|
111 |
gridBagConstraints.gridx = 0;
|
112 |
pGeneral = new JPanel(); |
113 |
pGeneral.setLayout(new GridBagLayout()); |
114 |
pGeneral.setPreferredSize(new java.awt.Dimension(400,240)); |
115 |
gridBagConstraints.gridwidth = 1;
|
116 |
pGeneral.add(getPPointSelection(), gridBagConstraints); |
117 |
pGeneral.add(getPControlPoint(), gridBagConstraints1); |
118 |
} |
119 |
return pGeneral;
|
120 |
} |
121 |
|
122 |
/**
|
123 |
* This method initializes pFileSelection
|
124 |
*
|
125 |
* @return javax.swing.JPanel
|
126 |
*/
|
127 |
private JPanel getPPointSelection() { |
128 |
if (pPointSelection == null) { |
129 |
FlowLayout flowLayout = new FlowLayout(); |
130 |
flowLayout.setVgap(0);
|
131 |
flowLayout.setAlignment(java.awt.FlowLayout.LEFT); |
132 |
pPointSelection = new JPanel(); |
133 |
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)); |
134 |
pPointSelection.setName("");
|
135 |
pPointSelection.setLayout(flowLayout); |
136 |
pPointSelection.setPreferredSize(new java.awt.Dimension(382,35)); |
137 |
flowLayout.setHgap(0);
|
138 |
if(this.tableControlerPanel == null){ |
139 |
tableControlerPanel = new TableControlerPanel();
|
140 |
tableControlerPanel.getBFirst().addActionListener(this);
|
141 |
tableControlerPanel.getBLast().addActionListener(this);
|
142 |
tableControlerPanel.getBNext().addActionListener(this);
|
143 |
tableControlerPanel.getBPrev().addActionListener(this);
|
144 |
tableControlerPanel.getCPoint().addActionListener(this);
|
145 |
} |
146 |
//pPointSelection.add(getPTableControl(), null);
|
147 |
pPointSelection.add(tableControlerPanel, null);
|
148 |
pPointSelection.add(getPManagerPoint(), null);
|
149 |
pPointSelection.add(getBSelectFromView(), null);
|
150 |
pPointSelection.add(getPExtend(), null);
|
151 |
} |
152 |
return pPointSelection;
|
153 |
} |
154 |
|
155 |
/**
|
156 |
* This method initializes pControls
|
157 |
*
|
158 |
*/
|
159 |
private JPanel getPControlPoint() { |
160 |
if (pControlPoint == null) { |
161 |
GridBagConstraints gridBagConstraints11 = new GridBagConstraints(); |
162 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
163 |
gridBagConstraints2.gridx = 0;
|
164 |
gridBagConstraints2.insets = new java.awt.Insets(0,0,0,0); |
165 |
gridBagConstraints2.gridy = 0;
|
166 |
pControlPoint = new JPanel(); |
167 |
pControlPoint.setLayout(new GridBagLayout()); |
168 |
pControlPoint.setPreferredSize(new java.awt.Dimension(382,160)); |
169 |
pControlPoint.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,0,0,0)); |
170 |
gridBagConstraints11.gridy = 0;
|
171 |
gridBagConstraints11.gridx = 1;
|
172 |
if(this.dataPointPanel == null){ |
173 |
dataPointPanel = new DataPointPanel();
|
174 |
dataPointPanel.getTX().addKeyListener(this);
|
175 |
dataPointPanel.getTY().addKeyListener(this);
|
176 |
dataPointPanel.getLatitud().addKeyListener(this);
|
177 |
dataPointPanel.getLongitud().addKeyListener(this);
|
178 |
} |
179 |
pControlPoint.add(dataPointPanel, gridBagConstraints2); |
180 |
|
181 |
if(this.errorPointPanel == null) |
182 |
errorPointPanel = new ErrorPointPanel();
|
183 |
pControlPoint.add(errorPointPanel, gridBagConstraints11); |
184 |
} |
185 |
return pControlPoint;
|
186 |
} |
187 |
|
188 |
/**
|
189 |
* Recorta los decimales para el visualizado en la selecci?n de puntos
|
190 |
* @param s Cadena de entrada
|
191 |
* @return Cadena de salida con decimales recortados
|
192 |
*/
|
193 |
public static String tailDecimal(String s){ |
194 |
int len = 2; |
195 |
int index = s.indexOf("."); |
196 |
if( index == -1) |
197 |
return s;
|
198 |
else{
|
199 |
if((index + len) >= s.length())
|
200 |
return s;
|
201 |
return s.substring(0, index + len + 1); |
202 |
} |
203 |
} |
204 |
|
205 |
/**
|
206 |
* Busca el punto en la capa FLyrPoint que corresponde con la posicion pos
|
207 |
* y carga la informaci?n de este en el panel de informaci?n.
|
208 |
* @param pos
|
209 |
*/
|
210 |
private void loadInfoPoint(int pos){ |
211 |
GeoPoint pto = lyrPoints.getPoint(pos); |
212 |
if(pto.pixelPoint != null){ |
213 |
dataPointPanel.getTX().setText(""+pto.pixelPoint.getX());
|
214 |
dataPointPanel.getTY().setText(""+pto.pixelPoint.getY());
|
215 |
} |
216 |
if(pto.mapPoint != null){ |
217 |
dataPointPanel.getLatitud().setText(tailDecimal(""+pto.mapPoint.getY()));
|
218 |
dataPointPanel.getLongitud().setText(tailDecimal(""+pto.mapPoint.getX()));
|
219 |
} |
220 |
} |
221 |
|
222 |
/**
|
223 |
* Comprueba si los valores de un punto en los campos de texto est?n
|
224 |
* vacios y lanza una excepci?n si hay alguno sin informaci?n.
|
225 |
* @throws NoSuchFieldException
|
226 |
*/
|
227 |
private void checkInfoPointText()throws NoSuchFieldException{ |
228 |
if( dataPointPanel.getTX().getText().equals("") || |
229 |
dataPointPanel.getTY().getText().equals("") ||
|
230 |
dataPointPanel.getLatitud().getText().equals("") ||
|
231 |
dataPointPanel.getLongitud().getText().equals("")){
|
232 |
isNew = true;
|
233 |
tableControlerPanel.getCPoint().setSelectedIndex(lastIndexSelection); |
234 |
throw new NoSuchFieldException(); |
235 |
} |
236 |
} |
237 |
|
238 |
/**
|
239 |
* Comprueba la posici?n del combo para ver si tiene que
|
240 |
* habilitar o deshabilitar las flechas de delante y detr?s.
|
241 |
*/
|
242 |
private void checkArrows(){ |
243 |
if(tableControlerPanel.getCPoint().getSelectedIndex() == -1){ |
244 |
tableControlerPanel.getBPrev().setEnabled(false);
|
245 |
tableControlerPanel.getBNext().setEnabled(false);
|
246 |
tableControlerPanel.getBLast().setEnabled(false);
|
247 |
tableControlerPanel.getBFirst().setEnabled(false);
|
248 |
return;
|
249 |
} |
250 |
if(tableControlerPanel.getCPoint().getSelectedIndex() == 0){ |
251 |
tableControlerPanel.getBPrev().setEnabled(false);
|
252 |
tableControlerPanel.getBFirst().setEnabled(false);
|
253 |
}else{
|
254 |
tableControlerPanel.getBPrev().setEnabled(true);
|
255 |
tableControlerPanel.getBFirst().setEnabled(true);
|
256 |
} |
257 |
|
258 |
if(tableControlerPanel.getCPoint().getSelectedIndex() == (tableControlerPanel.getCPoint().getItemCount() - 1) ){ |
259 |
tableControlerPanel.getBNext().setEnabled(false);
|
260 |
tableControlerPanel.getBLast().setEnabled(false);
|
261 |
}else{
|
262 |
tableControlerPanel.getBNext().setEnabled(true);
|
263 |
tableControlerPanel.getBLast().setEnabled(true);
|
264 |
} |
265 |
} |
266 |
|
267 |
/**
|
268 |
* Actualiza el punto de la capa que corresponde con el que
|
269 |
* hay seleccionado en el combo. Los valores que se usan para la
|
270 |
* actualizaci?n son los del info del panel. Si hubiese alg?n valor
|
271 |
* en blanco la actualizaci?n no se produce.
|
272 |
*/
|
273 |
private void updatePoint()throws NoSuchFieldException{ |
274 |
if(tableControlerPanel.getCPoint().getSelectedIndex() != -1){ |
275 |
Point2D pixel = null, map = null; |
276 |
checkInfoPointText(); |
277 |
pixel = new Point2D.Double(); |
278 |
pixel.setLocation( Double.valueOf(dataPointPanel.getTX().getText()).doubleValue(),
|
279 |
Double.valueOf(dataPointPanel.getTY().getText()).doubleValue());
|
280 |
map = new Point2D.Double(); |
281 |
map.setLocation( Double.valueOf(dataPointPanel.getLongitud().getText()).doubleValue(),
|
282 |
Double.valueOf(dataPointPanel.getLatitud().getText()).doubleValue());
|
283 |
lyrPoints.updatePoint(pixel, map, tableControlerPanel.getCPoint().getSelectedIndex()); |
284 |
} |
285 |
} |
286 |
|
287 |
/**
|
288 |
* Esta funci?n resetea los controles del panel de info de un punto.
|
289 |
*/
|
290 |
public void resetControls(boolean active){ |
291 |
dataPointPanel.getTX().setText("");
|
292 |
dataPointPanel.getTY().setText("");
|
293 |
dataPointPanel.getLatitud().setText("");
|
294 |
dataPointPanel.getLongitud().setText("");
|
295 |
getBSelectFromView().setEnabled(active); |
296 |
getBClear().setEnabled(active); |
297 |
getBDelPoint().setEnabled(active); |
298 |
} |
299 |
|
300 |
/**
|
301 |
* Cuando pasamos de un punto a otro o se va a crear uno nuevo
|
302 |
* <UL>
|
303 |
* <LI>Cargamos la capa FLyrPoint si no est? ya cargada.</LI>
|
304 |
* <LI>Actualizamos el punto seleccionado en ese momento y lanzamos una excepci?n si hay alg?n campo vacio.</LI>
|
305 |
* <LI>Insertamos el nuevo punto seleccionado en los campos de informaci?n.</LI>
|
306 |
* <LI>Checkeamos las flechas para ver si tenemos que activarlas o desactivarlas.</LI>
|
307 |
* </UL>
|
308 |
* @param changeSelection Cambia la posici?n seleccionada del combo si es true
|
309 |
* @param pos Posici?n a la que cambia el combo si el parametro chageSelection es true
|
310 |
*/
|
311 |
private void changePoint(boolean changeSelection, int pos){ |
312 |
loadLyrPoint(); |
313 |
try{
|
314 |
updatePoint(); |
315 |
if(changeSelection){
|
316 |
isNew = true;
|
317 |
lastIndexSelection = pos; |
318 |
tableControlerPanel.getCPoint().setSelectedIndex(pos); |
319 |
} |
320 |
loadInfoPoint(tableControlerPanel.getCPoint().getSelectedIndex()); |
321 |
checkArrows(); |
322 |
}catch(NoSuchFieldException exc){ |
323 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
324 |
PluginServices.getText(this, "coordenadas_vacias")); |
325 |
} |
326 |
} |
327 |
|
328 |
/**
|
329 |
* Limpia la lista de puntos y borra el dialogo.
|
330 |
*/
|
331 |
public void clearList(){ |
332 |
loadLyrPoint(); |
333 |
lyrPoints.clear(); |
334 |
resetControls(false);
|
335 |
isNew = true;
|
336 |
tableControlerPanel.getCPoint().removeAllItems(); |
337 |
tableControlerPanel.getLNumberOfPoints().setText(PluginServices.getText(this, "de") + " " + lyrPoints.getCountPoints()); |
338 |
checkArrows(); |
339 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
340 |
theView.getMapControl().getMapContext().invalidate(); |
341 |
} |
342 |
|
343 |
|
344 |
/**
|
345 |
* Este m?todo inicializa el bot?n que crea un nuevo punto de georreferenciaci?n.
|
346 |
*
|
347 |
* @return javax.swing.JButton
|
348 |
*/
|
349 |
private JButton getBNew() { |
350 |
if (bNew == null) { |
351 |
bNew = new JButton(); |
352 |
bNew.setText("");
|
353 |
bNew.setPreferredSize(new java.awt.Dimension(25,25)); |
354 |
bNew.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/newico.png"))); |
355 |
bNew.setActionCommand("");
|
356 |
bNew.addActionListener(new java.awt.event.ActionListener() {
|
357 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
358 |
loadLyrPoint(); |
359 |
try{
|
360 |
updatePoint(); |
361 |
lyrPoints.addPoint(null, null); |
362 |
isNew = true;
|
363 |
tableControlerPanel.getCPoint().addItem("" + lyrPoints.getCountPoints());
|
364 |
tableControlerPanel.getLNumberOfPoints().setText(PluginServices.getText(this, "de ") + " " + lyrPoints.getCountPoints()); |
365 |
isNew = true;
|
366 |
lastIndexSelection = lyrPoints.getCountPoints() - 1;
|
367 |
tableControlerPanel.getCPoint().setSelectedIndex(tableControlerPanel.getCPoint().getItemCount() - 1);
|
368 |
resetControls(true);
|
369 |
checkArrows(); |
370 |
}catch(NoSuchFieldException exc){ |
371 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
372 |
PluginServices.getText(this, "coordenadas_vacias")); |
373 |
} |
374 |
} |
375 |
}); |
376 |
} |
377 |
return bNew;
|
378 |
} |
379 |
|
380 |
/**
|
381 |
* Este m?todo inicializa el bot?n del clear que har? que se eliminen todos los
|
382 |
* puntos seleccionados.
|
383 |
*
|
384 |
* @return javax.swing.JButton
|
385 |
*/
|
386 |
private JButton getBClear() { |
387 |
if (bClear == null) { |
388 |
bClear = new JButton(); |
389 |
bClear.setText("");
|
390 |
bClear.setPreferredSize(new java.awt.Dimension(25,25)); |
391 |
bClear.setEnabled(false);
|
392 |
bClear.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/delall.png"))); |
393 |
bClear.setActionCommand("");
|
394 |
bClear.addActionListener(new java.awt.event.ActionListener() {
|
395 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
396 |
clearList(); |
397 |
} |
398 |
}); |
399 |
} |
400 |
return bClear;
|
401 |
} |
402 |
|
403 |
/**
|
404 |
* Este m?todo inicializa el bot?n del eliminar punto que har? que se elimine
|
405 |
* el punto seleccionado.
|
406 |
*
|
407 |
* @return javax.swing.JButton
|
408 |
*/
|
409 |
private JButton getBDelPoint() { |
410 |
if (bDelPoint == null) { |
411 |
bDelPoint = new JButton(); |
412 |
bDelPoint.setText("");
|
413 |
bDelPoint.setEnabled(false);
|
414 |
bDelPoint.setPreferredSize(new java.awt.Dimension(25,25)); |
415 |
bDelPoint.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/delone.png"))); |
416 |
bDelPoint.addActionListener(new java.awt.event.ActionListener() {
|
417 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
418 |
if(lyrPoints.length() == 1) //Si solo hay un punto reseteamos |
419 |
clearList(); |
420 |
else{
|
421 |
loadLyrPoint(); |
422 |
int posSelect = tableControlerPanel.getCPoint().getSelectedIndex();
|
423 |
lyrPoints.remove(posSelect); |
424 |
isNew = true;
|
425 |
tableControlerPanel.getCPoint().removeAllItems(); |
426 |
for(int i=0;i<lyrPoints.length();i++){ |
427 |
isNew = true;
|
428 |
tableControlerPanel.getCPoint().addItem(String.valueOf(i+1)); |
429 |
} |
430 |
isNew = true;
|
431 |
if(posSelect == 0){ |
432 |
lastIndexSelection = posSelect; |
433 |
tableControlerPanel.getCPoint().setSelectedIndex(posSelect); |
434 |
loadInfoPoint(posSelect); |
435 |
}else{
|
436 |
lastIndexSelection = posSelect -1 ;
|
437 |
tableControlerPanel.getCPoint().setSelectedIndex(posSelect - 1);
|
438 |
loadInfoPoint(posSelect - 1);
|
439 |
} |
440 |
tableControlerPanel.getLNumberOfPoints().setText(PluginServices.getText(this, "de ") + " " + lyrPoints.getCountPoints()); |
441 |
checkArrows(); |
442 |
} |
443 |
} |
444 |
}); |
445 |
} |
446 |
return bDelPoint;
|
447 |
} |
448 |
|
449 |
/**
|
450 |
* Obtiene una capa de puntos. Si no existe crea una.
|
451 |
* @return
|
452 |
*/
|
453 |
private FLyrPoints loadLyrPoint(){
|
454 |
//Buscamos una capa FlyrPoint en la vista y si no la hay la creamos
|
455 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
456 |
|
457 |
//Si todavia no hay ninguna cargada la buscamos
|
458 |
if(lyrPoints == null){ |
459 |
for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
460 |
FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i); |
461 |
if(lyr instanceof FLyrPoints) |
462 |
lyrPoints = (FLyrPoints)lyr; |
463 |
} |
464 |
} |
465 |
|
466 |
//Si no hemos encontrado ninguna la creamos
|
467 |
if(lyrPoints == null){ |
468 |
lyrPoints = new FLyrPoints();
|
469 |
lyrPoints.setName("Points");
|
470 |
lyrPoints.setVisible(true);
|
471 |
theView.getMapControl().getMapContext().beginAtomicEvent(); |
472 |
theView.getMapControl().getMapContext().getLayers().addLayer(lyrPoints); |
473 |
theView.getMapControl().getMapContext().endAtomicEvent(); |
474 |
} |
475 |
return lyrPoints;
|
476 |
} |
477 |
|
478 |
|
479 |
|
480 |
/**
|
481 |
* Este m?todo inicializa el bot?n seleccionar desde la vista. Cuando lo
|
482 |
* activamos se carga la herramienta de selecci?n de puntos desde la vista.
|
483 |
*
|
484 |
* @return javax.swing.JButton
|
485 |
*/
|
486 |
public JButton getBSelectFromView() { |
487 |
if (bSelectFromView == null) { |
488 |
bSelectFromView = new JButton(); |
489 |
bSelectFromView.setText("");
|
490 |
bSelectFromView.setPreferredSize(new java.awt.Dimension(25,25)); |
491 |
bSelectFromView.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/selectfromview.png"))); |
492 |
bSelectFromView.setEnabled(false);
|
493 |
bSelectFromView.addActionListener(new java.awt.event.ActionListener() {
|
494 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
495 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
496 |
loadLyrPoint(); |
497 |
lyrPoints.setLastTool(theView.getMapControl().getTool()); |
498 |
GeorefPointerListener.posPoint = tableControlerPanel.getCPoint().getSelectedIndex(); |
499 |
GeorefPointerListener.firstPoint = true;
|
500 |
theView.getMapControl().setTool("pointLyrSelection");
|
501 |
} |
502 |
}); |
503 |
} |
504 |
return bSelectFromView;
|
505 |
} |
506 |
|
507 |
/**
|
508 |
* Checkea un textField para que contenga caracteres numericos y actualiza
|
509 |
* un punto con el valor actual de l JTextField. Si no hay puntos en la
|
510 |
* lista no salvar? ning?n valor.
|
511 |
*/
|
512 |
public void checkTextField(JTextField tf, boolean xValue, boolean pixelValue, int code){ |
513 |
|
514 |
//Ignoramos las teclas Del, Spr, Mayusculas, Alt, Ctrl, Enter
|
515 |
if(code == 8 || code == 127 || code == 16 || code == 20 || |
516 |
code == 18 || code == 17 || code == 10 ) |
517 |
return;
|
518 |
|
519 |
//Si el caracter introducido es erroneo avisamos y volvemos
|
520 |
if((code < 48 || code > 57) && code != 46){ |
521 |
tf.setText("");
|
522 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
523 |
PluginServices.getText(this, "caracteres_erroneos")); |
524 |
return;
|
525 |
} |
526 |
|
527 |
//Si no hay puntos en la lista no se hace nada
|
528 |
if(lyrPoints == null || lyrPoints.getCountPoints() == 0) |
529 |
return;
|
530 |
|
531 |
//Si el caracter era valido salvamos el valor en la capa
|
532 |
if(!tf.getText().equals("")){ |
533 |
loadLyrPoint(); |
534 |
Point2D p = null; |
535 |
if(pixelValue)
|
536 |
p = ((GeoPoint)lyrPoints.getPoint(tableControlerPanel.getCPoint().getSelectedIndex())).pixelPoint; |
537 |
else
|
538 |
p = ((GeoPoint)lyrPoints.getPoint(tableControlerPanel.getCPoint().getSelectedIndex())).mapPoint; |
539 |
if(xValue){
|
540 |
if(p != null) |
541 |
p.setLocation(Double.valueOf(tf.getText()).doubleValue(), p.getY());
|
542 |
else{
|
543 |
p = new Point2D.Double(); |
544 |
p.setLocation(Double.valueOf(tf.getText()).doubleValue(), 0.0); |
545 |
} |
546 |
}else{
|
547 |
if(p != null) |
548 |
p.setLocation(p.getX(), Double.valueOf(tY.getText()).doubleValue());
|
549 |
else{
|
550 |
p = new Point2D.Double(); |
551 |
p.setLocation(0.0, Double.valueOf(tY.getText()).doubleValue()); |
552 |
} |
553 |
} |
554 |
} |
555 |
} |
556 |
|
557 |
/**
|
558 |
* Carga el panel desde los datos contenidos en una capa de puntos
|
559 |
* @param lyr
|
560 |
*/
|
561 |
public void loadFromLyrPoints(FLyrPoints lyr){ |
562 |
if(lyr != null){ |
563 |
lyr.clean(); |
564 |
lyrPoints = new FLyrPoints();
|
565 |
lyrPoints.setListPoint(lyr.getListPoint()); |
566 |
|
567 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
568 |
theView.getMapControl().getMapContext().beginAtomicEvent(); |
569 |
theView.getMapControl().getMapContext().getLayers().addLayer(lyr); |
570 |
theView.getMapControl().getMapContext().endAtomicEvent(); |
571 |
|
572 |
tableControlerPanel.getCPoint().removeAllItems(); |
573 |
for(int i=0;i<lyr.getCountPoints();i++) |
574 |
tableControlerPanel.getCPoint().addItem("" + (i + 1)); |
575 |
tableControlerPanel.getLNumberOfPoints().setText(PluginServices.getText(this, "de") + " " + lyrPoints.getCountPoints()); |
576 |
if(lyr.getCountPoints() >= 1){ |
577 |
changePoint(true, 0); |
578 |
getBSelectFromView().setEnabled(true);
|
579 |
getBClear().setEnabled(true);
|
580 |
getBDelPoint().setEnabled(true);
|
581 |
} |
582 |
} |
583 |
} |
584 |
|
585 |
/**
|
586 |
* This method initializes jPanel
|
587 |
*
|
588 |
* @return javax.swing.JPanel
|
589 |
*/
|
590 |
private JPanel getPManagerPoint() { |
591 |
if (pManagerPoint == null) { |
592 |
FlowLayout flowLayout11 = new FlowLayout(); |
593 |
pManagerPoint = new JPanel(); |
594 |
pManagerPoint.setLayout(flowLayout11); |
595 |
flowLayout11.setVgap(0);
|
596 |
flowLayout11.setHgap(0);
|
597 |
pManagerPoint.add(getBNew(), null);
|
598 |
pManagerPoint.add(getBDelPoint(), null);
|
599 |
pManagerPoint.add(getBClear(), null);
|
600 |
} |
601 |
return pManagerPoint;
|
602 |
} |
603 |
/**
|
604 |
* This method initializes jButton
|
605 |
*
|
606 |
* @return javax.swing.JButton
|
607 |
*/
|
608 |
private JButton getBExtended() { |
609 |
if (bExtended == null) { |
610 |
bExtended = new JButton(); |
611 |
bExtended.setPreferredSize(new java.awt.Dimension(25,25)); |
612 |
bExtended.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/down.png"))); |
613 |
bExtended.addActionListener(this);
|
614 |
} |
615 |
return bExtended;
|
616 |
} |
617 |
/**
|
618 |
* This method initializes jPanel
|
619 |
*
|
620 |
* @return javax.swing.JPanel
|
621 |
*/
|
622 |
private JPanel getPExtend() { |
623 |
if (pExtend == null) { |
624 |
FlowLayout flowLayout21 = new FlowLayout(); |
625 |
pExtend = new JPanel(); |
626 |
pExtend.setLayout(flowLayout21); |
627 |
flowLayout21.setHgap(0);
|
628 |
flowLayout21.setVgap(0);
|
629 |
flowLayout21.setAlignment(java.awt.FlowLayout.RIGHT); |
630 |
pExtend.setPreferredSize(new java.awt.Dimension(35,25)); |
631 |
pExtend.add(getBExtended(), null);
|
632 |
} |
633 |
return pExtend;
|
634 |
} |
635 |
|
636 |
/**
|
637 |
* @return Returns the dataPointPanel.
|
638 |
*/
|
639 |
public DataPointPanel getDataPointPanel() {
|
640 |
return dataPointPanel;
|
641 |
} |
642 |
|
643 |
/**
|
644 |
* @param dataPointPanel The dataPointPanel to set.
|
645 |
*/
|
646 |
public void setDataPointPanel(DataPointPanel dataPointPanel) { |
647 |
this.dataPointPanel = dataPointPanel;
|
648 |
} |
649 |
|
650 |
/**
|
651 |
* @return Returns the tableControlerPanel.
|
652 |
*/
|
653 |
public TableControlerPanel getTableControlerPanel() {
|
654 |
return tableControlerPanel;
|
655 |
} |
656 |
|
657 |
/**
|
658 |
* @param tableControlerPanel The tableControlerPanel to set.
|
659 |
*/
|
660 |
public void setTableControlerPanel(TableControlerPanel tableControlerPanel) { |
661 |
this.tableControlerPanel = tableControlerPanel;
|
662 |
} |
663 |
|
664 |
/**
|
665 |
* Control de eventos de TableControlerPanel
|
666 |
*/
|
667 |
public void actionPerformed(ActionEvent e) { |
668 |
|
669 |
//Bot?n de ir al punto inicial
|
670 |
if(e.getSource() == tableControlerPanel.getBFirst()){
|
671 |
if(tableControlerPanel.getCPoint().getItemCount() >= 1) |
672 |
changePoint(true, 0); |
673 |
} |
674 |
|
675 |
//Bot?n de ir al punto anterior
|
676 |
if(e.getSource() == tableControlerPanel.getBPrev()){
|
677 |
if(tableControlerPanel.getCPoint().getSelectedIndex() != 0) |
678 |
changePoint(true, tableControlerPanel.getCPoint().getSelectedIndex() - 1); |
679 |
} |
680 |
|
681 |
//Bot?n de ir al punto siguiente
|
682 |
if(e.getSource() == tableControlerPanel.getBNext()){
|
683 |
if(tableControlerPanel.getCPoint().getSelectedIndex() != (tableControlerPanel.getCPoint().getItemCount() - 1)) |
684 |
changePoint(true, tableControlerPanel.getCPoint().getSelectedIndex() + 1); |
685 |
|
686 |
} |
687 |
|
688 |
//Bot?n de ir al punto final
|
689 |
if(e.getSource() == tableControlerPanel.getBLast()){
|
690 |
if(tableControlerPanel.getCPoint().getItemCount() >= 1) |
691 |
changePoint(true, tableControlerPanel.getCPoint().getItemCount() - 1); |
692 |
} |
693 |
|
694 |
//Combo de selecci?n de punto
|
695 |
if(e.getSource() == tableControlerPanel.getCPoint()){
|
696 |
if(tableControlerPanel.getCPoint().getSelectedIndex() != -1){ |
697 |
if(!isNew){
|
698 |
loadInfoPoint(tableControlerPanel.getCPoint().getSelectedIndex()); |
699 |
checkArrows(); |
700 |
} |
701 |
} |
702 |
isNew = false;
|
703 |
} |
704 |
|
705 |
if(e.getSource() == this.getBExtended()){ |
706 |
if(grd.isEnlarge()){
|
707 |
grd.setEnlarge(false);
|
708 |
bExtended.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/down.png"))); |
709 |
}else{
|
710 |
grd.setEnlarge(true);
|
711 |
bExtended.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/up.png"))); |
712 |
} |
713 |
} |
714 |
|
715 |
} |
716 |
|
717 |
|
718 |
/* (non-Javadoc)
|
719 |
* @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
|
720 |
*/
|
721 |
public void keyPressed(KeyEvent e) { |
722 |
// TODO Auto-generated method stub
|
723 |
|
724 |
} |
725 |
|
726 |
/**
|
727 |
* Control de eventos de las entradas de texto de los puntos
|
728 |
*/
|
729 |
public void keyReleased(KeyEvent e) { |
730 |
//Campo de texto de la coordenada X en pixeles
|
731 |
if(e.getSource() == dataPointPanel.getTX()){
|
732 |
checkTextField(dataPointPanel.getTX(), true, true, e.getKeyCode()); |
733 |
} |
734 |
|
735 |
//Campo de texto de la coordenada Y en pixeles
|
736 |
if(e.getSource() == dataPointPanel.getTY()){
|
737 |
checkTextField(dataPointPanel.getTY(), false, true, e.getKeyCode()); |
738 |
} |
739 |
|
740 |
//Campo de texto de la coordenada X en coordenadas del mundo
|
741 |
if(e.getSource() == dataPointPanel.getLatitud()){
|
742 |
checkTextField(dataPointPanel.getLatitud(), true, false, e.getKeyCode()); |
743 |
} |
744 |
|
745 |
//Campo de texto de la coordenada Y en coordenadas del mundo
|
746 |
if(e.getSource() == dataPointPanel.getLongitud()){
|
747 |
checkTextField(dataPointPanel.getLongitud(), false, false, e.getKeyCode()); |
748 |
} |
749 |
|
750 |
} |
751 |
|
752 |
/* (non-Javadoc)
|
753 |
* @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
|
754 |
*/
|
755 |
public void keyTyped(KeyEvent e) { |
756 |
// TODO Auto-generated method stub
|
757 |
|
758 |
} |
759 |
|
760 |
|
761 |
} |