Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRemoteSensing / src / es / idr / teledeteccion / gridmath / gui / OutputOptionsPanel.java @ 12184

History | View | Annotate | Download (29.2 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 es.idr.teledeteccion.gridmath.gui;
42

    
43
import info.clearthought.layout.TableLayout;
44

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

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

    
71
import org.gvsig.fmap.layers.FLyrRasterSE;
72
import org.gvsig.gui.beans.incrementabletask.IncrementableTask;
73
import org.gvsig.raster.buffer.RasterBufferInvalidException;
74
import org.gvsig.raster.grid.Grid;
75
import org.gvsig.rastertools.RasterModule;
76

    
77
import com.iver.andami.PluginServices;
78
import com.iver.andami.ui.mdiManager.IWindow;
79
import com.iver.andami.ui.mdiManager.WindowInfo;
80
import com.iver.cit.gvsig.fmap.MapContext;
81
import com.iver.cit.gvsig.fmap.layers.FLayer;
82
import com.iver.cit.gvsig.fmap.layers.FLayers;
83
import com.iver.cit.gvsig.project.documents.view.gui.View;
84

    
85
import es.idr.teledeteccion.gridmath.GridMathProcess;
86

    
87

    
88
/**Clase que implementa la interfaz de configuracion del extent de salida del resultado de 
89
 * @author Alejandro Mu?oz
90
 *
91
 */
92
public class OutputOptionsPanel extends JPanel implements IWindow,ActionListener,FocusListener,KeyListener {
93
        
94
        
95
        private static final long serialVersionUID = 1L;
96
        private JButton aceptar = null;
97
        private JButton cancelar = null;
98
        
99
        private JPanel namePanel = null;
100
        private JPanel panelExtension = null;
101
        private JPanel paramPanel = null;
102
        
103
        private JTextField jTextNombreCapa = null;
104
        private JTextField  jTextRangoX1 = null;
105
        private JTextField  jTextRangoX2 = null;
106
        private JTextField jTextRangoY1 = null;
107
        private JTextField jTextRangoY2 = null;
108
        private JTextField jTextCellSize = null;
109
        private JTextField  jTextNumFiCol1 = null;
110
        private JTextField jTextNumFiCol2 = null;
111
        private FLayers layers = null;
112
        
113
        private JLabel etiq4 = null;
114
        
115
        private JRadioButton rButtom1 = null;
116
        private JRadioButton rButtom2 = null;
117
        private JRadioButton rButtom3 = null;
118
        private JRadioButton rButtom4 = null;
119
        
120
        private JRadioButton rButtonFile = null;
121
        private JRadioButton rButtonMemory = null;
122
        
123
        private JComboBox jComboCapas = null;
124
        private MapContext mapContext = null;
125
        
126
        private int wPanel=780;
127
        private int hPanel=325;
128
        private CalculatorPanel cp = null;
129
        
130
        // Constructor que toma como parametros la vista de la aplicacion y el 
131
        // CalculatorPanel desde el que se invoca.
132
        public OutputOptionsPanel(View vista, CalculatorPanel cp) {
133
                
134
                super();        
135
                if (vista!=null){
136
                        mapContext = vista.getModel().getMapContext();        
137
                        layers = mapContext.getLayers();
138
                }
139
                this.cp=cp;
140
                Inicializar();
141
                //InicializarOpcion();
142
        }
143
        
144
        
145
        // Inicializa el cuadro de dialogo
146
        public void  Inicializar(){
147
                BorderLayout bd=new BorderLayout();
148
                this.setLayout(bd);
149
                this.setBorder( new EmptyBorder(10, 10, 10, 10));
150
                this.add(getNamePanel(),BorderLayout.NORTH);
151
                this.add(getPanelExtension(),BorderLayout.WEST);
152
                this.add(getParameterPanel(),BorderLayout.CENTER);
153
                this.setNewLayerText();
154
                getRadioMemory().setSelected(true);
155
        }
156
        
157
        
158
        public WindowInfo getWindowInfo() {
159
                
160
                WindowInfo m_viewinfo = new WindowInfo(WindowInfo.RESIZABLE);
161
                //Establecer el tamao del formulario
162
                m_viewinfo.setWidth(wPanel);
163
                m_viewinfo.setHeight(hPanel);
164
                //Establecer el ttulo del formulario
165
                m_viewinfo.setTitle(PluginServices.getText(this,"Configuracion de salida raster"));
166
                //punto X de la pantalla donde se situa
167
                m_viewinfo.setX(80);
168
        
169
                return m_viewinfo;
170
        
171
}
172

    
173
        public JButton getAceptar() {
174
                
175
                if (aceptar==null){
176
                        aceptar=new JButton();
177
                        aceptar.setText(PluginServices.getText(this,"aceptar"));
178
                        aceptar.addActionListener(this);
179
                }
180
                return aceptar;
181
                
182
        }
183

    
184

    
185
        public JButton getCancelar() {
186
                
187
                if (cancelar==null){
188
                        cancelar=new JButton();
189
                        cancelar.setText(PluginServices.getText(this,"cancelar"));
190
                        cancelar.addActionListener(this);
191
                }
192
        
193
                return cancelar;
194
        }
195
        
196
        public JRadioButton getRadioFile(){
197
                if (rButtonFile == null){
198
                        rButtonFile = new JRadioButton(PluginServices.getText(this,"a_fichero"));
199
                        rButtonFile.addActionListener(this);
200
                }
201
                return rButtonFile;
202
        }
203
        
204
        public JRadioButton getRadioMemory(){
205
                if (rButtonMemory == null){
206
                        rButtonMemory = new JRadioButton(PluginServices.getText(this,"a_memoria"));
207
                        rButtonMemory.addActionListener(this);
208
                }
209
                return rButtonMemory;
210
        }
211

    
212
        /**
213
         * Panel con el para especificar el nombre de la capa y si se escribe en 
214
         * memoria o en disco.
215
         * 
216
         * @return JPanel
217
         */
218
        public JPanel getNamePanel() {
219
                
220
                if (namePanel==null){
221
                        namePanel=new JPanel();
222
                        
223
                        GridBagConstraints gridBagConstraints;
224
                        
225
                        JPanel radioPanel = new JPanel();
226
                        radioPanel.setLayout(new GridBagLayout());
227
                        radioPanel.setBorder(BorderFactory.createTitledBorder(""));
228
                        ButtonGroup buttonGroup = new ButtonGroup();
229
                        buttonGroup.add(getRadioMemory());
230
                        gridBagConstraints = new java.awt.GridBagConstraints();
231
                        gridBagConstraints.gridx = 0;
232
                        gridBagConstraints.gridy = 1;
233
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
234
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
235
                        radioPanel.add(getRadioMemory(),gridBagConstraints);
236
                        buttonGroup.add(getRadioFile());
237
                        gridBagConstraints = new java.awt.GridBagConstraints();
238
                        gridBagConstraints.gridx = 0;
239
                        gridBagConstraints.gridy = 2;
240
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
241
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
242
                        radioPanel.add(getRadioFile(),gridBagConstraints);
243
                 
244
                        //Establece la separacin entre los elementos
245
                        namePanel.setLayout(new GridBagLayout());
246
                        
247
                        gridBagConstraints = new java.awt.GridBagConstraints();
248
                        gridBagConstraints.gridx = 0;
249
                        gridBagConstraints.gridy = 0;
250
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
251
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
252
                        namePanel.add(getEtiq4(),gridBagConstraints);
253
                        
254
                        gridBagConstraints = new java.awt.GridBagConstraints();
255
                        gridBagConstraints.gridx = 1;
256
                        gridBagConstraints.gridy = 0;
257
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
258
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
259
                        namePanel.add(getJTextNombreCapa(),gridBagConstraints);
260
                        
261
                        gridBagConstraints = new java.awt.GridBagConstraints();
262
                        gridBagConstraints.gridx = 2;
263
                        gridBagConstraints.gridy = 0;
264
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
265
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
266
                        namePanel.add(radioPanel,gridBagConstraints);
267
                }
268
                        
269
                return namePanel;
270
        }
271

    
272

    
273

    
274
    // TextField NombreCapa
275
        public JTextField getJTextNombreCapa() {
276
                
277
                if (jTextNombreCapa==null){
278
                        
279
                        jTextNombreCapa=new JTextField(15);
280
                        jTextNombreCapa.addFocusListener(this);
281

    
282
                }
283
                
284
                return jTextNombreCapa;
285
        }
286

    
287

    
288

    
289
        // Etiqueta 
290
        public JLabel getEtiq4() {
291
                
292
                if(etiq4==null){
293
                        etiq4 = new JLabel( (PluginServices.getText(this,"nombre_capa")),SwingConstants.RIGHT );
294
                        
295
                }                
296
                return etiq4;
297
        }
298

    
299

    
300

    
301
        /*Panel PanelExtension, los radioButton y el comboCapas */
302
        public JPanel getPanelExtension() {
303
                
304
                
305
                if (panelExtension==null){
306
                        
307
                        panelExtension=new JPanel();
308
                        TitledBorder topBorder = BorderFactory.createTitledBorder((PluginServices.getText(this,"extension_from")));
309
                    topBorder.setTitlePosition(TitledBorder.TOP);
310
                    panelExtension.setBorder(new CompoundBorder(topBorder,new EmptyBorder(0,5,6,5)));
311
                        
312
                    JPanel p=new JPanel();
313
                    p.setPreferredSize(new Dimension(250,120));
314
                                TableLayout thisLayout = new TableLayout(new double[][] {
315
                                                {50, TableLayout.PREFERRED},         
316
                                                {TableLayout.PREFERRED,TableLayout.PREFERRED,TableLayout.PREFERRED, TableLayout.PREFERRED,TableLayout.PREFERRED }}); 
317
                                                //Establece la separacin entre los elementos
318
                                                thisLayout.setHGap(5);
319
                                                thisLayout.setVGap(5);
320
                                                p.setLayout(thisLayout);
321
                                                p.add(getRButtom1(),"1,0");
322
                                                p.add(getRButtom2(),"1,1");
323
                                                p.add(getRButtom3(),"1,2");
324
                                                p.add(getRButtom4(),"1,3");
325
                                                p.add(getJComboCapas(),"1,4");
326
                                
327
                     panelExtension.add(p);
328
                }
329
                
330
                return panelExtension;
331
        }
332

    
333

    
334
        /*Panel ParameterPanel, con cada uno de los parametros de configuracin de la salida raster. */
335
        public JPanel getParameterPanel() {
336
                
337
                
338
                if (paramPanel==null){
339
                        paramPanel=new JPanel();
340
                        TitledBorder topBorder = BorderFactory.createTitledBorder((PluginServices.getText(this,"parametros")));
341
                    topBorder.setTitlePosition(TitledBorder.TOP);
342
                    paramPanel.setBorder(new CompoundBorder(topBorder,new EmptyBorder(0,5,6,5)));
343
                        
344
                    
345
                    JPanel p=new JPanel();
346
                    p.setPreferredSize(new Dimension(320,130));
347
                        TableLayout thisLayout = new TableLayout(new double[][] {
348
                                 {150,75, 75},         
349
                                {3,20,20,20,20}}); 
350
                                //Establece la separacin entre los elementos
351
                                thisLayout.setHGap(5);
352
                                thisLayout.setVGap(10);
353
                                p.setLayout(thisLayout);
354
                                
355
                                //Aado los diferentes elementos
356
                                p.add(new JLabel((PluginServices.getText(this,"rangox"))),"0,1");
357
                                p.add(new JLabel((PluginServices.getText(this,"rangoy"))),"0,2");
358
                                p.add(new JLabel((PluginServices.getText(this,"tamanio_celda"))),"0,3");
359
                                p.add(new JLabel((PluginServices.getText(this,"num_filas_columnas"))),"0,4");
360
                                p.add(getJTextCellSize(),"1,3");
361
                                p.add(getJTextNumFiCol1(),"1,4");
362
                                p.add(getJTextNumFiCol2(),"2,4");
363
                                p.add(getJTextRangoX1(),"1,1");
364
                                p.add(getJTextRangoX2(),"2,1");
365
                                p.add(getJTextRangoY1(),"1,2");
366
                                p.add(getJTextRangoY2(),"2,2");
367
                                
368
                                paramPanel.add(p);
369
                }
370
                return paramPanel;
371
        }
372

    
373
        
374

    
375
        //RadioButton1
376
        public JRadioButton getRButtom1() {
377
                if(rButtom1==null){
378
                        rButtom1=new JRadioButton((PluginServices.getText(this,"ajustar_entrada")), true);
379
                        rButtom1.addActionListener(this);
380
                        }
381
                return rButtom1;
382
        }
383

    
384

    
385

    
386
        //RadioButton2
387
        public JRadioButton getRButtom2() {
388
                if(rButtom2==null){
389
                        rButtom2=new JRadioButton((PluginServices.getText(this,"definida_usuario")), false);
390
                        rButtom2.addActionListener(this);
391
                }
392
                return rButtom2;
393
        }
394

    
395

    
396

    
397
        //RadioButton3
398
        public JRadioButton getRButtom3() {
399
                if(rButtom3==null){
400
                        rButtom3=new JRadioButton((PluginServices.getText(this,"extension_vista")), false);
401
                        rButtom3.addActionListener(this);                        
402
                }
403
                return rButtom3;
404
        }
405

    
406

    
407

    
408

    
409
        //RadioButton4
410
        public JRadioButton getRButtom4() {
411
                if(rButtom4==null){
412
                        rButtom4=new JRadioButton((PluginServices.getText(this,"extension_capa")), false);
413
                        rButtom4.addActionListener(this);        
414
                }
415
                return rButtom4;
416
        }
417

    
418

    
419
        // Tamo de celda
420
        public JTextField getJTextCellSize() {
421
                
422
                if (jTextCellSize==null){
423
                        jTextCellSize=new JTextField();
424
                        jTextCellSize.setEditable(false);
425
                        jTextCellSize.addKeyListener(this);   
426
                }
427
                
428
                return jTextCellSize;
429
        }
430

    
431

    
432
        // Numero filas
433
        public JTextField getJTextNumFiCol1() {
434
                
435
                if (jTextNumFiCol1==null){
436
                        jTextNumFiCol1=new JTextField ();
437
                        jTextNumFiCol1.setEditable(false);
438
                
439
                        
440
                }
441
                
442
                return jTextNumFiCol1;
443
        }
444

    
445

    
446

    
447
        // Rango x inferior
448
        public JTextField  getJTextRangoX1() {
449

    
450
                if (jTextRangoX1==null){
451
                                        
452
                        jTextRangoX1 =new JTextField ();
453
                        jTextRangoX1.setEditable(false);
454
                        jTextRangoX1.addKeyListener(this);        
455
                        
456
                }
457
                
458
                
459
                return jTextRangoX1;
460
        }
461

    
462

    
463

    
464
        // Rango x superior
465
        public JTextField getJTextRangoX2() {
466

    
467
                if (jTextRangoX2==null){
468
                        jTextRangoX2=new JTextField ();
469
                        jTextRangoX2.setEditable(false);
470
                        jTextRangoX2.addKeyListener(this);
471
                        
472
                }
473
                return jTextRangoX2;
474
        }
475

    
476

    
477

    
478
        // Rango y inferior
479
        public JTextField  getJTextRangoY1() {
480

    
481
                if (jTextRangoY1==null){
482
                        jTextRangoY1=new JTextField ();
483
                        jTextRangoY1.setEditable(false);
484
                        jTextRangoY1.addKeyListener(this);
485
                        }
486
                return jTextRangoY1;
487
        }
488

    
489

    
490
        // Rango y superior
491
        public JTextField  getJTextRangoY2() {
492

    
493
                if (jTextRangoY2==null){
494
                        jTextRangoY2=new JTextField ();
495
                        jTextRangoY2.setEditable(false);
496
                        jTextRangoY2.addKeyListener(this);
497
                }
498
                return jTextRangoY2;
499
        }
500

    
501

    
502

    
503
        // Numero columnas
504
        public JTextField getJTextNumFiCol2() {
505
                
506
                if (jTextNumFiCol2==null){
507
                        jTextNumFiCol2=new JTextField ();
508
                        jTextNumFiCol2.setEditable(false);
509
                        
510
                }
511
                return jTextNumFiCol2;
512
        }
513

    
514

    
515

    
516
    // JComboCapas
517
        public JComboBox getJComboCapas() {
518
                
519
                if (jComboCapas==null){
520
                        ComboBoxModel jComboBoxLayersModel = new DefaultComboBoxModel(getLayerNames());
521
                        jComboCapas = new JComboBox();
522
                        jComboCapas.setModel(jComboBoxLayersModel);
523
                        jComboCapas.setEnabled(false);
524
                        jComboCapas.addActionListener(this);
525
                }
526
                                
527
                                        
528
                return jComboCapas;
529
        }
530

    
531

    
532
        // Devuelve el nombre de los ficheros cargados actualmente
533
        private String[] getLayerNames() {
534
                String[] sNames = {};
535
                if (layers!=null){
536
                        sNames = new String[layers.getLayersCount()];
537
                        for (int i = 0; i < layers.getLayersCount(); i++) {                      
538
                                sNames[i] = (layers.getLayer(i)).getName();
539
                        }
540
                }    
541
                return sNames;
542
        }
543

    
544
        // Establece la opcion por defecto cuando se crea el cuadro de dialogo. El extent por defecto, 
545
        public void InicializarOpcion(){
546
                
547
                DesabilitarTodo();
548
                rButtom1.setSelected(true);
549
                
550
                // Comprobar que todas las variables estan asignadas
551
                boolean allAssigned = false;
552
                for (int i=0; i<cp.getJTableVariables().getTableFormat().getRowCount(); i++){
553
                        allAssigned = true;
554
                        if (cp.getJTableVariables().getTableFormat().getValueAt(i,1).toString().equals(""))
555
                        { 
556
                                allAssigned=false; 
557
                                break;
558
                        }
559
                }
560
                
561
                if(allAssigned){
562
                        
563
                        String layerName = cp.getJTableVariables().getTableFormat().getValueAt(0,1).toString();
564
                        layerName = layerName.substring(0,layerName.indexOf("["));
565
                        FLyrRasterSE rasterLayer = (FLyrRasterSE)mapContext.getLayers().getLayer(layerName);
566
                        
567
                        double xMin =rasterLayer.getDatasource().getExtent().minX();
568
                        double xMax =rasterLayer.getDatasource().getExtent().maxX();
569
                        double yMin =rasterLayer.getDatasource().getExtent().minY();
570
                        double yMax =rasterLayer.getDatasource().getExtent().maxY();
571
                        double cellSize=rasterLayer.getDatasource().getXCellSize();
572
                        
573
                        for (int i=0;i<cp.getJTableVariables().getTableFormat().getRowCount();i++){
574
                                layerName = cp.getJTableVariables().getTableFormat().getValueAt(i,1).toString();
575
                                layerName = layerName.substring(0,layerName.indexOf("["));
576
                                rasterLayer = (FLyrRasterSE)mapContext.getLayers().getLayer(layerName);
577
                                
578
                                xMin = Math.min(xMin,rasterLayer.getDatasource().getExtent().minX());
579
                                xMax = Math.max(rasterLayer.getDatasource().getExtent().maxX(),xMax);
580
                                yMin = Math.min(yMin,rasterLayer.getDatasource().getExtent().minY());
581
                                yMax = Math.max(yMax,rasterLayer.getDatasource().getExtent().maxY());
582
                                cellSize = Math.min(cellSize,rasterLayer.getDatasource().getXCellSize());                                
583
                        }
584
                        cp.getOutputExtent().setXRange(xMin,xMax);
585
                        cp.getOutputExtent().setYRange(yMin,yMax);
586
                        cp.getOutputExtent().setCellSize(cellSize);
587
                        getJTextRangoX1().setText(String.valueOf(cp.getOutputExtent().minX()));
588
                        getJTextRangoX2().setText(String.valueOf(cp.getOutputExtent().maxX()));
589
                        getJTextRangoY1().setText(String.valueOf(cp.getOutputExtent().minY()));
590
                        getJTextRangoY2().setText(String.valueOf(cp.getOutputExtent().maxY()));
591
                        getJTextCellSize().setText(String.valueOf(cellSize));
592
                        cp.getOutputExtent().setCellSize(cellSize);
593
                        extentHasChanged();
594
                }
595
        }
596

    
597
        
598
        // Desabilita los componentes variables de la interfaz
599
        public void DesabilitarTodo(){
600
                
601
                rButtom1.setSelected(false);
602
                rButtom2.setSelected(false);
603
                rButtom3.setSelected(false);
604
                rButtom4.setSelected(false);
605
                jComboCapas.setEnabled(false);
606
                jTextRangoX1.setEditable(false);
607
        
608
                jTextRangoX1.setEnabled(false);
609
                jTextRangoX2.setEditable(false);
610
                jTextRangoX2.setEnabled(false);
611
                jTextRangoY1.setEditable(false);
612
                jTextRangoY1.setEnabled(false);
613
                jTextRangoY2.setEditable(false);
614
                jTextRangoY2.setEnabled(false);
615
                jTextNumFiCol1.setEditable(false);
616
                jTextCellSize.setEditable(false);
617
                jTextCellSize.setEnabled(false);
618
                jTextNumFiCol1.setEnabled(false);
619
                jTextNumFiCol2.setEditable(false);
620
                jTextNumFiCol2.setEnabled(false);
621
                jComboCapas.updateUI();
622
                
623
        }
624
        
625
        
626
public void extentHasChanged(){
627
                
628
                double dRangeX;
629
                double dRangeY;
630
                double dCellSize;
631
                int iRows;
632
                int iCols;
633
                // Se actualiza la X                
634
                try {
635
                        dRangeX = Math.abs(Double.parseDouble(getJTextRangoX2().getText())
636
                                                                - Double.parseDouble(getJTextRangoX1().getText()));
637
                        dCellSize = Double.parseDouble(getJTextCellSize().getText());        
638
                        iCols = (int) Math.floor(dRangeX / dCellSize);
639
                        getJTextNumFiCol2().setText(Integer.toString(iCols));
640
                
641
                } catch (NumberFormatException e) {
642
                                e.printStackTrace();
643
                        return;
644
                }
645
                
646
                // Se actualiza la Y        
647
                try {
648
                dRangeY = Math.abs(Double.parseDouble(getJTextRangoY2().getText())
649
                                        - Double.parseDouble(getJTextRangoY1().getText()));
650
                        dCellSize = Double.parseDouble(getJTextCellSize().getText());                        
651
                        iRows = (int) Math.floor(dRangeY / dCellSize);
652
                        getJTextNumFiCol1().setText(Integer.toString(iRows));
653
                        
654
                        
655
                } catch (NumberFormatException e) {
656
                        
657
                        e.printStackTrace();
658
                        return;
659
                }
660
}
661
        
662
        private void validateKeyTyping(KeyEvent event) {
663
                String text = ((JTextField)event.getSource()).getText();
664
                jComboCapas.updateUI();
665
                switch (event.getKeyChar()) {
666
                        
667
                        case KeyEvent.VK_ENTER:
668
                                extentHasChanged();
669
                                jComboCapas.updateUI();
670
                                break;
671
                        
672
                        case KeyEvent.VK_BACK_SPACE:
673
                                extentHasChanged();
674
                                break;
675
                        case KeyEvent.VK_0 :
676
                                extentHasChanged();
677
                                break;
678
                        case KeyEvent.VK_1 :
679
                                extentHasChanged();
680
                                break;
681
                        case KeyEvent.VK_2 :
682
                                extentHasChanged();
683
                                break;
684
                        case KeyEvent.VK_3:
685
                                extentHasChanged();
686
                                break;
687
                        case KeyEvent.VK_4:  
688
                                extentHasChanged();
689
                                break;
690
                        case KeyEvent.VK_5: 
691
                                extentHasChanged();
692
                                break;
693
                        case KeyEvent.VK_6: 
694
                                extentHasChanged();
695
                                break;
696
                        case KeyEvent.VK_7: 
697
                                extentHasChanged();
698
                                break;
699
                        case KeyEvent.VK_8: 
700
                                extentHasChanged();
701
                                break;
702
                        case KeyEvent.VK_9 :                        
703
                                extentHasChanged();
704
                                break;
705
                }
706
        }
707
        
708
        public void actionPerformed(ActionEvent e) {
709
                
710
                if (e.getSource()==getAceptar()){
711
                                //FLyrRaster outpuLayer = null;
712
                                //RasterMemoryDriver outputRMD = null;
713
                                int nBand;
714
                                String layerBand;
715
                                String layerName;
716
                                FLyrRasterSE rasterLayer;
717
                                Grid qWindow;
718
                                
719
                                
720
                                // Opcion  de RadioButton2
721
                                if (getRButtom2().isSelected()){
722
                                        cp.getOutputExtent().setXRange(Double.parseDouble(jTextRangoX1.getText()),Double.parseDouble(jTextRangoX2.getText()));
723
                                        cp.getOutputExtent().setYRange(Double.parseDouble(jTextRangoY1.getText()), Double.parseDouble(jTextRangoY2.getText()));
724
                                        cp.getOutputExtent().setCellSize(Double.parseDouble(jTextCellSize.getText()));        
725
                                }
726
                
727
                                
728
                                //        Opcion del RadioButton4
729
                                if(getRButtom4().isSelected()){
730
                                        
731
                                        
732
                                        try {
733
                                                double dCoord;        
734
                                                FLayer layer = layers.getLayer(jComboCapas.getSelectedIndex());        
735
                                                
736
                                                cp.getOutputExtent().setXRange(layer.getFullExtent().getMinX(),
737
                                                                layer.getFullExtent().getMaxX());
738
                                                cp.getOutputExtent().setYRange(dCoord = layer.getFullExtent().getMinY(),
739
                                                                layer.getFullExtent().getMaxY());
740
                                                
741
                                                cp.getOutputExtent().setCellSize(Double.parseDouble(jTextCellSize.getText()));
742
                                                /*if (layer instanceof FLyrRaster){
743
                                                        cp.getOutputExtent().setCellSize(((FLyrRaster) layer).getGrid().getXCellSize());
744
                                                }
745
                                                
746
                                                if (layer instanceof FLyrRaster){
747
                                                        getJTextCellSize().setText(String.valueOf(cp.getOutputExtent().getCellSize()));
748
                                                }*/
749
                                        
750
                                                extentHasChanged();
751
                                        } catch (Exception ex) {
752
                                                ex.printStackTrace();
753
                                        }
754
                                }
755
                                
756
                                cp.getGridMath().setResultExtent(cp.getOutputExtent());
757
                                
758
                                /*
759
                                 * Rellenar el HasMap con el Grid corespondiente a cada variable.
760
                                 */
761
                                for (int i=0;i<cp.getJTableVariables().getTableFormat().getRowCount();i++){
762
                                        layerBand= cp.getJTableVariables().getTableFormat().getValueAt(i,1).toString();
763
                                        layerName = layerBand.substring(0,layerBand.indexOf("["));
764
                                        nBand = Integer.valueOf(layerBand.substring(layerBand.lastIndexOf("Band")+4,layerBand.lastIndexOf("]"))).intValue();
765
                                        rasterLayer = (FLyrRasterSE)mapContext.getLayers().getLayer(layerName);
766
                                        qWindow=null;
767
                                        try {
768
                                                qWindow = new Grid(rasterLayer.getDatasource(),new int[]{nBand-1});
769
                                        
770
                                        } catch (RasterBufferInvalidException e1) {
771
                                                // TODO Auto-generated catch block
772
                                                e1.printStackTrace();
773
                                        }
774
                                        // Establecer el m?todo de interpolaci?n.
775
                                        /*if (rasterLayer.getDatasource().getDataType() ==  DataBuffer.TYPE_FLOAT  ||
776
                                                        rasterLayer.getDatasource().getDataType() ==  DataBuffer.TYPE_DOUBLE)
777
                                                qWindow.setInterpolationMethod(GrGridWrapperInterpolated.INTERPOLATION_BSpline);
778
                                        else
779
                                                qWindow.setInterpolationMethod(GridWrapperInterpolated.INTERPOLATION_NearestNeighbour);*/
780
                                        cp.getQWindowsHash().put(cp.getJTableVariables().getTableFormat().getValueAt(i,0).toString(),qWindow);
781
                                }                                
782
                                cp.getGridMath().setParams(cp.getQWindowsHash());
783
                                
784
                                /*
785
                                 * Lanzar el c?lculo.
786
                                 */
787
                                //String expression, HashMap params
788
                                
789
                                GridMathProcess process = new GridMathProcess(cp.getJTextExpression().getText(),cp.getGridMath().getParams(),cp.getOutputExtent(),mapContext,getJTextNombreCapa().getText());
790
                                IncrementableTask incrementableTask = new IncrementableTask(process);
791
                                process.setIncrementableTask(incrementableTask);
792
                                incrementableTask.showWindow();
793
                            process.start();
794
                                incrementableTask.start();        
795
                                PluginServices.getMDIManager().closeWindow(this);        
796
                                
797
                }
798
                
799
                   else if (e.getSource()==getCancelar()){
800
                           
801
                PluginServices.getMDIManager().closeWindow(this);
802
                }
803
        
804
                //Radiobutton1
805
                else  if (e.getSource()==getRButtom1()){
806
                        
807
                        InicializarOpcion();
808
                        
809
                }
810
        
811
                // RadioButtom2
812
                else  if (e.getSource()==getRButtom2()){
813
                        
814
                        DesabilitarTodo();
815
                        rButtom2.setSelected(true);
816
                        getJTextRangoX1().setEnabled(true);
817
                        getJTextRangoX1().setEditable(true);
818
                        getJTextRangoX2().setEnabled(true);
819
                        getJTextRangoX2().setEditable(true);
820
                        getJTextRangoY1().setEnabled(true);
821
                        getJTextRangoY1().setEditable(true);
822
                        getJTextRangoY2().setEditable(true);
823
                        getJTextRangoY2().setEnabled(true);
824
                        getJTextCellSize().setEditable(true);
825
                        getJTextCellSize().setEnabled(true);
826
                        //getJTextCellSize().setText("1.0");
827
                        
828
                        /*try {
829
                                //cp.getOutputExtent().setXRange
830
                                cp.getOutputExtent().setXRange(new Double(getJTextRangoX1().getText()).doubleValue(), new Double(getJTextRangoX2().getText()).doubleValue());
831
                                cp.getOutputExtent().setXRange(new Double(getJTextRangoY1().getText()).doubleValue(), new Double(getJTextRangoY2().getText()).doubleValue());
832
                                cp.getOutputExtent().setCellSize(1.0);
833
                                
834
                                getJTextRangoX1().setText(String.valueOf(cp.getOutputExtent().getXMin()));
835
                                getJTextRangoX2().setText(String.valueOf(cp.getOutputExtent().getXMax()));
836
                                getJTextRangoY1().setText(String.valueOf(cp.getOutputExtent().getYMin()));
837
                                getJTextRangoY2().setText(String.valueOf(cp.getOutputExtent().getYMax()));
838
                                
839
                                dCoord =m_MapContext.getViewPort().getAdjustedExtent().getMinX();
840
                                getJTextRangoX1().setText(new Double(dCoord).toString());
841
                                dCoord = m_MapContext.getViewPort().getAdjustedExtent().getMaxX();
842
                                getJTextRangoX2().setText(new Double(dCoord).toString());
843
                                dCoord =m_MapContext.getViewPort().getAdjustedExtent().getMinY();
844
                                getJTextRangoY1().setText(new Double(dCoord).toString());
845
                                dCoord = m_MapContext.getViewPort().getAdjustedExtent().getMaxY();
846
                                getJTextRangoY2().setText(new Double(dCoord).toString());
847
                                //setTextFieldsEnabled(false);                                                
848
                                extentHasChanged();
849
                        } catch (Exception ex) {}
850
                        
851
                        */
852
                }
853
                
854
        
855
                // RadioButtom3
856
                else  if (e.getSource()==getRButtom3()){
857
                        
858
                        DesabilitarTodo();
859
                        rButtom3.setSelected(true);
860
                        jTextCellSize.setEditable(true);
861
                        jTextCellSize.setEnabled(true);
862
                        getJTextCellSize().setText("1.0");
863
                        double dCoord;
864
                        
865
                        cp.getOutputExtent().setXRange(mapContext.getViewPort().getAdjustedExtent().getMinX(),
866
                                                mapContext.getViewPort().getAdjustedExtent().getMaxX());
867
                                
868
                        cp.getOutputExtent().setYRange(mapContext.getViewPort().getAdjustedExtent().getMinY(),
869
                                                mapContext.getViewPort().getAdjustedExtent().getMaxY());
870
                                
871
                                //Tomamos y Ajustamos para correcta visualizacion del double
872
                                dCoord= cp.getOutputExtent().minX();
873
                                getJTextRangoX1().setText(" "+String.valueOf(dCoord));
874
                                getJTextRangoX1().setHorizontalAlignment(JTextField.LEFT);
875
                                
876
                                // Tomamos y Ajustamos para correcta visualizacin el double
877
                                dCoord= cp.getOutputExtent().maxX();
878
                                getJTextRangoX2().setText(" "+String.valueOf(dCoord));
879
                                getJTextRangoX2().setHorizontalAlignment(JTextField.LEFT);
880
                                
881
                                //Tomamos y Ajustamos para correcta visualizacin el double
882
                                dCoord= cp.getOutputExtent().minY();
883
                                getJTextRangoY1().setText(" "+String.valueOf(dCoord));
884
                                getJTextRangoY1().setAlignmentX(JTextField.LEFT);
885
                                
886
                                //Tomamos y Ajustamos para correcta visualizacin el double
887
                                dCoord= cp.getOutputExtent().maxY();
888
                                getJTextRangoY2().setText(" "+String.valueOf(dCoord));
889
                                getJTextRangoY2().setAlignmentX(JTextField.LEFT);
890
                                
891
                                getJTextRangoX1().updateUI();        
892
                                getJTextRangoX2().updateUI();        
893
                                getJTextRangoY1().updateUI();        
894
                                getJTextRangoY2().updateUI();        
895
                                /*dCoord =m_MapContext.getViewPort().getAdjustedExtent().getMinX();
896
                                getJTextRangoX1().setText(new Double(dCoord).toString());
897
                                dCoord = m_MapContext.getViewPort().getAdjustedExtent().getMaxX();
898
                                getJTextRangoX2().setText(new Double(dCoord).toString());
899
                                dCoord =m_MapContext.getViewPort().getAdjustedExtent().getMinY();
900
                                getJTextRangoY1().setText(new Double(dCoord).toString());
901
                                dCoord = m_MapContext.getViewPort().getAdjustedExtent().getMaxY();
902
                                getJTextRangoY2().setText(new Double(dCoord).toString());*/
903
                                //setTextFieldsEnabled(false);                                                
904
                                extentHasChanged();
905
                }
906
        
907
                // RadioButtom4
908
                else  if (e.getSource()==getRButtom4()){
909
                        
910
                        DesabilitarTodo();
911
                        rButtom4.setSelected(true);
912
                        jComboCapas.setEnabled(true);
913
                        jTextCellSize.setEditable(true);
914
                        jTextCellSize.setEnabled(true);
915
                        getJComboCapas().updateUI();
916
                        textsFromLayer();
917
                }
918
                
919
                else  if (e.getSource()==getRadioFile()){
920
                        rButtonFile.setSelected(true);
921
                }
922
                
923
                else  if (e.getSource()==getRadioMemory()){
924
                        rButtonMemory.setSelected(true);
925
                }
926
                        
927
                // ComboCapas        
928
                else if (e.getSource()==getJComboCapas()){
929
                        textsFromLayer();
930
                                
931
                }
932
        }
933

    
934
        private void textsFromLayer(){
935
                double dCoord;        
936
                if (getRButtom4().isSelected()){
937
                        try {
938
                                FLayer layer = layers.getLayer(jComboCapas.getSelectedIndex());        
939
                                dCoord = layer.getFullExtent().getMinX();
940
                                getJTextRangoX1().setText(new Double(dCoord).toString());
941
                                dCoord = layer.getFullExtent().getMaxX();
942
                                getJTextRangoX2().setText(new Double(dCoord).toString());
943
                                dCoord = layer.getFullExtent().getMinY();
944
                                getJTextRangoY1().setText(new Double(dCoord).toString());
945
                                dCoord = layer.getFullExtent().getMaxY();
946
                                getJTextRangoY2().setText(new Double(dCoord).toString());
947
                                if (layer instanceof FLyrRasterSE){
948
                                        getJTextCellSize().setText(new Double(
949
                                                        ((FLyrRasterSE) layer).getDatasource().getXCellSize())
950
                                                        .toString());
951
                                }
952
                                extentHasChanged();
953
                        } catch (Exception ex) {}        
954
                }
955
                
956
        }
957
        
958
        // Eventos de teclado
959
        public void keyReleased(KeyEvent e) {
960

    
961
                if(e.getSource()==getJTextRangoX1()){
962
                        validateKeyTyping(e);
963
                }
964
                
965
                if(e.getSource()==getJTextRangoX2()){
966
                        validateKeyTyping(e);
967
                }
968
                
969
                if(e.getSource()==getJTextRangoY1()){
970
                        validateKeyTyping(e);
971
                }
972
                
973
                if(e.getSource()==getJTextRangoY2()){
974
                        validateKeyTyping(e);
975
                }
976
                
977
                if (e.getSource()==getJTextCellSize()){
978
                        
979
                        validateKeyTyping(e);
980
                }
981
        }
982
        
983
        /**
984
         * Especificar el nombre de la nueva capa para el recuadro de texto asign?ndo
985
         * en cada llamada un nombre consecutivo.
986
         */
987
        public void setNewLayerText() {
988
                getJTextNombreCapa().setText("NewLayer_" + RasterModule.layerCount);
989
                RasterModule.layerCount++;
990
        }
991

    
992

    
993
        
994
        
995

    
996
        
997
        public void focusGained(FocusEvent arg0) {
998
                // TODO Auto-generated method stub
999
                
1000
        }
1001

    
1002
        public void focusLost(FocusEvent arg0) {
1003
                // TODO Auto-generated method stub
1004
                
1005
        }
1006

    
1007

    
1008

    
1009
        public void keyPressed(KeyEvent arg0) {
1010
                // TODO Auto-generated method stub
1011
                
1012
        }
1013

    
1014
        
1015
        
1016
        public void keyTyped(KeyEvent arg0) {
1017
                // TODO Auto-generated method stub
1018
                
1019
        }
1020
}