Statistics
| Revision:

root / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / gridmath / gui / OutputOptionsPanel.java @ 18961

History | View | Annotate | Download (22.1 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.raster.RasterLibrary;
70
import org.gvsig.raster.util.PropertyEvent;
71
import org.gvsig.raster.util.PropertyListener;
72
import org.gvsig.raster.util.RasterToolsUtil;
73

    
74
import com.iver.andami.PluginServices;
75
import com.iver.cit.gvsig.fmap.MapContext;
76
import com.iver.cit.gvsig.fmap.layers.FLayers;
77
import com.iver.cit.gvsig.project.documents.view.gui.View;
78

    
79
/**
80
 * Panel de configuracion de las opciones de salida.
81
 * Puede ajustarse el extent de salida y las opciones habituales de salvado de la
82
 * capa.
83
 * 
84
 * @author Alejandro Mu?oz S?nchez (alejandro.munoz@uclm.es)
85
 * @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
86
 * @version 22/10/2007
87
 */
88
public class OutputOptionsPanel extends JPanel implements ActionListener,FocusListener,KeyListener,PropertyListener {
89

    
90
        private static final long serialVersionUID = 1L;        
91
        private JPanel namePanel = null;
92
        private JPanel panelExtension = null;
93
        private JPanel paramPanel = null;
94
        
95
        private JTextField jTextNombreCapa = null;
96
        private JTextField  jTextRangoX1 = null;
97
        private JTextField  jTextRangoX2 = null;
98
        private JTextField jTextRangoY1 = null;
99
        private JTextField jTextRangoY2 = null;
100
        private JTextField jTextCellSize = null;
101
        private JTextField  jTextNumFiCol1 = null;
102
        private JTextField jTextNumFiCol2 = null;
103
        private FLayers layers = null;
104
        
105
        private JRadioButton rButtom1 = null;
106
        private JRadioButton rButtom2 = null;
107
        private JRadioButton rButtom4 = null;
108
        private JRadioButton rButtonFile = null;
109
        private JRadioButton rButtonMemory = null;
110
        private JComboBox jComboCapas = null;
111
        private MapContext mapContext = null;
112
        private GridMathPanel cp = null;
113
        
114
        
115
        /**
116
        * Constructor
117
        * @param vista vista de la aplicaci?n
118
        * @param cp calculatorPanel desde el que se invoca
119
        */
120
        public OutputOptionsPanel(View vista, GridMathPanel cp) {
121
                super();        
122
                if (vista!=null){
123
                        mapContext = vista.getModel().getMapContext();        
124
                        layers = mapContext.getLayers();
125
                }
126
                this.cp=cp;
127
                Inicializar();
128
        }
129
        
130
        /**
131
         * Inicializaci?n del panel
132
         */
133
        public void  Inicializar(){
134
                BorderLayout bd=new BorderLayout();
135
                this.setLayout(bd);
136
                this.setBorder( new EmptyBorder(2, 2, 2, 2));
137
                this.add(getNamePanel(),BorderLayout.NORTH);
138
                this.add(getPanelExtension(),BorderLayout.WEST);
139
                this.add(getParameterPanel(),BorderLayout.CENTER);
140
                getRadioMemory().setSelected(true);        
141
        }
142
        
143

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

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

    
221

    
222
         /**
223
          * @return javax.swing.JTextField
224
          */        
225
         public JTextField getJTextNombreCapa() {
226
                if (jTextNombreCapa==null) {
227
                        jTextNombreCapa=new JTextField(10);
228
                        jTextNombreCapa.setText(RasterLibrary.getOnlyLayerName());
229
                        jTextNombreCapa.addFocusListener(this);
230
                        RasterLibrary.addOnlyLayerNameListener(this);
231
                }
232
                return jTextNombreCapa;
233
        }
234

    
235

    
236

    
237

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

    
274

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

    
316
        
317

    
318
        /**
319
         * @return JRadioButton  ajustar a datos de entrada
320
         */
321
        public JRadioButton getRButtom1() {
322
                if(rButtom1==null){
323
                        rButtom1=new JRadioButton((PluginServices.getText(this,"ajustar_entrada")), true);
324
                        rButtom1.addActionListener(this);
325
                        }
326
                return rButtom1;
327
        }
328

    
329

    
330

    
331
        /**
332
         * @return JRadioButton extension definida por el  usuario 
333
         */
334
        public JRadioButton getRButtom2() {
335
                if(rButtom2==null){
336
                        rButtom2=new JRadioButton((PluginServices.getText(this,"definida_usuario")), false);
337
                        rButtom2.addActionListener(this);
338
                }
339
                return rButtom2;
340
        }
341

    
342

    
343

    
344
        /**
345
         * @return JRadioButton extension ajustada a otra capa 
346
         */
347
        public JRadioButton getRButtom4() {
348
                if(rButtom4==null){
349
                        rButtom4=new JRadioButton((PluginServices.getText(this,"extension_capa")), false);
350
                        rButtom4.addActionListener(this);        
351
                }
352
                return rButtom4;
353
        }
354

    
355

    
356
        /**
357
         * @return JTextField tama?o de celda 
358
         */
359
        public JTextField getJTextCellSize() {
360
                if (jTextCellSize==null){
361
                        jTextCellSize=new JTextField(15);;
362
                        jTextCellSize.setEditable(false);
363
                        jTextCellSize.addKeyListener(this);   
364
                }
365
                return jTextCellSize;
366
        }
367

    
368

    
369
        
370
        /**
371
         * @return JTextField numero de filas
372
         */
373
        public JTextField getJTextNumFiCol1() {
374
                if (jTextNumFiCol1==null){
375
                        jTextNumFiCol1=new JTextField ();
376
                        jTextNumFiCol1.setEditable(false);
377
                }
378
                return jTextNumFiCol1;
379
        }
380

    
381

    
382

    
383
        /**
384
         * @return JTextField coordenada x m?nima
385
         */
386
        public JTextField  getJTextRangoX1() {
387
                if (jTextRangoX1==null){                        
388
                        jTextRangoX1 =new JTextField ();
389
                        jTextRangoX1.setEditable(false);
390
                        jTextRangoX1.addKeyListener(this);        
391
                        
392
                }
393
                return jTextRangoX1;
394
        }
395

    
396

    
397

    
398
        /**
399
         * @return JTextField coordenada x m?xima
400
         */
401
        public JTextField getJTextRangoX2() {
402
                if (jTextRangoX2==null){
403
                        jTextRangoX2=new JTextField ();
404
                        jTextRangoX2.setEditable(false);
405
                        jTextRangoX2.addKeyListener(this);
406
                        
407
                }
408
                return jTextRangoX2;
409
        }
410

    
411

    
412

    
413

    
414
        /**
415
         * @return JTextField coordenada y m?mnima
416
         */
417
        public JTextField  getJTextRangoY1() {
418
                if (jTextRangoY1==null){
419
                        jTextRangoY1=new JTextField ();
420
                        jTextRangoY1.setEditable(false);
421
                        jTextRangoY1.addKeyListener(this);
422
                        }
423
                return jTextRangoY1;
424
        }
425

    
426

    
427

    
428
        /**
429
         * @return JTextField coordenada y m?xima
430
         */
431
        public JTextField  getJTextRangoY2() {
432
                if (jTextRangoY2==null){
433
                        jTextRangoY2=new JTextField ();
434
                        jTextRangoY2.setEditable(false);
435
                        jTextRangoY2.addKeyListener(this);
436
                }
437
                return jTextRangoY2;
438
        }
439

    
440

    
441

    
442

    
443
        /**
444
         * @return JTextField numero de columnas
445
         */
446
        public JTextField getJTextNumFiCol2() {
447
                if (jTextNumFiCol2==null){
448
                        jTextNumFiCol2=new JTextField ();
449
                        jTextNumFiCol2.setEditable(false);                
450
                }
451
                return jTextNumFiCol2;
452
        }
453

    
454

    
455

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

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

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

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

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

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

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

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

    
779

    
780
        
781
        public void focusGained(FocusEvent arg0) {
782
                // TODO Auto-generated method stub
783
                
784
        }
785

    
786
        public void focusLost(FocusEvent arg0) {
787
                // TODO Auto-generated method stub
788
                
789
        }
790

    
791

    
792

    
793
        public void keyPressed(KeyEvent arg0) {
794
                // TODO Auto-generated method stub
795
                
796
        }
797

    
798
        
799
        
800
        public void keyTyped(KeyEvent arg0) {
801
                // TODO Auto-generated method stub
802
                
803
        }
804

    
805
        public void actionValueChanged(PropertyEvent e) {
806
                updateNewLayerText();        
807
        }
808
}