Statistics
| Revision:

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

History | View | Annotate | Download (24.2 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.FocusEvent;
10
import java.awt.event.FocusListener;
11
import java.awt.event.KeyEvent;
12
import java.awt.event.KeyListener;
13
import java.awt.geom.Point2D;
14

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

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

    
30
public class SelectPointsPanel extends JPanel implements ActionListener, KeyListener, FocusListener{
31

    
32
        private JPanel pGeneral = null;
33
        private JPanel pPointSelection = null;
34
        private JPanel pControlPoint = null;
35
        private JPanel pInfoPoint = null;
36
        private JPanel pX = null;
37
        private JPanel pY = null;
38
        private JPanel pLatitud = null;
39
        private JPanel pLongitud = null;
40
        private JTextField tX = null;
41
        private JLabel lX = null;
42
        private JLabel lY = null;
43
        private JTextField tY = null;
44
        private JLabel lLongitud = null;
45
        private JLabel lLatitud = null;
46
        private JTextField tLatitud = null;
47
        private JTextField tLongitud = null;
48

    
49
        private JPanel pControls = null;
50
        private JPanel pSelectFromView = null;
51
        private JButton bSelectFromView = null;
52
        private FLyrPoints lyrPoints = null;
53
        private boolean disableEvent = false;
54
        private JButton bClear = null;
55
        private JButton bDelPoint = null;
56
        private int lastIndexSelection = -1;
57

    
58
        private JPanel pManagerPoint = null;
59
        private JButton bExtended = null;
60
        private JPanel pExtend = null;
61
        
62
        private TableControlerPanel tableControlerPanel = null;
63
        private DataPointPanel dataPointPanel = null;
64
        private ErrorPointPanel errorPointPanel = null;
65
        
66
        private GeoreferencingDialog grd = null;
67
        
68
        /**
69
         * Valores ?ltimos que se han introducido en los JTextField para poder reponerlos.
70
         */
71
        public String lastTx = "", lastTy = "", lastLong = "", lastLat = "";
72
        
73
        public SelectPointsPanel() {
74
                super();
75
                initialize();
76
        }
77
        
78
        /**
79
         * This is the default constructor
80
         */
81
        public SelectPointsPanel(GeoreferencingDialog grd) {
82
                super();
83
                initialize();
84
                this.grd = grd;
85
        }
86

    
87
        private void init(){}
88
        
89
        /**
90
         * This method initializes this
91
         * 
92
         * @return void
93
         */
94
        private void initialize() {
95
        this.setPreferredSize(new java.awt.Dimension(380,160));
96
        this.setSize(new java.awt.Dimension(380,160));
97
        this.setLocation(new java.awt.Point(0,0));
98
        this.add(getPGeneral(), null);
99
        }
100

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

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

    
170
        /**
171
         * This method initializes pControls        
172
         *                 
173
         */
174
        private JPanel getPControlPoint() {
175
                if (pControlPoint == null) {
176
                        GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
177
                        GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
178
                        gridBagConstraints2.gridx = 0;
179
                        gridBagConstraints2.insets = new java.awt.Insets(0,0,0,0);
180
                        gridBagConstraints2.gridy = 0;
181
                        pControlPoint = new JPanel();
182
                        pControlPoint.setLayout(new GridBagLayout());
183
                        pControlPoint.setPreferredSize(new java.awt.Dimension(382,120));
184
                        pControlPoint.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,0,0,0));
185
                        gridBagConstraints11.gridy = 0;
186
                        gridBagConstraints11.gridx = 1;
187
                        if(this.dataPointPanel == null){
188
                                dataPointPanel = new DataPointPanel();
189
                                dataPointPanel.getTX().addKeyListener(this);
190
                                dataPointPanel.getTY().addKeyListener(this);
191
                                dataPointPanel.getLatitud().addKeyListener(this);
192
                                dataPointPanel.getLongitud().addKeyListener(this);
193
                                dataPointPanel.getTX().addFocusListener(this);
194
                                dataPointPanel.getTY().addFocusListener(this);
195
                                dataPointPanel.getLatitud().addFocusListener(this);
196
                                dataPointPanel.getLongitud().addFocusListener(this);
197
                        }
198
                        pControlPoint.add(dataPointPanel, gridBagConstraints2);
199
                        
200
                        if(this.errorPointPanel == null)
201
                                errorPointPanel = new ErrorPointPanel();
202
                        pControlPoint.add(errorPointPanel, gridBagConstraints11);
203
                }
204
                return pControlPoint;
205
        }
206
                
207
        /**
208
         * Actualiza el n?mero de puntos del combo a partir de los contenidos en
209
         * la capa de puntos. Esta funci?n es usada desde otros paneles que cambien
210
         * el punto seleccionado para comunicar al control la nueva selecci?n.
211
         */
212
        public void updateComboPoint(int pointSelected){
213
                disableEvent = true;
214
                try{
215
                        loadLyrPoint();
216
                }catch(InstantiationException exc){
217
                    JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
218
                                        PluginServices.getText(this, "error_capa_puntos"));
219
                    return;
220
            }
221
                
222
                tableControlerPanel.setNItems(lyrPoints.getCountPoints());
223
                tableControlerPanel.getCPoint().setSelectedIndex(pointSelected);
224
                tableControlerPanel.checkArrows();
225
                lyrPoints.loadVisualPoint(pointSelected, this.grd);
226
                disableEvent = false;
227
        }
228
        
229
        /**
230
         * Comprueba si los valores de un punto en los campos de texto est?n
231
         * vacios y lanza una excepci?n si hay alguno sin informaci?n.
232
         * @throws NoSuchFieldException
233
         */
234
        public void checkInfoPointText()throws NoSuchFieldException{
235
                if(        dataPointPanel.getTX().getText().equals("") ||
236
                                dataPointPanel.getTY().getText().equals("") ||
237
                                dataPointPanel.getLatitud().getText().equals("") ||
238
                                dataPointPanel.getLongitud().getText().equals("")){
239
                                disableEvent = true;
240
                                try{
241
                                        tableControlerPanel.getCPoint().setSelectedIndex(lastIndexSelection);
242
                                        disableEvent = false;
243
                                }catch(IllegalArgumentException ex){
244
                                        //Si el lastIndex tiene un valor erroneo no hacemos ninguna selecci?n
245
                                }
246
                                throw new NoSuchFieldException();
247
                }
248
        }
249
                
250
        /**
251
         * Esta funci?n resetea los controles del panel de info de un punto.
252
         */
253
        public void resetControls(boolean active){
254
                dataPointPanel.getTX().setText("");
255
                dataPointPanel.getTY().setText("");
256
                dataPointPanel.getLatitud().setText("");
257
                dataPointPanel.getLongitud().setText("");
258
                getBSelectFromView().setEnabled(active);
259
                getTableControlerPanel().getBClear().setEnabled(active);
260
                getTableControlerPanel().getBDelPoint().setEnabled(active);
261
        }
262
        
263
        /**
264
         * Cuando pasamos de un punto a otro o se va a crear uno nuevo
265
         * <UL>
266
         * <LI>Cargamos la capa FLyrPoint si no est? ya cargada.</LI>
267
         * <LI>Comprobamos que los campos no esten vacios y lanzamos una excepci?n si hay alg?n campo vacio si lo est?n.</LI>
268
         * <LI>Insertamos el nuevo punto seleccionado en los campos de informaci?n.</LI>
269
         * <LI>Checkeamos las flechas para ver si tenemos que activarlas o desactivarlas.</LI>
270
         * </UL>
271
         * @param changeSelection        Cambia la posici?n seleccionada del combo si es true
272
         * @param pos        Posici?n a la que cambia el combo si el parametro chageSelection es true
273
         */
274
        private void changePoint(boolean changeSelection, int pos){
275
                disableEvent = true;
276
            try{
277
                    loadLyrPoint();
278
                    checkInfoPointText();                        
279
                if(changeSelection){
280
                        lastIndexSelection = pos;
281
                        tableControlerPanel.setSelectedIndex(pos);
282
                }
283
                lyrPoints.loadVisualPoint(tableControlerPanel.getSelectedIndex(), this.grd);
284
                tableControlerPanel.checkArrows();
285
            }catch(NoSuchFieldException exc){
286
                    JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
287
                                        PluginServices.getText(this, "coordenadas_vacias"));
288
            }catch(InstantiationException e){
289
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
290
                                        PluginServices.getText(this, "error_capa_puntos"));
291
                }
292
            disableEvent = false;
293
        }
294
        
295
        /**
296
         * Limpia la lista de puntos y borra el dialogo.
297
         */
298
        public void clearList(){
299
                try{
300
                    loadLyrPoint();
301
                    lyrPoints.clearVisualList(this, 
302
                                                            grd.getConectorPanel().getDataPointsTabPanel().getTablePointsPanel(), 
303
                                                            grd.getConectorPanel().getAdjustGeorefPanel());
304
                }catch(InstantiationException e){
305
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
306
                                        PluginServices.getText(this, "error_capa_puntos"));
307
                }
308
        }
309
        
310
        /**
311
         * Obtiene una capa de puntos. Si no existe crea una.
312
         * @return
313
         */
314
        private void loadLyrPoint() throws InstantiationException{
315
                //Buscamos una capa FlyrPoint en la vista y si no la hay la creamos
316
                View theView = (View) PluginServices.getMDIManager().getActiveView();
317
                
318
                if(lyrPoints == null){
319
                        for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){
320
                                FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i);
321
                                if(        lyr instanceof FLyrGeoRaster &&
322
                                        lyr.getName().startsWith("*") &&
323
                                        lyr.isActive())
324
                                        lyrPoints = ((FLyrGeoRaster)lyr).getFLyrPoints();
325
                        }
326
                }
327
                
328
                if(lyrPoints == null)
329
                        throw new InstantiationException("No se ha podido obtener una capa de puntos");
330

    
331
        }
332
        
333

    
334

    
335
        /**
336
         * Este m?todo inicializa el bot?n seleccionar desde la vista. Cuando lo 
337
         * activamos se carga la herramienta de selecci?n de puntos desde la vista. 
338
         *         
339
         * @return javax.swing.JButton        
340
         */    
341
        public JButton getBSelectFromView() {
342
                if (bSelectFromView == null) {
343
                        bSelectFromView = new JButton();
344
                        bSelectFromView.setText("");
345
                        bSelectFromView.setPreferredSize(new java.awt.Dimension(22,22));
346
                        bSelectFromView.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/selectfromview.png")));
347
                        bSelectFromView.setEnabled(false);
348
                        bSelectFromView.addActionListener(new java.awt.event.ActionListener() { 
349
                                public void actionPerformed(java.awt.event.ActionEvent e) {
350
                                        View theView = (View) PluginServices.getMDIManager().getActiveView();
351
                                        try{
352
                                                loadLyrPoint();
353
                                                lyrPoints.setLastTool(theView.getMapControl().getTool());
354
                                                GeorefPointerListener.posPoint = tableControlerPanel.getSelectedIndex();
355
                                                GeorefPointerListener.firstPoint = true;
356
                                                theView.getMapControl().setTool("pointLyrSelection");
357
                                        }catch(InstantiationException exc){
358
                                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
359
                                                                PluginServices.getText(this, "error_capa_puntos"));
360
                                        }
361
                                }
362
                        });
363
                }
364
                return bSelectFromView;
365
        }
366
        
367
        /**
368
         * Checkea un textField para que contenga caracteres validos. Consideramos validos
369
         * los caracteres del 0 al 9, el punto, DEL, Supr, flechas y Enter teniendo en cuenta que el 
370
         * c?digo ascii del teclado numerico es distinto.
371
         */
372
        public boolean checkTextField(JTextField tf, int code, String lastText){
373
                        System.out.println(code);
374
                //Si el caracter es erroneo pasamos de el y reponemos el texto que habia
375
                if(        (code >= 0 && code <= 7) || 
376
                        code == 9 || 
377
                        (code >= 11 && code <= 36) ||
378
                        (code >= 41 && code <= 45) ||
379
                        code == 47 ||
380
                        (code >= 58 && code <= 95) ||
381
                        (code >= 106 && code <= 109) ||
382
                        (code >= 111 && code <= 126) ||
383
                        code >= 128){
384
                        tf.setText(lastText);
385
                        return false;
386
                }
387
                
388
                return true;
389
        }
390
                
391
        /**
392
         * Carga el panel desde los datos contenidos en una capa de puntos
393
         * @param lyr
394
         */
395
        public void loadFromLyrPoints(FLyrPoints lyr){
396
                if(lyr != null){
397
                        lyr.clean();
398
                        lyrPoints = new FLyrPoints();
399
                        lyrPoints.setListPoint(lyr.getListPoint());
400
                        
401
                        View theView = (View) PluginServices.getMDIManager().getActiveView();
402
                        theView.getMapControl().getMapContext().beginAtomicEvent();
403
                        theView.getMapControl().getMapContext().getLayers().addLayer(lyr);
404
                        theView.getMapControl().getMapContext().endAtomicEvent();
405
                        
406
                        tableControlerPanel.getCPoint().removeAllItems();
407
                        for(int i=0;i<lyr.getCountPoints();i++)
408
                                tableControlerPanel.getCPoint().addItem("" + (i + 1));
409
                        tableControlerPanel.getLNumberOfPoints().setText(PluginServices.getText(this, "de") + " " + lyrPoints.getCountPoints());
410
                        if(lyr.getCountPoints() >= 1){
411
                                changePoint(true, 0);
412
                                getBSelectFromView().setEnabled(true);
413
                                getTableControlerPanel().getBClear().setEnabled(true);
414
                                getTableControlerPanel().getBDelPoint().setEnabled(true);
415
                        }
416
                }
417
        }
418

    
419
        /**
420
         * @return Returns the lyrPoints.
421
         */
422
        public FLyrPoints getLyrPoints() {
423
                if(lyrPoints == null){
424
                        try{
425
                                loadLyrPoint();
426
                                        }catch(InstantiationException exc){
427
                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
428
                                                PluginServices.getText(this, "error_capa_puntos"));
429
                        }
430
                }
431
                return lyrPoints;
432
        }
433
        
434
        /**
435
         * This method initializes jButton        
436
         *         
437
         * @return javax.swing.JButton        
438
         */    
439
        private JButton getBExtended() {
440
                if (bExtended == null) {
441
                        bExtended = new JButton();
442
                        bExtended.setPreferredSize(new java.awt.Dimension(22,22));
443
                        bExtended.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/down.png")));
444
                        bExtended.addActionListener(this);
445
                }
446
                return bExtended;
447
        }
448
        /**
449
         * This method initializes jPanel        
450
         *         
451
         * @return javax.swing.JPanel        
452
         */    
453
        private JPanel getPExtend() {
454
                if (pExtend == null) {
455
                        FlowLayout flowLayout21 = new FlowLayout();
456
                        pExtend = new JPanel();
457
                        pExtend.setLayout(flowLayout21);
458
                        flowLayout21.setHgap(0);
459
                        flowLayout21.setVgap(0);
460
                        flowLayout21.setAlignment(java.awt.FlowLayout.RIGHT);
461
                        pExtend.setPreferredSize(new java.awt.Dimension(35,22));
462
                        pExtend.add(getBExtended(), null);
463
                }
464
                return pExtend;
465
        }
466

    
467
        /**
468
         * @return Returns the dataPointPanel.
469
         */
470
        public DataPointPanel getDataPointPanel() {
471
                return dataPointPanel;
472
        }
473

    
474
        /**
475
         * @param dataPointPanel The dataPointPanel to set.
476
         */
477
        public void setDataPointPanel(DataPointPanel dataPointPanel) {
478
                this.dataPointPanel = dataPointPanel;
479
        }
480
        
481
        /**
482
         * @return Returns the tableControlerPanel.
483
         */
484
        public TableControlerPanel getTableControlerPanel() {
485
                return tableControlerPanel;
486
        }
487

    
488
        /**
489
         * @param tableControlerPanel The tableControlerPanel to set.
490
         */
491
        public void setTableControlerPanel(TableControlerPanel tableControlerPanel) {
492
                this.tableControlerPanel = tableControlerPanel;
493
        }
494

    
495
        /**
496
         * Control de eventos de TableControlerPanel
497
         */
498
        public void actionPerformed(ActionEvent e) {
499
                
500
                //Bot?n de ir al punto inicial
501
                if(e.getSource() == tableControlerPanel.getBFirst()){
502
                        if(tableControlerPanel.getItemCount() >= 1)
503
                                changePoint(true, 0);
504
                }
505
                
506
                //Bot?n de ir al punto anterior
507
                if(e.getSource() == tableControlerPanel.getBPrev()){
508
                        if(tableControlerPanel.getSelectedIndex() != 0)                                 
509
                               changePoint(true, tableControlerPanel.getSelectedIndex() - 1);
510
                }
511
                
512
                //Bot?n de ir al punto siguiente
513
                if(e.getSource() == tableControlerPanel.getBNext()){
514
                        if(tableControlerPanel.getSelectedIndex() != (tableControlerPanel.getItemCount() - 1))
515
                        changePoint(true, tableControlerPanel.getSelectedIndex() + 1);
516
                
517
                }
518
                
519
                //Bot?n de ir al punto final
520
                if(e.getSource() == tableControlerPanel.getBLast()){
521
                        if(tableControlerPanel.getItemCount() >= 1)
522
                                changePoint(true, tableControlerPanel.getItemCount() - 1);
523
                }
524
                
525
                //Combo de selecci?n de punto
526
                if(e.getSource() == tableControlerPanel.getCPoint()){
527
                        if(tableControlerPanel.getSelectedIndex() != -1){
528
                                 if(!disableEvent){
529
                                        lyrPoints.loadVisualPoint(tableControlerPanel.getSelectedIndex(), grd);
530
                                         tableControlerPanel.checkArrows();
531
                                 }
532
                        }
533
                }
534
                
535
                //Bot?n de nuevo punto
536
                if(e.getSource() == tableControlerPanel.getBNew()){
537
                        try{
538
                                disableEvent = true;
539
                                loadLyrPoint();
540
                                if(this.getTableControlerPanel().getItemCount() > 0)
541
                                        checkInfoPointText();
542
                                lyrPoints.addPoint(null, null);
543
                                tableControlerPanel.getCPoint().addItem("" + lyrPoints.getCountPoints());
544
                                tableControlerPanel.getLNumberOfPoints().setText(PluginServices.getText(this, "de ") + " " + lyrPoints.getCountPoints());
545
                                lastIndexSelection = lyrPoints.getCountPoints() - 1;
546
                                tableControlerPanel.setSelectedIndex(tableControlerPanel.getItemCount() - 1);
547
                                resetControls(true);
548
                                tableControlerPanel.checkArrows();
549
                        }catch(NoSuchFieldException exc){
550
                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
551
                                                PluginServices.getText(this, "coordenadas_vacias"));
552
                        }catch(InstantiationException exc){
553
                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
554
                                                PluginServices.getText(this, "error_capa_puntos"));
555
                        }
556
                        disableEvent = false;
557
                }
558
                
559
                //Bot?n de eliminado de todos los puntos
560
                if(e.getSource() == getTableControlerPanel().getBClear()){
561
                        clearList();
562
                }
563
                
564
                //Bot?n de eliminado de un punto
565
                if(e.getSource() == getTableControlerPanel().getBDelPoint()){
566
                        if(lyrPoints.length() == 1) //Si solo hay un punto reseteamos
567
                                clearList();
568
                        else{
569
                                disableEvent = true;
570
                                int posSelect = tableControlerPanel.getSelectedIndex();
571
                                if(posSelect == -1)
572
                                        return;
573
                                lyrPoints.deleteVisualPoint(posSelect, grd);        
574
                                                                                        
575
                                if(posSelect == 0){
576
                                        lastIndexSelection = posSelect;
577
                                }else{
578
                                                lastIndexSelection = posSelect -1 ;
579
                                }                                        
580
                                disableEvent = false;
581
                        }
582
                }
583
                
584
                //Bot?n de extensi?n del cuadro de dialogo
585
                if(e.getSource() == this.getBExtended()){
586
                        if(grd.isEnlarge()){
587
                                grd.setEnlarge(false);
588
                                bExtended.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/down.png")));
589
                        }else{
590
                                grd.setEnlarge(true);
591
                                bExtended.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/up.png")));
592
                        }
593
                }
594
                
595
        }
596

    
597
        /* (non-Javadoc)
598
         * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
599
         */
600
        public void keyPressed(KeyEvent e) {
601
                // TODO Auto-generated method stu
602
        }
603

    
604
        /**
605
         * Actualiza los valores del punto nuevo introducido desde el teclado llamando a la funci?n
606
         * de la capa updataData que actualizar? los controles necesarios para que se refresquen la vista
607
         * mini imagenes, textfields, tabla y capa de puntos. 
608
         * @param pixel Pixel de la imagen
609
         * @param map Coordenadas de la vista.
610
         */
611
        private void updatePointsValue(Point2D pixel, Point2D map){
612
                //Actualizamos los controles con los nuevos valores
613
                View theView = (View) PluginServices.getMDIManager().getActiveView();
614
                for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){
615
                        FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i);
616
                        if(        lyr instanceof FLyrGeoRaster && 
617
                                lyr.getName().startsWith("*") &&
618
                                lyr.isActive()){
619
                                ((FLyrGeoRaster)lyr).updateData(Integer.valueOf(this.grd.getSelectPointsPanel().getTableControlerPanel().getSelectedItem()).intValue(),
620
                                                                                                pixel, 
621
                                                                                                map, 
622
                                                                                                this.grd,
623
                                                                                                theView, 
624
                                                                                                lyrPoints);
625
                        }
626
                }
627
        }
628
        
629
        /**
630
         * Control de eventos de las entradas de texto de los puntos
631
         */
632
        public void keyReleased(KeyEvent e) {
633
                //Campo de texto de la coordenada X en pixeles
634
                Point2D pixel = null;
635
                Point2D map = null;
636
                boolean update = false;
637
                
638
                try{
639
                        if(e.getSource() == dataPointPanel.getTX()){
640
                                if(checkTextField(dataPointPanel.getTX(), e.getKeyCode(), lastTx)){
641
                                        pixel = new Point2D.Double();
642
                                        pixel.setLocation(        Double.valueOf(dataPointPanel.getTX().getText()).doubleValue(), 
643
                                                                                Double.valueOf(dataPointPanel.getTY().getText()).doubleValue());
644
                                        if(e.getKeyCode() == 10)
645
                                                update = true;
646
                                        lastTx = dataPointPanel.getTX().getText();
647
                                }
648
                        }
649
                        
650
                        //Campo de texto de la coordenada Y en pixeles
651
                        if(e.getSource() == dataPointPanel.getTY()){
652
                                if(checkTextField(dataPointPanel.getTY(), e.getKeyCode(), lastTy)){
653
                                        pixel = new Point2D.Double();
654
                                        pixel.setLocation(        Double.valueOf(dataPointPanel.getTX().getText()).doubleValue(), 
655
                                                                                Double.valueOf(dataPointPanel.getTY().getText()).doubleValue());
656
                                        if(e.getKeyCode() == 10)
657
                                                update = true;
658
                                        lastTy = dataPointPanel.getTY().getText();
659
                                }
660
                        }
661
        
662
                        //Campo de texto de la coordenada X en coordenadas del mundo
663
                        if(e.getSource() == dataPointPanel.getLatitud()){
664
                                if(checkTextField(dataPointPanel.getLatitud(), e.getKeyCode(), lastLat)){
665
                                        map = new Point2D.Double();
666
                                        map.setLocation(        Double.valueOf(dataPointPanel.getLongitud().getText()).doubleValue(), 
667
                                                                                Double.valueOf(dataPointPanel.getLatitud().getText()).doubleValue());
668
                                        if(e.getKeyCode() == 10)
669
                                                update = true;
670
                                        lastLat = dataPointPanel.getLatitud().getText();
671
                                }
672
                        }
673
        
674
                        //Campo de texto de la coordenada Y en coordenadas del mundo
675
                        if(e.getSource() == dataPointPanel.getLongitud()){
676
                                if(checkTextField(dataPointPanel.getLongitud(), e.getKeyCode(), lastLong)){
677
                                        map = new Point2D.Double();
678
                                        map.setLocation(        Double.valueOf(dataPointPanel.getLongitud().getText()).doubleValue(), 
679
                                                                                Double.valueOf(dataPointPanel.getLatitud().getText()).doubleValue());
680
                                        if(e.getKeyCode() == 10)
681
                                                update = true;
682
                                        lastLong = dataPointPanel.getLongitud().getText();
683
                                }
684
                        }
685
                        
686
                        if(update)
687
                                this.updatePointsValue(pixel, map);
688
                        
689
                }catch(NumberFormatException exc){
690
                        System.out.println("Formato numerico erroneo");
691
                }
692
                
693
        }
694

    
695
        /* (non-Javadoc)
696
         * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
697
         */
698
        public void keyTyped(KeyEvent e) {
699
                // TODO Auto-generated method stub
700
                
701
        }
702
        
703
        /* (non-Javadoc)
704
         * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
705
         */
706
        public void focusGained(FocusEvent arg0) {
707
                // TODO Auto-generated method stub
708

    
709
        }
710
        
711
        /**
712
         * Los campos de texto de las coordenadas cuando pierden el foco actualizan el valor del pixel
713
         * en la cap, vista, mini imagen y tabla
714
         */
715
        public void focusLost(FocusEvent arg0) {
716
                Point2D pixel = new Point2D.Double();
717
                Point2D map = new Point2D.Double();
718
                pixel.setLocation(Double.valueOf(dataPointPanel.getTX().getText()).doubleValue(),
719
                                                  Double.valueOf(dataPointPanel.getTY().getText()).doubleValue());
720
                map.setLocation(Double.valueOf(dataPointPanel.getLongitud().getText()).doubleValue(),
721
                                                Double.valueOf(dataPointPanel.getLatitud().getText()).doubleValue());
722
                this.updatePointsValue(pixel, map);
723

    
724
        }
725

    
726
 }