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