Statistics
| Revision:

root / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / Panels / SelectPointsPanel.java @ 2964

History | View | Annotate | Download (24.5 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 lLatitud = null;
44
        private JLabel lLongitud = 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
         * Busca el punto en la capa FLyrPoint que corresponde con la posicion pos
160
         * y carga la informaci?n de este en el panel de informaci?n.
161
         * @param pos
162
         */
163
        private void loadInfoPoint(int pos){
164
                GeoPoint pto = lyrPoints.getPoint(pos);
165
                if(pto.pixelPoint != null){
166
                getTX().setText(""+pto.pixelPoint.getX());
167
                    getTY().setText(""+pto.pixelPoint.getY());
168
            }
169
            if(pto.mapPoint != null){
170
                    getLatitud().setText(""+pto.mapPoint.getX());
171
                    getLongitud().setText(""+pto.mapPoint.getY());
172
            }
173
        }
174
        
175
        /**
176
         * Comprueba si los valores de un punto en los campos de texto est?n
177
         * vacios y lanza una excepci?n si hay alguno sin informaci?n.
178
         * @throws NoSuchFieldException
179
         */
180
        private void checkInfoPointText()throws NoSuchFieldException{
181
                if(        getTX().getText().equals("") ||
182
                                getTY().getText().equals("") ||
183
                                getLatitud().getText().equals("") ||
184
                                getLongitud().getText().equals("")){
185
                                isNew = true;
186
                                getCPoint().setSelectedIndex(lastIndexSelection);
187
                                throw new NoSuchFieldException();
188
                }
189
        }
190
        
191
        /**
192
         * Comprueba la posici?n del combo para ver si tiene que
193
         * habilitar o deshabilitar las flechas de delante y detr?s.
194
         */
195
        private void checkArrows(){
196
                if(getCPoint().getSelectedIndex() == -1){
197
                        bPrev.setEnabled(false);
198
                        bNext.setEnabled(false);
199
                        return;
200
                }
201
                if(getCPoint().getSelectedIndex() == 0)
202
                        bPrev.setEnabled(false);
203
                else
204
                        bPrev.setEnabled(true);
205
                
206
                if(getCPoint().getSelectedIndex() == (getCPoint().getItemCount() - 1) )
207
                        bNext.setEnabled(false);
208
                else
209
                        bNext.setEnabled(true);
210
        }
211
        
212
        /**
213
         * Actualiza el punto de la capa que corresponde con el que 
214
         * hay seleccionado en el combo. Los valores que se usan para la
215
         * actualizaci?n son los del info del panel. Si hubiese alg?n valor
216
         * en blanco la actualizaci?n no se produce.
217
         */
218
        private void updatePoint()throws NoSuchFieldException{
219
                if(getCPoint().getSelectedIndex() != -1){
220
                        Point2D pixel = null, map = null;
221
                        checkInfoPointText();
222
                        pixel = new Point2D.Double();
223
                        pixel.setLocation(        Double.valueOf(getTX().getText()).doubleValue(), 
224
                                                                Double.valueOf(getTY().getText()).doubleValue());
225
                        map = new Point2D.Double();
226
                        map.setLocation(        Double.valueOf(getLatitud().getText()).doubleValue(), 
227
                                                                Double.valueOf(getLongitud().getText()).doubleValue());
228
                        lyrPoints.updatePoint(pixel, map, getCPoint().getSelectedIndex());
229
                }
230
        }
231
        
232
        /**
233
         * Esta funci?n resetea los controles del panel de info de un punto.
234
         */
235
        private void resetControls(boolean active){
236
                getTX().setText("");
237
                getTY().setText("");
238
                getLatitud().setText("");
239
                getLongitud().setText("");
240
                getBSelectFromView().setEnabled(active);
241
                getBClear().setEnabled(active);
242
                getBDelPoint().setEnabled(active);
243
        }
244
        
245
        /**
246
         * Cuando pasamos de un punto a otro o se va a crear uno nuevo
247
         * <UL>
248
         * <LI>Cargamos la capa FLyrPoint si no est? ya cargada.</LI>
249
         * <LI>Actualizamos el punto seleccionado en ese momento y lanzamos una excepci?n si hay alg?n campo vacio.</LI>
250
         * <LI>Insertamos el nuevo punto seleccionado en los campos de informaci?n.</LI>
251
         * <LI>Checkeamos las flechas para ver si tenemos que activarlas o desactivarlas.</LI>
252
         * </UL>
253
         * @param changeSelection        Cambia la posici?n seleccionada del combo si es true
254
         * @param pos        Posici?n a la que cambia el combo si el parametro chageSelection es true
255
         */
256
        private void changePoint(boolean changeSelection, int pos){
257
                loadLyrPoint();
258
            try{
259
                updatePoint();
260
                if(changeSelection){
261
                        isNew = true;
262
                        lastIndexSelection = pos;
263
                        getCPoint().setSelectedIndex(pos);
264
                }
265
                loadInfoPoint(getCPoint().getSelectedIndex());
266
                checkArrows();
267
            }catch(NoSuchFieldException exc){
268
                    JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
269
                                        PluginServices.getText(this, "coordenadas_vacias"));
270
            }
271
        }
272
        
273
        /**
274
         * Limpia la lista de puntos y borra el dialogo.
275
         */
276
        private void clearList(){
277
                loadLyrPoint();
278
                lyrPoints.clear();
279
                resetControls(false);
280
                isNew = true;
281
                getCPoint().removeAllItems();
282
                checkArrows();
283
        }
284
        
285
        /**
286
         * This method initializes bBefore        
287
         *         
288
         * @return javax.swing.JButton        
289
         */
290
        private JButton getBPrev() {
291
                if (bPrev == null) {
292
                        bPrev = new JButton();
293
                        bPrev.setText("<");
294
                        bPrev.setEnabled(false);
295
                        bPrev.addActionListener(new java.awt.event.ActionListener() { 
296
                                public void actionPerformed(java.awt.event.ActionEvent e) {
297
                                if(getCPoint().getSelectedIndex() != 0)                                 
298
                                        changePoint(true, getCPoint().getSelectedIndex() - 1);
299
                                }
300
                        });
301
                }
302
                return bPrev;
303
        }
304

    
305
        /**
306
         * This method initializes bNext        
307
         *         
308
         * @return javax.swing.JButton        
309
         */
310
        private JButton getBNext() {
311
                if (bNext == null) {
312
                        bNext = new JButton();
313
                        bNext.setText(">");
314
                        bNext.setEnabled(false);
315
                        bNext.addActionListener(new java.awt.event.ActionListener() { 
316
                                public void actionPerformed(java.awt.event.ActionEvent e) {
317
                                        if(getCPoint().getSelectedIndex() != (getCPoint().getItemCount() - 1))
318
                                        changePoint(true, getCPoint().getSelectedIndex() + 1);
319
                                }
320
                        });
321
                }
322
                return bNext;
323
        }
324
        
325
        /**
326
         * Este m?todo inicializa el combo que contiene el n?mero de puntos.        
327
         *         
328
         * @return javax.swing.JComboBox        
329
         */
330
        public JComboBox getCPoint() {
331
                if (cPoint == null) {
332
                        cPoint = new JComboBox();
333
                        cPoint.addActionListener(new java.awt.event.ActionListener() { 
334
                                public void actionPerformed(java.awt.event.ActionEvent e) {
335
                                         if(getCPoint().getSelectedIndex() != -1){
336
                                                 if(!isNew){
337
                                                         changePoint(false, 0); 
338
                                                 }
339
                                                 isNew = false;
340
                                         }
341
                                }
342
                        });
343
                }
344
                return cPoint;
345
        }
346
        
347
        /**
348
         * Este m?todo inicializa el bot?n que crea un nuevo punto de georreferenciaci?n.        
349
         *         
350
         * @return javax.swing.JButton        
351
         */
352
        private JButton getBNew() {
353
                if (bNew == null) {
354
                        bNew = new JButton();
355
                        bNew.setText("Nuevo");
356
                        bNew.setPreferredSize(new java.awt.Dimension(84,25));
357
                bNew.addActionListener(new java.awt.event.ActionListener() { 
358
                                public void actionPerformed(java.awt.event.ActionEvent e) {
359
                                        loadLyrPoint();
360
                                        try{
361
                                                updatePoint();
362
                                                lyrPoints.addPoint(null, null);
363
                                                isNew = true;
364
                                                getCPoint().addItem("" + lyrPoints.getCountPoints());
365
                                                isNew = true;
366
                                                lastIndexSelection = lyrPoints.getCountPoints() - 1;
367
                                                getCPoint().setSelectedIndex(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(PluginServices.getText(this, "borrar_todos"));
390
                        bClear.setPreferredSize(new java.awt.Dimension(125,25));
391
                        bClear.setEnabled(false);
392
                        bClear.addActionListener(new java.awt.event.ActionListener() { 
393
                                public void actionPerformed(java.awt.event.ActionEvent e) {
394
                                        clearList();
395
                                }
396
                        });
397
                }
398
                return bClear;
399
        }
400

    
401
        /**
402
         * Este m?todo inicializa el bot?n del eliminar punto que har? que se elimine
403
         * el punto seleccionado.        
404
         *         
405
         * @return javax.swing.JButton        
406
         */
407
        private JButton getBDelPoint() {
408
                if (bDelPoint == null) {
409
                        bDelPoint = new JButton();
410
                        bDelPoint.setText(PluginServices.getText(this, "eliminar_punto"));
411
                        bDelPoint.setEnabled(false);
412
                        bDelPoint.addActionListener(new java.awt.event.ActionListener() { 
413
                                public void actionPerformed(java.awt.event.ActionEvent e) {
414
                                        if(lyrPoints.length() == 1) //Si solo hay un punto reseteamos
415
                                                clearList();
416
                                        else{
417
                                                loadLyrPoint();
418
                                                int posSelect = getCPoint().getSelectedIndex();        
419
                                                lyrPoints.remove(posSelect);
420
                                                isNew = true;
421
                                                getCPoint().removeAllItems();
422
                                                for(int i=0;i<lyrPoints.length();i++){
423
                                                        isNew = true;
424
                                                        getCPoint().addItem(String.valueOf(i+1));
425
                                                }
426
                                                isNew = true;
427
                                                if(posSelect == 0){
428
                                                        lastIndexSelection = posSelect;
429
                                                        getCPoint().setSelectedIndex(posSelect);
430
                                                        loadInfoPoint(posSelect);
431
                                                }else{
432
                                                        lastIndexSelection = posSelect -1 ;
433
                                                        getCPoint().setSelectedIndex(posSelect - 1);
434
                                                        loadInfoPoint(posSelect - 1);
435
                                                }
436
                                                checkArrows();
437
                                        }
438
                                }
439
                        });
440
                }
441
                return bDelPoint;
442
        }
443
        
444
        /**
445
         * Obtiene una capa de puntos. Si no existe crea una.
446
         * @return
447
         */
448
        private FLyrPoints loadLyrPoint(){
449
                //Buscamos una capa FlyrPoint en la vista y si no la hay la creamos
450
                View theView = (View) PluginServices.getMDIManager().getActiveView();
451
                
452
                //Si todavia no hay ninguna cargada la buscamos
453
                if(lyrPoints == null){
454
                        for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){
455
                                FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i);
456
                                if(lyr instanceof FLyrPoints)
457
                                        lyrPoints = (FLyrPoints)lyr;
458
                        }
459
                }
460
                
461
                //Si no hemos encontrado ninguna la creamos
462
                if(lyrPoints == null){
463
                        lyrPoints = new FLyrPoints();
464
                        lyrPoints.setName("layerPoints");
465
                        lyrPoints.setVisible(true);
466
                        theView.getMapControl().getMapContext().getLayers().addLayer(lyrPoints);
467
                }
468
                return lyrPoints;
469
        }
470
        
471

    
472

    
473
        /**
474
         * Este m?todo inicializa el bot?n seleccionar desde la vista. Cuando lo 
475
         * activamos se carga la herramienta de selecci?n de puntos desde la vista. 
476
         *         
477
         * @return javax.swing.JButton        
478
         */    
479
        public JButton getBSelectFromView() {
480
                if (bSelectFromView == null) {
481
                        bSelectFromView = new JButton();
482
                        bSelectFromView.setText(PluginServices.getText(this, PluginServices.getText(this, "seleccionar")));
483
                        bSelectFromView.setPreferredSize(new java.awt.Dimension(125,25));
484
                        bSelectFromView.setEnabled(false);
485
                        bSelectFromView.addActionListener(new java.awt.event.ActionListener() { 
486
                                public void actionPerformed(java.awt.event.ActionEvent e) {
487
                                        View theView = (View) PluginServices.getMDIManager().getActiveView();
488
                                        loadLyrPoint();
489
                                        lyrPoints.setLastTool(theView.getMapControl().getTool());
490
                                        GeorefPointerListener.posPoint = getCPoint().getSelectedIndex();
491
                                        theView.getMapControl().setTool("pointLyrSelection");
492
                                }
493
                        });
494
                }
495
                return bSelectFromView;
496
        }
497
        
498
        /**
499
         * This method initializes pPoint        
500
         *         
501
         * @return javax.swing.JPanel        
502
         */
503
        private JPanel getPInfoPoint() {
504
                if (pInfoPoint == null) {
505
                        GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
506
                        gridBagConstraints6.insets = new java.awt.Insets(0,0,0,0);
507
                        gridBagConstraints6.gridy = 3;
508
                        gridBagConstraints6.gridx = 0;
509
                        GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
510
                        gridBagConstraints5.insets = new java.awt.Insets(0,0,0,0);
511
                        gridBagConstraints5.gridy = 2;
512
                        gridBagConstraints5.weighty = 0.0D;
513
                        gridBagConstraints5.gridx = 0;
514
                        GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
515
                        gridBagConstraints4.insets = new java.awt.Insets(0,0,0,0);
516
                        gridBagConstraints4.gridy = 1;
517
                        gridBagConstraints4.weighty = 0.0D;
518
                        gridBagConstraints4.gridx = 0;
519
                        GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
520
                        gridBagConstraints3.insets = new java.awt.Insets(0,0,0,0);
521
                        gridBagConstraints3.gridy = 0;
522
                        gridBagConstraints3.ipadx = 0;
523
                        gridBagConstraints3.gridx = 0;
524
                        pInfoPoint = new JPanel();
525
                        pInfoPoint.setLayout(new GridBagLayout());
526
                        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));
527
                        pInfoPoint.setPreferredSize(new java.awt.Dimension(200,160));
528
                        pInfoPoint.add(getPX(), gridBagConstraints3);
529
                        pInfoPoint.add(getPY(), gridBagConstraints4);
530
                        pInfoPoint.add(getPLatitud(), gridBagConstraints5);
531
                        pInfoPoint.add(getPLongitud(), gridBagConstraints6);
532
                }
533
                return pInfoPoint;
534
        }
535

    
536
        /**
537
         * This method initializes pX        
538
         *         
539
         * @return javax.swing.JPanel        
540
         */
541
        private JPanel getPX() {
542
                if (pX == null) {
543
                        lX = new JLabel();
544
                        lX.setText("X: ");
545
                        FlowLayout flowLayout2 = new FlowLayout();
546
                        flowLayout2.setAlignment(java.awt.FlowLayout.RIGHT);
547
                        pX = new JPanel();
548
                        pX.setLayout(flowLayout2);
549
                        pX.setPreferredSize(new java.awt.Dimension(185,29));
550
                        pX.add(lX, null);
551
                        pX.add(getTX(), null);
552
                }
553
                return pX;
554
        }
555

    
556
        /**
557
         * This method initializes pY        
558
         *         
559
         * @return javax.swing.JPanel        
560
         */
561
        private JPanel getPY() {
562
                if (pY == null) {
563
                        lY = new JLabel();
564
                        lY.setText("Y:");
565
                        FlowLayout flowLayout1 = new FlowLayout();
566
                        flowLayout1.setAlignment(java.awt.FlowLayout.RIGHT);
567
                        pY = new JPanel();
568
                        pY.setLayout(flowLayout1);
569
                        pY.setPreferredSize(new java.awt.Dimension(185,29));
570
                        pY.add(lY, null);
571
                        pY.add(getTY(), null);
572
                }
573
                return pY;
574
        }
575

    
576
        /**
577
         * This method initializes pLatitud        
578
         *         
579
         * @return javax.swing.JPanel        
580
         */
581
        private JPanel getPLatitud() {
582
                if (pLatitud == null) {
583
                        lLatitud = new JLabel();
584
                        lLatitud.setText(PluginServices.getText(this,"latitud")+":");
585
                        FlowLayout flowLayout3 = new FlowLayout();
586
                        flowLayout3.setAlignment(java.awt.FlowLayout.RIGHT);
587
                        pLatitud = new JPanel();
588
                        pLatitud.setLayout(flowLayout3);
589
                        pLatitud.setPreferredSize(new java.awt.Dimension(185,29));
590
                        pLatitud.add(lLatitud, null);
591
                        pLatitud.add(getLatitud(), null);
592
                }
593
                return pLatitud;
594
        }
595

    
596
        /**
597
         * This method initializes pLongitud        
598
         *         
599
         * @return javax.swing.JPanel        
600
         */
601
        private JPanel getPLongitud() {
602
                if (pLongitud == null) {
603
                        lLongitud = new JLabel();
604
                        lLongitud.setText(PluginServices.getText(this, "longitud")+":");
605
                        FlowLayout flowLayout4 = new FlowLayout();
606
                        flowLayout4.setAlignment(java.awt.FlowLayout.RIGHT);
607
                        pLongitud = new JPanel();
608
                        pLongitud.setLayout(flowLayout4);
609
                        pLongitud.setPreferredSize(new java.awt.Dimension(185,29));
610
                        pLongitud.add(lLongitud, null);
611
                        pLongitud.add(getLongitud(), null);
612
                }
613
                return pLongitud;
614
        }
615
        
616
        /**
617
         * Checkea un textField y actualiza un punto con el valor
618
         * actual del textField
619
         *
620
         */
621
        private void checkTextField(JTextField tf, boolean xValue, boolean pixelValue, int code){                
622
                //Si el caracter introducido es erroneo avisamos y volvemos
623
                if((code < 48 || code > 57) && code != 46){
624
                        tf.setText("");
625
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
626
                                        PluginServices.getText(this, "caracteres_erroneos"));
627
                        return;
628
                }
629
                
630
                //Si no hay puntos en la lista no se hace nada
631
                if(lyrPoints == null || lyrPoints.getCountPoints() == 0)
632
                        return;
633
                
634
                //Si el caracter era valido salvamos el valor en la capa
635
                if(!tf.getText().equals("")){
636
                        loadLyrPoint();
637
                        Point2D p = null;
638
                        if(pixelValue)
639
                                p = ((GeoPoint)lyrPoints.getPoint(getCPoint().getSelectedIndex())).pixelPoint;
640
                        else
641
                                p = ((GeoPoint)lyrPoints.getPoint(getCPoint().getSelectedIndex())).mapPoint;
642
                        if(xValue){
643
                                if(p != null)
644
                                        p.setLocation(Double.valueOf(tf.getText()).doubleValue(), p.getY());
645
                                else{
646
                                        p = new Point2D.Double();
647
                                        p.setLocation(Double.valueOf(tf.getText()).doubleValue(), 0.0);
648
                                }
649
                        }else{
650
                                if(p != null)
651
                                        p.setLocation(p.getX(), Double.valueOf(tY.getText()).doubleValue());
652
                                else{
653
                                        p = new Point2D.Double();
654
                                        p.setLocation(0.0, Double.valueOf(tY.getText()).doubleValue());
655
                                }
656
                        }
657
                }
658
        }
659
        
660
        /**
661
         * Este m?todo inicializa el campo de texto que tiene la coordenada en X 
662
         * de la vista. Controla que le sean introducidos valores numericos y
663
         * salva el valor que contiene en la capa.        
664
         *         
665
         * @return javax.swing.JTextField        
666
         */
667
        public JTextField getTX() {
668
                if (tX == null) {
669
                        tX = new JTextField();
670
                        tX.setPreferredSize(new java.awt.Dimension(90,19));
671
                        tX.addKeyListener(new java.awt.event.KeyListener() { 
672
                                public void keyPressed(java.awt.event.KeyEvent e) {}
673
                                public void keyReleased(java.awt.event.KeyEvent e) {
674
                                        checkTextField(tX, true, true, e.getKeyCode());
675
                                }
676
                                public void keyTyped(java.awt.event.KeyEvent e) {}
677
                        });
678
                }
679
                return tX;
680
        }
681

    
682
        /**
683
         * Este m?todo inicializa el campo de texto que tiene la coordenada en Y 
684
         * de la vista. Controla que le sean introducidos valores numericos y
685
         * salva el valor que contiene en la capa.        
686
         *         
687
         * @return javax.swing.JTextField        
688
         */
689
        public JTextField getTY() {
690
                if (tY == null) {
691
                        tY = new JTextField();
692
                        tY.setPreferredSize(new java.awt.Dimension(90,19));
693
                        tY.addKeyListener(new java.awt.event.KeyListener() { 
694
                                public void keyPressed(java.awt.event.KeyEvent e) {}
695
                                public void keyReleased(java.awt.event.KeyEvent e){
696
                                        checkTextField(tY, false, true, e.getKeyCode());
697
                                }
698
                                public void keyTyped(java.awt.event.KeyEvent e) {}
699
                        });
700
                }
701
                return tY;
702
        }
703

    
704
        /**
705
         * Este m?todo inicializa el campo de texto que tiene la coordenada en Y 
706
         * del mundo real. Controla que le sean introducidos valores numericos y
707
         * salva el valor que contiene en la capa.        
708
         *         
709
         * @return javax.swing.JTextField        
710
         */
711
        public JTextField getLatitud() {
712
                if (tLatitud == null) {
713
                        tLatitud = new JTextField();
714
                        tLatitud.setPreferredSize(new java.awt.Dimension(111,19));
715
                        tLatitud.addKeyListener(new java.awt.event.KeyListener() { 
716
                                public void keyPressed(java.awt.event.KeyEvent e) {}
717
                                public void keyReleased(java.awt.event.KeyEvent e) {
718
                                        checkTextField(tLatitud, true, false, e.getKeyCode());        
719
                                }
720
                                public void keyTyped(java.awt.event.KeyEvent e) {}
721
                        });
722
                        
723
                }
724
                return tLatitud;
725
        }
726

    
727
        /**
728
         * Este m?todo inicializa el campo de texto que tiene la coordenada en X 
729
         * del mundo real. Controla que le sean introducidos valores numericos y
730
         * salva el valor que contiene en la capa.
731
         *         
732
         * @return javax.swing.JTextField        
733
         */
734
        public JTextField getLongitud() {
735
                if (tLongitud == null) {
736
                        tLongitud = new JTextField();
737
                        tLongitud.setPreferredSize(new java.awt.Dimension(111,19));
738
                        tLongitud.addKeyListener(new java.awt.event.KeyListener() { 
739
                                public void keyPressed(java.awt.event.KeyEvent e) {}
740
                                public void keyReleased(java.awt.event.KeyEvent e) {
741
                                        checkTextField(tLongitud, false, false, e.getKeyCode());        
742
                                }
743
                                public void keyTyped(java.awt.event.KeyEvent e) {}
744
                        });
745
                }
746
                return tLongitud;
747
        }
748
        
749
        /**
750
         * This method initializes jPanel        
751
         *         
752
         * @return javax.swing.JPanel        
753
         */    
754
        private JPanel getPControls() {
755
                if (pControls == null) {
756
                        pControls = new JPanel();
757
                        pControls.setPreferredSize(new java.awt.Dimension(180,160));
758
                        pControls.add(getPSelectFromView(), null);
759
                }
760
                return pControls;
761
        }
762
        /**
763
         * This method initializes jPanel        
764
         *         
765
         * @return javax.swing.JPanel        
766
         */    
767
        private JPanel getPSelectFromView() {
768
                if (pSelectFromView == null) {
769
                        GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
770
                        gridBagConstraints9.gridx = 0;
771
                        gridBagConstraints9.insets = new java.awt.Insets(2,2,2,2);
772
                        gridBagConstraints9.gridy = 2;
773
                        GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
774
                        gridBagConstraints8.gridx = 0;
775
                        gridBagConstraints8.insets = new java.awt.Insets(2,2,2,2);
776
                        gridBagConstraints8.gridy = 1;
777
                        GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
778
                        gridBagConstraints7.insets = new java.awt.Insets(2,2,2,2);
779
                        gridBagConstraints7.gridy = 0;
780
                        gridBagConstraints7.gridx = 0;
781
                        pSelectFromView = new JPanel();
782
                        pSelectFromView.setLayout(new GridBagLayout());
783
                        pSelectFromView.setPreferredSize(new java.awt.Dimension(150,150));
784
                        pSelectFromView.add(getBSelectFromView(), gridBagConstraints7);
785
                        pSelectFromView.add(getBClear(), gridBagConstraints8);
786
                        pSelectFromView.add(getBDelPoint(), gridBagConstraints9);
787
                }
788
                return pSelectFromView;
789
        }
790

    
791
   }