Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / gridmath / gui / OutputOptionsPanel.java @ 16088

History | View | Annotate | Download (21.9 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Iba?ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
34
 *   Campus Universitario s/n
35
 *   02071 Alabacete
36
 *   Spain
37
 *
38
 *   +34 967 599 200
39
 */
40

    
41
package org.gvsig.remotesensing.gridmath.gui;
42

    
43
import info.clearthought.layout.TableLayout;
44

    
45
import java.awt.BorderLayout;
46
import java.awt.GridBagConstraints;
47
import java.awt.GridBagLayout;
48
import java.awt.event.ActionEvent;
49
import java.awt.event.ActionListener;
50
import java.awt.event.FocusEvent;
51
import java.awt.event.FocusListener;
52
import java.awt.event.KeyEvent;
53
import java.awt.event.KeyListener;
54

    
55
import javax.swing.BorderFactory;
56
import javax.swing.ButtonGroup;
57
import javax.swing.ComboBoxModel;
58
import javax.swing.DefaultComboBoxModel;
59
import javax.swing.JComboBox;
60
import javax.swing.JLabel;
61
import javax.swing.JPanel;
62
import javax.swing.JRadioButton;
63
import javax.swing.JTextField;
64
import javax.swing.border.CompoundBorder;
65
import javax.swing.border.EmptyBorder;
66
import javax.swing.border.TitledBorder;
67

    
68
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
69
import org.gvsig.rastertools.RasterModule;
70

    
71
import com.iver.andami.PluginServices;
72
import com.iver.cit.gvsig.fmap.MapContext;
73
import com.iver.cit.gvsig.fmap.layers.FLayers;
74
import com.iver.cit.gvsig.project.documents.view.gui.View;
75

    
76
/**
77
 * Clase que implementa la interfaz de configuracion de las opciones de salida.
78
 * Puede ajustarse el extent de salida y las opciones habituales de salvado de la
79
 * capa.
80
 * 
81
 * @author Alejandro Mu?oz S?nchez (alejandro.munoz@uclm.es)
82
 * @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
83
 * @version 22/10/2007
84
 */
85
public class OutputOptionsPanel extends JPanel implements ActionListener,FocusListener,KeyListener {
86
        
87
        private static final long serialVersionUID = 1L;        
88
        private JPanel namePanel = null;
89
        private JPanel panelExtension = null;
90
        private JPanel paramPanel = null;
91
        
92
        private JTextField jTextNombreCapa = null;
93
        private JTextField  jTextRangoX1 = null;
94
        private JTextField  jTextRangoX2 = null;
95
        private JTextField jTextRangoY1 = null;
96
        private JTextField jTextRangoY2 = null;
97
        private JTextField jTextCellSize = null;
98
        private JTextField  jTextNumFiCol1 = null;
99
        private JTextField jTextNumFiCol2 = null;
100
        private FLayers layers = null;
101
        
102
        private JRadioButton rButtom1 = null;
103
        private JRadioButton rButtom2 = null;
104
        private JRadioButton rButtom4 = null;
105
        private JRadioButton rButtonFile = null;
106
        private JRadioButton rButtonMemory = null;
107
        private JComboBox jComboCapas = null;
108
        private MapContext mapContext = null;
109
        private CalculatorPanel cp = null;
110
        
111
        
112
        /**
113
        * Constructor
114
        * @param vista vista de la aplicaci?n
115
        * @param cp calculatorPanel desde el que se invoca
116
        */
117
        public OutputOptionsPanel(View vista, CalculatorPanel cp) {
118
                super();        
119
                if (vista!=null){
120
                        mapContext = vista.getModel().getMapContext();        
121
                        layers = mapContext.getLayers();
122
                }
123
                this.cp=cp;
124
                Inicializar();
125
        }
126
        
127
        /**
128
         * Inicializaci?n del panel
129
         */
130
        public void  Inicializar(){
131
                BorderLayout bd=new BorderLayout();
132
                this.setLayout(bd);
133
                this.setBorder( new EmptyBorder(2, 2, 2, 2));
134
                this.add(getNamePanel(),BorderLayout.NORTH);
135
                this.add(getPanelExtension(),BorderLayout.WEST);
136
                this.add(getParameterPanel(),BorderLayout.CENTER);
137
                this.setNewLayerText();
138
                getRadioMemory().setSelected(true);        
139
        }
140
        
141

    
142
        /**
143
         * @return JRadioButton de generar fichero
144
         */
145
        public JRadioButton getRadioFile(){
146
                if (rButtonFile == null){
147
                        rButtonFile = new JRadioButton(PluginServices.getText(this,"a_fichero"));
148
                        rButtonFile.addActionListener(this);
149
                }
150
                return rButtonFile;
151
        }
152
        
153
        /**
154
         * @return JRadioButton de generar en memoria
155
         */
156
        public JRadioButton getRadioMemory(){
157
                if (rButtonMemory == null){
158
                        rButtonMemory = new JRadioButton(PluginServices.getText(this,"a_memoria"));
159
                        rButtonMemory.addActionListener(this);
160
                }
161
                return rButtonMemory;
162
        }
163

    
164
        
165
        /**
166
         * @return panel que incluye el nombre de la capa y las opciones de almacenamieto de la capa de salida 
167
         */
168
        public JPanel getNamePanel() {
169
                
170
                if (namePanel==null){
171
                        namePanel=new JPanel();
172
                        GridBagConstraints gridBagConstraints;
173
                        JPanel radioPanel = new JPanel();
174
                        radioPanel.setLayout(new GridBagLayout());
175
                        radioPanel.setBorder(BorderFactory.createTitledBorder(""));
176
                        ButtonGroup buttonGroup = new ButtonGroup();
177
                        buttonGroup.add(getRadioMemory());
178
                        gridBagConstraints = new java.awt.GridBagConstraints();
179
                        gridBagConstraints.gridx = 0;
180
                        gridBagConstraints.gridy = 1;
181
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
182
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
183
                        radioPanel.add(getRadioMemory(),gridBagConstraints);
184
                        buttonGroup.add(getRadioFile());
185
                        gridBagConstraints = new java.awt.GridBagConstraints();
186
                        gridBagConstraints.gridx = 0;
187
                        gridBagConstraints.gridy = 2;
188
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
189
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
190
                        radioPanel.add(getRadioFile(),gridBagConstraints);
191
                 
192
                        //Establece la separacin entre los elementos
193
                        namePanel.setLayout(new GridBagLayout());
194
                        
195
                        gridBagConstraints = new java.awt.GridBagConstraints();
196
                        gridBagConstraints.gridx = 0;
197
                        gridBagConstraints.gridy = 0;
198
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
199
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
200
                        namePanel.add(new JLabel(PluginServices.getText(this,"nombre_capa")),gridBagConstraints);
201
                        
202
                        gridBagConstraints = new java.awt.GridBagConstraints();
203
                        gridBagConstraints.gridx = 1;
204
                        gridBagConstraints.gridy = 0;
205
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
206
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
207
                        namePanel.add(getJTextNombreCapa(),gridBagConstraints);
208
                        
209
                        gridBagConstraints = new java.awt.GridBagConstraints();
210
                        gridBagConstraints.gridx = 2;
211
                        gridBagConstraints.gridy = 0;
212
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
213
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
214
                        namePanel.add(radioPanel,gridBagConstraints);
215
                }
216
                return namePanel;
217
        }
218

    
219

    
220
        /**
221
         * @return textField con el nombre de la capa
222
         */
223
        public JTextField getJTextNombreCapa() {
224
                if (jTextNombreCapa==null){
225
                        jTextNombreCapa=new JTextField(15);
226
                        jTextNombreCapa.addFocusListener(this);
227
                }
228
                return jTextNombreCapa;
229
        }
230

    
231

    
232

    
233
        /** 
234
        * @return panel con las opciones de configuraci?n de extent, 
235
        * los radioButton y el comboCapas
236
        */
237
        public JPanel getPanelExtension() {
238
                
239
                if (panelExtension==null){
240
                        panelExtension=new JPanel();
241
                        TitledBorder topBorder = BorderFactory.createTitledBorder((PluginServices.getText(this,"extension_from")));
242
                    topBorder.setTitlePosition(TitledBorder.TOP);
243
                    panelExtension.setBorder(new CompoundBorder(topBorder,new EmptyBorder(5,5,6,5)));
244
                        
245
                    JPanel p=new JPanel();
246
                    //p.setPreferredSize(new Dimension(200,130));
247
                                TableLayout thisLayout = new TableLayout(new double[][] {
248
                                                {200},         
249
                                                {TableLayout.PREFERRED,TableLayout.PREFERRED,TableLayout.PREFERRED, TableLayout.PREFERRED}}); 
250
                                                //Establece la separacin entre los elementos
251
                                                thisLayout.setHGap(5);
252
                                                thisLayout.setVGap(5);
253
                                                panelExtension.setLayout(thisLayout);
254
                                                p.setLayout(thisLayout);
255
                                                ButtonGroup buttonGroup = new ButtonGroup();
256
                                                buttonGroup.add(getRButtom1());
257
                                                buttonGroup.add(getRButtom2());
258
                                                buttonGroup.add(getRButtom4());
259
                                                panelExtension.add(getRButtom1(),"0,0");
260
                                                panelExtension.add(getRButtom2(),"0,1");
261
                                                panelExtension.add(getRButtom4(),"0,2");
262
                                                panelExtension.add(getJComboCapas(),"0,3");
263
                
264
                }
265
                
266
                return panelExtension;
267
        }
268

    
269

    
270
        /** 
271
         * @return panel con los parametros de configuraci?n de extensi?n de la salida raster. 
272
         */
273
        public JPanel getParameterPanel() {
274
                
275
                
276
                if (paramPanel==null){
277
                        paramPanel=new JPanel();
278
                        TitledBorder topBorder = BorderFactory.createTitledBorder((PluginServices.getText(this,"parametros")));
279
                    topBorder.setTitlePosition(TitledBorder.TOP);
280
                    paramPanel.setBorder(new CompoundBorder(topBorder,new EmptyBorder(5,5,6,5)));
281
                        
282
                    
283
                    JPanel p=new JPanel();
284
                   // p.setPreferredSize(new Dimension(320,130));
285
                        TableLayout thisLayout = new TableLayout(new double[][] {
286
                                 {150,75, 75},         
287
                                {20,20,20,20}}); 
288
                                //Establece la separacin entre los elementos
289
                                thisLayout.setHGap(3);
290
                                thisLayout.setVGap(3);
291
                                p.setLayout(thisLayout);
292
                                
293
                                //Aado los diferentes elementos
294
                                p.add(new JLabel((PluginServices.getText(this,"rangox"))),"0,0");
295
                                p.add(new JLabel((PluginServices.getText(this,"rangoy"))),"0,1");
296
                                p.add(new JLabel((PluginServices.getText(this,"tamanio_celda"))),"0,2");
297
                                p.add(new JLabel((PluginServices.getText(this,"num_filas_columnas"))),"0,3");
298
                                p.add(getJTextCellSize(),"1,2");
299
                                p.add(getJTextNumFiCol1(),"1,3");
300
                                p.add(getJTextNumFiCol2(),"2,3");
301
                                p.add(getJTextRangoX1(),"1,0");
302
                                p.add(getJTextRangoX2(),"2,0");
303
                                p.add(getJTextRangoY1(),"1,1");
304
                                p.add(getJTextRangoY2(),"2,1");
305
                                
306
                                paramPanel.add(p);
307
                }
308
                return paramPanel;
309
        }
310

    
311
        
312

    
313
        /**
314
         * @return JRadioButton  ajustar a datos de entrada
315
         */
316
        public JRadioButton getRButtom1() {
317
                if(rButtom1==null){
318
                        rButtom1=new JRadioButton((PluginServices.getText(this,"ajustar_entrada")), true);
319
                        rButtom1.addActionListener(this);
320
                        }
321
                return rButtom1;
322
        }
323

    
324

    
325

    
326
        /**
327
         * @return JRadioButton extension definida por el  usuario 
328
         */
329
        public JRadioButton getRButtom2() {
330
                if(rButtom2==null){
331
                        rButtom2=new JRadioButton((PluginServices.getText(this,"definida_usuario")), false);
332
                        rButtom2.addActionListener(this);
333
                }
334
                return rButtom2;
335
        }
336

    
337

    
338

    
339
        /**
340
         * @return JRadioButton extension ajustada a otra capa 
341
         */
342
        public JRadioButton getRButtom4() {
343
                if(rButtom4==null){
344
                        rButtom4=new JRadioButton((PluginServices.getText(this,"extension_capa")), false);
345
                        rButtom4.addActionListener(this);        
346
                }
347
                return rButtom4;
348
        }
349

    
350

    
351
        /**
352
         * @return JTextField tama?o de celda 
353
         */
354
        public JTextField getJTextCellSize() {
355
                if (jTextCellSize==null){
356
                        jTextCellSize=new JTextField(15);;
357
                        jTextCellSize.setEditable(false);
358
                        jTextCellSize.addKeyListener(this);   
359
                }
360
                return jTextCellSize;
361
        }
362

    
363

    
364
        
365
        /**
366
         * @return JTextField numero de filas
367
         */
368
        public JTextField getJTextNumFiCol1() {
369
                if (jTextNumFiCol1==null){
370
                        jTextNumFiCol1=new JTextField ();
371
                        jTextNumFiCol1.setEditable(false);
372
                }
373
                return jTextNumFiCol1;
374
        }
375

    
376

    
377

    
378
        /**
379
         * @return JTextField coordenada x m?nima
380
         */
381
        public JTextField  getJTextRangoX1() {
382
                if (jTextRangoX1==null){                        
383
                        jTextRangoX1 =new JTextField ();
384
                        jTextRangoX1.setEditable(false);
385
                        jTextRangoX1.addKeyListener(this);        
386
                        
387
                }
388
                return jTextRangoX1;
389
        }
390

    
391

    
392

    
393
        /**
394
         * @return JTextField coordenada x m?xima
395
         */
396
        public JTextField getJTextRangoX2() {
397
                if (jTextRangoX2==null){
398
                        jTextRangoX2=new JTextField ();
399
                        jTextRangoX2.setEditable(false);
400
                        jTextRangoX2.addKeyListener(this);
401
                        
402
                }
403
                return jTextRangoX2;
404
        }
405

    
406

    
407

    
408

    
409
        /**
410
         * @return JTextField coordenada y m?mnima
411
         */
412
        public JTextField  getJTextRangoY1() {
413
                if (jTextRangoY1==null){
414
                        jTextRangoY1=new JTextField ();
415
                        jTextRangoY1.setEditable(false);
416
                        jTextRangoY1.addKeyListener(this);
417
                        }
418
                return jTextRangoY1;
419
        }
420

    
421

    
422

    
423
        /**
424
         * @return JTextField coordenada y m?xima
425
         */
426
        public JTextField  getJTextRangoY2() {
427
                if (jTextRangoY2==null){
428
                        jTextRangoY2=new JTextField ();
429
                        jTextRangoY2.setEditable(false);
430
                        jTextRangoY2.addKeyListener(this);
431
                }
432
                return jTextRangoY2;
433
        }
434

    
435

    
436

    
437

    
438
        /**
439
         * @return JTextField numero de columnas
440
         */
441
        public JTextField getJTextNumFiCol2() {
442
                if (jTextNumFiCol2==null){
443
                        jTextNumFiCol2=new JTextField ();
444
                        jTextNumFiCol2.setEditable(false);                
445
                }
446
                return jTextNumFiCol2;
447
        }
448

    
449

    
450

    
451
        /**
452
         * @return JCombo con las capas raster cargadas en la vista
453
         */
454
        public JComboBox getJComboCapas() {
455
                if (jComboCapas==null){
456
                        ComboBoxModel jComboBoxLayersModel = new DefaultComboBoxModel(getLayerNames());
457
                        jComboCapas = new JComboBox();
458
                        jComboCapas.setModel(jComboBoxLayersModel);
459
                        jComboCapas.setEnabled(false);
460
                        jComboCapas.addActionListener(this);
461
                }        
462
                return jComboCapas;
463
        }
464

    
465
        /**
466
         * @return array con el nombre de los ficheros cargados en la vista
467
         */
468
        private String[] getLayerNames() {
469
                String[] sNames = {};
470
                if (layers!=null){
471
                        sNames = new String[layers.getLayersCount()];
472
                        for (int i = 0; i < layers.getLayersCount(); i++) {                      
473
                                sNames[i] = (layers.getLayer(i)).getName();
474
                        }
475
                }    
476
                return sNames;
477
        }
478

    
479
        
480
        /**
481
         * Establece la opci?n por defecto cuando se crea en cuadro de dialogo
482
         */
483
        public void InicializarOpcion(){
484
                
485
                DesabilitarTodo();
486
                rButtom1.setSelected(true);
487
                // Comprobar que todas las variables estan asignadas
488
                boolean allAssigned = false;
489
                for (int i=0; i<cp.getJTableVariables().getTableFormat().getRowCount(); i++){
490
                        allAssigned = true;
491
                        if (cp.getJTableVariables().getTableFormat().getValueAt(i,1).toString().equals(""))
492
                        { 
493
                                allAssigned=false; 
494
                                break;
495
                        }
496
                }
497
                if(allAssigned){
498
                // Establecemos la opcion por defecto.
499
                setAjustInDataExtent();        
500
                }
501
        }
502

    
503
        
504
        /**
505
        * Deshabilita todos los componetes variables de la interfaz
506
        */
507
        public void DesabilitarTodo(){
508
                
509
                jComboCapas.setEnabled(false);
510
                jTextRangoX1.setEditable(false);
511
                jTextRangoX1.setEnabled(false);
512
                jTextRangoX2.setEditable(false);
513
                jTextRangoX2.setEnabled(false);
514
                jTextRangoY1.setEditable(false);
515
                jTextRangoY1.setEnabled(false);
516
                jTextRangoY2.setEditable(false);
517
                jTextRangoY2.setEnabled(false);
518
                jTextNumFiCol1.setEditable(false);
519
                jTextCellSize.setEditable(false);
520
                jTextCellSize.setEnabled(false);
521
                jTextNumFiCol1.setEnabled(false);
522
                jTextNumFiCol2.setEditable(false);
523
                jTextNumFiCol2.setEnabled(false);
524
                jComboCapas.updateUI();
525
                
526
        }
527
        
528

    
529
        /**
530
         * Reestablece el numero de filas y columnas ante cuanquier variaci?n de la interfaz
531
         */
532
        public void extentHasChanged(){
533
                
534
                double dRangeX;
535
                double dRangeY;
536
                double dCellSize;
537
                int iRows;
538
                int iCols;
539
                // Se actualiza la X                
540
                try {
541
                        dRangeX = Math.abs(Double.parseDouble(getJTextRangoX2().getText())
542
                                                                - Double.parseDouble(getJTextRangoX1().getText()));
543
                        dCellSize = Double.parseDouble(getJTextCellSize().getText());        
544
                        iCols = (int) Math.floor(dRangeX / dCellSize);
545
                        getJTextNumFiCol2().setText(Integer.toString(iCols));
546
                
547
                } catch (NumberFormatException e) {
548
                                e.printStackTrace();
549
                        return;
550
                }
551
                
552
                // Se actualiza la Y        
553
                try {
554
                dRangeY = Math.abs(Double.parseDouble(getJTextRangoY2().getText())
555
                                        - Double.parseDouble(getJTextRangoY1().getText()));
556
                        dCellSize = Double.parseDouble(getJTextCellSize().getText());                        
557
                        iRows = (int) Math.floor(dRangeY / dCellSize);
558
                        getJTextNumFiCol1().setText(Integer.toString(iRows));
559
                        
560
                        
561
                } catch (NumberFormatException e) {
562
                        
563
                        e.printStackTrace();
564
                        return;
565
                }
566
}
567
        
568
        private void validateKeyTyping(KeyEvent event) {
569
                jComboCapas.updateUI();
570
                switch (event.getKeyChar()) {
571
                        
572
                        case KeyEvent.VK_ENTER:
573
                                extentHasChanged();
574
                                jComboCapas.updateUI();
575
                                break;
576
                        
577
                        case KeyEvent.VK_BACK_SPACE:
578
                                extentHasChanged();
579
                                break;
580
                        case KeyEvent.VK_0 :
581
                                extentHasChanged();
582
                                break;
583
                        case KeyEvent.VK_1 :
584
                                extentHasChanged();
585
                                break;
586
                        case KeyEvent.VK_2 :
587
                                extentHasChanged();
588
                                break;
589
                        case KeyEvent.VK_3:
590
                                extentHasChanged();
591
                                break;
592
                        case KeyEvent.VK_4:  
593
                                extentHasChanged();
594
                                break;
595
                        case KeyEvent.VK_5: 
596
                                extentHasChanged();
597
                                break;
598
                        case KeyEvent.VK_6: 
599
                                extentHasChanged();
600
                                break;
601
                        case KeyEvent.VK_7: 
602
                                extentHasChanged();
603
                                break;
604
                        case KeyEvent.VK_8: 
605
                                extentHasChanged();
606
                                break;
607
                        case KeyEvent.VK_9 :                        
608
                                extentHasChanged();
609
                                break;
610
                }
611
        }
612
        
613
        
614
        
615
        /**
616
        * Fija las acciones que se realizan cuando se produce un evento
617
        * @param e Objeto que genera el evento
618
        */
619
        public void actionPerformed(ActionEvent e) {
620
                
621
                //Radiobutton1
622
                if (e.getSource()==getRButtom1()){
623
                        DesabilitarTodo();
624
                        setAjustInDataExtent();
625
                        updateParams();
626
                }
627
        
628
                // RadioButtom2
629
                else  if (e.getSource()==getRButtom2()){
630
                        
631
                        DesabilitarTodo();
632
                        rButtom2.setSelected(true);
633
                        getJTextRangoX1().setEnabled(true);
634
                        getJTextRangoX1().setEditable(true);
635
                        getJTextRangoX2().setEnabled(true);
636
                        getJTextRangoX2().setEditable(true);
637
                        getJTextRangoY1().setEnabled(true);
638
                        getJTextRangoY1().setEditable(true);
639
                        getJTextRangoY2().setEditable(true);
640
                        getJTextRangoY2().setEnabled(true);
641
                        getJTextCellSize().setEditable(true);
642
                        getJTextCellSize().setEnabled(true);
643
                        updateParams();
644
                }
645
                
646
        
647
                // RadioButtom4
648
                else  if (e.getSource()==getRButtom4()){
649
                        
650
                        DesabilitarTodo();
651
                        rButtom4.setSelected(true);
652
                        jComboCapas.setEnabled(true);
653
                        jTextCellSize.setEditable(true);
654
                        jTextCellSize.setEnabled(true);
655
                        getJComboCapas().updateUI();
656
                        updateParams();
657
                }
658
                
659
                else  if (e.getSource()==getRadioFile()){
660
                        rButtonFile.setSelected(true);
661
                }
662
                
663
                else  if (e.getSource()==getRadioMemory()){
664
                        rButtonMemory.setSelected(true);
665
                }
666
                        
667
                // ComboCapas        
668
                else if (e.getSource()==getJComboCapas()){
669
                        updateParams();
670
                                
671
                }
672
        }
673

    
674
        /** 
675
         *  Actualizacion de los parametros ajustandolos a los de la capa seleccionada
676
         */
677
        private void updateParams(){
678
                double dCoord;        
679
                if (getRButtom4().isSelected()){
680
                        try {
681
                                FLyrRasterSE rasterLayer = (FLyrRasterSE)mapContext.getLayers().getLayer((String)getJComboCapas().getSelectedItem());        
682
                                dCoord = rasterLayer.getFullExtent().getMinX();
683
                                getJTextRangoX1().setText(new Double(dCoord).toString());
684
                                dCoord = rasterLayer.getFullExtent().getMaxX();
685
                                getJTextRangoX2().setText(new Double(dCoord).toString());
686
                                dCoord = rasterLayer.getFullExtent().getMinY();
687
                                getJTextRangoY1().setText(new Double(dCoord).toString());
688
                                dCoord = rasterLayer.getFullExtent().getMaxY();
689
                                getJTextRangoY2().setText(new Double(dCoord).toString());
690
                                if (rasterLayer instanceof FLyrRasterSE){
691
                                        getJTextCellSize().setText(new Double(
692
                                                        ((FLyrRasterSE) rasterLayer).getBufferFactory().getXCellSize())
693
                                                        .toString());
694
                                }
695
                                extentHasChanged();
696
                        } catch (Exception ex) {}        
697
                }
698
                
699
        }
700
        
701

    
702
        
703
        /**
704
         * Establece el extent de salida ajustandolo a los datos de entrada. 
705
         */
706
        private void setAjustInDataExtent(){
707
                // Si no hay variables asignadas no hace nada. No dejara lanzar el calculo
708
                if( cp.getJTableVariables().getTableFormat().getRowCount()>0 && cp.getJTableVariables().getTableFormat().getValueAt(0,1).toString()!=""){
709
                
710
                        String layerName = cp.getJTableVariables().getTableFormat().getValueAt(0,1).toString();
711
                        layerName = layerName.substring(0,layerName.indexOf("["));
712
                        FLyrRasterSE rasterLayer = (FLyrRasterSE)mapContext.getLayers().getLayer(layerName);
713
                
714
                        double xMin =rasterLayer.getBufferFactory().getExtent().minX();
715
                        double xMax =rasterLayer.getBufferFactory().getExtent().maxX();
716
                        double yMin =rasterLayer.getBufferFactory().getExtent().minY();
717
                        double yMax =rasterLayer.getBufferFactory().getExtent().maxY();
718
                        double cellSize=rasterLayer.getBufferFactory().getXCellSize();
719
                
720
                        for (int i=0;i<cp.getJTableVariables().getTableFormat().getRowCount();i++){
721
                                layerName = cp.getJTableVariables().getTableFormat().getValueAt(i,1).toString();
722
                                layerName = layerName.substring(0,layerName.indexOf("["));
723
                                rasterLayer = (FLyrRasterSE)mapContext.getLayers().getLayer(layerName);
724
                        
725
                                xMin = Math.min(xMin,rasterLayer.getBufferFactory().getExtent().minX());
726
                                xMax = Math.max(rasterLayer.getBufferFactory().getExtent().maxX(),xMax);
727
                                yMin = Math.min(yMin,rasterLayer.getBufferFactory().getExtent().minY());
728
                                yMax = Math.max(yMax,rasterLayer.getBufferFactory().getExtent().maxY());
729
                                cellSize = Math.min(cellSize,rasterLayer.getBufferFactory().getXCellSize());
730
                        }
731
                
732
                        cp.getOutputExtent().setXRange(xMin,xMax);
733
                        cp.getOutputExtent().setYRange(yMin,yMax);
734
                        cp.getOutputExtent().setCellSize(cellSize);
735
                
736
                        getJTextRangoX1().setText(String.valueOf(cp.getOutputExtent().minX()));
737
                        getJTextRangoX2().setText(String.valueOf(cp.getOutputExtent().maxX()));
738
                        getJTextRangoY1().setText(String.valueOf(cp.getOutputExtent().minY()));
739
                        getJTextRangoY2().setText(String.valueOf(cp.getOutputExtent().maxY()));
740
                        getJTextCellSize().setText(String.valueOf(cellSize));
741
                        cp.getOutputExtent().setCellSize(cellSize);
742
                        extentHasChanged();
743
                }         
744
        }
745
        
746
        /**
747
         * Eventos del teclado 
748
         */
749
        public void keyReleased(KeyEvent e) {
750

    
751
                if(e.getSource()==getJTextRangoX1()){
752
                        validateKeyTyping(e);
753
                }
754
                
755
                if(e.getSource()==getJTextRangoX2()){
756
                        validateKeyTyping(e);
757
                }
758
                
759
                if(e.getSource()==getJTextRangoY1()){
760
                        validateKeyTyping(e);
761
                }
762
                
763
                if(e.getSource()==getJTextRangoY2()){
764
                        validateKeyTyping(e);
765
                }
766
                
767
                if (e.getSource()==getJTextCellSize()){
768
                        
769
                        validateKeyTyping(e);
770
                }
771
        }
772
        
773
        /**
774
         * Especificar el nombre de la nueva capa para el recuadro de texto asign?ndo
775
         * en cada llamada un nombre consecutivo.
776
         */
777
        public void setNewLayerText() {
778
                getJTextNombreCapa().setText("NewLayer_" + RasterModule.layerCount);
779
                RasterModule.layerCount++;
780
        }
781

    
782

    
783
        
784
        public void focusGained(FocusEvent arg0) {
785
                // TODO Auto-generated method stub
786
                
787
        }
788

    
789
        public void focusLost(FocusEvent arg0) {
790
                // TODO Auto-generated method stub
791
                
792
        }
793

    
794

    
795

    
796
        public void keyPressed(KeyEvent arg0) {
797
                // TODO Auto-generated method stub
798
                
799
        }
800

    
801
        
802
        
803
        public void keyTyped(KeyEvent arg0) {
804
                // TODO Auto-generated method stub
805
                
806
        }
807
}