Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extRemoteSensing / src / org / gvsig / remotesensing / gridmath / gui / OutputOptionsPanel.java @ 31496

History | View | Annotate | Download (23.1 KB)

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

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

    
43
import info.clearthought.layout.TableLayout;
44

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

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

    
68
import org.gvsig.andami.PluginServices;
69
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
70
import org.gvsig.fmap.mapcontext.MapContext;
71
import org.gvsig.fmap.mapcontext.layers.FLayers;
72
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
73
import org.gvsig.raster.RasterLibrary;
74
import org.gvsig.raster.util.PropertyEvent;
75
import org.gvsig.raster.util.PropertyListener;
76
import org.gvsig.raster.util.RasterToolsUtil;
77

    
78

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

    
90
        private static final long serialVersionUID = 1L;
91
        private JPanel namePanel = null;
92
        private JPanel panelExtension = null;
93
        private JPanel paramPanel = null;
94

    
95
        private JTextField jTextNombreCapa = null;
96
        private JTextField  jTextRangoX1 = null;
97
        private JTextField  jTextRangoX2 = null;
98
        private JTextField jTextRangoY1 = null;
99
        private JTextField jTextRangoY2 = null;
100
        private JTextField jTextCellSizeX = null;
101
        private JTextField jTextCellSizeY = null;
102
        private JTextField  jTextNumFiCol1 = null;
103
        private JTextField jTextNumFiCol2 = null;
104
        private FLayers layers = null;
105

    
106
        private JRadioButton rButtom1 = null;
107
        private JRadioButton rButtom2 = null;
108
        private JRadioButton rButtom4 = null;
109
        private JRadioButton rButtonFile = null;
110
        private JRadioButton rButtonMemory = null;
111
        private JComboBox jComboCapas = null;
112
        private MapContext mapContext = null;
113
        private GridMathPanel cp = null;
114

    
115

    
116
        /**
117
        * Constructor
118
        * @param vista vista de la aplicaci?n
119
        * @param cp calculatorPanel desde el que se invoca
120
        */
121
        public OutputOptionsPanel(DefaultViewPanel vista, GridMathPanel cp) {
122
                super();
123
                if (vista!=null){
124
                        mapContext = vista.getModel().getMapContext();
125
                        layers = mapContext.getLayers();
126
                }
127
                this.cp=cp;
128
                Inicializar();
129
        }
130

    
131
        /**
132
         * Inicializaci?n del panel
133
         */
134
        public void  Inicializar(){
135
                BorderLayout bd=new BorderLayout();
136
                this.setLayout(bd);
137
                this.setBorder( new EmptyBorder(2, 2, 2, 2));
138
                this.add(getNamePanel(),BorderLayout.NORTH);
139
                this.add(getPanelExtension(),BorderLayout.WEST);
140
                this.add(getParameterPanel(),BorderLayout.CENTER);
141
                getRadioMemory().setSelected(true);
142
        }
143

    
144

    
145
        /**
146
         * @return JRadioButton de generar fichero
147
         */
148
        public JRadioButton getRadioFile(){
149
                if (rButtonFile == null){
150
                        rButtonFile = new JRadioButton(PluginServices.getText(this,"a_fichero"));
151
                        rButtonFile.addActionListener(this);
152
                }
153
                return rButtonFile;
154
        }
155

    
156
        /**
157
         * @return JRadioButton de generar en memoria
158
         */
159
        public JRadioButton getRadioMemory(){
160
                if (rButtonMemory == null){
161
                        rButtonMemory = new JRadioButton(PluginServices.getText(this,"a_memoria"));
162
                        rButtonMemory.addActionListener(this);
163
                }
164
                return rButtonMemory;
165
        }
166

    
167

    
168
        /**
169
         * @return panel que incluye el nombre de la capa y las opciones de almacenamieto de la capa de salida
170
         */
171
        public JPanel getNamePanel() {
172

    
173
                if (namePanel==null){
174
                        namePanel=new JPanel();
175
                        GridBagConstraints gridBagConstraints;
176
                        JPanel radioPanel = new JPanel();
177
                        radioPanel.setLayout(new GridBagLayout());
178
                        radioPanel.setBorder(BorderFactory.createTitledBorder(""));
179
                        ButtonGroup buttonGroup = new ButtonGroup();
180
                        buttonGroup.add(getRadioMemory());
181
                        gridBagConstraints = new java.awt.GridBagConstraints();
182
                        gridBagConstraints.gridx = 0;
183
                        gridBagConstraints.gridy = 1;
184
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
185
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
186
                        radioPanel.add(getRadioMemory(),gridBagConstraints);
187
                        buttonGroup.add(getRadioFile());
188
                        gridBagConstraints = new java.awt.GridBagConstraints();
189
                        gridBagConstraints.gridx = 0;
190
                        gridBagConstraints.gridy = 2;
191
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
192
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
193
                        radioPanel.add(getRadioFile(),gridBagConstraints);
194

    
195
                        //Establece la separacin entre los elementos
196
                        namePanel.setLayout(new GridBagLayout());
197

    
198
                        gridBagConstraints = new java.awt.GridBagConstraints();
199
                        gridBagConstraints.gridx = 0;
200
                        gridBagConstraints.gridy = 0;
201
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
202
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
203
                        namePanel.add(new JLabel(PluginServices.getText(this,"nombre_capa")),gridBagConstraints);
204

    
205
                        gridBagConstraints = new java.awt.GridBagConstraints();
206
                        gridBagConstraints.gridx = 1;
207
                        gridBagConstraints.gridy = 0;
208
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
209
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
210
                        namePanel.add(getJTextNombreCapa(),gridBagConstraints);
211

    
212
                        gridBagConstraints = new java.awt.GridBagConstraints();
213
                        gridBagConstraints.gridx = 2;
214
                        gridBagConstraints.gridy = 0;
215
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
216
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
217
                        namePanel.add(radioPanel,gridBagConstraints);
218
                }
219
                return namePanel;
220
        }
221

    
222

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

    
236

    
237

    
238

    
239
        /**
240
        * @return panel con las opciones de configuraci?n de extent,
241
        * los radioButton y el comboCapas
242
        */
243
        public JPanel getPanelExtension() {
244

    
245
                if (panelExtension==null){
246
                        panelExtension=new JPanel();
247
                        TitledBorder topBorder = BorderFactory.createTitledBorder((PluginServices.getText(this,"extension_from")));
248
                    topBorder.setTitlePosition(TitledBorder.TOP);
249
                    panelExtension.setBorder(new CompoundBorder(topBorder,new EmptyBorder(5,5,6,5)));
250

    
251
                    JPanel p=new JPanel();
252
                    //p.setPreferredSize(new Dimension(200,130));
253
                                TableLayout thisLayout = new TableLayout(new double[][] {
254
                                                {200},
255
                                                {TableLayout.PREFERRED,TableLayout.PREFERRED,TableLayout.PREFERRED, TableLayout.PREFERRED}});
256
                                                //Establece la separacin entre los elementos
257
                                                thisLayout.setHGap(5);
258
                                                thisLayout.setVGap(5);
259
                                                panelExtension.setLayout(thisLayout);
260
                                                p.setLayout(thisLayout);
261
                                                ButtonGroup buttonGroup = new ButtonGroup();
262
                                                buttonGroup.add(getRButtom1());
263
                                                buttonGroup.add(getRButtom2());
264
                                                buttonGroup.add(getRButtom4());
265
                                                panelExtension.add(getRButtom1(),"0,0");
266
                                                panelExtension.add(getRButtom2(),"0,1");
267
                                                panelExtension.add(getRButtom4(),"0,2");
268
                                                panelExtension.add(getJComboCapas(),"0,3");
269

    
270
                }
271

    
272
                return panelExtension;
273
        }
274

    
275

    
276
        /**
277
         * @return panel con los parametros de configuraci?n de extensi?n de la salida raster.
278
         */
279
        public JPanel getParameterPanel() {
280

    
281

    
282
                if (paramPanel==null){
283
                        paramPanel=new JPanel();
284
                        TitledBorder topBorder = BorderFactory.createTitledBorder((PluginServices.getText(this,"parametros")));
285
                    topBorder.setTitlePosition(TitledBorder.TOP);
286
                    paramPanel.setBorder(new CompoundBorder(topBorder,new EmptyBorder(5,5,6,5)));
287

    
288

    
289
                    JPanel p=new JPanel();
290
                   // p.setPreferredSize(new Dimension(320,130));
291
                        TableLayout thisLayout = new TableLayout(new double[][] {
292
                                 {150,75, 75},
293
                                {20,20,20,20}});
294
                                //Establece la separacin entre los elementos
295
                                thisLayout.setHGap(3);
296
                                thisLayout.setVGap(3);
297
                                p.setLayout(thisLayout);
298

    
299
                                //Aado los diferentes elementos
300
                                p.add(new JLabel((PluginServices.getText(this,"rangox"))),"0,0");
301
                                p.add(new JLabel((PluginServices.getText(this,"rangoy"))),"0,1");
302
                                p.add(new JLabel((PluginServices.getText(this,"tamanio_celda"))),"0,2");
303
                                p.add(new JLabel((PluginServices.getText(this,"num_filas_columnas"))),"0,3");
304
                                p.add(getJTextCellSizeX(),"1,2");
305
                                p.add(getJTextCellSizeY(),"2,2");
306
                                p.add(getJTextNumFiCol1(),"1,3");
307
                                p.add(getJTextNumFiCol2(),"2,3");
308
                                p.add(getJTextRangoX1(),"1,0");
309
                                p.add(getJTextRangoX2(),"2,0");
310
                                p.add(getJTextRangoY1(),"1,1");
311
                                p.add(getJTextRangoY2(),"2,1");
312

    
313
                                paramPanel.add(p);
314
                }
315
                return paramPanel;
316
        }
317

    
318

    
319

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

    
331

    
332

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

    
344

    
345

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

    
357

    
358
        /**
359
         * @return JTextField tama?o de celda en X
360
         */
361
        public JTextField getJTextCellSizeX() {
362
                if (jTextCellSizeX==null){
363
                        jTextCellSizeX=new JTextField(15);;
364
                        jTextCellSizeX.setEditable(false);
365
                        jTextCellSizeX.addKeyListener(this);
366
                }
367
                return jTextCellSizeX;
368
        }
369

    
370
        /**
371
         * @return JTextField tama?o de celda en Y
372
         */
373
        public JTextField getJTextCellSizeY() {
374
                if (jTextCellSizeY==null){
375
                        jTextCellSizeY=new JTextField(15);;
376
                        jTextCellSizeY.setEditable(false);
377
                        jTextCellSizeY.addKeyListener(this);
378
                }
379
                return jTextCellSizeY;
380
        }
381

    
382

    
383

    
384
        /**
385
         * @return JTextField numero de filas
386
         */
387
        public JTextField getJTextNumFiCol1() {
388
                if (jTextNumFiCol1==null){
389
                        jTextNumFiCol1=new JTextField ();
390
                        jTextNumFiCol1.setEditable(false);
391
                }
392
                return jTextNumFiCol1;
393
        }
394

    
395

    
396

    
397
        /**
398
         * @return JTextField coordenada x m?nima
399
         */
400
        public JTextField  getJTextRangoX1() {
401
                if (jTextRangoX1==null){
402
                        jTextRangoX1 =new JTextField ();
403
                        jTextRangoX1.setEditable(false);
404
                        jTextRangoX1.addKeyListener(this);
405

    
406
                }
407
                return jTextRangoX1;
408
        }
409

    
410

    
411

    
412
        /**
413
         * @return JTextField coordenada x m?xima
414
         */
415
        public JTextField getJTextRangoX2() {
416
                if (jTextRangoX2==null){
417
                        jTextRangoX2=new JTextField ();
418
                        jTextRangoX2.setEditable(false);
419
                        jTextRangoX2.addKeyListener(this);
420

    
421
                }
422
                return jTextRangoX2;
423
        }
424

    
425

    
426

    
427

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

    
440

    
441

    
442
        /**
443
         * @return JTextField coordenada y m?xima
444
         */
445
        public JTextField  getJTextRangoY2() {
446
                if (jTextRangoY2==null){
447
                        jTextRangoY2=new JTextField ();
448
                        jTextRangoY2.setEditable(false);
449
                        jTextRangoY2.addKeyListener(this);
450
                }
451
                return jTextRangoY2;
452
        }
453

    
454

    
455

    
456

    
457
        /**
458
         * @return JTextField numero de columnas
459
         */
460
        public JTextField getJTextNumFiCol2() {
461
                if (jTextNumFiCol2==null){
462
                        jTextNumFiCol2=new JTextField ();
463
                        jTextNumFiCol2.setEditable(false);
464
                }
465
                return jTextNumFiCol2;
466
        }
467

    
468

    
469

    
470
        /**
471
         * @return JCombo con las capas raster cargadas en la vista
472
         */
473
        public JComboBox getJComboCapas() {
474
                if (jComboCapas==null){
475
                        ComboBoxModel jComboBoxLayersModel = new DefaultComboBoxModel(getLayerNames());
476
                        jComboCapas = new JComboBox();
477
                        jComboCapas.setModel(jComboBoxLayersModel);
478
                        jComboCapas.setEnabled(false);
479
                        jComboCapas.addActionListener(this);
480
                }
481
                return jComboCapas;
482
        }
483

    
484
        /**
485
         * @return array con el nombre de los ficheros cargados en la vista
486
         */
487
        private String[] getLayerNames() {
488
                String[] sNames = {};
489
                if (layers!=null){
490
                        sNames = new String[layers.getLayersCount()];
491
                        for (int i = 0; i < layers.getLayersCount(); i++) {
492
                                sNames[i] = (layers.getLayer(i)).getName();
493
                        }
494
                }
495
                return sNames;
496
        }
497

    
498

    
499
        /**
500
         * Establece la opci?n por defecto cuando se crea en cuadro de dialogo
501
         */
502
        public void InicializarOpcion(){
503

    
504
                DesabilitarTodo();
505
                rButtom1.setSelected(true);
506
                // Comprobar que todas las variables estan asignadas
507
                boolean allAssigned = false;
508
                for (int i=0; i<cp.getCalculatorPanel().getJTableVariables().getTableFormat().getRowCount(); i++){
509
                        allAssigned = true;
510
                        if (cp.getCalculatorPanel().getJTableVariables().getTableFormat().getValueAt(i,1).toString().equals(""))
511
                        {
512
                                allAssigned=false;
513
                                break;
514
                        }
515
                }
516
                if(allAssigned){
517
                // Establecemos la opcion por defecto.
518
                setAjustInDataExtent();
519
                }
520
        }
521

    
522

    
523
        /**
524
        * Deshabilita todos los componetes variables de la interfaz
525
        */
526
        public void DesabilitarTodo(){
527

    
528
                jComboCapas.setEnabled(false);
529
                jTextRangoX1.setEditable(false);
530
                jTextRangoX1.setEnabled(false);
531
                jTextRangoX2.setEditable(false);
532
                jTextRangoX2.setEnabled(false);
533
                jTextRangoY1.setEditable(false);
534
                jTextRangoY1.setEnabled(false);
535
                jTextRangoY2.setEditable(false);
536
                jTextRangoY2.setEnabled(false);
537
                jTextNumFiCol1.setEditable(false);
538
                jTextCellSizeX.setEditable(false);
539
                jTextCellSizeX.setEnabled(false);
540
                jTextCellSizeY.setEditable(false);
541
                jTextCellSizeY.setEnabled(false);
542
                jTextNumFiCol1.setEnabled(false);
543
                jTextNumFiCol2.setEditable(false);
544
                jTextNumFiCol2.setEnabled(false);
545
                jComboCapas.updateUI();
546

    
547
        }
548

    
549

    
550
        /**
551
         * Reestablece el numero de filas y columnas ante cuanquier variaci?n de la interfaz
552
         */
553
        public void extentHasChanged(){
554

    
555
                double dRangeX;
556
                double dRangeY;
557
                double dCellSizeX;
558
                double dCellSizeY;
559
                int iRows;
560
                int iCols;
561
                // Se actualiza la X
562
                try {
563
                        dRangeX = Math.abs(Double.parseDouble(getJTextRangoX2().getText())
564
                                                                - Double.parseDouble(getJTextRangoX1().getText()));
565
                        dCellSizeX = Double.parseDouble(getJTextCellSizeX().getText());
566
                        iCols = (int) Math.floor(dRangeX / dCellSizeX);
567
                        getJTextNumFiCol2().setText(Integer.toString(iCols));
568

    
569
                        // Se actualiza la Y
570
                        dRangeY = Math.abs(Double.parseDouble(getJTextRangoY2().getText())
571
                                        - Double.parseDouble(getJTextRangoY1().getText()));
572
                        dCellSizeY = Double.parseDouble(getJTextCellSizeY().getText());
573
                        iRows = (int) Math.floor(dRangeY / dCellSizeY);
574
                        getJTextNumFiCol1().setText(Integer.toString(iRows));
575

    
576

    
577
                } catch (NumberFormatException e) {
578
                        RasterToolsUtil.messageBoxError(PluginServices.getText(this, "invalid_number"), this);
579
                }
580
}
581

    
582
        private void validateKeyTyping(KeyEvent event) {
583
                jComboCapas.updateUI();
584
                switch (event.getKeyChar()) {
585

    
586
                        case KeyEvent.VK_ENTER:
587
                                extentHasChanged();
588
                                jComboCapas.updateUI();
589
                                break;
590

    
591
                        case KeyEvent.VK_BACK_SPACE:
592
                                extentHasChanged();
593
                                break;
594
                        case KeyEvent.VK_0 :
595
                                extentHasChanged();
596
                                break;
597
                        case KeyEvent.VK_1 :
598
                                extentHasChanged();
599
                                break;
600
                        case KeyEvent.VK_2 :
601
                                extentHasChanged();
602
                                break;
603
                        case KeyEvent.VK_3:
604
                                extentHasChanged();
605
                                break;
606
                        case KeyEvent.VK_4:
607
                                extentHasChanged();
608
                                break;
609
                        case KeyEvent.VK_5:
610
                                extentHasChanged();
611
                                break;
612
                        case KeyEvent.VK_6:
613
                                extentHasChanged();
614
                                break;
615
                        case KeyEvent.VK_7:
616
                                extentHasChanged();
617
                                break;
618
                        case KeyEvent.VK_8:
619
                                extentHasChanged();
620
                                break;
621
                        case KeyEvent.VK_9 :
622
                                extentHasChanged();
623
                                break;
624
                }
625
        }
626

    
627

    
628

    
629
        /**
630
        * Fija las acciones que se realizan cuando se produce un evento
631
        * @param e Objeto que genera el evento
632
        */
633
        public void actionPerformed(ActionEvent e) {
634

    
635
                //Radiobutton1
636
                if (e.getSource()==getRButtom1()){
637
                        DesabilitarTodo();
638
                        setAjustInDataExtent();
639
                        updateParams();
640
                }
641

    
642
                // RadioButtom2
643
                else  if (e.getSource()==getRButtom2()){
644

    
645
                        DesabilitarTodo();
646
                        rButtom2.setSelected(true);
647
                        getJTextRangoX1().setEnabled(true);
648
                        getJTextRangoX1().setEditable(true);
649
                        getJTextRangoX2().setEnabled(true);
650
                        getJTextRangoX2().setEditable(true);
651
                        getJTextRangoY1().setEnabled(true);
652
                        getJTextRangoY1().setEditable(true);
653
                        getJTextRangoY2().setEditable(true);
654
                        getJTextRangoY2().setEnabled(true);
655
                        getJTextCellSizeX().setEditable(true);
656
                        getJTextCellSizeX().setEnabled(true);
657
                        getJTextCellSizeY().setEditable(true);
658
                        getJTextCellSizeY().setEnabled(true);
659
                        updateParams();
660
                }
661

    
662

    
663
                // RadioButtom4
664
                else  if (e.getSource()==getRButtom4()){
665

    
666
                        DesabilitarTodo();
667
                        rButtom4.setSelected(true);
668
                        jComboCapas.setEnabled(true);
669
                        jTextCellSizeX.setEditable(true);
670
                        jTextCellSizeX.setEnabled(true);
671
                        jTextCellSizeY.setEditable(true);
672
                        jTextCellSizeY.setEnabled(true);
673
                        getJComboCapas().updateUI();
674
                        updateParams();
675
                }
676

    
677
                else  if (e.getSource()==getRadioFile()){
678
                        rButtonFile.setSelected(true);
679
                }
680

    
681
                else  if (e.getSource()==getRadioMemory()){
682
                        rButtonMemory.setSelected(true);
683
                }
684

    
685
                // ComboCapas
686
                else if (e.getSource()==getJComboCapas()){
687
                        updateParams();
688

    
689
                }
690
        }
691

    
692
        /**
693
         *  Actualizacion de los parametros ajustandolos a los de la capa seleccionada
694
         */
695
        private void updateParams(){
696
                double dCoord;
697
                if (getRButtom4().isSelected()){
698
                        try {
699
                                FLyrRasterSE rasterLayer = (FLyrRasterSE)mapContext.getLayers().getLayer((String)getJComboCapas().getSelectedItem());
700
                                dCoord = rasterLayer.getFullEnvelope().getMinimum(0);
701
                                getJTextRangoX1().setText(new Double(dCoord).toString());
702
                                dCoord = rasterLayer.getFullEnvelope().getMaximum(0);
703
                                getJTextRangoX2().setText(new Double(dCoord).toString());
704
                                dCoord = rasterLayer.getFullEnvelope().getMinimum(1);
705
                                getJTextRangoY1().setText(new Double(dCoord).toString());
706
                                dCoord = rasterLayer.getFullEnvelope().getMaximum(1);
707
                                getJTextRangoY2().setText(new Double(dCoord).toString());
708
                                if (rasterLayer instanceof FLyrRasterSE){
709
                                        getJTextCellSizeX().setText(new Double(
710
                                                        Math.abs(((FLyrRasterSE) rasterLayer).getAffineTransform().getScaleX()))
711
                                                        .toString());
712
                                        getJTextCellSizeY().setText(new Double(
713
                                                        Math.abs(((FLyrRasterSE) rasterLayer).getAffineTransform().getScaleY()))
714
                                                        .toString());
715
                                }
716
                                extentHasChanged();
717
                        } catch (Exception ex) {}
718
                }
719

    
720
        }
721

    
722

    
723

    
724
        /**
725
         * Establece el extent de salida ajustandolo a los datos de entrada.
726
         */
727
        private void setAjustInDataExtent(){
728
                // Si no hay variables asignadas no hace nada. No dejara lanzar el calculo
729
                if( cp.getCalculatorPanel().getJTableVariables().getTableFormat().getRowCount()>0 && cp.getCalculatorPanel().getJTableVariables().getTableFormat().getValueAt(0,1).toString()!=""){
730

    
731
                        String layerName = cp.getCalculatorPanel().getJTableVariables().getTableFormat().getValueAt(0,1).toString();
732
                        layerName = layerName.substring(0,layerName.indexOf("["));
733
                        FLyrRasterSE rasterLayer = (FLyrRasterSE)mapContext.getLayers().getLayer(layerName);
734

    
735
                        double xMin =rasterLayer.getFullRasterExtent().minX();
736
                        double xMax =rasterLayer.getFullRasterExtent().maxX();
737
                        double yMin =rasterLayer.getFullRasterExtent().minY();
738
                        double yMax =rasterLayer.getFullRasterExtent().maxY();
739
                        double cellSizeX = Math.abs(rasterLayer.getAffineTransform().getScaleX());
740
                        double cellSizeY = Math.abs(rasterLayer.getAffineTransform().getScaleY());
741

    
742
                        for (int i=0;i<cp.getCalculatorPanel().getJTableVariables().getTableFormat().getRowCount();i++){
743
                                layerName = cp.getCalculatorPanel().getJTableVariables().getTableFormat().getValueAt(i,1).toString();
744
                                layerName = layerName.substring(0,layerName.indexOf("["));
745
                                rasterLayer = (FLyrRasterSE)mapContext.getLayers().getLayer(layerName);
746

    
747
                                xMin = Math.min(xMin,rasterLayer.getFullRasterExtent().minX());
748
                                xMax = Math.max(rasterLayer.getFullRasterExtent().maxX(),xMax);
749
                                yMin = Math.min(yMin,rasterLayer.getFullRasterExtent().minY());
750
                                yMax = Math.max(yMax,rasterLayer.getFullRasterExtent().maxY());
751
                                cellSizeX = Math.min(cellSizeX,Math.abs(rasterLayer.getAffineTransform().getScaleX()));
752
                                cellSizeY = Math.min(cellSizeY,Math.abs(rasterLayer.getAffineTransform().getScaleY()));
753
                        }
754

    
755
                        cp.getOutputExtent().setXRange(xMin,xMax);
756
                        cp.getOutputExtent().setYRange(yMin,yMax);
757

    
758
                        getJTextRangoX1().setText(String.valueOf(cp.getOutputExtent().minX()));
759
                        getJTextRangoX2().setText(String.valueOf(cp.getOutputExtent().maxX()));
760
                        getJTextRangoY1().setText(String.valueOf(cp.getOutputExtent().minY()));
761
                        getJTextRangoY2().setText(String.valueOf(cp.getOutputExtent().maxY()));
762
                        getJTextCellSizeX().setText(String.valueOf(cellSizeX));
763
                        getJTextCellSizeY().setText(String.valueOf(cellSizeY));
764
                        cp.getOutputExtent().setCellSizeX(cellSizeX);
765
                        cp.getOutputExtent().setCellSizeY(cellSizeY);
766
                        extentHasChanged();
767
                }
768
        }
769

    
770
        /**
771
         * Eventos del teclado
772
         */
773
        public void keyReleased(KeyEvent e) {
774

    
775
                if(e.getSource()==getJTextRangoX1()){
776
                        validateKeyTyping(e);
777
                }
778

    
779
                if(e.getSource()==getJTextRangoX2()){
780
                        validateKeyTyping(e);
781
                }
782

    
783
                if(e.getSource()==getJTextRangoY1()){
784
                        validateKeyTyping(e);
785
                }
786

    
787
                if(e.getSource()==getJTextRangoY2()){
788
                        validateKeyTyping(e);
789
                }
790

    
791
                if (e.getSource()==getJTextCellSizeX()){
792

    
793
                        validateKeyTyping(e);
794
                }
795

    
796
                if (e.getSource()==getJTextCellSizeY()){
797

    
798
                        validateKeyTyping(e);
799
                }
800
        }
801

    
802
        /**
803
         * Especificar el nombre de la nueva capa para el recuadro de texto asign?ndo
804
         * en cada llamada un nombre consecutivo.
805
         */
806
         public void updateNewLayerText() {
807
                         getJTextNombreCapa().setText(RasterLibrary.getOnlyLayerName());
808
         }
809

    
810

    
811

    
812

    
813
        public void focusGained(FocusEvent arg0) {
814
                // TODO Auto-generated method stub
815

    
816
        }
817

    
818
        public void focusLost(FocusEvent arg0) {
819
                // TODO Auto-generated method stub
820

    
821
        }
822

    
823

    
824

    
825
        public void keyPressed(KeyEvent arg0) {
826
                // TODO Auto-generated method stub
827

    
828
        }
829

    
830

    
831

    
832
        public void keyTyped(KeyEvent arg0) {
833
                // TODO Auto-generated method stub
834

    
835
        }
836

    
837
        public void actionValueChanged(PropertyEvent e) {
838
                updateNewLayerText();
839
        }
840
}