Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extRemoteSensing / src / org / gvsig / remotesensing / classification / gui / ClassificationPanel.java @ 31496

History | View | Annotate | Download (24.6 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
package org.gvsig.remotesensing.classification.gui;
41

    
42
import java.awt.BorderLayout;
43
import java.awt.Component;
44
import java.awt.Container;
45
import java.awt.Dimension;
46
import java.awt.GridBagConstraints;
47
import java.awt.GridBagLayout;
48
import java.awt.Insets;
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.io.File;
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.JLabel;
60
import javax.swing.JOptionPane;
61
import javax.swing.JPanel;
62
import javax.swing.JRadioButton;
63
import javax.swing.JScrollPane;
64
import javax.swing.JTabbedPane;
65
import javax.swing.JTable;
66
import javax.swing.JTextField;
67
import javax.swing.SwingConstants;
68
import javax.swing.border.CompoundBorder;
69
import javax.swing.border.EmptyBorder;
70
import javax.swing.border.TitledBorder;
71

    
72
import org.gvsig.andami.PluginServices;
73
import org.gvsig.andami.Utilities;
74
import org.gvsig.andami.ui.mdiManager.IWindow;
75
import org.gvsig.andami.ui.mdiManager.IWindowListener;
76
import org.gvsig.andami.ui.mdiManager.WindowInfo;
77
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
78
import org.gvsig.fmap.mapcontext.MapContext;
79
import org.gvsig.fmap.mapcontext.layers.FLayers;
80
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
81
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
82
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent;
83
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener;
84
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel;
85
import org.gvsig.gui.beans.swing.JFileChooser;
86
import org.gvsig.raster.RasterLibrary;
87
import org.gvsig.raster.dataset.GeoRasterWriter;
88
import org.gvsig.raster.grid.GridException;
89
import org.gvsig.raster.util.ExtendedFileFilter;
90
import org.gvsig.raster.util.PropertyEvent;
91
import org.gvsig.raster.util.PropertyListener;
92
import org.gvsig.raster.util.RasterToolsUtil;
93
import org.gvsig.rastertools.roi.ui.ROIsTablePanel;
94
import org.gvsig.remotesensing.classification.ClassificationGeneralProcess;
95
import org.gvsig.remotesensing.classification.ClassificationMaximumLikelihoodProcess;
96
import org.gvsig.remotesensing.classification.ClassificationMinimumDistanceProcess;
97
import org.gvsig.remotesensing.classification.ClassificationParallelepipedProcess;
98
import org.gvsig.remotesensing.classification.NoSupervisedClassificationProcess;
99
import org.gvsig.remotesensing.principalcomponents.gui.BandTableFormat;
100
import org.gvsig.utils.swing.JComboBox;
101

    
102

    
103
/**
104
 * Clase que define la interfaz del proceso de clasificacion de una imagen. Recoge la
105
 * imagen a clasificar con la selecci?n de bandas correspondiente. Posibilita la elecci?n del
106
 * m?todo empleado y da la posibilidad de manejar la lista de clases que intervienen en el proceso.
107
 * Permite ajustar algunos parametros del proceso y configurar las opciones de salida.
108
 *
109
 * @author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es)
110
 * @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
111
 * @version 19/10/2007
112
 */
113
public class ClassificationPanel extends DefaultButtonsPanel implements PropertyListener, IWindow, IWindowListener,
114
        ButtonsPanelListener,ActionListener,FocusListener{
115

    
116
        private static final long                 serialVersionUID = 1L;
117
        private DefaultViewPanel                                         view = null;
118
        private int                                         width=400;
119
        private int                                         height=555;
120
        private MapContext                                 m_MapContext=null;
121
        private FLayers                                 layers=null;
122
        private int nMethods                        = 4;
123
        private JRadioButton                         rButtonFile=null;
124
        private JRadioButton                         rButtonMemory =null;
125
        private JTextField                                 jTextNombreCapa=null;
126
        private JPanel                                         panelTab1=null;
127
        private JPanel                                         panelTab2=null;
128
        private JScrollPane                                scrollBandas=null;
129
        private JScrollPane                                scrollTable=null;
130
        private JComboBox                                comboLayers= null;
131
        private JComboBox                                comboMethods= null;
132
        private ROIsTablePanel                         roisTablePanel= null;
133
        private BandTableFormat                 mModeloTabla=null;
134
        private JTable                                         jTableBandas=null;
135
        private JPanel                                         nombreCapa=null;
136
        private int[]                                         bands= null;
137
        private JPanel                                        panelParametros=null;
138
        private JTextField                                stevField =  null;
139
        private JPanel                                        panelParametros2=null;
140
        private JTextField                                numClases =  null;
141
        /**
142
         * @see com.DefaultViewPanel.mdiApp.ui.MDIManager.View#getViewInfo()
143
         */
144
        public WindowInfo getWindowInfo(){
145
                WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE);
146
                m_viewinfo.setWidth(width);
147
                m_viewinfo.setHeight(height);
148
                m_viewinfo.setTitle(PluginServices.getText(this,"classification"));
149
                m_viewinfo.setX(300);
150
                return m_viewinfo;
151
        }
152

    
153
        /**
154
         * @param view vista de la aplicacion
155
         */
156
        public ClassificationPanel(DefaultViewPanel view) {
157
                this.view = view;
158
                m_MapContext = view.getModel().getMapContext();
159
                layers = m_MapContext.getLayers();
160
                this.setPreferredSize(new Dimension(width, height));
161
                this.setSize(width, height);
162
                this.setLayout(new BorderLayout(1, 1));
163
                this.addButtonPressedListener(this);
164
                initialize();
165
        }
166

    
167

    
168
        /**
169
         * Inicializaci?n del cuadro de dialogo
170
         */
171
        private void initialize(){
172
                BorderLayout bd=new BorderLayout();
173
                this.setLayout(bd);
174
                TitledBorder topBorder = BorderFactory.createTitledBorder(" ");
175
                topBorder.setTitlePosition(TitledBorder.TOP);
176
                this.setBorder(new CompoundBorder(topBorder,new EmptyBorder(0,5,5,5)));
177
                JTabbedPane tabbedPane = new JTabbedPane();
178
                 tabbedPane.addTab(PluginServices.getText(this, "operacion"), getPanelTab1());
179
                tabbedPane.addTab(PluginServices.getText(this, "opciones"), getPanelTab2());
180
                this.setLayout(new BorderLayout());
181
                this.add(tabbedPane, BorderLayout.CENTER);
182
                getBandas();
183
        }
184

    
185
        /**
186
         * @return panel para el tab operacion.
187
         */
188
         private JPanel getPanelTab1(){
189
                if (panelTab1==null){
190
                        panelTab1 = new JPanel();
191
                        panelTab1.setLayout(new GridBagLayout());
192

    
193
                        // Panel superior opcion Selecion de imagen y bandas
194
                        JPanel selectionImagenPanel= new JPanel();
195
                        TitledBorder topBorder = BorderFactory.createTitledBorder(" Imagen");
196
                        topBorder.setTitlePosition(TitledBorder.TOP);
197
                        JPanel aux= new JPanel();
198
                        aux.setPreferredSize(new Dimension(300,110));
199

    
200
                        BorderLayout bd=new BorderLayout();
201
                        aux.setLayout(bd);
202

    
203
                        aux.add(getComboCapas(),BorderLayout.NORTH);
204
                        aux.add(getScrollBands(),BorderLayout.SOUTH);
205
                        selectionImagenPanel.add(aux);
206

    
207
                        selectionImagenPanel.setBorder(topBorder);
208
                        GridBagConstraints c = new GridBagConstraints();
209
                        c.fill = GridBagConstraints.BOTH;
210
                        c.insets=new Insets(2,2,2,2);
211
                        c.weightx = 1;
212
                        c.weighty = 0.5;
213
                        c.gridx = 0;
214
                        c.gridy = 0;
215
                        panelTab1.add(selectionImagenPanel, c);
216

    
217

    
218
                        // Panel seleccion metodo
219
                        JPanel methodPanel= new JPanel();
220
                        TitledBorder topBorderMethod = BorderFactory.createTitledBorder("Metodo");
221
                        topBorder.setTitlePosition(TitledBorder.TOP);
222
                        methodPanel.setBorder(topBorderMethod);
223
                        methodPanel.add(new JLabel(PluginServices.getText(this, "metodo")));
224
                        methodPanel.add(getComboMethods());
225
                        c.fill = GridBagConstraints.BOTH;
226
                        c.insets=new Insets(2,2,2,2);
227
                        c.weightx = 1;
228
                        c.weighty = 0.1;
229
                        c.gridx = 0;
230
                        c.gridy = 1;
231
                        panelTab1.add(methodPanel, c);
232

    
233
                        // Insercion del panel de las clases
234
                        c.fill = GridBagConstraints.BOTH;
235
                        c.insets=new Insets(2,2,2,2);
236
                        c.weightx = 1;
237
                        c.weighty = 1;
238
                        c.gridx = 0;
239
                        c.gridy = 2;
240
                        panelTab1.add(getRoisTablePanel(), c);
241
                 }
242
                 return panelTab1;
243
         }
244

    
245
         /**
246
          * @return Panel para el tab de opciones.
247
          */
248
         private JPanel getPanelTab2(){
249
                if (panelTab2==null){
250
                        panelTab2 = new JPanel();
251
                        panelTab2.setLayout(new GridBagLayout());
252

    
253
                        JPanel parameterPanel= new JPanel();
254
                        TitledBorder topBorder = BorderFactory.createTitledBorder(PluginServices.getText(this, "parametros"));
255
                        topBorder.setTitlePosition(TitledBorder.TOP);
256
                        JPanel aux= new JPanel();
257
                        aux.setPreferredSize(new Dimension(300,110));
258

    
259
                        BorderLayout bd=new BorderLayout();
260
                        aux.setLayout(bd);
261

    
262
                        //aux.add(new JButton(),BorderLayout.NORTH);
263
                        parameterPanel.add(aux);
264

    
265
                        parameterPanel.setBorder(topBorder);
266
                        BorderLayout bordlayout= new BorderLayout();
267
                        parameterPanel.setLayout(bordlayout);
268
                        parameterPanel.add(getPanelParametros(),BorderLayout.NORTH);
269
                        parameterPanel.add(getPanelParametros2(),BorderLayout.CENTER);
270
                        GridBagConstraints c = new GridBagConstraints();
271
                        c.fill = GridBagConstraints.BOTH;
272
                        c.insets=new Insets(2,2,2,2);
273
                        c.weightx = 1;
274
                        c.weighty = 1;
275
                        c.gridx = 0;
276
                        c.gridy = 0;
277
                        panelTab2.add(parameterPanel, c);
278

    
279
                        // Insercion del panel de las clases
280
                        c.fill = GridBagConstraints.BOTH;
281
                        c.insets=new Insets(2,2,2,2);
282
                        c.weightx = 0.05;
283
                        c.weighty = 0.05;
284
                        c.gridx = 0;
285
                        c.gridy = 1;
286

    
287
                        panelTab2.add(getOutputOptionsPanel(), c);
288

    
289
                }
290
                return panelTab2;
291
         }
292

    
293

    
294
         // Paneel de parametros
295

    
296
         JPanel getPanelParametros(){
297
                 if (panelParametros==null){
298

    
299
                         panelParametros= new JPanel();
300
                         panelParametros.add(new JLabel(PluginServices.getText(this,"max_stev_interval_multiplo")));
301
                         panelParametros.add(getStevField());
302
                         panelParametros.setVisible(false);
303

    
304
                 }
305
                 return panelParametros;
306
         }
307

    
308

    
309
         JPanel getPanelParametros2(){
310
                 if (panelParametros2==null){
311
                         BorderLayout bd= new BorderLayout();
312
                         panelParametros2= new JPanel();
313
                         panelParametros2.add(new JLabel(PluginServices.getText(this,"numclases")),BorderLayout.NORTH);
314
                         panelParametros2.add(getNumClases());
315
                         panelParametros2.setVisible(false);
316
                 }
317
                 return panelParametros2;
318
         }
319

    
320

    
321
         /**
322
         * @return  Scroll con la tabla de clases intervienen en el proceso de clasificaci?n.
323
         */
324
         public JScrollPane getScrollTable() {
325

    
326
                if(scrollTable==null){
327
                        scrollTable=new JScrollPane();
328
                        TitledBorder topBorder = BorderFactory.createTitledBorder((PluginServices.getText(this,"clases")));
329
                    topBorder.setTitlePosition(TitledBorder.TOP);
330
                    scrollTable.setBorder(new CompoundBorder(topBorder,new EmptyBorder(2,2,2,2)));
331
                        scrollTable.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
332
                        scrollTable.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
333
                }
334
                return scrollTable;
335
        }
336

    
337
         /**
338
          * @return javax.swing.JTextField
339
          */
340
         public JTextField getJTextNombreCapa() {
341
                if (jTextNombreCapa==null) {
342
                        jTextNombreCapa=new JTextField(10);
343
                        jTextNombreCapa.setText(RasterLibrary.getOnlyLayerName());
344
                        jTextNombreCapa.addFocusListener(this);
345
                        RasterLibrary.addOnlyLayerNameListener(this);
346
                }
347
                return jTextNombreCapa;
348
        }
349

    
350

    
351
        /**
352
         * Especificar el nombre de la nueva capa para el recuadro de texto asign?ndo
353
         * en cada llamada un nombre consecutivo.
354
         */
355
         public void updateNewLayerText() {
356
                         getJTextNombreCapa().setText(RasterLibrary.getOnlyLayerName());
357
         }
358

    
359
        /**
360
         * @return JRadioButton de generar fichero
361
         */
362
        public JRadioButton getRadioFile(){
363
                if (rButtonFile == null){
364
                        rButtonFile = new JRadioButton(PluginServices.getText(this,"a_fichero"));
365
                        rButtonFile.addActionListener(this);
366
                }
367
                return rButtonFile;
368
        }
369

    
370
        /**
371
         * @return JRadioButton de generar en memoria
372
         */
373
        public JRadioButton getRadioMemory(){
374
                if (rButtonMemory == null){
375
                        rButtonMemory = new JRadioButton(PluginServices.getText(this,"a_memoria"),true);
376
                        rButtonMemory.addActionListener(this);
377
                }
378
                return rButtonMemory;
379
        }
380

    
381

    
382
        /**
383
         * @return JComboBox con los r?ster cargados en la vista.
384
         */
385
         public JComboBox getComboCapas() {
386
                if (comboLayers==null){
387
                        ComboBoxModel jComboBoxLayersModel = new
388
                DefaultComboBoxModel(getLayerNames());
389
                        comboLayers = new JComboBox();
390
                        comboLayers.setModel(jComboBoxLayersModel);
391
                        comboLayers.setEnabled(true);
392
                        comboLayers.addActionListener(this);
393
                        comboLayers.setSelectedIndex(0);
394
                }
395
                return comboLayers;
396
        }
397

    
398

    
399
        /**
400
         * Acciones a ejecuar al cerrar el di?logo.
401
         */
402
        public void close(){
403
                try {
404
                        RasterLibrary.removeOnlyLayerNameListener(this);
405
                        PluginServices.getMDIManager().closeWindow(this);
406
                } catch (ArrayIndexOutOfBoundsException ex) {
407
                        // Si la ventana no se puede eliminar no hacemos nada
408
                }
409
        }
410

    
411

    
412
        /**
413
         * @return array de string con los nombre de las capas raster
414
         */
415
        private String[] getLayerNames() {
416

    
417
                int i, capasraster=0;
418
                for (i = 0; i < layers.getLayersCount(); i++) {
419
                        if (layers.getLayer(i)instanceof  FLyrRasterSE)
420
                                capasraster++;
421
                }
422
                // Solo se toman las capas raster.
423
                String[] sNames = new String[capasraster];
424
                capasraster=0;
425

    
426
                for (i = 0; i < layers.getLayersCount(); i++) {
427
                        if (layers.getLayer(i)instanceof FLyrRasterSE){
428
                                sNames[capasraster] =layers.getLayer(i).getName();
429
                                capasraster++;
430
                        }
431
                }
432
                return sNames;
433
        }
434

    
435

    
436
        /**
437
         * Devuelve la ruta del fichero donde se va a guardar, en caso de guardarse
438
         * en memoria, calcula el nombre sin preguntar y devuelve la ruta.
439
         * @return string con la ruta de salida
440
         */
441
        public String getFileSelected() {
442
                String path = "";
443
                if (getRadioFile().isSelected()) {
444
                        JFileChooser chooser = new JFileChooser("CLASSIFICATION_PANEL",JFileChooser.getLastPath("CLASSIFICATION_PANEL", null));
445
                        chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero"));
446
                        //A?adimos las extensiones que hayan sido registradas en el driver
447
                        String[] extList = GeoRasterWriter.getDriversExtensions();
448
                        for(int i=0;i<extList.length;i++)
449
                                chooser.addChoosableFileFilter(new ExtendedFileFilter(extList[i]));
450

    
451
                        if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION)
452
                                return null;
453

    
454
                        JFileChooser.setLastPath("CLASSIFICATION_PANEL", chooser.getSelectedFile());
455
                        ExtendedFileFilter fileFilter = (ExtendedFileFilter) chooser.getFileFilter();
456
                        path = fileFilter.getNormalizedFilename(chooser.getSelectedFile());
457
                } else {
458
                        String file = getJTextNombreCapa().getText();
459
                        path = Utilities.createTempDirectory() + File.separator + getJTextNombreCapa().getText() + ".tif";
460
                        if(file.compareTo(RasterLibrary.getOnlyLayerName()) == 0)
461
                                RasterLibrary.usesOnlyLayerName();
462
                        updateNewLayerText();
463
                }
464
                return path;
465
        }
466

    
467
        /**
468
         * Acciones al aceptar
469
         */
470
        public void accept(){
471

    
472
                // Imagen que va a ser clasificada
473
                FLyrRasterSE rasterLayer= ((FLyrRasterSE)layers.getLayer((String) getComboCapas().getSelectedItem()));
474
                /*
475
                 * Bandas que intervienen en la clasificaci?n.
476
                 */
477
                boolean bandsSelected[] = getModeloTabla().getSeleccionadas();
478
                int bandCount = 0;
479
                for (int i= 0; i<bandsSelected.length;i++)
480
                        if(bandsSelected[i]==true)
481
                                bandCount++;
482
                int bandList[] = new int[bandCount];
483
                int index = 0;
484
                for (int i = 0; i < bandsSelected.length; i++){
485
                        if (bandsSelected[i])
486
                                {        bandList[index]=i;
487
                                        index++;
488
                                }
489
                }
490

    
491
                ClassificationGeneralProcess process=null;
492
                if(getComboMethods().getSelectedIndex()==0)
493
                        process = new ClassificationMaximumLikelihoodProcess();
494
                if(getComboMethods().getSelectedIndex()==1)
495
                        process =  new ClassificationMinimumDistanceProcess();
496
                if(getComboMethods().getSelectedIndex()==2){
497
                        process= new ClassificationParallelepipedProcess();
498
                        process.addParam("dev", new Double(Double.parseDouble(getStevField().getText())));
499
                }
500
                if(getComboMethods().getSelectedIndex()==3){
501
                        process= new NoSupervisedClassificationProcess();
502
                        process.addParam("numClases",new Integer(Integer.parseInt(getNumClases().getText())));
503
                }
504
                process.addParam("layer",rasterLayer);
505
                process.addParam("rois",getRoisTablePanel().getROIs());
506
                process.addParam("bandList",bandList);
507
                process.addParam("filename",getFileSelected());
508
                process.addParam("view", view);
509
                process.start();
510
        }
511

    
512
        /*
513
         * (non-Javadoc)
514
         * @see org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener#actionButtonPressed(org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent)
515
         */
516
        public void actionButtonPressed(ButtonsPanelEvent e) {
517
                        // Bot?n de Aceptar
518
                if (e.getButton() == ButtonsPanel.BUTTON_ACCEPT) {
519
                        if(!(getRoisTablePanel().getROIs().isEmpty() && getComboMethods().getSelectedIndex()!=3))
520
                                {accept(); close();}
521
                        else
522
                                JOptionPane.showMessageDialog(null,        PluginServices.getText(this,"no_clases"), PluginServices.getText(this,"no_clases"),JOptionPane.WARNING_MESSAGE);
523
                }
524

    
525
                // Bot?n de Aplicar
526
                if (e.getButton() == ButtonsPanel.BUTTON_APPLY) {
527
                        if(!(getRoisTablePanel().getROIs().isEmpty()&& getComboMethods().getSelectedIndex()!=3))
528
                                accept();
529
                        else
530
                                JOptionPane.showMessageDialog(null,        PluginServices.getText(this,"no_clases"), PluginServices.getText(this,"clasificacion"),JOptionPane.WARNING_MESSAGE);
531
                }
532

    
533
                // Bot?n de Cerrar
534
                if (e.getButton() == ButtonsPanel.BUTTON_CANCEL) {
535
                        close();
536
                }
537
         }
538

    
539
        /**
540
          *Actualizaci?n de las bandas cuando cambia la imagen seleccionada
541
          */
542
        public void actionPerformed(ActionEvent arg0) {
543
                if(arg0.getSource()==getComboCapas()){
544
                        getBandas();
545
                }
546
                if(arg0.getSource()==getComboMethods()){
547
                        if(getComboMethods().getSelectedIndex()==2){
548
                                getPanelParametros().setVisible(true);
549
                                getPanelParametros2().setVisible(false);
550
                                //getScrollTable().setEnabled(true);
551
                                setEnabled(getRoisTablePanel(), true);
552
                        }
553
                        else if(getComboMethods().getSelectedIndex()==3){
554
                                getPanelParametros().setVisible(false);
555
                                getPanelParametros2().setVisible(true);
556
                                 //getScrollTable().setEnabled(false);
557
                                setEnabled(getRoisTablePanel(), false);
558
                        }
559
                        else{
560
                                getPanelParametros().setVisible(false);
561
                                getPanelParametros2().setVisible(false);
562
                                //getScrollTable().setEnabled(true);
563
                                setEnabled(getRoisTablePanel(), true);
564
                        }
565
                updateUI();
566
                }
567
        }
568

    
569

    
570
        /**
571
         * @return tabla conlas bandas de la imagen
572
         */
573
        private JTable getTableBands(){
574
                if (jTableBandas==null){
575
                        jTableBandas=new JTable(getModeloTabla());
576
                }
577
                return jTableBandas;
578
        }
579

    
580

    
581
        /**
582
         * @return modelo de tabla
583
         * @see BandTableFormat
584
         */
585
        public BandTableFormat getModeloTabla() {
586
                if(mModeloTabla==null){
587
                        mModeloTabla=new BandTableFormat();
588
                }
589
                return mModeloTabla;
590
        }
591

    
592
        /**
593
         * @return
594
         * */
595
        public JTextField getStevField(){
596
                if (stevField==null){
597
                        stevField= new JTextField(5);
598
                        stevField.setText("3.0");
599
                }
600
                return stevField;
601
        }
602

    
603
        /**
604
         * @return scroll con bandas del r?ster
605
         */
606
        public JScrollPane getScrollBands() {
607
                if (scrollBandas==null){
608
                        scrollBandas=new JScrollPane();
609
                }
610
                getTableBands().getColumn("").setPreferredWidth(30);
611
                scrollBandas.setPreferredSize(new Dimension(250,80));
612
                scrollBandas.setViewportView(getTableBands());
613
                scrollBandas.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
614
                return scrollBandas;
615
        }
616

    
617

    
618
        /**
619
         * @return panel de gesti?n de ROIs
620
         */
621
        public ROIsTablePanel getRoisTablePanel() {
622
                if (roisTablePanel==null){
623
                        roisTablePanel= new ROIsTablePanel(null);
624
                }
625
                return roisTablePanel;
626
        }
627

    
628

    
629
        /**
630
         * @return JComboBox con los m?todos de clasificaci?n
631
         */
632
        public JComboBox getComboMethods() {
633
                if (comboMethods==null){
634
                        comboMethods= new JComboBox();
635
                        String[] sNames = new String[nMethods];
636
                        sNames[0]= new String(PluginServices.getText(this, "metodo_maxima_probabilidad"));
637
                        sNames[1]= new String(PluginServices.getText(this, "metodo_minima_diatancia"));
638
                        sNames[2]= new String(PluginServices.getText(this, "metodo_paralelepipedos"));
639
                        sNames[3]= new String(PluginServices.getText(this, "metodo_noSupervisado"));
640
                        ComboBoxModel jComboBoxLayersModel = new  DefaultComboBoxModel(sNames);
641
                        comboMethods.setModel(jComboBoxLayersModel);
642
                        comboMethods.setEnabled(true);
643
                        comboMethods.addActionListener(this);
644
                }
645
                return comboMethods;
646
        }
647

    
648
        /**
649
         * Toma las Bandas de la imagen seleccionada en el combo Imagen
650
         */
651
        public void getBandas(){
652

    
653
                // Antes de insertar se borra lo anterior
654
                getModeloTabla().LimpiarLista();
655

    
656
                FLyrRasterSE rasterLayer= (FLyrRasterSE)layers.getLayer((String)getComboCapas().getSelectedItem());
657
                String bandas[]=new String[rasterLayer.getBandCount()];
658
                bands= new int[rasterLayer.getBandCount()];
659
                if (layers.getLayer((String)getComboCapas().getSelectedItem()) instanceof  FLyrRasterSE ){
660
                        for (int j=0; j<rasterLayer.getBandCount(); j++){
661
                                        String s=(PluginServices.getText(this,"banda"))+(j+1);
662
                                        bandas[j]=s;
663
                                        bands[j]=j;
664
                                }
665
                        for (int i=0;i<bandas.length;i++)
666
                                getModeloTabla().addRow(bandas[i],true);
667
                        getTableBands().updateUI();
668
                        try {
669
                                getRoisTablePanel().setFLayer((FLyrRasterSE)layers.getLayer((String)getComboCapas().getSelectedItem()));
670
                        } catch (GridException e) {
671
                                RasterToolsUtil.messageBoxError(PluginServices.getText(this, "grid_error"), this, e);
672
                        }
673
                }
674
        }
675

    
676

    
677
        /**
678
         * @return panel con las opciones de salida.
679
         */
680
        public JPanel getOutputOptionsPanel() {
681
                if (nombreCapa==null){
682
                        nombreCapa=new JPanel();
683
                        nombreCapa.setPreferredSize(new Dimension(400,130));
684
                        TitledBorder topBorder = BorderFactory.createTitledBorder(PluginServices.getText(this, "salida"));
685
                        topBorder.setTitlePosition(TitledBorder.TOP);
686
                        nombreCapa.setBorder(topBorder);
687
                        GridBagConstraints gridBagConstraints;
688
                        JPanel radioPanel = new JPanel();
689
                        radioPanel.setLayout(new GridBagLayout());
690
                        radioPanel.setBorder(BorderFactory.createTitledBorder(""));
691
                        ButtonGroup buttonGroup = new ButtonGroup();
692
                        buttonGroup.add(getRadioMemory());
693
                        gridBagConstraints = new java.awt.GridBagConstraints();
694
                        gridBagConstraints.gridx = 0;
695
                        gridBagConstraints.gridy = 1;
696
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
697
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
698
                        radioPanel.add(getRadioMemory(),gridBagConstraints);
699
                        buttonGroup.add(getRadioFile());
700
                        gridBagConstraints = new java.awt.GridBagConstraints();
701
                        gridBagConstraints.gridx = 0;
702
                        gridBagConstraints.gridy = 2;
703
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
704
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
705
                        radioPanel.add(getRadioFile(),gridBagConstraints);
706
                        //Establece la separacion entre los elementos
707
                        nombreCapa.setLayout(new GridBagLayout());
708
                        gridBagConstraints = new java.awt.GridBagConstraints();
709
                        gridBagConstraints.gridx = 0;
710
                        gridBagConstraints.gridy = 0;
711
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
712
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
713
                        nombreCapa.add(new JLabel(("Nombre:"),SwingConstants.RIGHT ),gridBagConstraints);
714

    
715
                        gridBagConstraints = new java.awt.GridBagConstraints();
716
                        gridBagConstraints.gridx = 1;
717
                        gridBagConstraints.gridy = 0;
718
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
719
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
720
                        nombreCapa.add(getJTextNombreCapa(),gridBagConstraints);
721

    
722
                        gridBagConstraints = new java.awt.GridBagConstraints();
723
                        gridBagConstraints.gridx = 2;
724
                        gridBagConstraints.gridy = 0;
725
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
726
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
727
                        nombreCapa.add(radioPanel,gridBagConstraints);
728
                }
729
                return nombreCapa;
730
        }
731

    
732

    
733
        /**
734
          * Acciones al cerrar.
735
          */
736
        public void windowClosed() {
737
                /*
738
                 * Limpiar los gr?ficos de la vista:
739
                 */
740
                getRoisTablePanel().clearRoiGraphics();
741
                getRoisTablePanel().getMapControl().rePaintDirtyLayers();
742
                getRoisTablePanel().setPreviousTool();
743
        }
744

    
745
        public void focusGained(FocusEvent arg0) {
746

    
747
        }
748

    
749
        public void focusLost(FocusEvent arg0) {
750
                // TODO Auto-generated method stub
751

    
752
        }
753

    
754
        public void windowActivated() {}
755

    
756
        public void actionValueChanged(PropertyEvent e) {
757
                        updateNewLayerText();
758
        }
759

    
760
        public JTextField getNumClases() {
761
                if (numClases==null){
762
                        numClases= new JTextField(5);
763
                        numClases.setText("5");
764
                }
765
                return numClases;
766
        }
767

    
768
        public Object getWindowProfile() {
769
                return WindowInfo.PROPERTIES_PROFILE;
770
        }
771

    
772
        private void setEnabled(Container c, boolean enabled) {
773
        Component[] components = c.getComponents();
774
        for(int i=0; i<components.length; i++) {
775
            components[i].setEnabled(enabled);
776
            if(components[i] instanceof Container) {
777
                    setEnabled((Container)components[i], enabled);
778
            }
779
        }
780
    }
781
}
782

    
783

    
784

    
785

    
786

    
787

    
788

    
789

    
790

    
791

    
792

    
793

    
794