Statistics
| Revision:

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

History | View | Annotate | Download (27.5 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.fmap.layers.FLyrPoints.GeoPoint;
27
import com.iver.cit.gvsig.gui.View;
28
import com.iver.cit.gvsig.gui.Dialogs.GeoreferencingDialog;
29
import com.iver.cit.gvsig.gui.toolListeners.GeorefPointerListener;
30

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

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

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

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

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

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

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

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

    
363
                
364
        /**
365
         * Este m?todo inicializa el bot?n del clear que har? que se eliminen todos los
366
         * puntos seleccionados.        
367
         *         
368
         * @return javax.swing.JButton        
369
         */
370
        private JButton getBClear() {
371
                if (bClear == null) {
372
                        bClear = new JButton();
373
                        bClear.setText("");
374
                        bClear.setPreferredSize(new java.awt.Dimension(22,22));
375
                        bClear.setEnabled(false);
376
                        bClear.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/delall.png")));
377
                        bClear.setActionCommand("");
378
                        bClear.addActionListener(new java.awt.event.ActionListener() { 
379
                                public void actionPerformed(java.awt.event.ActionEvent e) {
380
                                        clearList();
381
                                }
382
                        });
383
                }
384
                return bClear;
385
        }
386

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

    
463

    
464
        /**
465
         * Este m?todo inicializa el bot?n seleccionar desde la vista. Cuando lo 
466
         * activamos se carga la herramienta de selecci?n de puntos desde la vista. 
467
         *         
468
         * @return javax.swing.JButton        
469
         */    
470
        public JButton getBSelectFromView() {
471
                if (bSelectFromView == null) {
472
                        bSelectFromView = new JButton();
473
                        bSelectFromView.setText("");
474
                        bSelectFromView.setPreferredSize(new java.awt.Dimension(22,22));
475
                        bSelectFromView.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/selectfromview.png")));
476
                        bSelectFromView.setEnabled(false);
477
                        bSelectFromView.addActionListener(new java.awt.event.ActionListener() { 
478
                                public void actionPerformed(java.awt.event.ActionEvent e) {
479
                                        View theView = (View) PluginServices.getMDIManager().getActiveView();
480
                                        loadLyrPoint();
481
                                        lyrPoints.setLastTool(theView.getMapControl().getTool());
482
                                        GeorefPointerListener.posPoint = tableControlerPanel.getCPoint().getSelectedIndex();
483
                                        GeorefPointerListener.firstPoint = true;
484
                                        theView.getMapControl().setTool("pointLyrSelection");
485
                                }
486
                        });
487
                }
488
                return bSelectFromView;
489
        }
490
        
491
        /**
492
         * Checkea un textField para que contenga caracteres validos. Consideramos validos
493
         * los caracteres del 0 al 9, el punto, DEL, Supr, flechas y Enter teniendo en cuenta que el 
494
         * c?digo ascii del teclado numerico es distinto.
495
         */
496
        public boolean checkTextField(JTextField tf, int code, String lastText){
497
                        System.out.println(code);
498
                //Si el caracter es erroneo pasamos de el y reponemos el texto que habia
499
                if(        (code >= 0 && code <= 7) || 
500
                        code == 9 || 
501
                        (code >= 11 && code <= 36) ||
502
                        (code >= 41 && code <= 45) ||
503
                        code == 47 ||
504
                        (code >= 58 && code <= 95) ||
505
                        (code >= 106 && code <= 109) ||
506
                        (code >= 111 && code <= 126) ||
507
                        code >= 128){
508
                        tf.setText(lastText);
509
                        return false;
510
                }
511
                
512
                return true;
513
        }
514
                
515
        /**
516
         * Carga el panel desde los datos contenidos en una capa de puntos
517
         * @param lyr
518
         */
519
        public void loadFromLyrPoints(FLyrPoints lyr){
520
                if(lyr != null){
521
                        lyr.clean();
522
                        lyrPoints = new FLyrPoints();
523
                        lyrPoints.setListPoint(lyr.getListPoint());
524
                        
525
                        View theView = (View) PluginServices.getMDIManager().getActiveView();
526
                        theView.getMapControl().getMapContext().beginAtomicEvent();
527
                        theView.getMapControl().getMapContext().getLayers().addLayer(lyr);
528
                        theView.getMapControl().getMapContext().endAtomicEvent();
529
                        
530
                        tableControlerPanel.getCPoint().removeAllItems();
531
                        for(int i=0;i<lyr.getCountPoints();i++)
532
                                tableControlerPanel.getCPoint().addItem("" + (i + 1));
533
                        tableControlerPanel.getLNumberOfPoints().setText(PluginServices.getText(this, "de") + " " + lyrPoints.getCountPoints());
534
                        if(lyr.getCountPoints() >= 1){
535
                                changePoint(true, 0);
536
                                getBSelectFromView().setEnabled(true);
537
                                getBClear().setEnabled(true);
538
                                getBDelPoint().setEnabled(true);
539
                        }
540
                }
541
        }
542

    
543
        /**
544
         * This method initializes jPanel        
545
         *         
546
         * @return javax.swing.JPanel        
547
         */    
548
        private JPanel getPManagerPoint() {
549
                if (pManagerPoint == null) {
550
                        FlowLayout flowLayout11 = new FlowLayout();
551
                        pManagerPoint = new JPanel();
552
                        pManagerPoint.setLayout(flowLayout11);
553
                        flowLayout11.setVgap(0);
554
                        flowLayout11.setHgap(0);
555
                        pManagerPoint.add(getBDelPoint(), null);
556
                        pManagerPoint.add(getBClear(), null);
557
                }
558
                return pManagerPoint;
559
        }
560
        /**
561
         * This method initializes jButton        
562
         *         
563
         * @return javax.swing.JButton        
564
         */    
565
        private JButton getBExtended() {
566
                if (bExtended == null) {
567
                        bExtended = new JButton();
568
                        bExtended.setPreferredSize(new java.awt.Dimension(22,22));
569
                        bExtended.setIcon(new ImageIcon(getClass().getResource("/com/iver/cit/gvsig/gui/Panels/images/down.png")));
570
                        bExtended.addActionListener(this);
571
                }
572
                return bExtended;
573
        }
574
        /**
575
         * This method initializes jPanel        
576
         *         
577
         * @return javax.swing.JPanel        
578
         */    
579
        private JPanel getPExtend() {
580
                if (pExtend == null) {
581
                        FlowLayout flowLayout21 = new FlowLayout();
582
                        pExtend = new JPanel();
583
                        pExtend.setLayout(flowLayout21);
584
                        flowLayout21.setHgap(0);
585
                        flowLayout21.setVgap(0);
586
                        flowLayout21.setAlignment(java.awt.FlowLayout.RIGHT);
587
                        pExtend.setPreferredSize(new java.awt.Dimension(35,22));
588
                        pExtend.add(getBExtended(), null);
589
                }
590
                return pExtend;
591
        }
592

    
593
        /**
594
         * @return Returns the dataPointPanel.
595
         */
596
        public DataPointPanel getDataPointPanel() {
597
                return dataPointPanel;
598
        }
599

    
600
        /**
601
         * @param dataPointPanel The dataPointPanel to set.
602
         */
603
        public void setDataPointPanel(DataPointPanel dataPointPanel) {
604
                this.dataPointPanel = dataPointPanel;
605
        }
606
        
607
        /**
608
         * @return Returns the tableControlerPanel.
609
         */
610
        public TableControlerPanel getTableControlerPanel() {
611
                return tableControlerPanel;
612
        }
613

    
614
        /**
615
         * @param tableControlerPanel The tableControlerPanel to set.
616
         */
617
        public void setTableControlerPanel(TableControlerPanel tableControlerPanel) {
618
                this.tableControlerPanel = tableControlerPanel;
619
        }
620

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

    
695
        
696
        /* (non-Javadoc)
697
         * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
698
         */
699
        public void keyPressed(KeyEvent e) {
700
                // TODO Auto-generated method stu
701
        }
702

    
703
        /**
704
         * Actualiza los valores del punto nuevo introducido desde el teclado llamando a la funci?n
705
         * de la capa updataData que actualizar? los controles necesarios para que se refresquen la vista
706
         * mini imagenes, textfields, tabla y capa de puntos. 
707
         * @param pixel Pixel de la imagen
708
         * @param map Coordenadas de la vista.
709
         */
710
        private void updatePointsValue(Point2D pixel, Point2D map){
711
                //Actualizamos los controles con los nuevos valores
712
                View theView = (View) PluginServices.getMDIManager().getActiveView();
713
                for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){
714
                        FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i);
715
                        if(        lyr instanceof FLyrGeoRaster && 
716
                                lyr.getName().startsWith("*") &&
717
                                lyr.isActive()){
718
                                ((FLyrGeoRaster)lyr).updateData(Integer.valueOf(this.grd.getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue(),
719
                                                                                                pixel, 
720
                                                                                                map, 
721
                                                                                                this.grd,
722
                                                                                                theView, 
723
                                                                                                lyrPoints);
724
                        }
725
                }
726
        }
727
        
728
        /**
729
         * Control de eventos de las entradas de texto de los puntos
730
         */
731
        public void keyReleased(KeyEvent e) {
732
                //Campo de texto de la coordenada X en pixeles
733
                Point2D pixel = null;
734
                Point2D map = null;
735
                boolean update = false;
736
                
737
                try{
738
                        if(e.getSource() == dataPointPanel.getTX()){
739
                                if(checkTextField(dataPointPanel.getTX(), e.getKeyCode(), lastTx)){
740
                                        pixel = new Point2D.Double();
741
                                        pixel.setLocation(        Double.valueOf(dataPointPanel.getTX().getText()).doubleValue(), 
742
                                                                                Double.valueOf(dataPointPanel.getTY().getText()).doubleValue());
743
                                        if(e.getKeyCode() == 10)
744
                                                update = true;
745
                                        lastTx = dataPointPanel.getTX().getText();
746
                                }
747
                        }
748
                        
749
                        //Campo de texto de la coordenada Y en pixeles
750
                        if(e.getSource() == dataPointPanel.getTY()){
751
                                if(checkTextField(dataPointPanel.getTY(), e.getKeyCode(), lastTy)){
752
                                        pixel = new Point2D.Double();
753
                                        pixel.setLocation(        Double.valueOf(dataPointPanel.getTX().getText()).doubleValue(), 
754
                                                                                Double.valueOf(dataPointPanel.getTY().getText()).doubleValue());
755
                                        if(e.getKeyCode() == 10)
756
                                                update = true;
757
                                        lastTy = dataPointPanel.getTY().getText();
758
                                }
759
                        }
760
        
761
                        //Campo de texto de la coordenada X en coordenadas del mundo
762
                        if(e.getSource() == dataPointPanel.getLatitud()){
763
                                if(checkTextField(dataPointPanel.getLatitud(), e.getKeyCode(), lastLat)){
764
                                        map = new Point2D.Double();
765
                                        map.setLocation(        Double.valueOf(dataPointPanel.getLongitud().getText()).doubleValue(), 
766
                                                                                Double.valueOf(dataPointPanel.getLatitud().getText()).doubleValue());
767
                                        if(e.getKeyCode() == 10)
768
                                                update = true;
769
                                        lastLat = dataPointPanel.getLatitud().getText();
770
                                }
771
                        }
772
        
773
                        //Campo de texto de la coordenada Y en coordenadas del mundo
774
                        if(e.getSource() == dataPointPanel.getLongitud()){
775
                                if(checkTextField(dataPointPanel.getLongitud(), e.getKeyCode(), lastLong)){
776
                                        map = new Point2D.Double();
777
                                        map.setLocation(        Double.valueOf(dataPointPanel.getLongitud().getText()).doubleValue(), 
778
                                                                                Double.valueOf(dataPointPanel.getLatitud().getText()).doubleValue());
779
                                        if(e.getKeyCode() == 10)
780
                                                update = true;
781
                                        lastLong = dataPointPanel.getLongitud().getText();
782
                                }
783
                        }
784
                        
785
                        if(update)
786
                                this.updatePointsValue(pixel, map);
787
                        
788
                }catch(NumberFormatException exc){
789
                        System.out.println("Formato numerico erroneo");
790
                }
791
                
792
        }
793

    
794
        /* (non-Javadoc)
795
         * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
796
         */
797
        public void keyTyped(KeyEvent e) {
798
                // TODO Auto-generated method stub
799
                
800
        }
801
        
802
        /* (non-Javadoc)
803
         * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
804
         */
805
        public void focusGained(FocusEvent arg0) {
806
                // TODO Auto-generated method stub
807

    
808
        }
809
        
810
        /**
811
         * Los campos de texto de las coordenadas cuando pierden el foco actualizan el valor del pixel
812
         * en la cap, vista, mini imagen y tabla
813
         */
814
        public void focusLost(FocusEvent arg0) {
815
                Point2D pixel = new Point2D.Double();
816
                Point2D map = new Point2D.Double();
817
                pixel.setLocation(Double.valueOf(dataPointPanel.getTX().getText()).doubleValue(),
818
                                                  Double.valueOf(dataPointPanel.getTY().getText()).doubleValue());
819
                map.setLocation(Double.valueOf(dataPointPanel.getLongitud().getText()).doubleValue(),
820
                                                Double.valueOf(dataPointPanel.getLatitud().getText()).doubleValue());
821
                this.updatePointsValue(pixel, map);
822

    
823
        }
824

    
825
 }