Statistics
| Revision:

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

History | View | Annotate | Download (23.3 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

    
22
public class SelectPointsPanel extends JPanel{
23

    
24
        private JPanel pGeneral = null;
25
        private JPanel pPointSelection = null;
26
        private JPanel pControlPoint = null;
27
        private JButton bPrev = null;
28
        private JComboBox cPoint = null;
29
        private JLabel lNumberOfPoints = null;
30
        private JLabel lPoint = null;
31
        private JButton bNext = null;
32
        private JButton bNew = null;
33
        private JPanel pInfoPoint = null;
34
        private JPanel pX = null;
35
        private JPanel pY = null;
36
        private JPanel pLatitud = null;
37
        private JPanel pLongitud = null;
38
        private JTextField tX = null;
39
        private JLabel lX = null;
40
        private JLabel lY = null;
41
        private JTextField tY = null;
42
        private JLabel lLatitud = null;
43
        private JLabel lLongitud = null;
44
        private JTextField tLatitud = null;
45
        private JTextField tLongitud = null;
46

    
47
        private JPanel pControls = null;
48
        private JPanel pSelectFromView = null;
49
        private JButton bSelectFromView = null;
50
        private FLyrPoints lyrPoints = null;
51
        private boolean isNew = false;
52
        private JButton bClear = null;
53
        private JButton bDelPoint = null;
54
        private int lastIndexSelection = -1;
55
        
56
        /**
57
         * This is the default constructor
58
         */
59
        public SelectPointsPanel() {
60
                super();
61
                initialize();
62
        }
63

    
64
        /**
65
         * This method initializes this
66
         * 
67
         * @return void
68
         */
69
        private void initialize() {
70
        this.setPreferredSize(new java.awt.Dimension(400,240));
71
        this.setSize(new java.awt.Dimension(400,240));
72
        this.setLocation(new java.awt.Point(0,0));
73
        this.add(getPGeneral(), null);
74
        }
75

    
76
        /**
77
         * This method initializes pGeneral        
78
         *         
79
         * @return javax.swing.JPanel        
80
         */
81
        private JPanel getPGeneral() {
82
                if (pGeneral == null) {
83
                        GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
84
                        gridBagConstraints1.insets = new java.awt.Insets(5,0,0,0);
85
                        gridBagConstraints1.gridy = 1;
86
                        gridBagConstraints1.gridx = 0;
87
                        GridBagConstraints gridBagConstraints = new GridBagConstraints();
88
                        gridBagConstraints.insets = new java.awt.Insets(0,0,4,0);
89
                        gridBagConstraints.gridy = 0;
90
                        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
91
                        gridBagConstraints.gridheight = 1;
92
                        gridBagConstraints.gridx = 0;
93
                        pGeneral = new JPanel();
94
                        pGeneral.setLayout(new GridBagLayout());
95
                        pGeneral.setPreferredSize(new java.awt.Dimension(400,240));
96
                        pGeneral.add(getPPointSelection(), gridBagConstraints);
97
                        pGeneral.add(getPControlPoint(), gridBagConstraints1);
98
                }
99
                return pGeneral;
100
        }
101

    
102
        /**
103
         * This method initializes pFileSelection        
104
         *         
105
         * @return javax.swing.JPanel        
106
         */
107
        private JPanel getPPointSelection() {
108
                if (pPointSelection == null) {
109
                        lPoint = new JLabel();
110
                        lPoint.setText(PluginServices.getText(this, "punto"));
111
                        lPoint.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
112
                        lPoint.setPreferredSize(new java.awt.Dimension(46,15));
113
                        lNumberOfPoints = new JLabel();
114
                        lNumberOfPoints.setText(PluginServices.getText(this, "de") + " 1");
115
                        lNumberOfPoints.setPreferredSize(new java.awt.Dimension(37,15));
116
                        FlowLayout flowLayout = new FlowLayout();
117
                        flowLayout.setVgap(8);
118
                        flowLayout.setAlignment(java.awt.FlowLayout.LEFT);
119
                        pPointSelection = new JPanel();
120
                        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));
121
                        pPointSelection.setName("");
122
                        pPointSelection.setLayout(flowLayout);
123
                        pPointSelection.setPreferredSize(new java.awt.Dimension(382,50));
124
                        pPointSelection.add(getBPrev(), null);
125
                        pPointSelection.add(lPoint, null);
126
                        pPointSelection.add(getCPoint(), null);
127
                        pPointSelection.add(lNumberOfPoints, null);
128
                        pPointSelection.add(getBNext(), null);
129
                        pPointSelection.add(getBNew(), null);
130
                }
131
                return pPointSelection;
132
        }
133

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

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

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

    
466

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

    
527
        /**
528
         * This method initializes pX        
529
         *         
530
         * @return javax.swing.JPanel        
531
         */
532
        private JPanel getPX() {
533
                if (pX == null) {
534
                        lX = new JLabel();
535
                        lX.setText("X: ");
536
                        FlowLayout flowLayout2 = new FlowLayout();
537
                        flowLayout2.setAlignment(java.awt.FlowLayout.RIGHT);
538
                        pX = new JPanel();
539
                        pX.setLayout(flowLayout2);
540
                        pX.setPreferredSize(new java.awt.Dimension(185,29));
541
                        pX.add(lX, null);
542
                        pX.add(getTX(), null);
543
                }
544
                return pX;
545
        }
546

    
547
        /**
548
         * This method initializes pY        
549
         *         
550
         * @return javax.swing.JPanel        
551
         */
552
        private JPanel getPY() {
553
                if (pY == null) {
554
                        lY = new JLabel();
555
                        lY.setText("Y:");
556
                        FlowLayout flowLayout1 = new FlowLayout();
557
                        flowLayout1.setAlignment(java.awt.FlowLayout.RIGHT);
558
                        pY = new JPanel();
559
                        pY.setLayout(flowLayout1);
560
                        pY.setPreferredSize(new java.awt.Dimension(185,29));
561
                        pY.add(lY, null);
562
                        pY.add(getTY(), null);
563
                }
564
                return pY;
565
        }
566

    
567
        /**
568
         * This method initializes pLatitud        
569
         *         
570
         * @return javax.swing.JPanel        
571
         */
572
        private JPanel getPLatitud() {
573
                if (pLatitud == null) {
574
                        lLatitud = new JLabel();
575
                        lLatitud.setText(PluginServices.getText(this,"latitud")+":");
576
                        FlowLayout flowLayout3 = new FlowLayout();
577
                        flowLayout3.setAlignment(java.awt.FlowLayout.RIGHT);
578
                        pLatitud = new JPanel();
579
                        pLatitud.setLayout(flowLayout3);
580
                        pLatitud.setPreferredSize(new java.awt.Dimension(185,29));
581
                        pLatitud.add(lLatitud, null);
582
                        pLatitud.add(getLatitud(), null);
583
                }
584
                return pLatitud;
585
        }
586

    
587
        /**
588
         * This method initializes pLongitud        
589
         *         
590
         * @return javax.swing.JPanel        
591
         */
592
        private JPanel getPLongitud() {
593
                if (pLongitud == null) {
594
                        lLongitud = new JLabel();
595
                        lLongitud.setText(PluginServices.getText(this, "longitud")+":");
596
                        FlowLayout flowLayout4 = new FlowLayout();
597
                        flowLayout4.setAlignment(java.awt.FlowLayout.RIGHT);
598
                        pLongitud = new JPanel();
599
                        pLongitud.setLayout(flowLayout4);
600
                        pLongitud.setPreferredSize(new java.awt.Dimension(185,29));
601
                        pLongitud.add(lLongitud, null);
602
                        pLongitud.add(getLongitud(), null);
603
                }
604
                return pLongitud;
605
        }
606
        
607
        /**
608
         * Checkea un textField y actualiza un punto con el valor
609
         * actual del textField
610
         *
611
         */
612
        private void checkTextField(JTextField tf, boolean xValue, boolean pixelValue, int code){
613
                System.out.println(code);
614
                
615
                //Si el caracter introducido es erroneo avisamos y volvemos
616
                if((code < 48 || code > 57) && code != 46){
617
                        tf.setText("");
618
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
619
                                        PluginServices.getText(this, "caracteres_erroneos"));
620
                        return;
621
                }
622
                
623
                //Si el caracter era valido salvamos el valor en la capa
624
                if(!tf.getText().equals("")){
625
                        loadLyrPoint();
626
                        Point2D p = null;
627
                        if(pixelValue)
628
                                p = ((GeoPoint)lyrPoints.getPoint(getCPoint().getSelectedIndex())).pixelPoint;
629
                        else
630
                                p = ((GeoPoint)lyrPoints.getPoint(getCPoint().getSelectedIndex())).mapPoint;
631
                        if(xValue){
632
                                if(p != null)
633
                                        p.setLocation(Double.valueOf(tf.getText()).doubleValue(), p.getY());
634
                                else{
635
                                        p = new Point2D.Double();
636
                                        p.setLocation(Double.valueOf(tf.getText()).doubleValue(), 0.0);
637
                                }
638
                        }else{
639
                                if(p != null)
640
                                        p.setLocation(p.getX(), Double.valueOf(tY.getText()).doubleValue());
641
                                else{
642
                                        p = new Point2D.Double();
643
                                        p.setLocation(0.0, Double.valueOf(tY.getText()).doubleValue());
644
                                }
645
                        }
646
                }
647
        }
648
        
649
        /**
650
         * This method initializes tX        
651
         *         
652
         * @return javax.swing.JTextField        
653
         */
654
        private JTextField getTX() {
655
                if (tX == null) {
656
                        tX = new JTextField();
657
                        tX.setPreferredSize(new java.awt.Dimension(90,19));
658
                        tX.addKeyListener(new java.awt.event.KeyListener() { 
659
                                public void keyPressed(java.awt.event.KeyEvent e) {}
660
                                public void keyReleased(java.awt.event.KeyEvent e) {
661
                                        checkTextField(tX, true, true, e.getKeyCode());
662
                                }
663
                                public void keyTyped(java.awt.event.KeyEvent e) {}
664
                        });
665
                }
666
                return tX;
667
        }
668

    
669
        /**
670
         * This method initializes jTextField        
671
         *         
672
         * @return javax.swing.JTextField        
673
         */
674
        private JTextField getTY() {
675
                if (tY == null) {
676
                        tY = new JTextField();
677
                        tY.setPreferredSize(new java.awt.Dimension(90,19));
678
                        tY.addKeyListener(new java.awt.event.KeyListener() { 
679
                                public void keyPressed(java.awt.event.KeyEvent e) {}
680
                                public void keyReleased(java.awt.event.KeyEvent e){
681
                                        checkTextField(tY, false, true, e.getKeyCode());
682
                                }
683
                                public void keyTyped(java.awt.event.KeyEvent e) {}
684
                        });
685
                }
686
                return tY;
687
        }
688

    
689
        /**
690
         * This method initializes jTextField1        
691
         *         
692
         * @return javax.swing.JTextField        
693
         */
694
        private JTextField getLatitud() {
695
                if (tLatitud == null) {
696
                        tLatitud = new JTextField();
697
                        tLatitud.setPreferredSize(new java.awt.Dimension(111,19));
698
                        tLatitud.addKeyListener(new java.awt.event.KeyListener() { 
699
                                public void keyPressed(java.awt.event.KeyEvent e) {}
700
                                public void keyReleased(java.awt.event.KeyEvent e) {
701
                                        checkTextField(tLatitud, true, false, e.getKeyCode());        
702
                                }
703
                                public void keyTyped(java.awt.event.KeyEvent e) {}
704
                        });
705
                        
706
                }
707
                return tLatitud;
708
        }
709

    
710
        /**
711
         * This method initializes jTextField2        
712
         *         
713
         * @return javax.swing.JTextField        
714
         */
715
        private JTextField getLongitud() {
716
                if (tLongitud == null) {
717
                        tLongitud = new JTextField();
718
                        tLongitud.setPreferredSize(new java.awt.Dimension(111,19));
719
                        tLongitud.addKeyListener(new java.awt.event.KeyListener() { 
720
                                public void keyPressed(java.awt.event.KeyEvent e) {}
721
                                public void keyReleased(java.awt.event.KeyEvent e) {
722
                                        checkTextField(tLongitud, false, false, e.getKeyCode());        
723
                                }
724
                                public void keyTyped(java.awt.event.KeyEvent e) {}
725
                        });
726
                }
727
                return tLongitud;
728
        }
729
        
730
        /**
731
         * This method initializes jPanel        
732
         *         
733
         * @return javax.swing.JPanel        
734
         */    
735
        private JPanel getPControls() {
736
                if (pControls == null) {
737
                        pControls = new JPanel();
738
                        pControls.setPreferredSize(new java.awt.Dimension(180,160));
739
                        pControls.add(getPSelectFromView(), null);
740
                }
741
                return pControls;
742
        }
743
        /**
744
         * This method initializes jPanel        
745
         *         
746
         * @return javax.swing.JPanel        
747
         */    
748
        private JPanel getPSelectFromView() {
749
                if (pSelectFromView == null) {
750
                        GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
751
                        gridBagConstraints9.gridx = 0;
752
                        gridBagConstraints9.insets = new java.awt.Insets(2,2,2,2);
753
                        gridBagConstraints9.gridy = 2;
754
                        GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
755
                        gridBagConstraints8.gridx = 0;
756
                        gridBagConstraints8.insets = new java.awt.Insets(2,2,2,2);
757
                        gridBagConstraints8.gridy = 1;
758
                        GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
759
                        gridBagConstraints7.insets = new java.awt.Insets(2,2,2,2);
760
                        gridBagConstraints7.gridy = 0;
761
                        gridBagConstraints7.gridx = 0;
762
                        pSelectFromView = new JPanel();
763
                        pSelectFromView.setLayout(new GridBagLayout());
764
                        pSelectFromView.setPreferredSize(new java.awt.Dimension(150,150));
765
                        pSelectFromView.add(getBSelectFromView(), gridBagConstraints7);
766
                        pSelectFromView.add(getBClear(), gridBagConstraints8);
767
                        pSelectFromView.add(getBDelPoint(), gridBagConstraints9);
768
                }
769
                return pSelectFromView;
770
        }
771

    
772
   }