root / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / principalcomponents / gui / PrincipalComponentCalculusPanel.java @ 14608
History | View | Annotate | Download (23.6 KB)
1 | 13790 | dguerrero | /* 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.Color; |
||
47 | import java.awt.Dimension; |
||
48 | import java.awt.FlowLayout; |
||
49 | import java.awt.GridBagConstraints; |
||
50 | import java.awt.GridBagLayout; |
||
51 | import java.awt.event.ActionEvent; |
||
52 | import java.awt.event.ActionListener; |
||
53 | import java.awt.event.FocusEvent; |
||
54 | import java.awt.event.FocusListener; |
||
55 | import java.awt.geom.AffineTransform; |
||
56 | import java.io.File; |
||
57 | import java.io.FileNotFoundException; |
||
58 | import java.io.FileOutputStream; |
||
59 | import java.io.IOException; |
||
60 | import java.io.OutputStream; |
||
61 | |||
62 | import javax.swing.BorderFactory; |
||
63 | import javax.swing.ButtonGroup; |
||
64 | import javax.swing.ImageIcon; |
||
65 | import javax.swing.JButton; |
||
66 | import javax.swing.JCheckBox; |
||
67 | import javax.swing.JFileChooser; |
||
68 | import javax.swing.JLabel; |
||
69 | import javax.swing.JOptionPane; |
||
70 | import javax.swing.JPanel; |
||
71 | import javax.swing.JRadioButton; |
||
72 | import javax.swing.JScrollPane; |
||
73 | import javax.swing.JTable; |
||
74 | import javax.swing.JTextField; |
||
75 | import javax.swing.SwingConstants; |
||
76 | import javax.swing.border.CompoundBorder; |
||
77 | import javax.swing.border.EmptyBorder; |
||
78 | import javax.swing.border.TitledBorder; |
||
79 | import javax.swing.filechooser.FileFilter; |
||
80 | |||
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.incrementabletask.IncrementableTask; |
||
86 | import org.gvsig.raster.dataset.GeoRasterWriter; |
||
87 | import org.gvsig.raster.grid.Grid; |
||
88 | import org.gvsig.rastertools.RasterModule; |
||
89 | import org.gvsig.remotesensing.principalcomponents.PCImageProcess; |
||
90 | import org.gvsig.remotesensing.principalcomponents.PCStatisticsProcess; |
||
91 | |||
92 | import Jama.Matrix; |
||
93 | |||
94 | import com.iver.andami.PluginServices; |
||
95 | import com.iver.andami.Utilities; |
||
96 | import com.iver.andami.ui.mdiManager.IWindow; |
||
97 | import com.iver.andami.ui.mdiManager.WindowInfo; |
||
98 | 14180 | amunoz | import com.iver.cit.gvsig.addlayer.fileopen.FileOpenWizard; |
99 | 13790 | dguerrero | import com.iver.cit.gvsig.fmap.MapContext; |
100 | import com.iver.cit.gvsig.project.documents.view.gui.View; |
||
101 | |||
102 | |||
103 | /*** Clase que implementa la ventana de seleccion de parametros para el calculo de la nueva imagen PC
|
||
104 | * @author Alejandro Mu?oz Sanchez
|
||
105 | * */
|
||
106 | public class PrincipalComponentCalculusPanel extends DefaultButtonsPanel implements ButtonsPanelListener, IWindow,ActionListener,FocusListener { |
||
107 | |||
108 | private static final long serialVersionUID = 1L; |
||
109 | private JPanel centerPanel; |
||
110 | private JPanel statisticsPanel; |
||
111 | private JPanel panelTodos; |
||
112 | private JPanel nombreCapaPanel; |
||
113 | private JButton exportar; |
||
114 | private JButton jexportVarMatrix; |
||
115 | private JButton jexportAutovectorMatrix; |
||
116 | private ComponentTableFormat tableFormatComponent;
|
||
117 | private JScrollPane scrollComponents; |
||
118 | private JTable tableComponent; |
||
119 | private JCheckBox jcheckselectAll; |
||
120 | private JTextField jTextNombreCapa; |
||
121 | private JButton todos; |
||
122 | private JButton ninguno; |
||
123 | 14608 | amunoz | private int wPanel=460; |
124 | private int hPanel=470; |
||
125 | 13790 | dguerrero | private double[] autovalores; |
126 | private PCStatisticsProcess pc;
|
||
127 | private JPanel panelSuperior; |
||
128 | private JRadioButton rButtonFile = null; |
||
129 | private JRadioButton rButtonMemory = null; |
||
130 | private JCheckBox bandasStatistics; |
||
131 | private JCheckBox varianceStatistics; |
||
132 | private JCheckBox autovectorStatistics; |
||
133 | |||
134 | |||
135 | public PrincipalComponentCalculusPanel(View vista,PCStatisticsProcess pC){ |
||
136 | |||
137 | autovalores = pC.getResult(); |
||
138 | pc=pC; |
||
139 | this.addButtonPressedListener(this); |
||
140 | Inicializar(); |
||
141 | } |
||
142 | |||
143 | public WindowInfo getWindowInfo() {
|
||
144 | |||
145 | WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
|
||
146 | //Establecer el tama?o del formulario
|
||
147 | m_viewinfo.setWidth(wPanel); |
||
148 | m_viewinfo.setHeight(hPanel); |
||
149 | //Establecer el t?tulo del formulario
|
||
150 | m_viewinfo.setTitle(PluginServices.getText(this,"principal_components_calculus")); |
||
151 | //punto X de la pantalla donde se situa
|
||
152 | m_viewinfo.setX(300);
|
||
153 | return m_viewinfo;
|
||
154 | |||
155 | } |
||
156 | |||
157 | |||
158 | // Panel con etiqueta y combo
|
||
159 | public JPanel getStatisticsPanel(){ |
||
160 | |||
161 | if(statisticsPanel==null){ |
||
162 | statisticsPanel=new JPanel(); |
||
163 | |||
164 | TableLayout thisLayout = new TableLayout(new double[][] { |
||
165 | 14608 | amunoz | {20,250,120}, |
166 | 13790 | dguerrero | {TableLayout.PREFERRED}}); |
167 | |||
168 | statisticsPanel.setLayout(thisLayout); |
||
169 | JPanel p= new JPanel(); |
||
170 | TitledBorder topBorder = BorderFactory.createTitledBorder((PluginServices.getText(this,"estadisticas"))); |
||
171 | topBorder.setTitlePosition(TitledBorder.TOP);
|
||
172 | statisticsPanel.setBorder(new CompoundBorder(topBorder,new EmptyBorder(5,5,5,5))); |
||
173 | BorderLayout bd=new BorderLayout(); |
||
174 | 14608 | amunoz | p.setPreferredSize(new Dimension(170,70)); |
175 | 13790 | dguerrero | bd.setVgap(5);
|
176 | bd.setHgap(5);
|
||
177 | p.setLayout(bd); |
||
178 | p.add(getBandasStatistics(),BorderLayout.NORTH);
|
||
179 | p.add(getVarianceStatistics(),BorderLayout.CENTER);
|
||
180 | p.add(getAutovectorStatistics(),BorderLayout.SOUTH);
|
||
181 | TableLayout thisLayout2 = new TableLayout(new double[][] { |
||
182 | 14608 | amunoz | {5 ,85}, |
183 | 13790 | dguerrero | {40,TableLayout.PREFERRED}});
|
184 | JPanel panelButton= new JPanel(); |
||
185 | panelButton.setLayout(thisLayout2); |
||
186 | panelButton.add(getExportar(),"1,1");
|
||
187 | statisticsPanel.add(p,"1,0");
|
||
188 | 14608 | amunoz | statisticsPanel.add(panelButton,"2,0");
|
189 | 13790 | dguerrero | |
190 | } |
||
191 | return statisticsPanel;
|
||
192 | } |
||
193 | |||
194 | |||
195 | private void Inicializar(){ |
||
196 | BorderLayout bd=new BorderLayout(); |
||
197 | this.setLayout(bd);
|
||
198 | TitledBorder topBorder = BorderFactory.createTitledBorder(" "); |
||
199 | topBorder.setTitlePosition(TitledBorder.TOP);
|
||
200 | this.setBorder(new CompoundBorder(topBorder,new EmptyBorder(10,10,10,10))); |
||
201 | this.add(getPanelSuperior(),BorderLayout.NORTH); |
||
202 | this.add(getStatisticsPanel(),BorderLayout.CENTER); |
||
203 | completarTabla(); |
||
204 | } |
||
205 | |||
206 | |||
207 | private JPanel getPanelSuperior(){ |
||
208 | if (panelSuperior==null){ |
||
209 | panelSuperior = new JPanel(); |
||
210 | TitledBorder topBorder = BorderFactory.createTitledBorder((PluginServices.getText(this,"salida_raster"))); |
||
211 | topBorder.setTitlePosition(TitledBorder.TOP);
|
||
212 | panelSuperior.setBorder(new CompoundBorder(topBorder,new EmptyBorder(5,5,5,5))); |
||
213 | JPanel p=new JPanel(); |
||
214 | TableLayout thisLayout = new TableLayout(new double[][] { |
||
215 | {390},
|
||
216 | 14608 | amunoz | {80,150,40}}); |
217 | 13790 | dguerrero | thisLayout.setHGap(5);
|
218 | 14608 | amunoz | thisLayout.setVGap(3);
|
219 | 13790 | dguerrero | p.setLayout(thisLayout); |
220 | p.add(getNombreCapaPanel(),"0,0");
|
||
221 | p.add(getScrollComponents(),"0,1");
|
||
222 | p.add(getPanelTodos(),"0,2");
|
||
223 | 14608 | amunoz | panelSuperior.add(p); |
224 | 13790 | dguerrero | } |
225 | return panelSuperior;
|
||
226 | |||
227 | } |
||
228 | |||
229 | |||
230 | |||
231 | public void completarTabla(){ |
||
232 | double acumulado=0; |
||
233 | for (int i=0;i<autovalores.length;i++) |
||
234 | acumulado+=autovalores[i]; |
||
235 | int autova[]=new int[ autovalores.length]; |
||
236 | int cont= autovalores.length-1; |
||
237 | for (int i=0; i<autovalores.length;i++){ |
||
238 | autova[i]=cont; |
||
239 | cont--; |
||
240 | } |
||
241 | |||
242 | for (int i=autovalores.length-1;i>=0;i--) |
||
243 | 14608 | amunoz | getTableFormatComponent().addRow(autova[i],autovalores[i],autovalores[i]/acumulado,true);
|
244 | 13790 | dguerrero | } |
245 | |||
246 | |||
247 | public JButton getExportar() { |
||
248 | |||
249 | if (exportar==null){ |
||
250 | exportar=new JButton((PluginServices.getText(this,"exportar"))); |
||
251 | exportar.addActionListener(this);
|
||
252 | } |
||
253 | return exportar;
|
||
254 | } |
||
255 | |||
256 | |||
257 | |||
258 | public JButton getNinguno() { |
||
259 | if (ninguno==null){ |
||
260 | ImageIcon icono = new ImageIcon(PrincipalComponentCalculusPanel.class.getClassLoader().getResource("images/table_delete.png")); |
||
261 | ninguno = new JButton(icono); |
||
262 | ninguno.addActionListener(this);
|
||
263 | } |
||
264 | return ninguno;
|
||
265 | } |
||
266 | |||
267 | |||
268 | public JButton getTodos() { |
||
269 | if (todos==null){ |
||
270 | ImageIcon icono = new ImageIcon(PrincipalComponentCalculusPanel.class.getClassLoader().getResource("images/table.png")); |
||
271 | todos = new JButton(icono); |
||
272 | todos.addActionListener(this);
|
||
273 | } |
||
274 | return todos;
|
||
275 | } |
||
276 | |||
277 | |||
278 | |||
279 | public void actionPerformed(ActionEvent e) { |
||
280 | if(e.getSource()==getExportar()){
|
||
281 | exportStatistics(); |
||
282 | |||
283 | } |
||
284 | if (e.getSource()==getTodos()){
|
||
285 | |||
286 | getTableFormatComponent().seleccionarTodas(); |
||
287 | updateUI(); |
||
288 | } |
||
289 | if (e.getSource()==getNinguno()){
|
||
290 | |||
291 | getTableFormatComponent().seleccionarNinguna(); |
||
292 | updateUI(); |
||
293 | } |
||
294 | } |
||
295 | |||
296 | |||
297 | |||
298 | public void focusGained(FocusEvent arg0) { |
||
299 | // TODO Auto-generated method stub
|
||
300 | |||
301 | } |
||
302 | |||
303 | public void focusLost(FocusEvent arg0) { |
||
304 | // TODO Auto-generated method stub
|
||
305 | |||
306 | } |
||
307 | |||
308 | public JButton getJexportVarMatrix() { |
||
309 | |||
310 | if(jexportVarMatrix==null){ |
||
311 | jexportVarMatrix=new JButton((PluginServices.getText(this,"var_matrix"))); |
||
312 | jexportVarMatrix.addActionListener(this);
|
||
313 | } |
||
314 | |||
315 | return jexportVarMatrix;
|
||
316 | } |
||
317 | |||
318 | public JButton getJexportAutovectorMatrix() { |
||
319 | |||
320 | if (jexportAutovectorMatrix==null){ |
||
321 | jexportAutovectorMatrix=new JButton((PluginServices.getText(this,"autovector_matrix"))); |
||
322 | jexportAutovectorMatrix.addActionListener(this);
|
||
323 | } |
||
324 | |||
325 | return jexportAutovectorMatrix;
|
||
326 | } |
||
327 | |||
328 | |||
329 | public JPanel getCenterPanel() { |
||
330 | |||
331 | if (centerPanel==null){ |
||
332 | centerPanel=new JPanel(); |
||
333 | |||
334 | TitledBorder topBorder = BorderFactory.createTitledBorder((PluginServices.getText(this,"seleccion_componente"))); |
||
335 | topBorder.setTitlePosition(TitledBorder.TOP);
|
||
336 | centerPanel.setBorder(new CompoundBorder(topBorder,new EmptyBorder(5,5,5,5))); |
||
337 | |||
338 | BorderLayout bd=new BorderLayout(); |
||
339 | JPanel p=new JPanel(); |
||
340 | 14608 | amunoz | p.setPreferredSize(new Dimension(300,250)); |
341 | 13790 | dguerrero | p.setLayout(bd); |
342 | p.add(getScrollComponents(),BorderLayout.CENTER);
|
||
343 | p.add(getPanelTodos(),BorderLayout.SOUTH);
|
||
344 | p.add( getNombreCapaPanel(),BorderLayout.NORTH);
|
||
345 | centerPanel.add(p); |
||
346 | |||
347 | } |
||
348 | |||
349 | return centerPanel;
|
||
350 | } |
||
351 | |||
352 | |||
353 | public ComponentTableFormat getTableFormatComponent() {
|
||
354 | if(tableFormatComponent==null){ |
||
355 | tableFormatComponent=new ComponentTableFormat();
|
||
356 | } |
||
357 | return tableFormatComponent;
|
||
358 | } |
||
359 | |||
360 | |||
361 | public JTable getTableComponents(){ |
||
362 | if (tableComponent==null){ |
||
363 | tableComponent=new JTable(getTableFormatComponent()); |
||
364 | } |
||
365 | return tableComponent;
|
||
366 | } |
||
367 | |||
368 | |||
369 | |||
370 | |||
371 | public JScrollPane getScrollComponents() { |
||
372 | |||
373 | if(scrollComponents==null){ |
||
374 | scrollComponents=new JScrollPane(); |
||
375 | } |
||
376 | getTableComponents().getColumn((PluginServices.getText(this,"componente"))).setPreferredWidth(110); |
||
377 | getTableComponents().getColumn((PluginServices.getText(this,"autovalor"))).setPreferredWidth(80); |
||
378 | getTableComponents().getColumn((PluginServices.getText(this,"%"))).setPreferredWidth(80); |
||
379 | |||
380 | scrollComponents.setViewportView(getTableComponents()); |
||
381 | scrollComponents.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||
382 | |||
383 | return scrollComponents;
|
||
384 | } |
||
385 | |||
386 | public JCheckBox getSelectAll() { |
||
387 | if(jcheckselectAll==null){ |
||
388 | |||
389 | jcheckselectAll=new JCheckBox((PluginServices.getText(this,"seleccion_todo"))); |
||
390 | jcheckselectAll.setSelected(true);
|
||
391 | jcheckselectAll.addActionListener(this);
|
||
392 | } |
||
393 | |||
394 | return jcheckselectAll;
|
||
395 | } |
||
396 | |||
397 | |||
398 | |||
399 | public JPanel getPanelTodos(){ |
||
400 | if (panelTodos==null){ |
||
401 | panelTodos= new JPanel(); |
||
402 | JPanel p = new JPanel(); |
||
403 | p.setLayout(new FlowLayout(FlowLayout.RIGHT,1,1)); |
||
404 | p.add(getTodos()); |
||
405 | p.add(getNinguno()); |
||
406 | p.setPreferredSize(new Dimension(375,30)); |
||
407 | panelTodos.add(p); |
||
408 | } |
||
409 | return panelTodos;
|
||
410 | } |
||
411 | |||
412 | |||
413 | public JPanel getNombreCapaPanel() { |
||
414 | |||
415 | if (nombreCapaPanel==null){ |
||
416 | nombreCapaPanel=new JPanel(); |
||
417 | GridBagConstraints gridBagConstraints;
|
||
418 | JPanel radioPanel = new JPanel(); |
||
419 | radioPanel.setLayout(new GridBagLayout()); |
||
420 | radioPanel.setBorder(BorderFactory.createTitledBorder("")); |
||
421 | ButtonGroup buttonGroup = new ButtonGroup(); |
||
422 | buttonGroup.add(getRadioMemory()); |
||
423 | gridBagConstraints = new java.awt.GridBagConstraints();
|
||
424 | gridBagConstraints.gridx = 0;
|
||
425 | gridBagConstraints.gridy = 1;
|
||
426 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
427 | gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); |
||
428 | radioPanel.add(getRadioMemory(),gridBagConstraints); |
||
429 | buttonGroup.add(getRadioFile()); |
||
430 | gridBagConstraints = new java.awt.GridBagConstraints();
|
||
431 | gridBagConstraints.gridx = 0;
|
||
432 | gridBagConstraints.gridy = 2;
|
||
433 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
434 | gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); |
||
435 | radioPanel.add(getRadioFile(),gridBagConstraints); |
||
436 | //Establece la separacion entre los elementos
|
||
437 | nombreCapaPanel.setLayout(new GridBagLayout()); |
||
438 | |||
439 | gridBagConstraints = new java.awt.GridBagConstraints();
|
||
440 | gridBagConstraints.gridx = 0;
|
||
441 | gridBagConstraints.gridy = 0;
|
||
442 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
443 | gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); |
||
444 | nombreCapaPanel.add(new JLabel( (PluginServices.getText(this,"nombre_capa")),SwingConstants.RIGHT ),gridBagConstraints); |
||
445 | |||
446 | gridBagConstraints = new java.awt.GridBagConstraints();
|
||
447 | gridBagConstraints.gridx = 1;
|
||
448 | gridBagConstraints.gridy = 0;
|
||
449 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
450 | gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); |
||
451 | nombreCapaPanel.add(getJTextNombreCapa(),gridBagConstraints); |
||
452 | |||
453 | gridBagConstraints = new java.awt.GridBagConstraints();
|
||
454 | gridBagConstraints.gridx = 2;
|
||
455 | gridBagConstraints.gridy = 0;
|
||
456 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
457 | gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3); |
||
458 | nombreCapaPanel.add(radioPanel,gridBagConstraints); |
||
459 | } |
||
460 | |||
461 | return nombreCapaPanel;
|
||
462 | } |
||
463 | |||
464 | public JTextField getJTextNombreCapa() { |
||
465 | |||
466 | if(jTextNombreCapa==null){ |
||
467 | 14608 | amunoz | jTextNombreCapa= new JTextField(10); |
468 | 13790 | dguerrero | jTextNombreCapa.setText("NewLayer_" + RasterModule.layerCount);
|
469 | RasterModule.layerCount++; |
||
470 | jTextNombreCapa.addFocusListener(this);
|
||
471 | } |
||
472 | return jTextNombreCapa;
|
||
473 | } |
||
474 | |||
475 | |||
476 | /**
|
||
477 | * Especificar el nombre de la nueva capa para el recuadro de texto asign?ndo
|
||
478 | * en cada llamada un nombre consecutivo.
|
||
479 | */
|
||
480 | public void setNewLayerText() { |
||
481 | getJTextNombreCapa().setText("NewLayer_" + RasterModule.layerCount);
|
||
482 | RasterModule.layerCount++; |
||
483 | } |
||
484 | |||
485 | |||
486 | public JRadioButton getRadioFile(){ |
||
487 | if (rButtonFile == null){ |
||
488 | rButtonFile = new JRadioButton(PluginServices.getText(this,"a_fichero")); |
||
489 | rButtonFile.addActionListener(this);
|
||
490 | } |
||
491 | return rButtonFile;
|
||
492 | } |
||
493 | |||
494 | public JRadioButton getRadioMemory(){ |
||
495 | if (rButtonMemory == null){ |
||
496 | rButtonMemory = new JRadioButton(PluginServices.getText(this,"a_memoria"),true); |
||
497 | rButtonMemory.addActionListener(this);
|
||
498 | } |
||
499 | return rButtonMemory;
|
||
500 | } |
||
501 | |||
502 | |||
503 | public void exportStatistics(){ |
||
504 | |||
505 | JFileChooser dlgExportar = new JFileChooser(); |
||
506 | dlgExportar.addChoosableFileFilter(new TxtFilter());
|
||
507 | int op= dlgExportar.showSaveDialog(this); |
||
508 | // Se comprueban las estadisticas a exportar
|
||
509 | if (op == JFileChooser.APPROVE_OPTION){ |
||
510 | |||
511 | File outFile = new |
||
512 | File(dlgExportar.getSelectedFile().getAbsolutePath()+".txt"); |
||
513 | OutputStream outputStream=null; |
||
514 | try {
|
||
515 | outputStream = new FileOutputStream(outFile); |
||
516 | } catch (FileNotFoundException e) { |
||
517 | e.printStackTrace(); |
||
518 | } |
||
519 | |||
520 | if(getBandasStatistics().isSelected()){
|
||
521 | ExportGridStatistic(pc.getInputGrid(), outputStream); |
||
522 | } |
||
523 | if(getVarianceStatistics().isSelected()){
|
||
524 | ExportarMatriz(pc.getcoVarMatrix(),true,outputStream);
|
||
525 | } |
||
526 | |||
527 | if (getAutovectorStatistics().isSelected()){
|
||
528 | ExportarMatriz(pc.getAutoVectorMatrix(),true,outputStream);
|
||
529 | } |
||
530 | |||
531 | try {
|
||
532 | outputStream.close(); |
||
533 | } catch (IOException e) { |
||
534 | e.printStackTrace(); |
||
535 | } |
||
536 | } |
||
537 | } |
||
538 | |||
539 | private void ExportGridStatistic(Grid grid,OutputStream outputStream ){ |
||
540 | |||
541 | try {
|
||
542 | outputStream.write("\t\t".getBytes());
|
||
543 | outputStream.write("Max Value\t".getBytes());
|
||
544 | outputStream.write("Min Value\t".getBytes());
|
||
545 | outputStream.write("Mean Value\t".getBytes());
|
||
546 | outputStream.write("\n".getBytes());
|
||
547 | String aux=""; |
||
548 | for(int i=0; i<grid.getBandCount();i++) |
||
549 | { |
||
550 | grid.setBandToOperate(i); |
||
551 | outputStream.write("\n".getBytes());
|
||
552 | outputStream.write(("Band"+(i+1)).getBytes()); |
||
553 | // Se escribe los valores con un numero de caracteres inferior a 8.
|
||
554 | outputStream.write(("\t\t").getBytes());
|
||
555 | Double var= new Double(grid.getMaxValue()); |
||
556 | if (var.toString().getBytes().length>7) |
||
557 | outputStream.write(var.toString().getBytes(),0,7);// Elementos de la matriz; |
||
558 | else{
|
||
559 | aux = var.toString(); |
||
560 | for (int k=var.toString().getBytes().length; k<8; k++) |
||
561 | aux=aux+" ";
|
||
562 | outputStream.write(aux.getBytes(),0,7); |
||
563 | } |
||
564 | outputStream.write(("\t").getBytes());
|
||
565 | var= new Double(grid.getMinValue()); |
||
566 | if (var.toString().getBytes().length>7) |
||
567 | outputStream.write(var.toString().getBytes(),0,7);// Elementos de la matriz; |
||
568 | else{
|
||
569 | aux = var.toString(); |
||
570 | for (int k=var.toString().getBytes().length; k<8; k++) |
||
571 | aux=aux+" ";
|
||
572 | outputStream.write(aux.getBytes(),0,7); |
||
573 | } |
||
574 | outputStream.write(("\t").getBytes());
|
||
575 | var= new Double(grid.getMeanValue()); |
||
576 | if (var.toString().getBytes().length>7) |
||
577 | outputStream.write(var.toString().getBytes(),0,7);// Elementos de la matriz; |
||
578 | else{
|
||
579 | aux = var.toString(); |
||
580 | for (int k=var.toString().getBytes().length; k<8; k++) |
||
581 | aux=aux+" ";
|
||
582 | outputStream.write(aux.getBytes(),0,7); |
||
583 | } |
||
584 | |||
585 | } |
||
586 | |||
587 | outputStream.write("\n\n".getBytes());
|
||
588 | } catch (IOException e) { |
||
589 | e.printStackTrace(); |
||
590 | } |
||
591 | |||
592 | |||
593 | } |
||
594 | |||
595 | // Funcion para exportar a disco la matriz que se le pasa por argumento.
|
||
596 | // Si es una matriz de autovectores ordena las columnas en orden descendente segun autovalores.
|
||
597 | private void ExportarMatriz(Matrix matriz, boolean isAutovectorMatrix,OutputStream outputStream ){ |
||
598 | |||
599 | // Orden correcto de las columnas de autovectores
|
||
600 | int resultOrden[]= new int[matriz.getRowDimension()]; |
||
601 | int cont = matriz.getRowDimension()-1; |
||
602 | for(int i=0;i<matriz.getRowDimension();i++){ |
||
603 | if (isAutovectorMatrix)
|
||
604 | resultOrden[i]=cont; |
||
605 | else
|
||
606 | resultOrden[i]=i; |
||
607 | |||
608 | cont--; |
||
609 | } |
||
610 | |||
611 | //s = dlgExportar.getSelectedFile().getName();
|
||
612 | String aux=null; |
||
613 | try{
|
||
614 | outputStream.write("\t\t\t".getBytes());
|
||
615 | for (int j=0; j<matriz.getColumnDimension();j++) |
||
616 | { |
||
617 | outputStream.write(("Band"+(j+1)).getBytes()); |
||
618 | outputStream.write("\t\t\t".getBytes());
|
||
619 | } |
||
620 | outputStream.write("\n".getBytes());
|
||
621 | |||
622 | // Volcado de la Matriz a disco
|
||
623 | for (int i=0 ; i<matriz.getRowDimension(); i++){ |
||
624 | |||
625 | outputStream.write(("Band"+(i+1)).getBytes()); |
||
626 | outputStream.write("\t\t".getBytes());
|
||
627 | |||
628 | for (int j=0; j<matriz.getColumnDimension();j++){ |
||
629 | Double var =new Double(matriz.get(i,resultOrden[j])); |
||
630 | if (var.toString().getBytes().length>15) |
||
631 | outputStream.write(var.toString().getBytes(),0,15);// Elementos de la matriz; |
||
632 | else{
|
||
633 | aux = var.toString(); |
||
634 | for (int k=var.toString().getBytes().length; k<16; k++) |
||
635 | aux=aux+" ";
|
||
636 | outputStream.write(aux.getBytes(),0,15); |
||
637 | } |
||
638 | |||
639 | |||
640 | outputStream.write("\t".getBytes());
|
||
641 | } |
||
642 | outputStream.write("\n".getBytes());
|
||
643 | |||
644 | } |
||
645 | outputStream.write("\n".getBytes());
|
||
646 | |||
647 | }catch (FileNotFoundException e) { |
||
648 | e.printStackTrace(); |
||
649 | } catch (IOException e) { |
||
650 | // TODO Auto-generated catch block
|
||
651 | e.printStackTrace(); |
||
652 | } |
||
653 | |||
654 | } |
||
655 | |||
656 | public JCheckBox getAutovectorStatistics() { |
||
657 | |||
658 | if(autovectorStatistics==null){ |
||
659 | autovectorStatistics=new JCheckBox(PluginServices.getText(this, "autovector_statistics"),true); |
||
660 | |||
661 | } |
||
662 | return autovectorStatistics;
|
||
663 | } |
||
664 | |||
665 | |||
666 | public JCheckBox getBandasStatistics() { |
||
667 | if(bandasStatistics==null){ |
||
668 | bandasStatistics=new JCheckBox(PluginServices.getText(this, "bandas_statistics"),true); |
||
669 | } |
||
670 | return bandasStatistics;
|
||
671 | } |
||
672 | |||
673 | |||
674 | public JCheckBox getVarianceStatistics() { |
||
675 | if(varianceStatistics==null){ |
||
676 | varianceStatistics=new JCheckBox(PluginServices.getText(this, "variance_statistics"),true); |
||
677 | } |
||
678 | |||
679 | return varianceStatistics;
|
||
680 | } |
||
681 | |||
682 | |||
683 | |||
684 | public void actionButtonPressed(ButtonsPanelEvent e) { |
||
685 | // Bot?n de Aceptar
|
||
686 | if (e.getButton() == ButtonsPanel.BUTTON_ACCEPT) {
|
||
687 | aplicar(); |
||
688 | close(); |
||
689 | } |
||
690 | |||
691 | // Bot?n de Aplicar
|
||
692 | if (e.getButton() == ButtonsPanel.BUTTON_APPLY) {
|
||
693 | aplicar(); |
||
694 | } |
||
695 | |||
696 | // Bot?n de Cerrar
|
||
697 | if (e.getButton() == ButtonsPanel.BUTTON_CANCEL) {
|
||
698 | close(); |
||
699 | } |
||
700 | |||
701 | } |
||
702 | |||
703 | |||
704 | public void aplicar(){ |
||
705 | |||
706 | if(getTableFormatComponent().getNumSelected()>0){ |
||
707 | |||
708 | 14372 | amunoz | PCImageProcess generateImageProcess = new PCImageProcess(pc,getTableFormatComponent().getSeleccionadas(),getFileSelected());
|
709 | 13790 | dguerrero | IncrementableTask incrementableTask = new IncrementableTask(generateImageProcess);
|
710 | generateImageProcess.setIncrementableTask(incrementableTask); |
||
711 | incrementableTask.showWindow(); |
||
712 | generateImageProcess.start(); |
||
713 | incrementableTask.start(); |
||
714 | |||
715 | } |
||
716 | else{
|
||
717 | JOptionPane.showMessageDialog(null, |
||
718 | PluginServices.getText(this,"no_components"), PluginServices.getText(this,"principal_components"), |
||
719 | JOptionPane.WARNING_MESSAGE);
|
||
720 | } |
||
721 | |||
722 | |||
723 | } |
||
724 | |||
725 | public void close(){try { |
||
726 | PluginServices.getMDIManager().closeWindow(this);
|
||
727 | } catch (ArrayIndexOutOfBoundsException ex) { |
||
728 | // Si la ventana no se puede eliminar no hacemos nada
|
||
729 | } |
||
730 | } |
||
731 | |||
732 | |||
733 | public String getFileSelected() { |
||
734 | String path = ""; |
||
735 | if (getRadioFile().isSelected()) {
|
||
736 | 14180 | amunoz | JFileChooser chooser = new JFileChooser(FileOpenWizard.getLastPath()); |
737 | 13790 | dguerrero | chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero")); |
738 | //A?adimos las extensiones que hayan sido registradas en el driver
|
||
739 | String[] extList = GeoRasterWriter.getDriversExtensions(); |
||
740 | for(int i=0;i<extList.length;i++) |
||
741 | chooser.addChoosableFileFilter(new WriterFilter(extList[i]));
|
||
742 | |||
743 | if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) |
||
744 | return null; |
||
745 | |||
746 | String fName = chooser.getSelectedFile().toString();
|
||
747 | String ext = ((WriterFilter)chooser.getFileFilter()).getDescription();
|
||
748 | |||
749 | ext = ext.toLowerCase().substring(ext.lastIndexOf(".") + 1, ext.length()); |
||
750 | |||
751 | if ((fName != null) && !fName.equals("")) |
||
752 | if (!fName.endsWith("." + ext)) |
||
753 | fName = fName + "." + ext;
|
||
754 | |||
755 | 14180 | amunoz | FileOpenWizard.setLastPath(chooser.getSelectedFile().getPath().substring(0, chooser.getSelectedFile().getPath().lastIndexOf(File.separator))); |
756 | 13790 | dguerrero | path = fName; |
757 | } else {
|
||
758 | path = Utilities.createTempDirectory() + File.separator +getJTextNombreCapa().getText() + ".tif"; |
||
759 | setNewLayerText(); |
||
760 | } |
||
761 | return path;
|
||
762 | } |
||
763 | |||
764 | |||
765 | } |
||
766 | |||
767 | |||
768 | class TxtFilter extends FileFilter { |
||
769 | |||
770 | final static String exp = "txt"; |
||
771 | public boolean accept(File f) { |
||
772 | if (f.isDirectory()) {
|
||
773 | return true; |
||
774 | } |
||
775 | String s = f.getName();
|
||
776 | int i = s.lastIndexOf('.'); |
||
777 | |||
778 | if (i > 0 && i < s.length() - 1) { |
||
779 | String extension = s.substring(i+1).toLowerCase(); |
||
780 | if (exp.equals(extension)){
|
||
781 | return true; |
||
782 | } else {
|
||
783 | return false; |
||
784 | } |
||
785 | } |
||
786 | return false; |
||
787 | } |
||
788 | |||
789 | public String getDescription() { |
||
790 | return "Archivos .txt"; |
||
791 | } |
||
792 | |||
793 | } |
||
794 | |||
795 | |||
796 | |||
797 | /**
|
||
798 | * @author Nacho Brodin <brodin_ign@gva.es>
|
||
799 | * Filtro para el selector de formatos de escritura
|
||
800 | */
|
||
801 | class WriterFilter extends javax.swing.filechooser.FileFilter { |
||
802 | private String filter; |
||
803 | |||
804 | public WriterFilter(String fil) { |
||
805 | this.filter = fil;
|
||
806 | } |
||
807 | |||
808 | public boolean accept(File f) { |
||
809 | return f.isDirectory() || f.getName().toLowerCase().endsWith("." + filter); |
||
810 | } |
||
811 | |||
812 | public String getDescription() { |
||
813 | return "." + filter; |
||
814 | } |
||
815 | } |