root / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / principalcomponents / gui / PrincipalComponentCalculusPanel.java @ 14794
History | View | Annotate | Download (24.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.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 | 14180 | amunoz | import com.iver.cit.gvsig.addlayer.fileopen.FileOpenWizard; |
97 | 13790 | dguerrero | import com.iver.cit.gvsig.project.documents.view.gui.View; |
98 | |||
99 | |||
100 | 14794 | amunoz | /**
|
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 | 13790 | dguerrero | 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 | 14794 | amunoz | private JButton jbExportar; |
117 | 13790 | dguerrero | private JButton jexportVarMatrix; |
118 | private JButton jexportAutovectorMatrix; |
||
119 | private ComponentTableFormat tableFormatComponent;
|
||
120 | private JScrollPane scrollComponents; |
||
121 | private JTable tableComponent; |
||
122 | private JTextField jTextNombreCapa; |
||
123 | 14794 | amunoz | private JButton jbTodos; |
124 | private JButton jbNinguno; |
||
125 | 14608 | amunoz | private int wPanel=460; |
126 | private int hPanel=470; |
||
127 | 13790 | dguerrero | 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 | 14794 | amunoz | /**
|
138 | * Constructor
|
||
139 | * @param vista vista de la aplicacion
|
||
140 | * @param pC proceso de estadisticas
|
||
141 | */
|
||
142 | 13790 | dguerrero | public PrincipalComponentCalculusPanel(View vista,PCStatisticsProcess pC){ |
143 | autovalores = pC.getResult(); |
||
144 | pc=pC; |
||
145 | this.addButtonPressedListener(this); |
||
146 | Inicializar(); |
||
147 | } |
||
148 | |||
149 | 14794 | amunoz | /**
|
150 | * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
||
151 | */
|
||
152 | 13790 | dguerrero | 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 | 14794 | amunoz | /**
|
166 | * @return panel con las opciones de exportar estadisticas
|
||
167 | */
|
||
168 | 13790 | dguerrero | public JPanel getStatisticsPanel(){ |
169 | 14794 | amunoz | |
170 | 13790 | dguerrero | if(statisticsPanel==null){ |
171 | statisticsPanel=new JPanel(); |
||
172 | TableLayout thisLayout = new TableLayout(new double[][] { |
||
173 | 14608 | amunoz | {20,250,120}, |
174 | 13790 | dguerrero | {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 | 14608 | amunoz | p.setPreferredSize(new Dimension(170,70)); |
183 | 13790 | dguerrero | 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 | 14608 | amunoz | {5 ,85}, |
191 | 13790 | dguerrero | {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 | 14608 | amunoz | statisticsPanel.add(panelButton,"2,0");
|
197 | 13790 | dguerrero | } |
198 | return statisticsPanel;
|
||
199 | } |
||
200 | |||
201 | |||
202 | 14794 | amunoz | /**
|
203 | * inicializaci?n del di?logo
|
||
204 | */
|
||
205 | 13790 | dguerrero | private void Inicializar(){ |
206 | BorderLayout bd=new BorderLayout(); |
||
207 | this.setLayout(bd);
|
||
208 | TitledBorder topBorder = BorderFactory.createTitledBorder(" "); |
||
209 | topBorder.setTitlePosition(TitledBorder.TOP);
|
||
210 | 14746 | amunoz | this.setBorder(new CompoundBorder(topBorder,new EmptyBorder(5,10,10,10))); |
211 | 13790 | dguerrero | this.add(getPanelSuperior(),BorderLayout.NORTH); |
212 | this.add(getStatisticsPanel(),BorderLayout.CENTER); |
||
213 | completarTabla(); |
||
214 | } |
||
215 | |||
216 | |||
217 | 14794 | amunoz | /**
|
218 | * @return panel con opciones de salida, tabla de componentes y botones de selecci?n todos/ninguno
|
||
219 | */
|
||
220 | 13790 | dguerrero | 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 | 14608 | amunoz | {80,150,40}}); |
230 | 13790 | dguerrero | thisLayout.setHGap(5);
|
231 | 14608 | amunoz | thisLayout.setVGap(3);
|
232 | 13790 | dguerrero | p.setLayout(thisLayout); |
233 | p.add(getNombreCapaPanel(),"0,0");
|
||
234 | p.add(getScrollComponents(),"0,1");
|
||
235 | p.add(getPanelTodos(),"0,2");
|
||
236 | 14608 | amunoz | panelSuperior.add(p); |
237 | 13790 | dguerrero | } |
238 | 14794 | amunoz | return panelSuperior;
|
239 | 13790 | dguerrero | } |
240 | |||
241 | |||
242 | 14794 | amunoz | /**
|
243 | * A?ade las filas a la tabla de selecci?n de componentes
|
||
244 | */
|
||
245 | public void completarTabla(){ |
||
246 | 13790 | dguerrero | 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 | 14608 | amunoz | getTableFormatComponent().addRow(autova[i],autovalores[i],autovalores[i]/acumulado,true);
|
258 | 13790 | dguerrero | } |
259 | |||
260 | 14794 | amunoz | |
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 | 13790 | dguerrero | } |
269 | 14794 | amunoz | return jbExportar;
|
270 | 13790 | dguerrero | } |
271 | |||
272 | |||
273 | 14794 | amunoz | /**
|
274 | * @return JButton jbNinguno
|
||
275 | */
|
||
276 | 13790 | dguerrero | public JButton getNinguno() { |
277 | 14794 | amunoz | if (jbNinguno==null){ |
278 | 13790 | dguerrero | ImageIcon icono = new ImageIcon(PrincipalComponentCalculusPanel.class.getClassLoader().getResource("images/table_delete.png")); |
279 | 14794 | amunoz | jbNinguno = new JButton(icono); |
280 | jbNinguno.addActionListener(this);
|
||
281 | 13790 | dguerrero | } |
282 | 14794 | amunoz | return jbNinguno;
|
283 | 13790 | dguerrero | } |
284 | |||
285 | |||
286 | 14794 | amunoz | /**
|
287 | * @return JButton jbTodos
|
||
288 | */
|
||
289 | 13790 | dguerrero | public JButton getTodos() { |
290 | 14794 | amunoz | if (jbTodos==null){ |
291 | 13790 | dguerrero | ImageIcon icono = new ImageIcon(PrincipalComponentCalculusPanel.class.getClassLoader().getResource("images/table.png")); |
292 | 14794 | amunoz | jbTodos = new JButton(icono); |
293 | jbTodos.addActionListener(this);
|
||
294 | 13790 | dguerrero | } |
295 | 14794 | amunoz | return jbTodos;
|
296 | 13790 | dguerrero | } |
297 | |||
298 | |||
299 | 14794 | amunoz | /**
|
300 | * @return JButton jexportVarMatrix
|
||
301 | */
|
||
302 | 13790 | dguerrero | 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 | 14794 | amunoz | |
311 | /**
|
||
312 | * @return JButton jexportAutovectorMatrix
|
||
313 | */
|
||
314 | 13790 | dguerrero | 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 | 14794 | amunoz | /**
|
324 | * @see ComponentTableFormat
|
||
325 | * @return modelo de tabla de componentes
|
||
326 | */
|
||
327 | 13790 | dguerrero | public ComponentTableFormat getTableFormatComponent() {
|
328 | if(tableFormatComponent==null){ |
||
329 | tableFormatComponent=new ComponentTableFormat();
|
||
330 | } |
||
331 | return tableFormatComponent;
|
||
332 | } |
||
333 | |||
334 | |||
335 | 14794 | amunoz | /**
|
336 | * @return tabla de componentes
|
||
337 | */
|
||
338 | 13790 | dguerrero | public JTable getTableComponents(){ |
339 | if (tableComponent==null){ |
||
340 | tableComponent=new JTable(getTableFormatComponent()); |
||
341 | } |
||
342 | return tableComponent;
|
||
343 | } |
||
344 | |||
345 | |||
346 | 14794 | amunoz | /**
|
347 | * @return scroll con la tabla de componentes
|
||
348 | */
|
||
349 | 13790 | dguerrero | 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 | 14794 | amunoz | /**
|
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 | 13790 | dguerrero | } |
378 | 14794 | amunoz | return panelTodos;
|
379 | } |
||
380 | 13790 | dguerrero | |
381 | |||
382 | 14794 | amunoz | /**
|
383 | * @return panel que incluye el nombre de la capa y las opciones de almacenamieto de la capa de salida
|
||
384 | */
|
||
385 | 13790 | dguerrero | 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 | 14794 | amunoz | /**
|
436 | * @return javax.swing.JTextField
|
||
437 | */
|
||
438 | 13790 | dguerrero | public JTextField getJTextNombreCapa() { |
439 | |||
440 | if(jTextNombreCapa==null){ |
||
441 | 14608 | amunoz | jTextNombreCapa= new JTextField(10); |
442 | 13790 | dguerrero | 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 | 14794 | amunoz | /**
|
460 | * @return JRadioButton de generar fichero
|
||
461 | */
|
||
462 | 13790 | dguerrero | 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 | 14794 | amunoz | /**
|
471 | * @return JRadioButton de generar en memoria
|
||
472 | */
|
||
473 | 13790 | dguerrero | 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 | 14794 | amunoz | /**
|
483 | * M?todo para exportar las estadisticas seleccionadas a un fichero de texto
|
||
484 | */
|
||
485 | 13790 | dguerrero | 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 | 14794 | amunoz | |
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 | 13790 | dguerrero | |
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 | 14794 | amunoz | /**
|
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 | 13790 | dguerrero | 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 | 14794 | amunoz | outputStream.write("\t".getBytes());
|
626 | 13790 | dguerrero | } |
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 | 14794 | amunoz | /**
|
640 | * @return checkbox autovectores
|
||
641 | */
|
||
642 | 13790 | dguerrero | 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 | 14794 | amunoz | /**
|
651 | * @return checkbox estadisticas por banda
|
||
652 | */
|
||
653 | 13790 | dguerrero | 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 | 14794 | amunoz | /**
|
662 | * @return checkbox matriz varianza-covarianza
|
||
663 | */
|
||
664 | 13790 | dguerrero | 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 | 14794 | amunoz | /*
|
674 | * (non-Javadoc)
|
||
675 | * @see org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener#actionButtonPressed(org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent)
|
||
676 | */
|
||
677 | 13790 | dguerrero | 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 | 14794 | amunoz | /**
|
697 | * acciones al aplicar
|
||
698 | */
|
||
699 | 13790 | dguerrero | public void aplicar(){ |
700 | |||
701 | if(getTableFormatComponent().getNumSelected()>0){ |
||
702 | 14372 | amunoz | PCImageProcess generateImageProcess = new PCImageProcess(pc,getTableFormatComponent().getSeleccionadas(),getFileSelected());
|
703 | 13790 | dguerrero | IncrementableTask incrementableTask = new IncrementableTask(generateImageProcess);
|
704 | generateImageProcess.setIncrementableTask(incrementableTask); |
||
705 | incrementableTask.showWindow(); |
||
706 | generateImageProcess.start(); |
||
707 | incrementableTask.start(); |
||
708 | |||
709 | } |
||
710 | 14794 | amunoz | else{
|
711 | JOptionPane.showMessageDialog(null, |
||
712 | PluginServices.getText(this,"no_components"), PluginServices.getText(this,"principal_components"), |
||
713 | JOptionPane.WARNING_MESSAGE);
|
||
714 | 13790 | dguerrero | } |
715 | } |
||
716 | |||
717 | 14794 | amunoz | /**
|
718 | * acciones al cerrar
|
||
719 | */
|
||
720 | public void close(){ |
||
721 | try {
|
||
722 | PluginServices.getMDIManager().closeWindow(this);
|
||
723 | } catch (ArrayIndexOutOfBoundsException ex) { |
||
724 | 13790 | dguerrero | // Si la ventana no se puede eliminar no hacemos nada
|
725 | 14794 | amunoz | } |
726 | 13790 | dguerrero | } |
727 | |||
728 | |||
729 | 14794 | amunoz | /**
|
730 | * @return path con el fichero seleccionado
|
||
731 | */
|
||
732 | 13790 | dguerrero | public String getFileSelected() { |
733 | String path = ""; |
||
734 | if (getRadioFile().isSelected()) {
|
||
735 | 14180 | amunoz | JFileChooser chooser = new JFileChooser(FileOpenWizard.getLastPath()); |
736 | 13790 | dguerrero | 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 | 14180 | amunoz | FileOpenWizard.setLastPath(chooser.getSelectedFile().getPath().substring(0, chooser.getSelectedFile().getPath().lastIndexOf(File.separator))); |
755 | 13790 | dguerrero | path = fName; |
756 | } else {
|
||
757 | path = Utilities.createTempDirectory() + File.separator +getJTextNombreCapa().getText() + ".tif"; |
||
758 | setNewLayerText(); |
||
759 | } |
||
760 | return path;
|
||
761 | } |
||
762 | |||
763 | 14794 | amunoz | /*
|
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 | 13790 | dguerrero | } |
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 | } |