Statistics
| Revision:

root / trunk / extensions / extRemoteSensing / src / es / idr / teledeteccion / gridmath / gui / OutputOptionsPanel.java @ 12181

History | View | Annotate | Download (28.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 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

    
76
import com.iver.andami.PluginServices;
77
import com.iver.andami.ui.mdiManager.IWindow;
78
import com.iver.andami.ui.mdiManager.WindowInfo;
79
import com.iver.cit.gvsig.fmap.MapContext;
80
import com.iver.cit.gvsig.fmap.layers.FLayer;
81
import com.iver.cit.gvsig.fmap.layers.FLayers;
82
import com.iver.cit.gvsig.fmap.layers.FLyrRaster;
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
        }
154
        
155
        
156
        public WindowInfo getWindowInfo() {
157
                
158
                WindowInfo m_viewinfo = new WindowInfo(WindowInfo.RESIZABLE);
159
                //Establecer el tamao del formulario
160
                m_viewinfo.setWidth(wPanel);
161
                m_viewinfo.setHeight(hPanel);
162
                //Establecer el ttulo del formulario
163
                m_viewinfo.setTitle(PluginServices.getText(this,"Configuracion de salida raster"));
164
                //punto X de la pantalla donde se situa
165
                m_viewinfo.setX(80);
166
        
167
                return m_viewinfo;
168
        
169
}
170

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

    
182

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

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

    
270

    
271

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

    
280
                }
281
                
282
                return jTextNombreCapa;
283
        }
284

    
285

    
286

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

    
297

    
298

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

    
331

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

    
371
        
372

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

    
382

    
383

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

    
393

    
394

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

    
404

    
405

    
406

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

    
416

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

    
429

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

    
443

    
444

    
445
        // Rango x inferior
446
        public JTextField  getJTextRangoX1() {
447

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

    
460

    
461

    
462
        // Rango x superior
463
        public JTextField getJTextRangoX2() {
464

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

    
474

    
475

    
476
        // Rango y inferior
477
        public JTextField  getJTextRangoY1() {
478

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

    
487

    
488
        // Rango y superior
489
        public JTextField  getJTextRangoY2() {
490

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

    
499

    
500

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

    
512

    
513

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

    
529

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

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

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

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

    
959
                if(e.getSource()==getJTextRangoX1()){
960
                        validateKeyTyping(e);
961
                }
962
                
963
                if(e.getSource()==getJTextRangoX2()){
964
                        validateKeyTyping(e);
965
                }
966
                
967
                if(e.getSource()==getJTextRangoY1()){
968
                        validateKeyTyping(e);
969
                }
970
                
971
                if(e.getSource()==getJTextRangoY2()){
972
                        validateKeyTyping(e);
973
                }
974
                
975
                if (e.getSource()==getJTextCellSize()){
976
                        
977
                        validateKeyTyping(e);
978
                }
979
        }
980

    
981

    
982
        
983
        
984

    
985
        
986
        public void focusGained(FocusEvent arg0) {
987
                // TODO Auto-generated method stub
988
                
989
        }
990

    
991
        public void focusLost(FocusEvent arg0) {
992
                // TODO Auto-generated method stub
993
                
994
        }
995

    
996

    
997

    
998
        public void keyPressed(KeyEvent arg0) {
999
                // TODO Auto-generated method stub
1000
                
1001
        }
1002

    
1003
        
1004
        
1005
        public void keyTyped(KeyEvent arg0) {
1006
                // TODO Auto-generated method stub
1007
                
1008
        }
1009
}