root / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / principalcomponents / gui / PrincipalComponentPanel.java @ 24986
History | View | Annotate | Download (13.3 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.event.ActionEvent; |
49 |
import java.awt.event.ActionListener; |
50 |
import java.awt.event.FocusEvent; |
51 |
import java.awt.event.FocusListener; |
52 |
import java.io.File; |
53 |
|
54 |
import javax.swing.BorderFactory; |
55 |
import javax.swing.ComboBoxModel; |
56 |
import javax.swing.DefaultComboBoxModel; |
57 |
import javax.swing.ImageIcon; |
58 |
import javax.swing.JButton; |
59 |
import javax.swing.JOptionPane; |
60 |
import javax.swing.JPanel; |
61 |
import javax.swing.JScrollPane; |
62 |
import javax.swing.JTable; |
63 |
import javax.swing.border.CompoundBorder; |
64 |
import javax.swing.border.EmptyBorder; |
65 |
import javax.swing.border.TitledBorder; |
66 |
|
67 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
68 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
69 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent; |
70 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener; |
71 |
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel; |
72 |
import org.gvsig.raster.IProcessActions; |
73 |
import org.gvsig.raster.RasterLibrary; |
74 |
import org.gvsig.remotesensing.principalcomponents.PCStatistics; |
75 |
import org.gvsig.remotesensing.principalcomponents.PCStatisticsProcess; |
76 |
|
77 |
import com.iver.andami.PluginServices; |
78 |
import com.iver.andami.Utilities; |
79 |
import com.iver.andami.ui.mdiManager.IWindow; |
80 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
81 |
import com.iver.cit.gvsig.fmap.MapContext; |
82 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
83 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
84 |
import com.iver.utiles.swing.JComboBox; |
85 |
|
86 |
/**
|
87 |
* Clase que define la interfaz para la selecci?n de par?metros para el an?lisis de
|
88 |
* componentes principales. Para la imagen seleccionada se toman las bandas marcadas para el
|
89 |
* c?lculo de estad?sticas como matriz de varianza-covarianza, autovalores y autovectores.
|
90 |
*
|
91 |
* @author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es)
|
92 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
93 |
* @version 22/10/2007
|
94 |
*/
|
95 |
|
96 |
public class PrincipalComponentPanel extends DefaultButtonsPanel implements IWindow,ActionListener,FocusListener,ButtonsPanelListener, IProcessActions { |
97 |
|
98 |
private static final long serialVersionUID = 1L; |
99 |
private JPanel southPanel; |
100 |
private JPanel centerPanel; |
101 |
private BandTableFormat mModeloTabla;
|
102 |
private JPanel panelTodos; |
103 |
private JButton todos; |
104 |
private JButton ninguno; |
105 |
private int wPanel=325; |
106 |
private int hPanel=350; |
107 |
private JComboBox comboCapas; |
108 |
private JPanel panelImagen; |
109 |
private JTable jTableBandas; |
110 |
private JScrollPane scrollbandas; |
111 |
|
112 |
private MapContext m_MapContext;
|
113 |
private FLayers layers;
|
114 |
private View view; |
115 |
private String fileName = null; |
116 |
private PCStatisticsProcess statisticsProcess = null; |
117 |
private boolean selectecBands[] = null; |
118 |
|
119 |
|
120 |
/**
|
121 |
* Constructor
|
122 |
* @param vista vista actual de la aplicacion.
|
123 |
*/
|
124 |
public PrincipalComponentPanel(View vista) { |
125 |
super(ButtonsPanel.BUTTONS_ACCEPTCANCEL );
|
126 |
view = vista; |
127 |
m_MapContext = vista.getModel().getMapContext(); |
128 |
layers = m_MapContext.getLayers(); |
129 |
Inicializar(); |
130 |
} |
131 |
|
132 |
|
133 |
/**
|
134 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
135 |
*/
|
136 |
public WindowInfo getWindowInfo() {
|
137 |
WindowInfo m_viewinfo = new WindowInfo(WindowInfo.PALETTE | WindowInfo.RESIZABLE);
|
138 |
//Establecer el tamao del formulario
|
139 |
m_viewinfo.setWidth(wPanel); |
140 |
m_viewinfo.setHeight(hPanel); |
141 |
//Establecer el ttulo del formulario
|
142 |
m_viewinfo.setTitle(PluginServices.getText(this,"principal_components")); |
143 |
//punto X de la pantalla donde se situa
|
144 |
m_viewinfo.setX(300);
|
145 |
return m_viewinfo;
|
146 |
} |
147 |
|
148 |
/**
|
149 |
* Inicializaci?n del cuadro de dialogo.
|
150 |
*/
|
151 |
private void Inicializar(){ |
152 |
|
153 |
BorderLayout bd=new BorderLayout(); |
154 |
this.setLayout(bd);
|
155 |
TitledBorder topBorder = BorderFactory.createTitledBorder((PluginServices.getText(this,""))); |
156 |
topBorder.setTitlePosition(TitledBorder.TOP);
|
157 |
this.setBorder(new CompoundBorder(topBorder,new EmptyBorder(10,10,10,10))); |
158 |
this.add(getCenterPanel(), BorderLayout.CENTER); |
159 |
this.add(getSouthPanel(),BorderLayout.SOUTH); |
160 |
getBandas(); |
161 |
this.addButtonPressedListener(this); |
162 |
|
163 |
} |
164 |
|
165 |
|
166 |
/**
|
167 |
* @return panel con los botones aceptar y cancelar
|
168 |
*/
|
169 |
public JPanel getSouthPanel() { |
170 |
if (southPanel==null){ |
171 |
southPanel=new JPanel(); |
172 |
FlowLayout f= new FlowLayout(); |
173 |
southPanel.setLayout(f); |
174 |
} |
175 |
return southPanel;
|
176 |
} |
177 |
|
178 |
|
179 |
/**
|
180 |
* @return panel con panel imagen, tabla de bandas y botones de selecci?n
|
181 |
*/
|
182 |
public JPanel getCenterPanel() { |
183 |
|
184 |
if (centerPanel==null){ |
185 |
centerPanel=new JPanel(); |
186 |
TitledBorder topBorder = BorderFactory.createTitledBorder((PluginServices.getText(this,"seleccion_banda"))); |
187 |
topBorder.setTitlePosition(TitledBorder.TOP);
|
188 |
|
189 |
BorderLayout bd=new BorderLayout(); |
190 |
JPanel p=new JPanel(); |
191 |
p.setPreferredSize(new Dimension(275,200)); |
192 |
p.setLayout(bd); |
193 |
p.setBorder(new CompoundBorder(topBorder,new EmptyBorder(5,5,5,5))); |
194 |
p.add(getScrollVariables(),BorderLayout.CENTER);
|
195 |
p.add(getPanelTodos(),BorderLayout.SOUTH);
|
196 |
centerPanel.add(getPanelImagen()); |
197 |
centerPanel.add(p); |
198 |
|
199 |
} |
200 |
return centerPanel;
|
201 |
} |
202 |
|
203 |
/**
|
204 |
* @return panel con el combo de selecci?n de imagen.
|
205 |
*/
|
206 |
public JPanel getPanelImagen() { |
207 |
|
208 |
if (panelImagen==null){ |
209 |
panelImagen=new JPanel(); |
210 |
TitledBorder topBorder = BorderFactory.createTitledBorder((PluginServices.getText(this,"imagen"))); |
211 |
topBorder.setTitlePosition(TitledBorder.TOP);
|
212 |
panelImagen.setBorder(new CompoundBorder(topBorder,new EmptyBorder(2,2,2,2))); |
213 |
JPanel p= new JPanel(); |
214 |
|
215 |
TableLayout thisLayout = new TableLayout(new double[][] { |
216 |
{ 250},
|
217 |
{TableLayout.PREFERRED}}); |
218 |
|
219 |
p.setLayout(thisLayout); |
220 |
p.setPreferredSize(new Dimension(250,30)); |
221 |
p.add(getComboCapas(),"0,0");
|
222 |
panelImagen.add(p); |
223 |
} |
224 |
return panelImagen;
|
225 |
} |
226 |
|
227 |
|
228 |
/**
|
229 |
* @return panel con botones de seleccion todos/ninguno
|
230 |
*/
|
231 |
public JPanel getPanelTodos(){ |
232 |
|
233 |
if (panelTodos==null){ |
234 |
panelTodos= new JPanel(); |
235 |
JPanel p = new JPanel(); |
236 |
p.setLayout(new FlowLayout(FlowLayout.RIGHT,1,1)); |
237 |
p.add(getTodos()); |
238 |
p.add(getNinguno()); |
239 |
p.setPreferredSize(new Dimension(240,30)); |
240 |
panelTodos.add(p); |
241 |
} |
242 |
return panelTodos;
|
243 |
|
244 |
} |
245 |
|
246 |
|
247 |
/**
|
248 |
* @return combo con el nombre de las im?genes cargadas
|
249 |
*/
|
250 |
public JComboBox getComboCapas() { |
251 |
|
252 |
if (comboCapas==null){ |
253 |
ComboBoxModel jComboBoxLayersModel = new |
254 |
DefaultComboBoxModel(getLayerNames());
|
255 |
comboCapas = new JComboBox(); |
256 |
comboCapas.setModel(jComboBoxLayersModel); |
257 |
comboCapas.setEnabled(true);
|
258 |
comboCapas.addActionListener(this);
|
259 |
} |
260 |
return comboCapas;
|
261 |
} |
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
/**
|
268 |
* @return scroll con tabla de bandas de imagen seleccionada
|
269 |
*/
|
270 |
public JScrollPane getScrollVariables() { |
271 |
|
272 |
if (scrollbandas==null){ |
273 |
scrollbandas=new JScrollPane(); |
274 |
} |
275 |
getTableBands().getColumn("").setPreferredWidth(30); |
276 |
scrollbandas.setViewportView(getTableBands()); |
277 |
scrollbandas.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
278 |
return scrollbandas;
|
279 |
} |
280 |
|
281 |
|
282 |
/**
|
283 |
* @return array de String con los nombre de las capas cargadas
|
284 |
*/
|
285 |
private String[] getLayerNames() { |
286 |
|
287 |
int i, capasraster=0; |
288 |
for (i = 0; i < layers.getLayersCount(); i++) { |
289 |
if (layers.getLayer(i)instanceof FLyrRasterSE) |
290 |
capasraster++; |
291 |
} |
292 |
// Solo se toman las capas raster.
|
293 |
String[] sNames = new String[capasraster]; |
294 |
capasraster=0;
|
295 |
for (i = 0; i < layers.getLayersCount(); i++) { |
296 |
if (layers.getLayer(i)instanceof FLyrRasterSE){ |
297 |
sNames[capasraster] =layers.getLayer(i).getName(); |
298 |
capasraster++; |
299 |
} |
300 |
} |
301 |
return sNames;
|
302 |
} |
303 |
|
304 |
|
305 |
|
306 |
/**
|
307 |
* @return JTable con bandas de la imagen
|
308 |
*/
|
309 |
private JTable getTableBands(){ |
310 |
if (jTableBandas==null){ |
311 |
jTableBandas=new JTable(getModeloTabla()); |
312 |
} |
313 |
return jTableBandas;
|
314 |
} |
315 |
|
316 |
|
317 |
/**
|
318 |
* @see BandTableFormat
|
319 |
* @return modelo de tabla BandTableFormat
|
320 |
*/
|
321 |
public BandTableFormat getModeloTabla() {
|
322 |
if(mModeloTabla==null){ |
323 |
mModeloTabla=new BandTableFormat();
|
324 |
} |
325 |
return mModeloTabla;
|
326 |
} |
327 |
|
328 |
|
329 |
/**
|
330 |
* Toma las Bandas de la imagen seleccionada en el combo Imagen
|
331 |
*/
|
332 |
public void getBandas(){ |
333 |
|
334 |
// Antes de insertar se borra lo anterior
|
335 |
getModeloTabla().LimpiarLista(); |
336 |
FLyrRasterSE rasterLayer= (FLyrRasterSE)layers.getLayer((String)getComboCapas().getSelectedItem());
|
337 |
String bandas[]=new String[rasterLayer.getBandCount()]; |
338 |
if (layers.getLayer((String)getComboCapas().getSelectedItem()) instanceof FLyrRasterSE ){ |
339 |
for (int j=0; j<rasterLayer.getBandCount(); j++){ |
340 |
String s=(PluginServices.getText(this,"banda"))+(j+1); |
341 |
bandas[j]=s; |
342 |
} |
343 |
} |
344 |
// Insertar las bandas el la tabla
|
345 |
for (int i=0;i<bandas.length;i++) |
346 |
getModeloTabla().addRow(bandas[i],true);
|
347 |
getTableBands().updateUI(); |
348 |
|
349 |
} |
350 |
|
351 |
|
352 |
public void focusGained(FocusEvent arg0) { |
353 |
// TODO Auto-generated method stub
|
354 |
} |
355 |
|
356 |
|
357 |
public void focusLost(FocusEvent arg0) { |
358 |
// TODO Auto-generated method stub
|
359 |
} |
360 |
|
361 |
|
362 |
/**
|
363 |
* @return JButton seleccion ninguna banda
|
364 |
*/
|
365 |
public JButton getNinguno() { |
366 |
if (ninguno==null){ |
367 |
ImageIcon icono = new ImageIcon(PrincipalComponentCalculusPanel.class.getClassLoader().getResource("images/table_delete.png")); |
368 |
ninguno = new JButton(icono); |
369 |
ninguno.addActionListener(this);
|
370 |
} |
371 |
return ninguno;
|
372 |
} |
373 |
|
374 |
|
375 |
/**
|
376 |
* @return JButton seleccion todas las bandas
|
377 |
*/
|
378 |
public JButton getTodos() { |
379 |
if (todos==null){ |
380 |
ImageIcon icono = new ImageIcon(PrincipalComponentCalculusPanel.class.getClassLoader().getResource("images/table.png")); |
381 |
todos = new JButton(icono); |
382 |
todos.addActionListener(this);
|
383 |
} |
384 |
return todos;
|
385 |
} |
386 |
|
387 |
|
388 |
|
389 |
public void accept(){ |
390 |
|
391 |
if (getModeloTabla().getNumSelected()>0){ |
392 |
FLyrRasterSE rasterLayer= (FLyrRasterSE)layers.getLayer((String)getComboCapas().getSelectedItem());
|
393 |
PluginServices.getMDIManager().closeWindow(this);
|
394 |
statisticsProcess = new PCStatisticsProcess();
|
395 |
statisticsProcess.addParam("inputRasterLayer",rasterLayer);
|
396 |
selectecBands = getModeloTabla().getSeleccionadas(); |
397 |
statisticsProcess.addParam("selectedBands",selectecBands);
|
398 |
|
399 |
statisticsProcess.setActions(this);
|
400 |
statisticsProcess.start(); |
401 |
} |
402 |
else{
|
403 |
|
404 |
JOptionPane.showMessageDialog(null, |
405 |
PluginServices.getText(this,"no_bandas"), PluginServices.getText(this,"principal_components"), |
406 |
JOptionPane.WARNING_MESSAGE);
|
407 |
} |
408 |
|
409 |
} |
410 |
|
411 |
/**
|
412 |
* acciones al cerrar
|
413 |
*/
|
414 |
public void close(){ |
415 |
try {
|
416 |
PluginServices.getMDIManager().closeWindow(this);
|
417 |
} catch (ArrayIndexOutOfBoundsException ex) { |
418 |
// Si la ventana no se puede eliminar no hacemos nada
|
419 |
} |
420 |
} |
421 |
|
422 |
|
423 |
/*
|
424 |
* (non-Javadoc)
|
425 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
426 |
*/
|
427 |
public void actionPerformed(ActionEvent e) { |
428 |
|
429 |
|
430 |
// Check Seleccionar Todo
|
431 |
if(e.getSource()==getTodos()){
|
432 |
getModeloTabla().seleccionarTodas(); |
433 |
updateUI(); |
434 |
} |
435 |
if(e.getSource()==getNinguno()){
|
436 |
|
437 |
getModeloTabla().seleccionarNinguna(); |
438 |
updateUI(); |
439 |
} |
440 |
|
441 |
if (e.getSource()==getComboCapas()){
|
442 |
// Actualizar tabla de bandas
|
443 |
getBandas(); |
444 |
} |
445 |
} |
446 |
|
447 |
|
448 |
public void actionButtonPressed(ButtonsPanelEvent e) { |
449 |
// Bot?n de Aceptar
|
450 |
if (e.getButton() == ButtonsPanel.BUTTON_ACCEPT) {
|
451 |
accept(); |
452 |
close(); |
453 |
} |
454 |
|
455 |
// Bot?n de Aplicar
|
456 |
if (e.getButton() == ButtonsPanel.BUTTON_APPLY) {
|
457 |
accept(); |
458 |
} |
459 |
|
460 |
// Bot?n de Cerrar
|
461 |
if (e.getButton() == ButtonsPanel.BUTTON_CANCEL) {
|
462 |
close(); |
463 |
} |
464 |
} |
465 |
|
466 |
|
467 |
public void end(Object param) { |
468 |
fileName = Utilities.createTempDirectory() + File.separator; |
469 |
fileName = fileName + RasterLibrary.getOnlyLayerName() + ".tif";
|
470 |
RasterLibrary.usesOnlyLayerName(); |
471 |
|
472 |
PrincipalComponentCalculusPanel altPrincipalComponentCalculusPanel = new PrincipalComponentCalculusPanel(view,(PCStatistics)param,statisticsProcess,selectecBands);
|
473 |
altPrincipalComponentCalculusPanel.setFilename(fileName); |
474 |
PluginServices.getMDIManager().addWindow(altPrincipalComponentCalculusPanel); |
475 |
|
476 |
} |
477 |
|
478 |
|
479 |
public void interrupted() { |
480 |
// TODO Auto-generated method stub
|
481 |
|
482 |
} |
483 |
|
484 |
|
485 |
public Object getWindowProfile() { |
486 |
return WindowInfo.PROPERTIES_PROFILE;
|
487 |
} |
488 |
|
489 |
} |
490 |
|