Statistics
| Revision:

root / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / principalcomponents / gui / PrincipalComponentCalculusPanel.java @ 14794

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

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

    
43
import info.clearthought.layout.TableLayout;
44

    
45
import java.awt.BorderLayout;
46
import java.awt.Dimension;
47
import java.awt.FlowLayout;
48
import java.awt.GridBagConstraints;
49
import java.awt.GridBagLayout;
50
import java.awt.event.ActionEvent;
51
import java.awt.event.ActionListener;
52
import java.awt.event.FocusEvent;
53
import java.awt.event.FocusListener;
54
import java.io.File;
55
import java.io.FileNotFoundException;
56
import java.io.FileOutputStream;
57
import java.io.IOException;
58
import java.io.OutputStream;
59

    
60
import javax.swing.BorderFactory;
61
import javax.swing.ButtonGroup;
62
import javax.swing.ImageIcon;
63
import javax.swing.JButton;
64
import javax.swing.JCheckBox;
65
import javax.swing.JFileChooser;
66
import javax.swing.JLabel;
67
import javax.swing.JOptionPane;
68
import javax.swing.JPanel;
69
import javax.swing.JRadioButton;
70
import javax.swing.JScrollPane;
71
import javax.swing.JTable;
72
import javax.swing.JTextField;
73
import javax.swing.SwingConstants;
74
import javax.swing.border.CompoundBorder;
75
import javax.swing.border.EmptyBorder;
76
import javax.swing.border.TitledBorder;
77
import javax.swing.filechooser.FileFilter;
78

    
79
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
80
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent;
81
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener;
82
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel;
83
import org.gvsig.gui.beans.incrementabletask.IncrementableTask;
84
import org.gvsig.raster.dataset.GeoRasterWriter;
85
import org.gvsig.raster.grid.Grid;
86
import org.gvsig.rastertools.RasterModule;
87
import org.gvsig.remotesensing.principalcomponents.PCImageProcess;
88
import org.gvsig.remotesensing.principalcomponents.PCStatisticsProcess;
89

    
90
import Jama.Matrix;
91

    
92
import com.iver.andami.PluginServices;
93
import com.iver.andami.Utilities;
94
import com.iver.andami.ui.mdiManager.IWindow;
95
import com.iver.andami.ui.mdiManager.WindowInfo;
96
import com.iver.cit.gvsig.addlayer.fileopen.FileOpenWizard;
97
import com.iver.cit.gvsig.project.documents.view.gui.View;
98

    
99

    
100
/**
101
 * Clase que define la interfaz para la selecci?n de componentes que interviene la construcci?n de la
102
 * imagen resultante del analisis de componentes principales.
103
 *  
104
 * @see PCStatisticsProcess
105
 * @author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es)
106
 * @author Diego Guerrero Sevilla (diego.guerrero@uclm.es) 
107
 * @version 22/10/2007  
108
 */
109

    
110
public class PrincipalComponentCalculusPanel extends DefaultButtonsPanel implements ButtonsPanelListener, IWindow,ActionListener,FocusListener  {
111
        
112
        private static final long serialVersionUID = 1L;
113
        private JPanel statisticsPanel;
114
        private JPanel panelTodos;
115
        private JPanel nombreCapaPanel;
116
        private JButton jbExportar;
117
        private JButton jexportVarMatrix;
118
        private JButton jexportAutovectorMatrix;
119
        private ComponentTableFormat tableFormatComponent;
120
        private JScrollPane scrollComponents;
121
        private JTable tableComponent;
122
        private JTextField jTextNombreCapa;
123
        private JButton jbTodos;
124
        private JButton jbNinguno;
125
        private int wPanel=460;
126
        private int hPanel=470;
127
        private double[] autovalores;
128
        private PCStatisticsProcess pc;
129
        private JPanel panelSuperior;        
130
        private JRadioButton rButtonFile = null;
131
        private JRadioButton rButtonMemory = null;
132
        private JCheckBox bandasStatistics;
133
        private JCheckBox varianceStatistics;
134
        private JCheckBox autovectorStatistics;
135
        
136
        
137
        /**
138
         * Constructor
139
         * @param vista vista de la aplicacion
140
         * @param pC proceso de estadisticas 
141
         */
142
        public PrincipalComponentCalculusPanel(View vista,PCStatisticsProcess pC){
143
                autovalores = pC.getResult();
144
                pc=pC;
145
                this.addButtonPressedListener(this);
146
                Inicializar();
147
        }
148

    
149
        /**
150
         * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
151
         */
152
        public WindowInfo getWindowInfo() {
153
                WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
154
                //Establecer el tama?o del formulario
155
                m_viewinfo.setWidth(wPanel);
156
                m_viewinfo.setHeight(hPanel);
157
                //Establecer el t?tulo del formulario
158
                m_viewinfo.setTitle(PluginServices.getText(this,"principal_components_calculus"));
159
                //punto X de la pantalla donde se situa
160
                m_viewinfo.setX(300);
161
                return m_viewinfo;
162
        }
163

    
164

    
165
        /**
166
         * @return panel con las opciones de exportar estadisticas
167
         */
168
         public JPanel getStatisticsPanel(){
169

    
170
                 if(statisticsPanel==null){
171
                         statisticsPanel=new JPanel();
172
                         TableLayout thisLayout = new TableLayout(new double[][] {
173
                                                {20,250,120},         
174
                                                {TableLayout.PREFERRED}}); 
175
                                        
176
                         statisticsPanel.setLayout(thisLayout);
177
                         JPanel p= new JPanel();
178
                         TitledBorder topBorder = BorderFactory.createTitledBorder((PluginServices.getText(this,"estadisticas")));
179
                         topBorder.setTitlePosition(TitledBorder.TOP);
180
                         statisticsPanel.setBorder(new CompoundBorder(topBorder,new EmptyBorder(5,5,5,5)));
181
                         BorderLayout bd=new BorderLayout();
182
                         p.setPreferredSize(new Dimension(170,70));
183
                         bd.setVgap(5);
184
                         bd.setHgap(5);
185
                         p.setLayout(bd);
186
                         p.add(getBandasStatistics(),BorderLayout.NORTH);
187
                         p.add(getVarianceStatistics(),BorderLayout.CENTER);
188
                         p.add(getAutovectorStatistics(),BorderLayout.SOUTH);
189
                         TableLayout thisLayout2 = new TableLayout(new double[][] {
190
                                                {5 ,85},         
191
                                                {40,TableLayout.PREFERRED}}); 
192
                         JPanel panelButton= new JPanel();
193
                         panelButton.setLayout(thisLayout2);
194
                         panelButton.add(getExportar(),"1,1");
195
                         statisticsPanel.add(p,"1,0");
196
                         statisticsPanel.add(panelButton,"2,0");
197
                 }
198
                 return statisticsPanel;
199
         }
200
         
201
        
202
         /**
203
          * inicializaci?n del di?logo
204
          */
205
         private void Inicializar(){
206
                        BorderLayout bd=new BorderLayout();
207
                        this.setLayout(bd);
208
                        TitledBorder topBorder = BorderFactory.createTitledBorder(" ");
209
                        topBorder.setTitlePosition(TitledBorder.TOP);
210
                        this.setBorder(new CompoundBorder(topBorder,new EmptyBorder(5,10,10,10)));
211
                        this.add(getPanelSuperior(),BorderLayout.NORTH);
212
                    this.add(getStatisticsPanel(),BorderLayout.CENTER);
213
                        completarTabla();
214
         }
215

    
216
         
217
         /**
218
          * @return panel con opciones de salida, tabla de componentes y botones de selecci?n todos/ninguno
219
          */
220
         private JPanel getPanelSuperior(){         
221
                 if (panelSuperior==null){
222
                         panelSuperior = new JPanel();
223
                         TitledBorder topBorder = BorderFactory.createTitledBorder((PluginServices.getText(this,"salida_raster")));
224
                         topBorder.setTitlePosition(TitledBorder.TOP);
225
                         panelSuperior.setBorder(new CompoundBorder(topBorder,new EmptyBorder(5,5,5,5)));
226
                         JPanel p=new JPanel();
227
                         TableLayout thisLayout = new TableLayout(new double[][] {
228
                                         {390},         
229
                                        {80,150,40}}); 
230
                                thisLayout.setHGap(5);
231
                                thisLayout.setVGap(3);
232
                                p.setLayout(thisLayout);
233
                                p.add(getNombreCapaPanel(),"0,0");
234
                                p.add(getScrollComponents(),"0,1");
235
                                p.add(getPanelTodos(),"0,2");
236
                            panelSuperior.add(p);         
237
                 }
238
                 return panelSuperior; 
239
         }
240
         
241
         
242
         /**
243
         * A?ade las filas a la tabla de selecci?n de componentes
244
         */
245
        public void completarTabla(){
246
                double acumulado=0;
247
                for (int i=0;i<autovalores.length;i++)
248
                        acumulado+=autovalores[i];
249
                int autova[]=new int[ autovalores.length];
250
                int cont= autovalores.length-1;
251
                for (int i=0; i<autovalores.length;i++){
252
                        autova[i]=cont;
253
                        cont--;
254
                }
255
                
256
                for (int i=autovalores.length-1;i>=0;i--)
257
                        getTableFormatComponent().addRow(autova[i],autovalores[i],autovalores[i]/acumulado,true);         
258
         }
259
         
260
        
261
        /**
262
         * @return JButton jbExportar
263
         */
264
        public JButton getExportar() {        
265
                if (jbExportar==null){
266
                        jbExportar=new JButton((PluginServices.getText(this,"exportar")));
267
                        jbExportar.addActionListener(this);
268
                }        
269
                return jbExportar;
270
        }
271
        
272
        
273
        /**
274
         * @return JButton jbNinguno
275
         */
276
        public JButton getNinguno() {
277
                if (jbNinguno==null){
278
                        ImageIcon icono = new ImageIcon(PrincipalComponentCalculusPanel.class.getClassLoader().getResource("images/table_delete.png"));
279
                        jbNinguno = new JButton(icono);
280
                        jbNinguno.addActionListener(this);
281
                }
282
                return jbNinguno;
283
        }
284

    
285

    
286
        /**
287
         * @return JButton jbTodos
288
         */
289
        public JButton getTodos() {
290
                if (jbTodos==null){
291
                        ImageIcon icono = new ImageIcon(PrincipalComponentCalculusPanel.class.getClassLoader().getResource("images/table.png"));
292
                        jbTodos = new JButton(icono);
293
                        jbTodos.addActionListener(this);
294
                }
295
                return jbTodos;
296
        }
297
        
298

    
299
        /**
300
         * @return JButton jexportVarMatrix
301
         */
302
        public JButton getJexportVarMatrix() {
303
                if(jexportVarMatrix==null){
304
                        jexportVarMatrix=new JButton((PluginServices.getText(this,"var_matrix")));
305
                        jexportVarMatrix.addActionListener(this);
306
                }
307
                return jexportVarMatrix;
308
        }
309

    
310
        
311
        /**
312
         * @return JButton jexportAutovectorMatrix
313
         */
314
        public JButton getJexportAutovectorMatrix() {
315
                if (jexportAutovectorMatrix==null){
316
                        jexportAutovectorMatrix=new JButton((PluginServices.getText(this,"autovector_matrix")));
317
                        jexportAutovectorMatrix.addActionListener(this);
318
                }
319
                return jexportAutovectorMatrix;
320
        }
321

    
322
        
323
        /**
324
         * @see ComponentTableFormat
325
         * @return modelo de tabla de componentes
326
         */
327
        public ComponentTableFormat getTableFormatComponent() {
328
                if(tableFormatComponent==null){
329
                        tableFormatComponent=new ComponentTableFormat();
330
                }
331
                return tableFormatComponent;
332
        }
333

    
334
        
335
        /**
336
         * @return tabla de componentes
337
         */
338
        public JTable getTableComponents(){
339
                if (tableComponent==null){
340
                        tableComponent=new JTable(getTableFormatComponent());
341
                }
342
                return tableComponent;
343
        }
344
        
345
        
346
        /**
347
         * @return scroll con la tabla de componentes
348
         */
349
        public JScrollPane getScrollComponents() {
350
                
351
                if(scrollComponents==null){
352
                        scrollComponents=new JScrollPane();
353
                }
354
                 getTableComponents().getColumn((PluginServices.getText(this,"componente"))).setPreferredWidth(110);        
355
                 getTableComponents().getColumn((PluginServices.getText(this,"autovalor"))).setPreferredWidth(80);
356
                 getTableComponents().getColumn((PluginServices.getText(this,"%"))).setPreferredWidth(80);
357
        
358
                 scrollComponents.setViewportView(getTableComponents());
359
                 scrollComponents.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
360
                        
361
                return scrollComponents;
362
        }
363
        
364
         
365
        /**
366
         * @return panel con los botones de selecci?n todo/ninguno
367
         */
368
        public JPanel getPanelTodos(){
369
                if (panelTodos==null){ 
370
                        panelTodos= new JPanel();
371
                        JPanel p = new JPanel();
372
                        p.setLayout(new FlowLayout(FlowLayout.RIGHT,1,1));
373
                        p.add(getTodos());
374
                        p.add(getNinguno());
375
                        p.setPreferredSize(new Dimension(375,30));
376
                        panelTodos.add(p);
377
                 }
378
                 return panelTodos;        
379
        }
380

    
381
         
382
        /**
383
        * @return panel que incluye el nombre de la capa y las opciones de almacenamieto de la capa de salida 
384
        */
385
        public JPanel getNombreCapaPanel() {
386
                
387
                if (nombreCapaPanel==null){
388
                        nombreCapaPanel=new JPanel();
389
                        GridBagConstraints gridBagConstraints;
390
                        JPanel radioPanel = new JPanel();
391
                        radioPanel.setLayout(new GridBagLayout());
392
                        radioPanel.setBorder(BorderFactory.createTitledBorder(""));
393
                        ButtonGroup buttonGroup = new ButtonGroup();
394
                        buttonGroup.add(getRadioMemory());
395
                        gridBagConstraints = new java.awt.GridBagConstraints();
396
                        gridBagConstraints.gridx = 0;
397
                        gridBagConstraints.gridy = 1;
398
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
399
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
400
                        radioPanel.add(getRadioMemory(),gridBagConstraints);
401
                        buttonGroup.add(getRadioFile());
402
                        gridBagConstraints = new java.awt.GridBagConstraints();
403
                        gridBagConstraints.gridx = 0;
404
                        gridBagConstraints.gridy = 2;
405
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
406
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
407
                        radioPanel.add(getRadioFile(),gridBagConstraints);
408
                        //Establece la separacion entre los elementos
409
                        nombreCapaPanel.setLayout(new GridBagLayout());
410
                        
411
                        gridBagConstraints = new java.awt.GridBagConstraints();
412
                        gridBagConstraints.gridx = 0;
413
                        gridBagConstraints.gridy = 0;
414
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
415
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
416
                        nombreCapaPanel.add(new JLabel( (PluginServices.getText(this,"nombre_capa")),SwingConstants.RIGHT ),gridBagConstraints);
417
                        
418
                        gridBagConstraints = new java.awt.GridBagConstraints();
419
                        gridBagConstraints.gridx = 1;
420
                        gridBagConstraints.gridy = 0;
421
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
422
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
423
                        nombreCapaPanel.add(getJTextNombreCapa(),gridBagConstraints);
424
                        
425
                        gridBagConstraints = new java.awt.GridBagConstraints();
426
                        gridBagConstraints.gridx = 2;
427
                        gridBagConstraints.gridy = 0;
428
                        gridBagConstraints.anchor = GridBagConstraints.WEST;
429
                        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
430
                        nombreCapaPanel.add(radioPanel,gridBagConstraints);
431
                }
432
                return nombreCapaPanel;
433
        }
434

    
435
        /**
436
         * @return javax.swing.JTextField
437
         */        
438
        public JTextField getJTextNombreCapa() {
439
                
440
                if(jTextNombreCapa==null){
441
                        jTextNombreCapa= new JTextField(10);
442
                        jTextNombreCapa.setText("NewLayer_" + RasterModule.layerCount);
443
                        RasterModule.layerCount++;
444
                        jTextNombreCapa.addFocusListener(this);
445
                }
446
                return jTextNombreCapa;
447
        }
448
         
449
        
450
        /**
451
         * Especificar el nombre de la nueva capa para el recuadro de texto asign?ndo
452
         * en cada llamada un nombre consecutivo.
453
         */
454
        public void setNewLayerText() {
455
                getJTextNombreCapa().setText("NewLayer_" + RasterModule.layerCount);
456
                RasterModule.layerCount++;
457
        }
458
        
459
        /**
460
         * @return JRadioButton de generar fichero
461
         */
462
        public JRadioButton getRadioFile(){
463
                if (rButtonFile == null){
464
                        rButtonFile = new JRadioButton(PluginServices.getText(this,"a_fichero"));
465
                        rButtonFile.addActionListener(this);
466
                }
467
                return rButtonFile;
468
        }
469
        
470
        /**
471
         * @return JRadioButton de generar en memoria
472
         */
473
        public JRadioButton getRadioMemory(){
474
                if (rButtonMemory == null){
475
                        rButtonMemory = new JRadioButton(PluginServices.getText(this,"a_memoria"),true);
476
                        rButtonMemory.addActionListener(this);
477
                }
478
                return rButtonMemory;
479
        }
480

    
481
        
482
        /**
483
         * M?todo para exportar las estadisticas seleccionadas a un fichero de texto
484
         */
485
        public void exportStatistics(){
486
                
487
                JFileChooser dlgExportar = new JFileChooser();
488
                dlgExportar.addChoosableFileFilter(new TxtFilter());
489
                int op= dlgExportar.showSaveDialog(this);
490
                    // Se comprueban las estadisticas a exportar
491
                        if (op == JFileChooser.APPROVE_OPTION){
492
                                File outFile = new 
493
                                File(dlgExportar.getSelectedFile().getAbsolutePath()+".txt");
494
                                OutputStream outputStream=null;
495
                                try {
496
                                         outputStream = new FileOutputStream(outFile);
497
                                } catch (FileNotFoundException e) {
498
                                        e.printStackTrace();
499
                                }
500
                                
501
                                if(getBandasStatistics().isSelected()){
502
                                        ExportGridStatistic(pc.getInputGrid(), outputStream);
503
                                }
504
                                if(getVarianceStatistics().isSelected()){
505
                                        ExportarMatriz(pc.getcoVarMatrix(),true,outputStream);
506
                                }
507
                
508
                                if (getAutovectorStatistics().isSelected()){
509
                                        ExportarMatriz(pc.getAutoVectorMatrix(),true,outputStream);
510
                                }
511
                
512
                                try {
513
                                        outputStream.close();
514
                                } catch (IOException e) {
515
                                        e.printStackTrace();
516
                                }
517
                }
518
        }
519
        
520
        
521
        /**
522
         * M?todo para exportar a disco las estadisticas del grid que se pasa como argumento.
523
         * @param grid        grid con las estadisticas a exportar
524
         * @param descriptor de  fichero salida
525
         */
526
        private void ExportGridStatistic(Grid grid,OutputStream outputStream){
527
                
528
                try {
529
                        outputStream.write("\t\t".getBytes());
530
                        outputStream.write("Max Value\t".getBytes());
531
                        outputStream.write("Min Value\t".getBytes());
532
                        outputStream.write("Mean Value\t".getBytes());
533
                        outputStream.write("\n".getBytes());
534
                        String aux="";
535
                        for(int i=0; i<grid.getBandCount();i++)
536
                        {
537
                                grid.setBandToOperate(i);
538
                                outputStream.write("\n".getBytes());
539
                                outputStream.write(("Band"+(i+1)).getBytes());
540
                                // Se escribe los valores con un numero de caracteres inferior a 8.
541
                                outputStream.write(("\t\t").getBytes());
542
                                Double var= new Double(grid.getMaxValue());
543
                                if (var.toString().getBytes().length>7)
544
                                        outputStream.write(var.toString().getBytes(),0,7);// Elementos de la matriz;
545
                                else{
546
                                        aux = var.toString();
547
                                        for (int k=var.toString().getBytes().length; k<8; k++)
548
                                                aux=aux+" ";
549
                                        outputStream.write(aux.getBytes(),0,7);
550
                                }
551
                                outputStream.write(("\t").getBytes());
552
                                var= new Double(grid.getMinValue());
553
                                if (var.toString().getBytes().length>7)
554
                                        outputStream.write(var.toString().getBytes(),0,7);// Elementos de la matriz;
555
                                else{
556
                                        aux = var.toString();
557
                                        for (int k=var.toString().getBytes().length; k<8; k++)
558
                                                aux=aux+" ";
559
                                        outputStream.write(aux.getBytes(),0,7);
560
                                }
561
                                outputStream.write(("\t").getBytes());
562
                                var= new Double(grid.getMeanValue());
563
                                if (var.toString().getBytes().length>7)
564
                                        outputStream.write(var.toString().getBytes(),0,7);// Elementos de la matriz;
565
                                else{
566
                                        aux = var.toString();
567
                                        for (int k=var.toString().getBytes().length; k<8; k++)
568
                                                aux=aux+" ";
569
                                        outputStream.write(aux.getBytes(),0,7);
570
                                }
571
                                
572
                        }
573
                        
574
                        outputStream.write("\n\n".getBytes());
575
                } catch (IOException e) {
576
                        e.printStackTrace();
577
                }
578
                
579
                
580
        }
581
        
582
        /**
583
         * M?todo para exportar a disco la matriz que se le pasa por argumento.
584
         * Si es una matriz de autovectores ordena las columnas en orden descendente segun autovalores.
585
         * @param matriz matriz a exportar
586
         * @param isAutovectorMatrix true si es una matrix de autovectores
587
         * @param descriptor de  fichero de salida
588
         */
589
        private void ExportarMatriz(Matrix matriz, boolean isAutovectorMatrix,OutputStream outputStream ){        
590
                
591
                // Orden correcto de las columnas de autovectores
592
                int resultOrden[]= new int[matriz.getRowDimension()];
593
                int cont = matriz.getRowDimension()-1;
594
                for(int i=0;i<matriz.getRowDimension();i++){
595
                                if (isAutovectorMatrix)
596
                                        resultOrden[i]=cont;
597
                                else
598
                                        resultOrden[i]=i;
599
                                
600
                                cont--;
601
                }
602
                String aux=null;
603
                try{        
604
                        outputStream.write("\t\t\t".getBytes());
605
                                        for (int j=0; j<matriz.getColumnDimension();j++)
606
                                                {        
607
                                                        outputStream.write(("Band"+(j+1)).getBytes());
608
                                                        outputStream.write("\t\t\t".getBytes());
609
                                                }
610
                                        outputStream.write("\n".getBytes());
611
                                        // Volcado de la Matriz a disco
612
                                        for (int i=0 ; i<matriz.getRowDimension(); i++){
613
                                                outputStream.write(("Band"+(i+1)).getBytes());
614
                                                outputStream.write("\t\t".getBytes());
615
                                                for (int j=0; j<matriz.getColumnDimension();j++){                                        
616
                                                        Double var =new Double(matriz.get(i,resultOrden[j]));
617
                                                        if (var.toString().getBytes().length>15)
618
                                                                outputStream.write(var.toString().getBytes(),0,15);// Elementos de la matriz;
619
                                                        else{
620
                                                                aux = var.toString();
621
                                                                for (int k=var.toString().getBytes().length; k<16; k++)
622
                                                                        aux=aux+" ";
623
                                                                outputStream.write(aux.getBytes(),0,15);
624
                                                        }
625
                                                        outputStream.write("\t".getBytes());
626
                                                }
627
                                                outputStream.write("\n".getBytes());
628
                                        }
629
                                        outputStream.write("\n".getBytes());
630
                        }catch (FileNotFoundException e) {
631
                                e.printStackTrace();
632
                        } catch (IOException e) {
633
                                // TODO Auto-generated catch block
634
                                e.printStackTrace();
635
                        }
636
        
637
        }
638

    
639
        /**
640
         * @return checkbox autovectores
641
         */
642
        public JCheckBox getAutovectorStatistics() {
643
                if(autovectorStatistics==null){
644
                        autovectorStatistics=new JCheckBox(PluginServices.getText(this, "autovector_statistics"),true);
645
                }
646
                return autovectorStatistics;
647
        }
648

    
649

    
650
        /**
651
         * @return checkbox estadisticas por banda
652
         */
653
        public JCheckBox getBandasStatistics() {
654
                if(bandasStatistics==null){
655
                        bandasStatistics=new JCheckBox(PluginServices.getText(this, "bandas_statistics"),true);
656
                }
657
                return bandasStatistics;
658
        }
659

    
660

    
661
        /**
662
         * @return checkbox matriz varianza-covarianza 
663
         */
664
        public JCheckBox getVarianceStatistics() {
665
                if(varianceStatistics==null){
666
                        varianceStatistics=new JCheckBox(PluginServices.getText(this, "variance_statistics"),true);
667
                }
668
                
669
                return varianceStatistics;
670
        }
671

    
672

    
673
        /*
674
         * (non-Javadoc)
675
         * @see org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener#actionButtonPressed(org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent)
676
         */
677
        public void actionButtonPressed(ButtonsPanelEvent e) {
678
//                 Bot?n de Aceptar
679
                if (e.getButton() == ButtonsPanel.BUTTON_ACCEPT) {
680
                        aplicar();
681
                        close();
682
                }
683

    
684
                // Bot?n de Aplicar
685
                if (e.getButton() == ButtonsPanel.BUTTON_APPLY) {
686
                        aplicar();
687
                }
688

    
689
                // Bot?n de Cerrar
690
                if (e.getButton() == ButtonsPanel.BUTTON_CANCEL) {
691
                        close();
692
                }        
693
        }
694

    
695

    
696
        /**
697
         * acciones al aplicar
698
         */
699
        public void aplicar(){
700
                
701
                if(getTableFormatComponent().getNumSelected()>0){
702
                        PCImageProcess generateImageProcess = new PCImageProcess(pc,getTableFormatComponent().getSeleccionadas(),getFileSelected());
703
                        IncrementableTask incrementableTask = new IncrementableTask(generateImageProcess);
704
                        generateImageProcess.setIncrementableTask(incrementableTask);
705
                        incrementableTask.showWindow();
706
                        generateImageProcess.start();
707
                        incrementableTask.start();                
708
                        
709
                }
710
                else{                        
711
                        JOptionPane.showMessageDialog(null,
712
                        PluginServices.getText(this,"no_components"), PluginServices.getText(this,"principal_components"),
713
                        JOptionPane.WARNING_MESSAGE);
714
                }
715
        }
716
        
717
        /**
718
         * acciones al cerrar
719
         */
720
        public void close(){
721
                try {
722
                        PluginServices.getMDIManager().closeWindow(this);
723
                } catch (ArrayIndexOutOfBoundsException ex) {
724
                // Si la ventana no se puede eliminar no hacemos nada
725
                }
726
        }
727
        
728
        
729
        /**
730
         * @return path con el fichero seleccionado
731
         */
732
        public String getFileSelected() {
733
                String path = "";
734
                if (getRadioFile().isSelected()) {
735
                        JFileChooser chooser = new JFileChooser(FileOpenWizard.getLastPath());
736
                        chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero"));
737
                        //A?adimos las extensiones que hayan sido registradas en el driver
738
                        String[] extList = GeoRasterWriter.getDriversExtensions();
739
                        for(int i=0;i<extList.length;i++)
740
                                chooser.addChoosableFileFilter(new WriterFilter(extList[i]));
741

    
742
                        if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION)
743
                                return null;
744

    
745
                        String fName = chooser.getSelectedFile().toString();
746
                        String ext = ((WriterFilter)chooser.getFileFilter()).getDescription();
747

    
748
                        ext = ext.toLowerCase().substring(ext.lastIndexOf(".") + 1, ext.length());
749

    
750
                        if ((fName != null) && !fName.equals(""))
751
                                if (!fName.endsWith("." + ext))
752
                                        fName = fName + "." + ext;
753

    
754
                        FileOpenWizard.setLastPath(chooser.getSelectedFile().getPath().substring(0, chooser.getSelectedFile().getPath().lastIndexOf(File.separator)));
755
                        path = fName;
756
                } else {
757
                        path = Utilities.createTempDirectory() + File.separator +getJTextNombreCapa().getText() + ".tif";
758
                        setNewLayerText();
759
                }
760
                return path;
761
        }
762
        
763
        /*
764
         * (non-Javadoc)
765
         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
766
         */
767
        public void actionPerformed(ActionEvent e) {
768
                if(e.getSource()==getExportar()){
769
                        exportStatistics();
770
                }
771
                if (e.getSource()==getTodos()){        
772
                        getTableFormatComponent().seleccionarTodas();
773
                        updateUI();
774
                }
775
                if (e.getSource()==getNinguno()){
776
                        getTableFormatComponent().seleccionarNinguna();
777
                        updateUI();
778
                }
779
        }
780
        
781
        
782
        public void focusGained(FocusEvent arg0) {
783
                // TODO Auto-generated method stub
784
        }
785

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

    
792

    
793
class TxtFilter extends FileFilter {
794

    
795
        final static String exp = "txt";
796
        public boolean accept(File f) {
797
                if (f.isDirectory()) {
798
           return true;
799
       }
800
       String s = f.getName();
801
       int i = s.lastIndexOf('.');
802

    
803
       if (i > 0 &&  i < s.length() - 1) {
804
           String extension = s.substring(i+1).toLowerCase();
805
           if (exp.equals(extension)){
806
                   return true;
807
           } else {
808
               return false;
809
           }
810
       }
811
       return false;
812
        }
813

    
814
        public String getDescription() {
815
                 return "Archivos .txt";
816
        }
817
        
818
}
819

    
820

    
821
/**
822
 * @author Nacho Brodin <brodin_ign@gva.es>
823
 * Filtro para el selector de formatos de escritura
824
 */
825
class WriterFilter extends javax.swing.filechooser.FileFilter {
826
        private String                                filter;
827

    
828
        public WriterFilter(String fil) {
829
                this.filter = fil;
830
        }
831

    
832
        public boolean accept(File f) {
833
                return f.isDirectory() || f.getName().toLowerCase().endsWith("." + filter);
834
        }
835

    
836
        public String getDescription() {
837
                return "." + filter;
838
        }
839
}
840