Statistics
| Revision:

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

History | View | Annotate | Download (24.6 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.event.ActionEvent;
8
import java.awt.event.ActionListener;
9
import java.awt.event.KeyEvent;
10
import java.awt.event.KeyListener;
11
import java.awt.geom.Point2D;
12

    
13
import javax.swing.ImageIcon;
14
import javax.swing.JButton;
15
import javax.swing.JLabel;
16
import javax.swing.JOptionPane;
17
import javax.swing.JPanel;
18
import javax.swing.JTextField;
19

    
20
import com.iver.andami.PluginServices;
21
import com.iver.cit.gvsig.fmap.layers.FLayer;
22
import com.iver.cit.gvsig.fmap.layers.FLyrPoints;
23
import com.iver.cit.gvsig.fmap.layers.FLyrPoints.GeoPoint;
24
import com.iver.cit.gvsig.gui.View;
25
import com.iver.cit.gvsig.gui.Dialogs.GeoreferencingDialog;
26
import com.iver.cit.gvsig.gui.toolListeners.GeorefPointerListener;
27

    
28
public class SelectPointsPanel extends JPanel implements ActionListener, KeyListener{
29

    
30
        private JPanel pGeneral = null;
31
        private JPanel pPointSelection = null;
32
        private JPanel pControlPoint = 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 lLongitud = null;
43
        private JLabel lLatitud = 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
        private JPanel pManagerPoint = null;
57
        private JButton bExtended = null;
58
        private JPanel pExtend = null;
59
        
60
        private TableControlerPanel tableControlerPanel = null;
61
        private DataPointPanel dataPointPanel = null;
62
        private ErrorPointPanel errorPointPanel = null;
63
        
64
        private GeoreferencingDialog grd = null;
65
        
66
        private JLabel jLabel = null;
67
        public SelectPointsPanel() {
68
                super();
69
                initialize();
70
        }
71
        
72
        /**
73
         * This is the default constructor
74
         */
75
        public SelectPointsPanel(GeoreferencingDialog grd) {
76
                super();
77
                initialize();
78
                this.grd = grd;
79
        }
80

    
81
        private void init(){}
82
        
83
        /**
84
         * This method initializes this
85
         * 
86
         * @return void
87
         */
88
        private void initialize() {
89
        this.setPreferredSize(new java.awt.Dimension(400,210));
90
        this.setSize(new java.awt.Dimension(400,210));
91
        this.setLocation(new java.awt.Point(0,0));
92
        this.add(getPGeneral(), null);
93
        }
94

    
95
        /**
96
         * This method initializes pGeneral        
97
         *         
98
         * @return javax.swing.JPanel        
99
         */
100
        private JPanel getPGeneral() {
101
                if (pGeneral == null) {
102
                        GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
103
                        gridBagConstraints1.insets = new java.awt.Insets(0,0,0,0);
104
                        gridBagConstraints1.gridy = 0;
105
                        gridBagConstraints1.gridx = 0;
106
                        GridBagConstraints gridBagConstraints = new GridBagConstraints();
107
                        gridBagConstraints.insets = new java.awt.Insets(5,0,5,0);
108
                        gridBagConstraints.gridy = 1;
109
                        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
110
                        gridBagConstraints.gridheight = 1;
111
                        gridBagConstraints.gridx = 0;
112
                        pGeneral = new JPanel();
113
                        pGeneral.setLayout(new GridBagLayout());
114
                        pGeneral.setPreferredSize(new java.awt.Dimension(400,210));
115
                        gridBagConstraints.gridwidth = 1;
116
                        pGeneral.add(getPPointSelection(), gridBagConstraints);
117
                        pGeneral.add(getPControlPoint(), gridBagConstraints1);
118
                }
119
                return pGeneral;
120
        }
121

    
122
        /**
123
         * This method initializes pFileSelection        
124
         *         
125
         * @return javax.swing.JPanel        
126
         */
127
        private JPanel getPPointSelection() {
128
                if (pPointSelection == null) {
129
                        jLabel = new JLabel();
130
                        FlowLayout flowLayout1 = new FlowLayout();
131
                        FlowLayout flowLayout = new FlowLayout();
132
                        flowLayout.setVgap(-3);
133
                        flowLayout.setAlignment(java.awt.FlowLayout.LEFT);
134
                        pPointSelection = new JPanel();
135
                        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));
136
                        pPointSelection.setName("");
137
                        pPointSelection.setLayout(flowLayout);
138
                        pPointSelection.setPreferredSize(new java.awt.Dimension(380,27));
139
                        flowLayout.setHgap(0);
140
                        if(this.tableControlerPanel == null){
141
                                tableControlerPanel = new TableControlerPanel();
142
                                tableControlerPanel.setLayout(flowLayout1);
143
                                flowLayout1.setVgap(1);
144
                                flowLayout1.setHgap(0);
145
                                jLabel.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
146
                                tableControlerPanel.setLNumberOfPoints(jLabel);
147
                                tableControlerPanel.getBFirst().addActionListener(this);
148
                                tableControlerPanel.getBLast().addActionListener(this);
149
                                tableControlerPanel.getBNext().addActionListener(this);
150
                                tableControlerPanel.getBPrev().addActionListener(this);
151
                                tableControlerPanel.getBNew().addActionListener(this);
152
                                tableControlerPanel.getCPoint().addActionListener(this);
153
                        }
154
                        //pPointSelection.add(getPTableControl(), null);
155
                        pPointSelection.add(tableControlerPanel, null);
156
                        pPointSelection.add(getPManagerPoint(), null);
157
                        pPointSelection.add(getBSelectFromView(), null);
158
                        pPointSelection.add(getPExtend(), null);
159
                }
160
                return pPointSelection;
161
        }
162

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

    
351
                
352
        /**
353
         * Este m?todo inicializa el bot?n del clear que har? que se eliminen todos los
354
         * puntos seleccionados.        
355
         *         
356
         * @return javax.swing.JButton        
357
         */
358
        private JButton getBClear() {
359
                if (bClear == null) {
360
                        bClear = new JButton();
361
                        bClear.setText("");
362
                        bClear.setPreferredSize(new java.awt.Dimension(22,22));
363
                        bClear.setEnabled(false);
364
                        bClear.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/delall.png")));
365
                        bClear.setActionCommand("");
366
                        bClear.addActionListener(new java.awt.event.ActionListener() { 
367
                                public void actionPerformed(java.awt.event.ActionEvent e) {
368
                                        clearList();
369
                                }
370
                        });
371
                }
372
                return bClear;
373
        }
374

    
375
        /**
376
         * Este m?todo inicializa el bot?n del eliminar punto que har? que se elimine
377
         * el punto seleccionado.        
378
         *         
379
         * @return javax.swing.JButton        
380
         */
381
        private JButton getBDelPoint() {
382
                if (bDelPoint == null) {
383
                        bDelPoint = new JButton();
384
                        bDelPoint.setText("");
385
                        bDelPoint.setEnabled(false);
386
                        bDelPoint.setPreferredSize(new java.awt.Dimension(22,22));
387
                        bDelPoint.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/delone.png")));
388
                        bDelPoint.addActionListener(new java.awt.event.ActionListener() { 
389
                                public void actionPerformed(java.awt.event.ActionEvent e) {
390
                                        if(lyrPoints.length() == 1) //Si solo hay un punto reseteamos
391
                                                clearList();
392
                                        else{
393
                                                loadLyrPoint();
394
                                                int posSelect = tableControlerPanel.getCPoint().getSelectedIndex();        
395
                                                lyrPoints.remove(posSelect);
396
                                                isNew = true;
397
                                                tableControlerPanel.getCPoint().removeAllItems();
398
                                                for(int i=0;i<lyrPoints.length();i++){
399
                                                        isNew = true;
400
                                                        tableControlerPanel.getCPoint().addItem(String.valueOf(i+1));
401
                                                }
402
                                                isNew = true;
403
                                                if(posSelect == 0){
404
                                                        lastIndexSelection = posSelect;
405
                                                        tableControlerPanel.getCPoint().setSelectedIndex(posSelect);
406
                                                        loadInfoPoint(posSelect);
407
                                                }else{
408
                                                        lastIndexSelection = posSelect -1 ;
409
                                                        tableControlerPanel.getCPoint().setSelectedIndex(posSelect - 1);
410
                                                        loadInfoPoint(posSelect - 1);
411
                                                }
412
                                                tableControlerPanel.getLNumberOfPoints().setText(PluginServices.getText(this, "de ") + " " + lyrPoints.getCountPoints());
413
                                                checkArrows();
414
                                        }
415
                                }
416
                        });
417
                }
418
                return bDelPoint;
419
        }
420
        
421
        /**
422
         * Obtiene una capa de puntos. Si no existe crea una.
423
         * @return
424
         */
425
        private FLyrPoints loadLyrPoint(){
426
                //Buscamos una capa FlyrPoint en la vista y si no la hay la creamos
427
                View theView = (View) PluginServices.getMDIManager().getActiveView();
428
                
429
                //Si todavia no hay ninguna cargada la buscamos
430
                if(lyrPoints == null){
431
                        for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){
432
                                FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i);
433
                                if(lyr instanceof FLyrPoints)
434
                                        lyrPoints = (FLyrPoints)lyr;
435
                        }
436
                }
437
                
438
                //Si no hemos encontrado ninguna la creamos
439
                if(lyrPoints == null){
440
                        lyrPoints = new FLyrPoints();
441
                        lyrPoints.setName("Points");
442
                        lyrPoints.setVisible(true);
443
                        theView.getMapControl().getMapContext().beginAtomicEvent();
444
                        theView.getMapControl().getMapContext().getLayers().addLayer(lyrPoints);
445
                        theView.getMapControl().getMapContext().endAtomicEvent();
446
                }
447
                return lyrPoints;
448
        }
449
        
450

    
451

    
452
        /**
453
         * Este m?todo inicializa el bot?n seleccionar desde la vista. Cuando lo 
454
         * activamos se carga la herramienta de selecci?n de puntos desde la vista. 
455
         *         
456
         * @return javax.swing.JButton        
457
         */    
458
        public JButton getBSelectFromView() {
459
                if (bSelectFromView == null) {
460
                        bSelectFromView = new JButton();
461
                        bSelectFromView.setText("");
462
                        bSelectFromView.setPreferredSize(new java.awt.Dimension(22,22));
463
                        bSelectFromView.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/selectfromview.png")));
464
                        bSelectFromView.setEnabled(false);
465
                        bSelectFromView.addActionListener(new java.awt.event.ActionListener() { 
466
                                public void actionPerformed(java.awt.event.ActionEvent e) {
467
                                        View theView = (View) PluginServices.getMDIManager().getActiveView();
468
                                        loadLyrPoint();
469
                                        lyrPoints.setLastTool(theView.getMapControl().getTool());
470
                                        GeorefPointerListener.posPoint = tableControlerPanel.getCPoint().getSelectedIndex();
471
                                        GeorefPointerListener.firstPoint = true;
472
                                        theView.getMapControl().setTool("pointLyrSelection");
473
                                }
474
                        });
475
                }
476
                return bSelectFromView;
477
        }
478
        
479
        /**
480
         * Checkea un textField para que contenga caracteres numericos y actualiza 
481
         * un punto con el valor actual de l JTextField. Si no hay puntos en la 
482
         * lista no salvar? ning?n valor.
483
         */
484
        public void checkTextField(JTextField tf, boolean xValue, boolean pixelValue, int code){
485
                                
486
                //Ignoramos las teclas Del, Spr, Mayusculas, Alt, Ctrl, Enter
487
                if(code == 8 || code == 127 || code == 16 || code == 20 ||
488
                                code == 18 || code == 17 || code == 10 )
489
                        return;
490
                
491
                //Si el caracter introducido es erroneo avisamos y volvemos
492
                if((code < 48 || code > 57) && code != 46){
493
                        tf.setText("");
494
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
495
                                        PluginServices.getText(this, "caracteres_erroneos"));
496
                        return;
497
                }
498
                
499
                //Si no hay puntos en la lista no se hace nada
500
                if(lyrPoints == null || lyrPoints.getCountPoints() == 0)
501
                        return;
502
                
503
                //Si el caracter era valido salvamos el valor en la capa
504
                if(!tf.getText().equals("")){
505
                        loadLyrPoint();
506
                        Point2D p = null;
507
                        if(pixelValue)
508
                                p = ((GeoPoint)lyrPoints.getPoint(tableControlerPanel.getCPoint().getSelectedIndex())).pixelPoint;
509
                        else
510
                                p = ((GeoPoint)lyrPoints.getPoint(tableControlerPanel.getCPoint().getSelectedIndex())).mapPoint;
511
                        if(xValue){
512
                                if(p != null)
513
                                        p.setLocation(Double.valueOf(tf.getText()).doubleValue(), p.getY());
514
                                else{
515
                                        p = new Point2D.Double();
516
                                        p.setLocation(Double.valueOf(tf.getText()).doubleValue(), 0.0);
517
                                }
518
                        }else{
519
                                if(p != null)
520
                                        p.setLocation(p.getX(), Double.valueOf(tY.getText()).doubleValue());
521
                                else{
522
                                        p = new Point2D.Double();
523
                                        p.setLocation(0.0, Double.valueOf(tY.getText()).doubleValue());
524
                                }
525
                        }
526
                }
527
        }
528
                
529
        /**
530
         * Carga el panel desde los datos contenidos en una capa de puntos
531
         * @param lyr
532
         */
533
        public void loadFromLyrPoints(FLyrPoints lyr){
534
                if(lyr != null){
535
                        lyr.clean();
536
                        lyrPoints = new FLyrPoints();
537
                        lyrPoints.setListPoint(lyr.getListPoint());
538
                        
539
                        View theView = (View) PluginServices.getMDIManager().getActiveView();
540
                        theView.getMapControl().getMapContext().beginAtomicEvent();
541
                        theView.getMapControl().getMapContext().getLayers().addLayer(lyr);
542
                        theView.getMapControl().getMapContext().endAtomicEvent();
543
                        
544
                        tableControlerPanel.getCPoint().removeAllItems();
545
                        for(int i=0;i<lyr.getCountPoints();i++)
546
                                tableControlerPanel.getCPoint().addItem("" + (i + 1));
547
                        tableControlerPanel.getLNumberOfPoints().setText(PluginServices.getText(this, "de") + " " + lyrPoints.getCountPoints());
548
                        if(lyr.getCountPoints() >= 1){
549
                                changePoint(true, 0);
550
                                getBSelectFromView().setEnabled(true);
551
                                getBClear().setEnabled(true);
552
                                getBDelPoint().setEnabled(true);
553
                        }
554
                }
555
        }
556

    
557
        /**
558
         * This method initializes jPanel        
559
         *         
560
         * @return javax.swing.JPanel        
561
         */    
562
        private JPanel getPManagerPoint() {
563
                if (pManagerPoint == null) {
564
                        FlowLayout flowLayout11 = new FlowLayout();
565
                        pManagerPoint = new JPanel();
566
                        pManagerPoint.setLayout(flowLayout11);
567
                        flowLayout11.setVgap(0);
568
                        flowLayout11.setHgap(0);
569
                        pManagerPoint.add(getBDelPoint(), null);
570
                        pManagerPoint.add(getBClear(), null);
571
                }
572
                return pManagerPoint;
573
        }
574
        /**
575
         * This method initializes jButton        
576
         *         
577
         * @return javax.swing.JButton        
578
         */    
579
        private JButton getBExtended() {
580
                if (bExtended == null) {
581
                        bExtended = new JButton();
582
                        bExtended.setPreferredSize(new java.awt.Dimension(22,22));
583
                        bExtended.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/down.png")));
584
                        bExtended.addActionListener(this);
585
                }
586
                return bExtended;
587
        }
588
        /**
589
         * This method initializes jPanel        
590
         *         
591
         * @return javax.swing.JPanel        
592
         */    
593
        private JPanel getPExtend() {
594
                if (pExtend == null) {
595
                        FlowLayout flowLayout21 = new FlowLayout();
596
                        pExtend = new JPanel();
597
                        pExtend.setLayout(flowLayout21);
598
                        flowLayout21.setHgap(0);
599
                        flowLayout21.setVgap(0);
600
                        flowLayout21.setAlignment(java.awt.FlowLayout.RIGHT);
601
                        pExtend.setPreferredSize(new java.awt.Dimension(35,22));
602
                        pExtend.add(getBExtended(), null);
603
                }
604
                return pExtend;
605
        }
606

    
607
        /**
608
         * @return Returns the dataPointPanel.
609
         */
610
        public DataPointPanel getDataPointPanel() {
611
                return dataPointPanel;
612
        }
613

    
614
        /**
615
         * @param dataPointPanel The dataPointPanel to set.
616
         */
617
        public void setDataPointPanel(DataPointPanel dataPointPanel) {
618
                this.dataPointPanel = dataPointPanel;
619
        }
620
        
621
        /**
622
         * @return Returns the tableControlerPanel.
623
         */
624
        public TableControlerPanel getTableControlerPanel() {
625
                return tableControlerPanel;
626
        }
627

    
628
        /**
629
         * @param tableControlerPanel The tableControlerPanel to set.
630
         */
631
        public void setTableControlerPanel(TableControlerPanel tableControlerPanel) {
632
                this.tableControlerPanel = tableControlerPanel;
633
        }
634

    
635
        /**
636
         * Control de eventos de TableControlerPanel
637
         */
638
        public void actionPerformed(ActionEvent e) {
639
                
640
                //Bot?n de ir al punto inicial
641
                if(e.getSource() == tableControlerPanel.getBFirst()){
642
                        if(tableControlerPanel.getCPoint().getItemCount() >= 1)
643
                                changePoint(true, 0);
644
                }
645
                
646
                //Bot?n de ir al punto anterior
647
                if(e.getSource() == tableControlerPanel.getBPrev()){
648
                        if(tableControlerPanel.getCPoint().getSelectedIndex() != 0)                                 
649
                               changePoint(true, tableControlerPanel.getCPoint().getSelectedIndex() - 1);
650
                }
651
                
652
                //Bot?n de ir al punto siguiente
653
                if(e.getSource() == tableControlerPanel.getBNext()){
654
                        if(tableControlerPanel.getCPoint().getSelectedIndex() != (tableControlerPanel.getCPoint().getItemCount() - 1))
655
                        changePoint(true, tableControlerPanel.getCPoint().getSelectedIndex() + 1);
656
                
657
                }
658
                
659
                //Bot?n de ir al punto final
660
                if(e.getSource() == tableControlerPanel.getBLast()){
661
                        if(tableControlerPanel.getCPoint().getItemCount() >= 1)
662
                                changePoint(true, tableControlerPanel.getCPoint().getItemCount() - 1);
663
                }
664
                
665
                //Combo de selecci?n de punto
666
                if(e.getSource() == tableControlerPanel.getCPoint()){
667
                        if(tableControlerPanel.getCPoint().getSelectedIndex() != -1){
668
                                 if(!isNew){
669
                                         loadInfoPoint(tableControlerPanel.getCPoint().getSelectedIndex());
670
                                checkArrows();
671
                                 }
672
                        }
673
                        isNew = false;
674
                }
675
                
676
                //Bot?n de nuevo punto
677
                if(e.getSource() == tableControlerPanel.getBNew()){
678
                        loadLyrPoint();
679
                        try{
680
                                updatePoint();
681
                                lyrPoints.addPoint(null, null);
682
                                isNew = true;
683
                                tableControlerPanel.getCPoint().addItem("" + lyrPoints.getCountPoints());
684
                                tableControlerPanel.getLNumberOfPoints().setText(PluginServices.getText(this, "de ") + " " + lyrPoints.getCountPoints());
685
                                isNew = true;
686
                                lastIndexSelection = lyrPoints.getCountPoints() - 1;
687
                                tableControlerPanel.getCPoint().setSelectedIndex(tableControlerPanel.getCPoint().getItemCount() - 1);
688
                                resetControls(true);
689
                                checkArrows();
690
                        }catch(NoSuchFieldException exc){
691
                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
692
                                                PluginServices.getText(this, "coordenadas_vacias"));
693
                        }
694
                }
695
                
696
                //Bot?n de extensi?n del cuadro de dialogo
697
                if(e.getSource() == this.getBExtended()){
698
                        if(grd.isEnlarge()){
699
                                grd.setEnlarge(false);
700
                                bExtended.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/down.png")));
701
                        }else{
702
                                grd.setEnlarge(true);
703
                                bExtended.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/up.png")));
704
                        }
705
                }
706
                
707
        }
708

    
709
        
710
        /* (non-Javadoc)
711
         * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
712
         */
713
        public void keyPressed(KeyEvent e) {
714
                // TODO Auto-generated method stub
715
                
716
        }
717

    
718
        /**
719
         * Control de eventos de las entradas de texto de los puntos
720
         */
721
        public void keyReleased(KeyEvent e) {
722
                //Campo de texto de la coordenada X en pixeles
723
                if(e.getSource() == dataPointPanel.getTX()){
724
                        checkTextField(dataPointPanel.getTX(), true, true, e.getKeyCode());
725
                }
726
                
727
                //Campo de texto de la coordenada Y en pixeles
728
                if(e.getSource() == dataPointPanel.getTY()){
729
                        checkTextField(dataPointPanel.getTY(), false, true, e.getKeyCode());
730
                }
731

    
732
                //Campo de texto de la coordenada X en coordenadas del mundo
733
                if(e.getSource() == dataPointPanel.getLatitud()){
734
                        checkTextField(dataPointPanel.getLatitud(), true, false, e.getKeyCode());
735
                }
736

    
737
                //Campo de texto de la coordenada Y en coordenadas del mundo
738
                if(e.getSource() == dataPointPanel.getLongitud()){
739
                        checkTextField(dataPointPanel.getLongitud(), false, false, e.getKeyCode());
740
                }
741
                
742
        }
743

    
744
        /* (non-Javadoc)
745
         * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
746
         */
747
        public void keyTyped(KeyEvent e) {
748
                // TODO Auto-generated method stub
749
                
750
        }
751

    
752

    
753
 }