Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / Panels / SelectPointsPanel.java @ 2998

History | View | Annotate | Download (26.8 KB)

1
package com.iver.cit.gvsig.gui.Panels;
2

    
3
import java.awt.Component;
4
import java.awt.FlowLayout;
5
import java.awt.GridBagConstraints;
6
import java.awt.GridBagLayout;
7
import java.awt.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") + " 0");
116
                        lNumberOfPoints.setPreferredSize(new java.awt.Dimension(37,15));
117
                        FlowLayout flowLayout = new FlowLayout();
118
                        flowLayout.setVgap(8);
119
                        flowLayout.setAlignment(java.awt.FlowLayout.LEFT);
120
                        pPointSelection = new JPanel();
121
                        pPointSelection.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", java.awt.Font.BOLD, 12), java.awt.Color.black));
122
                        pPointSelection.setName("");
123
                        pPointSelection.setLayout(flowLayout);
124
                        pPointSelection.setPreferredSize(new java.awt.Dimension(382,50));
125
                        pPointSelection.add(getBPrev(), null);
126
                        pPointSelection.add(lPoint, null);
127
                        pPointSelection.add(getCPoint(), null);
128
                        pPointSelection.add(lNumberOfPoints, null);
129
                        pPointSelection.add(getBNext(), null);
130
                        pPointSelection.add(getBNew(), null);
131
                }
132
                return pPointSelection;
133
        }
134

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

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

    
423
        /**
424
         * Este m?todo inicializa el bot?n del eliminar punto que har? que se elimine
425
         * el punto seleccionado.        
426
         *         
427
         * @return javax.swing.JButton        
428
         */
429
        private JButton getBDelPoint() {
430
                if (bDelPoint == null) {
431
                        bDelPoint = new JButton();
432
                        bDelPoint.setText(PluginServices.getText(this, "eliminar_punto"));
433
                        bDelPoint.setEnabled(false);
434
                        bDelPoint.addActionListener(new java.awt.event.ActionListener() { 
435
                                public void actionPerformed(java.awt.event.ActionEvent e) {
436
                                        if(lyrPoints.length() == 1) //Si solo hay un punto reseteamos
437
                                                clearList();
438
                                        else{
439
                                                loadLyrPoint();
440
                                                int posSelect = getCPoint().getSelectedIndex();        
441
                                                lyrPoints.remove(posSelect);
442
                                                isNew = true;
443
                                                getCPoint().removeAllItems();
444
                                                for(int i=0;i<lyrPoints.length();i++){
445
                                                        isNew = true;
446
                                                        getCPoint().addItem(String.valueOf(i+1));
447
                                                }
448
                                                isNew = true;
449
                                                if(posSelect == 0){
450
                                                        lastIndexSelection = posSelect;
451
                                                        getCPoint().setSelectedIndex(posSelect);
452
                                                        loadInfoPoint(posSelect);
453
                                                }else{
454
                                                        lastIndexSelection = posSelect -1 ;
455
                                                        getCPoint().setSelectedIndex(posSelect - 1);
456
                                                        loadInfoPoint(posSelect - 1);
457
                                                }
458
                                                lNumberOfPoints.setText(PluginServices.getText(this, "de ") + " " + lyrPoints.getCountPoints());
459
                                                checkArrows();
460
                                        }
461
                                }
462
                        });
463
                }
464
                return bDelPoint;
465
        }
466
        
467
        /**
468
         * Obtiene una capa de puntos. Si no existe crea una.
469
         * @return
470
         */
471
        private FLyrPoints loadLyrPoint(){
472
                //Buscamos una capa FlyrPoint en la vista y si no la hay la creamos
473
                View theView = (View) PluginServices.getMDIManager().getActiveView();
474
                
475
                //Si todavia no hay ninguna cargada la buscamos
476
                if(lyrPoints == null){
477
                        for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){
478
                                FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i);
479
                                if(lyr instanceof FLyrPoints)
480
                                        lyrPoints = (FLyrPoints)lyr;
481
                        }
482
                }
483
                
484
                //Si no hemos encontrado ninguna la creamos
485
                if(lyrPoints == null){
486
                        lyrPoints = new FLyrPoints();
487
                        lyrPoints.setName("Points");
488
                        lyrPoints.setVisible(true);
489
                        theView.getMapControl().getMapContext().beginAtomicEvent();
490
                        theView.getMapControl().getMapContext().getLayers().addLayer(lyrPoints);
491
                        theView.getMapControl().getMapContext().endAtomicEvent();
492
                }
493
                return lyrPoints;
494
        }
495
        
496

    
497

    
498
        /**
499
         * Este m?todo inicializa el bot?n seleccionar desde la vista. Cuando lo 
500
         * activamos se carga la herramienta de selecci?n de puntos desde la vista. 
501
         *         
502
         * @return javax.swing.JButton        
503
         */    
504
        public JButton getBSelectFromView() {
505
                if (bSelectFromView == null) {
506
                        bSelectFromView = new JButton();
507
                        bSelectFromView.setText(PluginServices.getText(this, PluginServices.getText(this, "asignar_coordenadas")));
508
                        bSelectFromView.setPreferredSize(new java.awt.Dimension(125,25));
509
                        bSelectFromView.setEnabled(false);
510
                        bSelectFromView.addActionListener(new java.awt.event.ActionListener() { 
511
                                public void actionPerformed(java.awt.event.ActionEvent e) {
512
                                        View theView = (View) PluginServices.getMDIManager().getActiveView();
513
                                        loadLyrPoint();
514
                                        lyrPoints.setLastTool(theView.getMapControl().getTool());
515
                                        GeorefPointerListener.posPoint = getCPoint().getSelectedIndex();
516
                                        System.out.println("---->"+GeorefPointerListener.posPoint);
517
                                        GeorefPointerListener.firstPoint = true;
518
                                        theView.getMapControl().setTool("pointLyrSelection");
519
                                }
520
                        });
521
                }
522
                return bSelectFromView;
523
        }
524
        
525
        /**
526
         * This method initializes pPoint        
527
         *         
528
         * @return javax.swing.JPanel        
529
         */
530
        private JPanel getPInfoPoint() {
531
                if (pInfoPoint == null) {
532
                        GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
533
                        gridBagConstraints6.insets = new java.awt.Insets(0,0,0,0);
534
                        gridBagConstraints6.gridy = 3;
535
                        gridBagConstraints6.gridx = 0;
536
                        GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
537
                        gridBagConstraints5.insets = new java.awt.Insets(0,0,0,0);
538
                        gridBagConstraints5.gridy = 2;
539
                        gridBagConstraints5.weighty = 0.0D;
540
                        gridBagConstraints5.gridx = 0;
541
                        GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
542
                        gridBagConstraints4.insets = new java.awt.Insets(0,0,0,0);
543
                        gridBagConstraints4.gridy = 1;
544
                        gridBagConstraints4.weighty = 0.0D;
545
                        gridBagConstraints4.gridx = 0;
546
                        GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
547
                        gridBagConstraints3.insets = new java.awt.Insets(0,0,0,0);
548
                        gridBagConstraints3.gridy = 0;
549
                        gridBagConstraints3.ipadx = 0;
550
                        gridBagConstraints3.gridx = 0;
551
                        pInfoPoint = new JPanel();
552
                        pInfoPoint.setLayout(new GridBagLayout());
553
                        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));
554
                        pInfoPoint.setPreferredSize(new java.awt.Dimension(200,160));
555
                        pInfoPoint.add(getPX(), gridBagConstraints3);
556
                        pInfoPoint.add(getPY(), gridBagConstraints4);
557
                        pInfoPoint.add(getPLatitud(), gridBagConstraints5);
558
                        pInfoPoint.add(getPLongitud(), gridBagConstraints6);
559
                }
560
                return pInfoPoint;
561
        }
562

    
563
        /**
564
         * This method initializes pX        
565
         *         
566
         * @return javax.swing.JPanel        
567
         */
568
        private JPanel getPX() {
569
                if (pX == null) {
570
                        lX = new JLabel();
571
                        lX.setText("X: ");
572
                        FlowLayout flowLayout2 = new FlowLayout();
573
                        flowLayout2.setAlignment(java.awt.FlowLayout.RIGHT);
574
                        pX = new JPanel();
575
                        pX.setLayout(flowLayout2);
576
                        pX.setPreferredSize(new java.awt.Dimension(185,29));
577
                        pX.add(lX, null);
578
                        pX.add(getTX(), null);
579
                }
580
                return pX;
581
        }
582

    
583
        /**
584
         * This method initializes pY        
585
         *         
586
         * @return javax.swing.JPanel        
587
         */
588
        private JPanel getPY() {
589
                if (pY == null) {
590
                        lY = new JLabel();
591
                        lY.setText("Y:");
592
                        FlowLayout flowLayout1 = new FlowLayout();
593
                        flowLayout1.setAlignment(java.awt.FlowLayout.RIGHT);
594
                        pY = new JPanel();
595
                        pY.setLayout(flowLayout1);
596
                        pY.setPreferredSize(new java.awt.Dimension(185,29));
597
                        pY.add(lY, null);
598
                        pY.add(getTY(), null);
599
                }
600
                return pY;
601
        }
602

    
603
        /**
604
         * This method initializes pLatitud        
605
         *         
606
         * @return javax.swing.JPanel        
607
         */
608
        private JPanel getPLatitud() {
609
                if (pLatitud == null) {
610
                        lLongitud = new JLabel();
611
                        lLongitud.setText("longitud:");
612
                        FlowLayout flowLayout3 = new FlowLayout();
613
                        flowLayout3.setAlignment(java.awt.FlowLayout.RIGHT);
614
                        pLatitud = new JPanel();
615
                        pLatitud.setLayout(flowLayout3);
616
                        pLatitud.setPreferredSize(new java.awt.Dimension(185,29));
617
                        pLatitud.add(lLongitud, null);
618
                        pLatitud.add(getLongitud(), null);
619
                }
620
                return pLatitud;
621
        }
622

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

    
715
        /**
716
         * Este m?todo inicializa el campo de texto que tiene la coordenada en Y 
717
         * de la vista. Controla que le sean introducidos valores numericos y
718
         * salva el valor que contiene en la capa.        
719
         *         
720
         * @return javax.swing.JTextField        
721
         */
722
        public JTextField getTY() {
723
                if (tY == null) {
724
                        tY = new JTextField();
725
                        tY.setPreferredSize(new java.awt.Dimension(90,19));
726
                        tY.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(tY, false, true, e.getKeyCode());
730
                                }
731
                                public void keyTyped(java.awt.event.KeyEvent e) {}
732
                        });
733
                }
734
                return tY;
735
        }
736

    
737
        /**
738
         * Este m?todo inicializa el campo de texto que tiene la coordenada en Y 
739
         * del mundo real. Controla que le sean introducidos valores numericos y
740
         * salva el valor que contiene en la capa.        
741
         *         
742
         * @return javax.swing.JTextField        
743
         */
744
        public JTextField getLatitud() {
745
                if (tLatitud == null) {
746
                        tLatitud = new JTextField();
747
                        tLatitud.setPreferredSize(new java.awt.Dimension(111,19));
748
                        tLatitud.setHorizontalAlignment(javax.swing.JTextField.LEFT);
749
                        tLatitud.addKeyListener(new java.awt.event.KeyListener() { 
750
                                public void keyPressed(java.awt.event.KeyEvent e) {}
751
                                public void keyReleased(java.awt.event.KeyEvent e) {
752
                                        checkTextField(tLatitud, true, false, e.getKeyCode());        
753
                                }
754
                                public void keyTyped(java.awt.event.KeyEvent e) {}
755
                        });
756
                        
757
                }
758
                return tLatitud;
759
        }
760

    
761
        /**
762
         * Este m?todo inicializa el campo de texto que tiene la coordenada en X 
763
         * del mundo real. Controla que le sean introducidos valores numericos y
764
         * salva el valor que contiene en la capa.
765
         *         
766
         * @return javax.swing.JTextField        
767
         */
768
        public JTextField getLongitud() {
769
                if (tLongitud == null) {
770
                        tLongitud = new JTextField();
771
                        tLongitud.setPreferredSize(new java.awt.Dimension(111,19));
772
                        tLongitud.setHorizontalAlignment(javax.swing.JTextField.LEFT);
773
                        tLongitud.addKeyListener(new java.awt.event.KeyListener() { 
774
                                public void keyPressed(java.awt.event.KeyEvent e) {}
775
                                public void keyReleased(java.awt.event.KeyEvent e) {
776
                                        checkTextField(tLongitud, false, false, e.getKeyCode());        
777
                                }
778
                                public void keyTyped(java.awt.event.KeyEvent e) {}
779
                        });
780
                }
781
                return tLongitud;
782
        }
783
        
784
        /**
785
         * This method initializes jPanel        
786
         *         
787
         * @return javax.swing.JPanel        
788
         */    
789
        private JPanel getPControls() {
790
                if (pControls == null) {
791
                        pControls = new JPanel();
792
                        pControls.setPreferredSize(new java.awt.Dimension(180,160));
793
                        pControls.add(getPSelectFromView(), null);
794
                }
795
                return pControls;
796
        }
797
        /**
798
         * This method initializes jPanel        
799
         *         
800
         * @return javax.swing.JPanel        
801
         */    
802
        private JPanel getPSelectFromView() {
803
                if (pSelectFromView == null) {
804
                        GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
805
                        gridBagConstraints9.gridx = 0;
806
                        gridBagConstraints9.insets = new java.awt.Insets(2,2,2,2);
807
                        gridBagConstraints9.gridy = 2;
808
                        GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
809
                        gridBagConstraints8.gridx = 0;
810
                        gridBagConstraints8.insets = new java.awt.Insets(2,2,2,2);
811
                        gridBagConstraints8.gridy = 1;
812
                        GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
813
                        gridBagConstraints7.insets = new java.awt.Insets(2,2,2,2);
814
                        gridBagConstraints7.gridy = 0;
815
                        gridBagConstraints7.gridx = 0;
816
                        pSelectFromView = new JPanel();
817
                        pSelectFromView.setLayout(new GridBagLayout());
818
                        pSelectFromView.setPreferredSize(new java.awt.Dimension(150,150));
819
                        pSelectFromView.add(getBSelectFromView(), gridBagConstraints7);
820
                        pSelectFromView.add(getBClear(), gridBagConstraints8);
821
                        pSelectFromView.add(getBDelPoint(), gridBagConstraints9);
822
                }
823
                return pSelectFromView;
824
        }
825
        
826
        /**
827
         * Carga el panel desde los datos contenidos en una capa de puntos
828
         * @param lyr
829
         */
830
        public void loadFromLyrPoints(FLyrPoints lyr){
831
                if(lyr != null){
832
                        lyr.clean();
833
                        lyrPoints = lyr;
834
                        View theView = (View) PluginServices.getMDIManager().getActiveView();
835
                        theView.getMapControl().getMapContext().beginAtomicEvent();
836
                        theView.getMapControl().getMapContext().getLayers().addLayer(lyr);
837
                        theView.getMapControl().getMapContext().endAtomicEvent();
838
                        
839
                        this.getCPoint().removeAllItems();
840
                        for(int i=0;i<lyr.getCountPoints();i++)
841
                                this.getCPoint().addItem("" + (i + 1));
842
                        lNumberOfPoints.setText(PluginServices.getText(this, "de") + " " + lyrPoints.getCountPoints());
843
                        if(lyr.getCountPoints() >= 1){
844
                                changePoint(true, 0);
845
                                getBSelectFromView().setEnabled(true);
846
                                getBClear().setEnabled(true);
847
                                getBDelPoint().setEnabled(true);
848
                        }
849
                }
850
        }
851

    
852
   }