Statistics
| Revision:

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

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 = 5;
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
            //Cargamos las mini imagenes
242
            this.grd.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().setCenterPoint(lyrPoints.getCenterPoint(pos, false));
243
                this.grd.getConectorPanel().getAdjustGeorefPanel().setNumberPoint(pos);
244
            this.grd.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().setNewViewPort(lyrPoints.getMiniExtent(pos, false));
245
            this.grd.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().draw();
246
            
247
            this.grd.getConectorPanel().getAdjustGeorefPanel().getZoomRight().setCenterPoint(lyrPoints.getCenterPoint(pos, true));
248
                this.grd.getConectorPanel().getAdjustGeorefPanel().setNumberPoint(pos);
249
            this.grd.getConectorPanel().getAdjustGeorefPanel().getZoomRight().setNewViewPort(lyrPoints.getMiniExtent(pos, true));
250
            this.grd.getConectorPanel().getAdjustGeorefPanel().getZoomRight().draw();
251
        }
252
        
253
        /**
254
         * Comprueba si los valores de un punto en los campos de texto est?n
255
         * vacios y lanza una excepci?n si hay alguno sin informaci?n.
256
         * @throws NoSuchFieldException
257
         */
258
        private void checkInfoPointText()throws NoSuchFieldException{
259
                if(        dataPointPanel.getTX().getText().equals("") ||
260
                                dataPointPanel.getTY().getText().equals("") ||
261
                                dataPointPanel.getLatitud().getText().equals("") ||
262
                                dataPointPanel.getLongitud().getText().equals("")){
263
                                isNew = true;
264
                                tableControlerPanel.getCPoint().setSelectedIndex(lastIndexSelection);
265
                                throw new NoSuchFieldException();
266
                }
267
        }
268
        
269
        /**
270
         * Comprueba la posici?n del combo para ver si tiene que
271
         * habilitar o deshabilitar las flechas de delante y detr?s.
272
         */
273
        private void checkArrows(){
274
                if(tableControlerPanel.getCPoint().getSelectedIndex() == -1){
275
                        tableControlerPanel.getBPrev().setEnabled(false);
276
                        tableControlerPanel.getBNext().setEnabled(false);
277
                        tableControlerPanel.getBLast().setEnabled(false);
278
                        tableControlerPanel.getBFirst().setEnabled(false);
279
                        return;
280
                }
281
                if(tableControlerPanel.getCPoint().getSelectedIndex() == 0){
282
                        tableControlerPanel.getBPrev().setEnabled(false);
283
                        tableControlerPanel.getBFirst().setEnabled(false);
284
                }else{
285
                        tableControlerPanel.getBPrev().setEnabled(true);
286
                        tableControlerPanel.getBFirst().setEnabled(true);
287
                }
288
                
289
                if(tableControlerPanel.getCPoint().getSelectedIndex() == (tableControlerPanel.getCPoint().getItemCount() - 1) ){
290
                        tableControlerPanel.getBNext().setEnabled(false);
291
                        tableControlerPanel.getBLast().setEnabled(false);
292
                }else{
293
                        tableControlerPanel.getBNext().setEnabled(true);
294
                        tableControlerPanel.getBLast().setEnabled(true);
295
                }
296
        }
297
        
298
        /**
299
         * Esta funci?n resetea los controles del panel de info de un punto.
300
         */
301
        public void resetControls(boolean active){
302
                dataPointPanel.getTX().setText("");
303
                dataPointPanel.getTY().setText("");
304
                dataPointPanel.getLatitud().setText("");
305
                dataPointPanel.getLongitud().setText("");
306
                getBSelectFromView().setEnabled(active);
307
                getBClear().setEnabled(active);
308
                getBDelPoint().setEnabled(active);
309
        }
310
        
311
        /**
312
         * Cuando pasamos de un punto a otro o se va a crear uno nuevo
313
         * <UL>
314
         * <LI>Cargamos la capa FLyrPoint si no est? ya cargada.</LI>
315
         * <LI>Comprobamos que los campos no esten vacios y lanzamos una excepci?n si hay alg?n campo vacio si lo est?n.</LI>
316
         * <LI>Insertamos el nuevo punto seleccionado en los campos de informaci?n.</LI>
317
         * <LI>Checkeamos las flechas para ver si tenemos que activarlas o desactivarlas.</LI>
318
         * </UL>
319
         * @param changeSelection        Cambia la posici?n seleccionada del combo si es true
320
         * @param pos        Posici?n a la que cambia el combo si el parametro chageSelection es true
321
         */
322
        private void changePoint(boolean changeSelection, int pos){
323
                loadLyrPoint();
324
            try{
325
                    checkInfoPointText();                        
326
                if(changeSelection){
327
                        isNew = true;
328
                        lastIndexSelection = pos;
329
                        tableControlerPanel.getCPoint().setSelectedIndex(pos);
330
                }
331
                loadInfoPoint(tableControlerPanel.getCPoint().getSelectedIndex());
332
                checkArrows();
333
            }catch(NoSuchFieldException exc){
334
                    JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
335
                                        PluginServices.getText(this, "coordenadas_vacias"));
336
            }
337
        }
338
        
339
        /**
340
         * Limpia la lista de puntos y borra el dialogo.
341
         */
342
        public void clearList(){
343
                loadLyrPoint();
344
                lyrPoints.clear();
345
                resetControls(false);
346
                isNew = true;
347
                tableControlerPanel.getCPoint().removeAllItems();
348
                tableControlerPanel.getLNumberOfPoints().setText(PluginServices.getText(this, "de") + " " + lyrPoints.getCountPoints());
349
                checkArrows();
350
                View theView = (View) PluginServices.getMDIManager().getActiveView();
351
                theView.getMapControl().getMapContext().invalidate();
352
        }
353

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

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

    
454

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

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

    
584
        /**
585
         * @return Returns the dataPointPanel.
586
         */
587
        public DataPointPanel getDataPointPanel() {
588
                return dataPointPanel;
589
        }
590

    
591
        /**
592
         * @param dataPointPanel The dataPointPanel to set.
593
         */
594
        public void setDataPointPanel(DataPointPanel dataPointPanel) {
595
                this.dataPointPanel = dataPointPanel;
596
        }
597
        
598
        /**
599
         * @return Returns the tableControlerPanel.
600
         */
601
        public TableControlerPanel getTableControlerPanel() {
602
                return tableControlerPanel;
603
        }
604

    
605
        /**
606
         * @param tableControlerPanel The tableControlerPanel to set.
607
         */
608
        public void setTableControlerPanel(TableControlerPanel tableControlerPanel) {
609
                this.tableControlerPanel = tableControlerPanel;
610
        }
611

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

    
687
        
688
        /* (non-Javadoc)
689
         * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
690
         */
691
        public void keyPressed(KeyEvent e) {
692
                // TODO Auto-generated method stu
693
        }
694

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

    
786
        /* (non-Javadoc)
787
         * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
788
         */
789
        public void keyTyped(KeyEvent e) {
790
                // TODO Auto-generated method stub
791
                
792
        }
793
        
794
        /* (non-Javadoc)
795
         * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
796
         */
797
        public void focusGained(FocusEvent arg0) {
798
                // TODO Auto-generated method stub
799

    
800
        }
801
        
802
        /**
803
         * Los campos de texto de las coordenadas cuando pierden el foco actualizan el valor del pixel
804
         * en la cap, vista, mini imagen y tabla
805
         */
806
        public void focusLost(FocusEvent arg0) {
807
                Point2D pixel = new Point2D.Double();
808
                Point2D map = new Point2D.Double();
809
                pixel.setLocation(Double.valueOf(dataPointPanel.getTX().getText()).doubleValue(),
810
                                                  Double.valueOf(dataPointPanel.getTY().getText()).doubleValue());
811
                map.setLocation(Double.valueOf(dataPointPanel.getLongitud().getText()).doubleValue(),
812
                                                Double.valueOf(dataPointPanel.getLatitud().getText()).doubleValue());
813
                this.updatePointsValue(pixel, map);
814

    
815
        }
816

    
817
 }