Statistics
| Revision:

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

History | View | Annotate | Download (25.1 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
         * 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.getY());
171
                    getLongitud().setText(""+pto.mapPoint.getX());
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(getLongitud().getText()).doubleValue(), 
227
                                                                Double.valueOf(getLatitud().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
                View theView = (View) PluginServices.getMDIManager().getActiveView();
284
                theView.getMapControl().getMapContext().invalidate();
285
        }
286
        
287
        /**
288
         * This method initializes bBefore        
289
         *         
290
         * @return javax.swing.JButton        
291
         */
292
        private JButton getBPrev() {
293
                if (bPrev == null) {
294
                        bPrev = new JButton();
295
                        bPrev.setText("<");
296
                        bPrev.setEnabled(false);
297
                        bPrev.addActionListener(new java.awt.event.ActionListener() { 
298
                                public void actionPerformed(java.awt.event.ActionEvent e) {
299
                                if(getCPoint().getSelectedIndex() != 0)                                 
300
                                        changePoint(true, getCPoint().getSelectedIndex() - 1);
301
                                }
302
                        });
303
                }
304
                return bPrev;
305
        }
306

    
307
        /**
308
         * This method initializes bNext        
309
         *         
310
         * @return javax.swing.JButton        
311
         */
312
        private JButton getBNext() {
313
                if (bNext == null) {
314
                        bNext = new JButton();
315
                        bNext.setText(">");
316
                        bNext.setEnabled(false);
317
                        bNext.addActionListener(new java.awt.event.ActionListener() { 
318
                                public void actionPerformed(java.awt.event.ActionEvent e) {
319
                                        if(getCPoint().getSelectedIndex() != (getCPoint().getItemCount() - 1))
320
                                        changePoint(true, getCPoint().getSelectedIndex() + 1);
321
                                }
322
                        });
323
                }
324
                return bNext;
325
        }
326
        
327
        /**
328
         * Este m?todo inicializa el combo que contiene el n?mero de puntos.        
329
         *         
330
         * @return javax.swing.JComboBox        
331
         */
332
        public JComboBox getCPoint() {
333
                if (cPoint == null) {
334
                        cPoint = new JComboBox();
335
                        cPoint.addActionListener(new java.awt.event.ActionListener() { 
336
                                public void actionPerformed(java.awt.event.ActionEvent e) { 
337
                                         if(getCPoint().getSelectedIndex() != -1){
338
                                                 if(!isNew){
339
                                                         loadInfoPoint(getCPoint().getSelectedIndex());
340
                                                checkArrows();
341
                                                 }
342
                                         }
343
                                         isNew = false;
344
                                }
345
                        });
346
                }
347
                return cPoint;
348
        }
349
        
350
        /**
351
         * Este m?todo inicializa el bot?n que crea un nuevo punto de georreferenciaci?n.        
352
         *         
353
         * @return javax.swing.JButton        
354
         */
355
        private JButton getBNew() {
356
                if (bNew == null) {
357
                        bNew = new JButton();
358
                        bNew.setText("Nuevo");
359
                        bNew.setPreferredSize(new java.awt.Dimension(84,25));
360
                bNew.addActionListener(new java.awt.event.ActionListener() { 
361
                                public void actionPerformed(java.awt.event.ActionEvent e) {
362
                                        loadLyrPoint();
363
                                        try{
364
                                                updatePoint();
365
                                                lyrPoints.addPoint(null, null);
366
                                                isNew = true;
367
                                                getCPoint().addItem("" + lyrPoints.getCountPoints());
368
                                                isNew = true;
369
                                                lastIndexSelection = lyrPoints.getCountPoints() - 1;
370
                                                getCPoint().setSelectedIndex(getCPoint().getItemCount() - 1);
371
                                                resetControls(true);
372
                                                checkArrows();
373
                                        }catch(NoSuchFieldException exc){
374
                                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
375
                                                                PluginServices.getText(this, "coordenadas_vacias"));
376
                                        }
377
                                }
378
                        });
379
                }
380
                return bNew;
381
        }
382
        
383
        /**
384
         * Este m?todo inicializa el bot?n del clear que har? que se eliminen todos los
385
         * puntos seleccionados.        
386
         *         
387
         * @return javax.swing.JButton        
388
         */
389
        private JButton getBClear() {
390
                if (bClear == null) {
391
                        bClear = new JButton();
392
                        bClear.setText(PluginServices.getText(this, "borrar_todos"));
393
                        bClear.setPreferredSize(new java.awt.Dimension(125,25));
394
                        bClear.setEnabled(false);
395
                        bClear.addActionListener(new java.awt.event.ActionListener() { 
396
                                public void actionPerformed(java.awt.event.ActionEvent e) {
397
                                        clearList();
398
                                }
399
                        });
400
                }
401
                return bClear;
402
        }
403

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

    
475

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

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

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

    
579
        /**
580
         * This method initializes pLatitud        
581
         *         
582
         * @return javax.swing.JPanel        
583
         */
584
        private JPanel getPLatitud() {
585
                if (pLatitud == null) {
586
                        lLongitud = new JLabel();
587
                        lLongitud.setText("longitud:");
588
                        FlowLayout flowLayout3 = new FlowLayout();
589
                        flowLayout3.setAlignment(java.awt.FlowLayout.RIGHT);
590
                        pLatitud = new JPanel();
591
                        pLatitud.setLayout(flowLayout3);
592
                        pLatitud.setPreferredSize(new java.awt.Dimension(185,29));
593
                        pLatitud.add(lLongitud, null);
594
                        pLatitud.add(getLongitud(), null);
595
                }
596
                return pLatitud;
597
        }
598

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

    
692
        /**
693
         * Este m?todo inicializa el campo de texto que tiene la coordenada en Y 
694
         * de la vista. Controla que le sean introducidos valores numericos y
695
         * salva el valor que contiene en la capa.        
696
         *         
697
         * @return javax.swing.JTextField        
698
         */
699
        public JTextField getTY() {
700
                if (tY == null) {
701
                        tY = new JTextField();
702
                        tY.setPreferredSize(new java.awt.Dimension(90,19));
703
                        tY.addKeyListener(new java.awt.event.KeyListener() { 
704
                                public void keyPressed(java.awt.event.KeyEvent e) {}
705
                                public void keyReleased(java.awt.event.KeyEvent e){
706
                                        checkTextField(tY, false, true, e.getKeyCode());
707
                                }
708
                                public void keyTyped(java.awt.event.KeyEvent e) {}
709
                        });
710
                }
711
                return tY;
712
        }
713

    
714
        /**
715
         * Este m?todo inicializa el campo de texto que tiene la coordenada en Y 
716
         * del mundo real. Controla que le sean introducidos valores numericos y
717
         * salva el valor que contiene en la capa.        
718
         *         
719
         * @return javax.swing.JTextField        
720
         */
721
        public JTextField getLatitud() {
722
                if (tLatitud == null) {
723
                        tLatitud = new JTextField();
724
                        tLatitud.setPreferredSize(new java.awt.Dimension(111,19));
725
                        tLatitud.setHorizontalAlignment(javax.swing.JTextField.LEFT);
726
                        tLatitud.addKeyListener(new java.awt.event.KeyListener() { 
727
                                public void keyPressed(java.awt.event.KeyEvent e) {}
728
                                public void keyReleased(java.awt.event.KeyEvent e) {
729
                                        checkTextField(tLatitud, true, false, e.getKeyCode());        
730
                                }
731
                                public void keyTyped(java.awt.event.KeyEvent e) {}
732
                        });
733
                        
734
                }
735
                return tLatitud;
736
        }
737

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

    
803
   }