Revision 15666
org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.156/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.impl/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
3 |
<modelVersion>4.0.0</modelVersion> |
|
4 |
<artifactId>org.gvsig.raster.principalcomponents.swing.impl</artifactId> |
|
5 |
<packaging>jar</packaging> |
|
6 |
<name>org.gvsig.raster.principalcomponents.swing.impl</name> |
|
7 |
<parent> |
|
8 |
<groupId>org.gvsig</groupId> |
|
9 |
<artifactId>org.gvsig.raster.principalcomponents.swing</artifactId> |
|
10 |
<version>2.2.156</version> |
|
11 |
</parent> |
|
12 |
<dependencies> |
|
13 |
<dependency> |
|
14 |
<groupId>org.gvsig</groupId> |
|
15 |
<artifactId>org.gvsig.raster.principalcomponents.swing.api</artifactId> |
|
16 |
<scope>compile</scope> |
|
17 |
</dependency> |
|
18 |
<dependency> |
|
19 |
<groupId>org.gvsig</groupId> |
|
20 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
21 |
<scope>compile</scope> |
|
22 |
</dependency> |
|
23 |
<dependency> |
|
24 |
<groupId>org.gvsig</groupId> |
|
25 |
<artifactId>org.gvsig.tools.swing.api</artifactId> |
|
26 |
<scope>compile</scope> |
|
27 |
</dependency> |
|
28 |
<dependency> |
|
29 |
<groupId>org.gvsig</groupId> |
|
30 |
<artifactId>org.gvsig.i18n</artifactId> |
|
31 |
<scope>compile</scope> |
|
32 |
</dependency> |
|
33 |
|
|
34 |
<dependency> |
|
35 |
<groupId>org.gvsig</groupId> |
|
36 |
<artifactId>org.gvsig.fmap.dal.api</artifactId> |
|
37 |
<scope>compile</scope> |
|
38 |
</dependency> |
|
39 |
<dependency> |
|
40 |
<groupId>org.gvsig</groupId> |
|
41 |
<artifactId>org.gvsig.fmap.dal.impl</artifactId> |
|
42 |
<scope>compile</scope> |
|
43 |
</dependency> |
|
44 |
<dependency> |
|
45 |
<groupId>org.gvsig</groupId> |
|
46 |
<artifactId>org.gvsig.raster.principalcomponents.algorithm</artifactId> |
|
47 |
<scope>compile</scope> |
|
48 |
</dependency> |
|
49 |
</dependencies> |
|
50 |
</project> |
|
0 | 51 |
org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.156/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.impl/src/main/resources/org/gvsig/raster/principalcomponents/swing/impl/i18n/text.properties | ||
---|---|---|
1 |
components_selection=Selecci?n de componentes |
|
2 |
autovalor=Autovalor |
|
3 |
by_band=Por banda |
|
4 |
var_covar=Matriz varianza-covarianza |
|
5 |
autovector=Autovector |
|
6 |
generate=Generar |
|
7 |
stats=Estadisticas |
|
8 |
use_rois=Usar regiones de inter?s de la capa |
|
9 |
band=Banda |
|
10 |
max=M?ximo |
|
11 |
min=M?nimo |
|
12 |
mean=Media |
|
13 |
variance=Varianza |
|
14 |
standard_deviation=Desviaci?n est?ndar |
|
0 | 15 |
org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.156/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.impl/src/main/resources/org/gvsig/raster/principalcomponents/swing/impl/i18n/text_en.properties | ||
---|---|---|
1 |
components_selection=Component selection |
|
2 |
autovalor=Eigenvalue |
|
3 |
by_band=By band |
|
4 |
var_covar=Matrix variance-covariance |
|
5 |
autovector=Eigenvector |
|
6 |
generate=Generate |
|
7 |
stats=Statistics |
|
8 |
use_rois=Use regions of interest of the layer |
|
9 |
band=Band |
|
10 |
max=Maximum |
|
11 |
min=Minimum |
|
12 |
mean=Mean |
|
13 |
variance=Variance |
|
14 |
standard_deviation=Standard deviation |
|
0 | 15 |
org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.156/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.raster.principalcomponents.swing.impl.PrincipalComponentsDefaultSwingImplLibrary |
|
0 | 2 |
org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.156/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.impl/src/main/java/org/gvsig/raster/principalcomponents/swing/impl/stats/ReportStatisticsProcessPCA.java | ||
---|---|---|
1 |
package org.gvsig.raster.principalcomponents.swing.impl.stats; |
|
2 |
|
|
3 |
import java.text.DecimalFormat; |
|
4 |
|
|
5 |
import org.cresques.Messages; |
|
6 |
import org.gvsig.raster.principalcomponents.algorithm.PCStatsDataStructure; |
|
7 |
|
|
8 |
import Jama.Matrix; |
|
9 |
|
|
10 |
//* Clase encargada de crear un String html con los datos estad?sticos resultantes del |
|
11 |
//* PCAStatisticsTask (stadisticas por banda, matriz varianza-covarianza y autovalores) |
|
12 |
/** |
|
13 |
* |
|
14 |
* This class create a String with result statistics data of PCAStatisticsTask |
|
15 |
* @author seriznue |
|
16 |
*/ |
|
17 |
public class ReportStatisticsProcessPCA { |
|
18 |
private boolean rowColor = true; |
|
19 |
private final String bgColor0 = "\"#FEEDD6\""; // light salmon |
|
20 |
private final String bgColor1 = "\"#EAEAEA\""; // light grey |
|
21 |
// private final String bgColor3 = "\"#FBFFE1\""; // light yellow |
|
22 |
private final String bgColor4 = "\"#D6D6D6\""; // Gris |
|
23 |
private final String bgColorBody = "\"#FFFFFF\""; // white |
|
24 |
|
|
25 |
public DecimalFormat df = null; |
|
26 |
public String html = ""; |
|
27 |
|
|
28 |
private PCStatsDataStructure pcStatistics = null; |
|
29 |
private boolean bandStatistics = false; |
|
30 |
private boolean covar = false; |
|
31 |
private boolean autovect = false; |
|
32 |
|
|
33 |
public ReportStatisticsProcessPCA(PCStatsDataStructure pcStatistics, boolean bandStatistics, boolean covar, boolean autovect) { |
|
34 |
super(); |
|
35 |
this.pcStatistics = pcStatistics; |
|
36 |
this.bandStatistics = bandStatistics; |
|
37 |
this.covar = covar; |
|
38 |
this.autovect = autovect; |
|
39 |
init(); |
|
40 |
} |
|
41 |
|
|
42 |
public String getHtml() { |
|
43 |
return html; |
|
44 |
} |
|
45 |
|
|
46 |
public void init() { |
|
47 |
df = new DecimalFormat("0.00000"); |
|
48 |
|
|
49 |
html ="<blockquote>" + |
|
50 |
"<blockquote>" + |
|
51 |
"<html><body>" + |
|
52 |
" <body bgcolor=" + bgColorBody + " topmargin=\"0\" marginheight=\"0\">" + |
|
53 |
"<font size=3><h1><center>Informe estad?stico de Componentes Principales</center></h1>"; |
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
if(bandStatistics) { |
|
58 |
html += " <font face=\"Arial\" size=\"2\"><B>Estad?sticas de bandas : </B><br>"; |
|
59 |
CreateBandStatistic(pcStatistics.getMaxMinMean()); |
|
60 |
} |
|
61 |
if(covar) { |
|
62 |
html += " <font face=\"Arial\" size=\"2\"><B>Matriz varianza-covarianza : </B><br>"; |
|
63 |
ExportarMatriz(pcStatistics.getCoVarMatrix(), "Band"); |
|
64 |
} |
|
65 |
|
|
66 |
if (autovect) { |
|
67 |
//Hay que modificar el orden (Traspuesta y cambio de orden de columnas) |
|
68 |
//Colocamos la matriz en el orden correcto: |
|
69 |
/* |
|
70 |
* b3 b2 b1 |
|
71 |
* c1 |
|
72 |
* c2 |
|
73 |
* c3 |
|
74 |
* | | |
|
75 |
* | | Cambio de orden de columnas de la matriz transpuesta |
|
76 |
* ___ |
|
77 |
* \ / |
|
78 |
* V |
|
79 |
* c1 c2 c3 |
|
80 |
* b1 |
|
81 |
* b2 |
|
82 |
* b3 |
|
83 |
* */ |
|
84 |
html += " <font face=\"Arial\" size=\"2\"><B>Matriz de autovectores : </B><br>"; |
|
85 |
ExportarMatriz(ChangeColumns((pcStatistics.getAutoVectorsMatrix().transpose())), "Component"); |
|
86 |
|
|
87 |
} |
|
88 |
|
|
89 |
this.close(); |
|
90 |
} |
|
91 |
|
|
92 |
private Matrix ChangeColumns(Matrix m) { |
|
93 |
Matrix result = new Matrix(m.getRowDimension(), m.getColumnDimension()); |
|
94 |
int k = m.getColumnDimension() - 1; |
|
95 |
for(int i = 0; i < m.getRowDimension(); i++) { |
|
96 |
for(int j=0; j<m.getColumnDimension(); j++) { |
|
97 |
result.set(i, j, m.get(k - i, j)); |
|
98 |
} |
|
99 |
} |
|
100 |
return result; |
|
101 |
} |
|
102 |
|
|
103 |
private void ExportarMatriz(Matrix Matrix, String nameColumns) { |
|
104 |
//Creamos tabla |
|
105 |
html = html + "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\"\">"+ |
|
106 |
"<TR bgcolor=" + bgColor4 +" ALIGN=center>"; |
|
107 |
html += "<TH > <font face=\"Arial\" size=\"3\"><N></TH>"; |
|
108 |
//Crear primera fila: cabecera de tabla |
|
109 |
for(int i = 0; i < Matrix.getColumnDimension(); i++) { |
|
110 |
html += "<TH > <font face=\"Arial\" size=\"3\" b> "+ nameColumns + " " + (i + 1) + "</b></TH>"; |
|
111 |
} |
|
112 |
html += "</TR>"; |
|
113 |
//Rellenamos tabla |
|
114 |
for(int i = 0; i < Matrix.getRowDimension(); i++) { |
|
115 |
html = html + "<TR ><TD bgcolor=" + bgColor4 +"><center><font face=\"Arial\" size=\"3\">" +"<b>Band "+(i+1)+" </b></TD>"; |
|
116 |
String color = getColor(); |
|
117 |
for(int j = 0; j < Matrix.getColumnDimension(); j++){ |
|
118 |
html += "<TD bgcolor=" + color +"><center><font face=\"Arial\" size=\"3\">"+df.format(Matrix.get(i, j))+" </TD>"; |
|
119 |
} |
|
120 |
html += "</TR>"; |
|
121 |
} |
|
122 |
|
|
123 |
//Cerrar tabla |
|
124 |
html = html + "</TABLE><br><br>"; |
|
125 |
} |
|
126 |
|
|
127 |
private void CreateBandStatistic(double[][] maxminmean) { |
|
128 |
//Creamos tabla |
|
129 |
html = html + "<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\"\">" + |
|
130 |
"<TR bgcolor=" + bgColor4 +" ALIGN=center>"; |
|
131 |
//Crear primera fila: cabecera de tabla |
|
132 |
html += "<TH><font face=\"Arial\" size=\"3\">" + Messages.getText("band") + "</TH>" + |
|
133 |
"<TH> <font face=\"Arial\" size=\"3\"><N>" + Messages.getText("max") + "</TH>" + |
|
134 |
"<TH><font face=\"Arial\" size=\"3\">" + Messages.getText("min") + "</TH>" + |
|
135 |
"<TH><font face=\"Arial\" size=\"3\">" + Messages.getText("mean") + "</TH>" + |
|
136 |
"<TH><font face=\"Arial\" size=\"3\">" + Messages.getText("variance") + "</TH>" + |
|
137 |
"<TH><font face=\"Arial\" size=\"3\">" + Messages.getText("standard_deviation") + "</N></TH></TR>"; |
|
138 |
|
|
139 |
//Recorremos filas de datos |
|
140 |
for (int i = 0; i < maxminmean.length; i++) { |
|
141 |
html = html + "<TR bgcolor=" + getColor() + "><TD><center><font face=\"Arial\" size=\"3\">" +"band " + (i + 1) + " </TD>" + |
|
142 |
"<TD><center><font face=\"Arial\" size=\"3\">" + df.format(maxminmean[i][0]) + " </TD>" + |
|
143 |
"<TD><center><font face=\"Arial\" size=\"3\">" + df.format(maxminmean[i][1]) + " </TD>" + |
|
144 |
"<TD><center><font face=\"Arial\" size=\"3\">" + df.format(maxminmean[i][2]) + " </TD>" + |
|
145 |
"<TD><center><font face=\"Arial\" size=\"3\">" + df.format(maxminmean[i][3]) + " </TD>" + |
|
146 |
"<TD><center><font face=\"Arial\" size=\"3\">" + df.format(Math.sqrt(maxminmean[i][3])) + " </TD></TR>"; |
|
147 |
} |
|
148 |
//Cerrar tabla |
|
149 |
html = html + "</TABLE><br><br>"; |
|
150 |
} |
|
151 |
|
|
152 |
public void close() { |
|
153 |
html = html + "</BODY></HTML>"; |
|
154 |
} |
|
155 |
|
|
156 |
private String getColor() { |
|
157 |
String color = (rowColor ? bgColor0 : bgColor1); |
|
158 |
rowColor = !rowColor; |
|
159 |
return color; |
|
160 |
} |
|
161 |
} |
|
0 | 162 |
org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.156/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.impl/src/main/java/org/gvsig/raster/principalcomponents/swing/impl/stats/StatsPanelImpl.java | ||
---|---|---|
1 |
package org.gvsig.raster.principalcomponents.swing.impl.stats; |
|
2 |
|
|
3 |
import java.awt.BorderLayout; |
|
4 |
import java.awt.event.ActionEvent; |
|
5 |
import java.awt.event.ActionListener; |
|
6 |
import java.io.File; |
|
7 |
import java.io.FileWriter; |
|
8 |
import java.io.IOException; |
|
9 |
import java.io.PrintWriter; |
|
10 |
|
|
11 |
import javax.swing.BorderFactory; |
|
12 |
import javax.swing.Box; |
|
13 |
import javax.swing.BoxLayout; |
|
14 |
import javax.swing.JButton; |
|
15 |
import javax.swing.JFileChooser; |
|
16 |
import javax.swing.JOptionPane; |
|
17 |
import javax.swing.JPanel; |
|
18 |
import javax.swing.JScrollPane; |
|
19 |
import javax.swing.JTextPane; |
|
20 |
|
|
21 |
import org.cresques.Messages; |
|
22 |
|
|
23 |
import org.gvsig.raster.principalcomponents.algorithm.PCStatsDataStructure; |
|
24 |
import org.gvsig.tools.ToolsLocator; |
|
25 |
import org.gvsig.tools.i18n.I18nManager; |
|
26 |
|
|
27 |
import org.slf4j.Logger; |
|
28 |
import org.slf4j.LoggerFactory; |
|
29 |
|
|
30 |
public class StatsPanelImpl extends JPanel { |
|
31 |
private static final long serialVersionUID = 1L; |
|
32 |
private JButton save = null; |
|
33 |
//private JButton accept = null; |
|
34 |
private JTextPane text = null; |
|
35 |
private String html = null; |
|
36 |
private Logger log = LoggerFactory.getLogger(StatsPanelImpl.class); |
|
37 |
|
|
38 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
39 |
|
|
40 |
public StatsPanelImpl(PCStatsDataStructure pcStatistics, boolean bandStatistics, boolean covar, boolean autovect) { |
|
41 |
ReportStatisticsProcessPCA process = new ReportStatisticsProcessPCA(pcStatistics, bandStatistics, covar, autovect); |
|
42 |
html = process.getHtml(); |
|
43 |
this.setLayout(new BorderLayout()); |
|
44 |
//this.setPreferredSize(new Dimension(650, 400)); |
|
45 |
this.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); |
|
46 |
|
|
47 |
text = new JTextPane(); |
|
48 |
text.setContentType("text/html"); |
|
49 |
text.setEditable(false); |
|
50 |
text.setText(html); |
|
51 |
text.setCaretPosition(0); |
|
52 |
|
|
53 |
JScrollPane scrollPane = new JScrollPane(text); |
|
54 |
//scrollPane.setPreferredSize(new Dimension(500, 220)); |
|
55 |
|
|
56 |
/*accept = new JButton("Accept"); |
|
57 |
accept.addActionListener(new ActionListener() { |
|
58 |
public void actionPerformed(ActionEvent arg0) { |
|
59 |
setVisible(false); // Provoca el cierre de la ventana |
|
60 |
} |
|
61 |
});*/ |
|
62 |
|
|
63 |
save = new JButton(i18n.getTranslation("save")); |
|
64 |
save.addActionListener(new ActionListener() { |
|
65 |
public void actionPerformed(ActionEvent evt) { |
|
66 |
saveActionPerformed(evt); |
|
67 |
} |
|
68 |
}); |
|
69 |
|
|
70 |
JPanel buttonsPanel = new JPanel(); |
|
71 |
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, |
|
72 |
BoxLayout.LINE_AXIS)); |
|
73 |
buttonsPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); |
|
74 |
|
|
75 |
buttonsPanel.add(Box.createHorizontalGlue()); |
|
76 |
buttonsPanel.add(save); |
|
77 |
//buttonsPanel.add(accept); |
|
78 |
|
|
79 |
this.add(scrollPane, BorderLayout.CENTER); |
|
80 |
this.add(buttonsPanel, BorderLayout.SOUTH); |
|
81 |
this.setVisible(true); |
|
82 |
} |
|
83 |
|
|
84 |
private void saveActionPerformed(ActionEvent evt) { |
|
85 |
FileWriter reporte = null; |
|
86 |
PrintWriter escritura = null; |
|
87 |
JFileChooser chooser = new JFileChooser(); |
|
88 |
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); |
|
89 |
int returnVal = chooser.showSaveDialog(getParent()); |
|
90 |
if(returnVal == JFileChooser.APPROVE_OPTION) { |
|
91 |
if(chooser.getSelectedFile() != null){ |
|
92 |
try { |
|
93 |
File file = chooser.getSelectedFile(); |
|
94 |
if(file.isDirectory()) { |
|
95 |
if(file.canWrite()) |
|
96 |
file = new File(file.getAbsolutePath() + File.separator + "Report.html"); |
|
97 |
else |
|
98 |
JOptionPane.showMessageDialog(getParent(), Messages.getText("folder_not_writable")); |
|
99 |
} else { |
|
100 |
if(!file.getAbsolutePath().endsWith("html") && !file.getAbsolutePath().endsWith("htm")) |
|
101 |
file = new File(file.getAbsolutePath() + ".html"); |
|
102 |
} |
|
103 |
|
|
104 |
reporte = new FileWriter(file); |
|
105 |
} catch (IOException e1) { |
|
106 |
log.error("Error writing the statistics", e1); |
|
107 |
} |
|
108 |
|
|
109 |
escritura = new PrintWriter(reporte); |
|
110 |
escritura.println(html); |
|
111 |
escritura.close(); |
|
112 |
} |
|
113 |
|
|
114 |
} |
|
115 |
} |
|
116 |
|
|
117 |
} |
|
118 |
|
|
0 | 119 |
org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.156/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.impl/src/main/java/org/gvsig/raster/principalcomponents/swing/impl/DefaultPrincipalComponentsSwingManager.java | ||
---|---|---|
1 |
package org.gvsig.raster.principalcomponents.swing.impl; |
|
2 |
|
|
3 |
import javax.swing.JPanel; |
|
4 |
|
|
5 |
import org.gvsig.raster.algorithm.BasicAPISwingPanel; |
|
6 |
import org.gvsig.raster.principalcomponents.algorithm.PCStatsDataStructure; |
|
7 |
import org.gvsig.raster.principalcomponents.swing.PrincipalComponentsSwingManager; |
|
8 |
import org.gvsig.raster.principalcomponents.swing.impl.main.PCAComponentsListPanelImpl; |
|
9 |
import org.gvsig.raster.principalcomponents.swing.impl.main.PCAMainPanelImpl; |
|
10 |
import org.gvsig.raster.principalcomponents.swing.impl.stats.StatsPanelImpl; |
|
11 |
|
|
12 |
/** |
|
13 |
* Default {@link PrincipalComponentsManager} implementation. |
|
14 |
* |
|
15 |
* @author gvSIG Team |
|
16 |
* @version $Id$ |
|
17 |
*/ |
|
18 |
public class DefaultPrincipalComponentsSwingManager implements PrincipalComponentsSwingManager { |
|
19 |
private static DefaultPrincipalComponentsSwingManager internalInstance = new DefaultPrincipalComponentsSwingManager(); |
|
20 |
//private static final Logger logger = LoggerFactory.getLogger(DefaultPrincipalComponentsSwingManager.class); |
|
21 |
|
|
22 |
/** |
|
23 |
* Gets an instance of this object for internal use. |
|
24 |
* @return DefaultPrincipalComponentsManager |
|
25 |
*/ |
|
26 |
public static DefaultPrincipalComponentsSwingManager getInstance() { |
|
27 |
return internalInstance; |
|
28 |
} |
|
29 |
|
|
30 |
public BasicAPISwingPanel createPCAMainPanel( |
|
31 |
Object inputStore, |
|
32 |
String layerName, |
|
33 |
int bandList, |
|
34 |
String roisEPSG) { |
|
35 |
return new PCAMainPanelImpl(inputStore, layerName, bandList, roisEPSG); |
|
36 |
} |
|
37 |
|
|
38 |
public BasicAPISwingPanel createPCAComponentsListPanel( |
|
39 |
Object inputStore, |
|
40 |
PCStatsDataStructure stats, |
|
41 |
String fileName, |
|
42 |
boolean[] bands, |
|
43 |
String roisEPSG) { |
|
44 |
return new PCAComponentsListPanelImpl(inputStore, stats, fileName, bands, roisEPSG); |
|
45 |
} |
|
46 |
|
|
47 |
public JPanel createStatisticsPanel( |
|
48 |
PCStatsDataStructure pcStatistics, |
|
49 |
boolean bandStatistics, |
|
50 |
boolean covar, |
|
51 |
boolean autovect) { |
|
52 |
return new StatsPanelImpl(pcStatistics, bandStatistics, covar, autovect); |
|
53 |
} |
|
54 |
} |
|
0 | 55 |
org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.156/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.impl/src/main/java/org/gvsig/raster/principalcomponents/swing/impl/main/PCAComponentsListPanelImpl.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.principalcomponents.swing.impl.main; |
|
23 |
|
|
24 |
import java.awt.BorderLayout; |
|
25 |
import java.awt.GridBagConstraints; |
|
26 |
import java.awt.GridBagLayout; |
|
27 |
import java.awt.event.ActionListener; |
|
28 |
import java.util.EventListener; |
|
29 |
import java.util.List; |
|
30 |
|
|
31 |
import javax.swing.BorderFactory; |
|
32 |
import javax.swing.JButton; |
|
33 |
import javax.swing.JComponent; |
|
34 |
import javax.swing.JPanel; |
|
35 |
import javax.swing.JRadioButton; |
|
36 |
|
|
37 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
|
38 |
import org.gvsig.i18n.Messages; |
|
39 |
import org.gvsig.raster.algorithm.BasicAPISwingPanel; |
|
40 |
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary; |
|
41 |
import org.gvsig.raster.algorithm.process.DataProcess; |
|
42 |
import org.gvsig.raster.algorithm.process.ProcessException; |
|
43 |
import org.gvsig.raster.principalcomponents.algorithm.PCStatsDataStructure; |
|
44 |
import org.gvsig.raster.principalcomponents.algorithm.PrincipalComponentsAlgorithmLibrary; |
|
45 |
import org.gvsig.raster.principalcomponents.swing.PrincipalComponentsSwingLibrary; |
|
46 |
import org.gvsig.raster.swing.RasterSwingLocator; |
|
47 |
import org.gvsig.raster.swing.RasterSwingManager; |
|
48 |
import org.gvsig.raster.swing.pagedtable.ModelLoader; |
|
49 |
import org.gvsig.raster.swing.pagedtable.PagedTable; |
|
50 |
|
|
51 |
/** |
|
52 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
53 |
*/ |
|
54 |
public class PCAComponentsListPanelImpl extends JPanel implements BasicAPISwingPanel { |
|
55 |
private static final long serialVersionUID = 1L; |
|
56 |
private Object inputStore = null; |
|
57 |
private PagedTable table = null; |
|
58 |
private JRadioButton byBandRadioButton = null; |
|
59 |
private JRadioButton varCovarRadioButton = null; |
|
60 |
private JRadioButton autovectorRadioButton = null; |
|
61 |
private JButton generateButton = null; |
|
62 |
private PCStatsDataStructure stats = null; |
|
63 |
private String fileName = null; |
|
64 |
private boolean[] bands = null; |
|
65 |
private String roisEPSG = null; |
|
66 |
|
|
67 |
public PCAComponentsListPanelImpl( |
|
68 |
Object inputStore, |
|
69 |
PCStatsDataStructure stats, |
|
70 |
String fileName, |
|
71 |
boolean[] bands, |
|
72 |
String roisEPSG) { |
|
73 |
this.inputStore = inputStore; |
|
74 |
this.stats = stats; |
|
75 |
this.fileName = fileName; |
|
76 |
this.bands = bands; |
|
77 |
this.roisEPSG = roisEPSG; |
|
78 |
init(); |
|
79 |
} |
|
80 |
|
|
81 |
private void init() { |
|
82 |
setLayout(new GridBagLayout()); |
|
83 |
|
|
84 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
|
85 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; |
|
86 |
gridBagConstraints1.weightx = 1; |
|
87 |
gridBagConstraints1.weighty = 1; |
|
88 |
gridBagConstraints1.insets = new java.awt.Insets(0, 0, 0, 0); |
|
89 |
gridBagConstraints1.gridx = 0; |
|
90 |
gridBagConstraints1.gridy = 0; |
|
91 |
add(getInputsPanel(), gridBagConstraints1); |
|
92 |
|
|
93 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; |
|
94 |
gridBagConstraints1.weighty = 0; |
|
95 |
gridBagConstraints1.gridy = 1; |
|
96 |
add(getPanelStatistics(), gridBagConstraints1); |
|
97 |
} |
|
98 |
|
|
99 |
public JPanel getPanelStatistics() { |
|
100 |
JPanel p = new JPanel(); |
|
101 |
p.setBorder(BorderFactory.createTitledBorder(Messages.getText("statistics"))); |
|
102 |
p.setLayout(new GridBagLayout()); |
|
103 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
|
104 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; |
|
105 |
gridBagConstraints1.weightx = 1; |
|
106 |
gridBagConstraints1.insets = new java.awt.Insets(0, 0, 2, 0); |
|
107 |
gridBagConstraints1.gridwidth = 2; |
|
108 |
|
|
109 |
gridBagConstraints1.gridx = 0; |
|
110 |
gridBagConstraints1.gridy = 0; |
|
111 |
p.add(getByBandRadioButton(), gridBagConstraints1); |
|
112 |
|
|
113 |
gridBagConstraints1.gridwidth = 1; |
|
114 |
gridBagConstraints1.gridy = 1; |
|
115 |
p.add(getVarCovarRadioButton(), gridBagConstraints1); |
|
116 |
|
|
117 |
gridBagConstraints1.gridwidth = 2; |
|
118 |
gridBagConstraints1.gridy = 2; |
|
119 |
p.add(getAutovectorRadioButton(), gridBagConstraints1); |
|
120 |
|
|
121 |
gridBagConstraints1.gridwidth = 1; |
|
122 |
gridBagConstraints1.gridx = 1; |
|
123 |
gridBagConstraints1.gridy = 1; |
|
124 |
p.add(getGenerateButton(), gridBagConstraints1); |
|
125 |
|
|
126 |
return p; |
|
127 |
} |
|
128 |
|
|
129 |
public JRadioButton getByBandRadioButton() { |
|
130 |
if(byBandRadioButton == null) { |
|
131 |
byBandRadioButton = new JRadioButton(Messages.getText("by_band")); |
|
132 |
byBandRadioButton.setSelected(true); |
|
133 |
} |
|
134 |
return byBandRadioButton; |
|
135 |
} |
|
136 |
|
|
137 |
public JRadioButton getVarCovarRadioButton() { |
|
138 |
if(varCovarRadioButton == null) |
|
139 |
varCovarRadioButton = new JRadioButton(Messages.getText("var_covar")); |
|
140 |
return varCovarRadioButton; |
|
141 |
} |
|
142 |
|
|
143 |
public JRadioButton getAutovectorRadioButton() { |
|
144 |
if(autovectorRadioButton == null) |
|
145 |
autovectorRadioButton = new JRadioButton(Messages.getText("autovector")); |
|
146 |
return autovectorRadioButton; |
|
147 |
} |
|
148 |
|
|
149 |
public JButton getGenerateButton() { |
|
150 |
if(generateButton == null) |
|
151 |
generateButton = new JButton(Messages.getText("generate")); |
|
152 |
return generateButton; |
|
153 |
} |
|
154 |
|
|
155 |
private JPanel getInputsPanel() { |
|
156 |
JPanel p = new JPanel(); |
|
157 |
p.setBorder(BorderFactory.createTitledBorder(Messages.getText("components_selection"))); |
|
158 |
p.setLayout(new BorderLayout()); |
|
159 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
|
160 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; |
|
161 |
gridBagConstraints1.weightx = 1; |
|
162 |
gridBagConstraints1.weighty = 1; |
|
163 |
gridBagConstraints1.insets = new java.awt.Insets(2, 2, 2, 2); |
|
164 |
|
|
165 |
gridBagConstraints1.gridx = 0; |
|
166 |
gridBagConstraints1.gridy = 0; |
|
167 |
p.add(getPagedTable().getComponent(), BorderLayout.CENTER); |
|
168 |
|
|
169 |
return p; |
|
170 |
} |
|
171 |
|
|
172 |
public JComponent getComponent() { |
|
173 |
return this; |
|
174 |
} |
|
175 |
|
|
176 |
public PagedTable getPagedTable() { |
|
177 |
if(table == null) { |
|
178 |
RasterSwingManager manager = RasterSwingLocator.getSwingManager(); |
|
179 |
String[] columnNames = { |
|
180 |
"", |
|
181 |
"C", |
|
182 |
Messages.getText("autovalor"), |
|
183 |
"%"}; |
|
184 |
int[] columnSizes = {30, 35, -1, -1}; |
|
185 |
|
|
186 |
BandTableModel model = new BandTableModel(columnNames); |
|
187 |
ModelLoader loader = manager.createModelLoader(model); |
|
188 |
CheckBoxColumnRenderer render = new CheckBoxColumnRenderer(null); |
|
189 |
CheckBoxColumnEditor editor = new CheckBoxColumnEditor(); |
|
190 |
loader.setRenderForColumn(0, render); |
|
191 |
loader.setCellEditorForColumn(0, editor); |
|
192 |
loader.setColumnNames(columnNames); |
|
193 |
loader.setColumnWidths(columnSizes); |
|
194 |
|
|
195 |
table = manager.createPagedTable(loader); |
|
196 |
table.showControllerTable(false); |
|
197 |
table.showMoveRowsControls(false); |
|
198 |
} |
|
199 |
return table; |
|
200 |
} |
|
201 |
|
|
202 |
public Object getResult() throws ProcessException { |
|
203 |
DataProcess task = RasterBaseAlgorithmLibrary.getManager().createRasterTask(PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL); |
|
204 |
List<String> params = task.getRasterTaskInputParameters(PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL); |
|
205 |
for (int i = 0; i < params.size(); i++) { |
|
206 |
String paramName = params.get(i); |
|
207 |
Class<?> paramType = task.getParameterTypeByProcess(PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL, paramName); |
|
208 |
if(paramType == RasterDataStore.class) { |
|
209 |
task.addParam(paramName, (RasterDataStore)inputStore); |
|
210 |
} |
|
211 |
if(paramName.equals("SELECTEDPCS") && paramType == Boolean[].class) { |
|
212 |
boolean[] components = new boolean[getPagedTable().getRowCount()]; |
|
213 |
for (int j = 0; j < getPagedTable().getRowCount(); j++) { |
|
214 |
Object obj = getPagedTable().getValueAt(j, 0); |
|
215 |
if(obj instanceof Boolean) |
|
216 |
components[j] = ((Boolean)obj).booleanValue(); |
|
217 |
} |
|
218 |
task.addParam(paramName, components); |
|
219 |
} |
|
220 |
|
|
221 |
if(paramName.equals("BANDS") && paramType == Boolean[].class) { |
|
222 |
task.addParam(paramName, bands); |
|
223 |
} |
|
224 |
|
|
225 |
if(paramType == PCStatsDataStructure.class) { |
|
226 |
task.addParam(paramName, stats); |
|
227 |
} |
|
228 |
|
|
229 |
if(paramType == String.class) { |
|
230 |
task.addParam(paramName, fileName); |
|
231 |
} |
|
232 |
|
|
233 |
if(paramName.equals("ROI_EPSG")) { |
|
234 |
task.addParam(paramName, roisEPSG); |
|
235 |
} |
|
236 |
} |
|
237 |
return new Object[]{task, getByBandRadioButton().isSelected(), getVarCovarRadioButton().isSelected(), getAutovectorRadioButton().isSelected()}; |
|
238 |
} |
|
239 |
|
|
240 |
|
|
241 |
public void initialize() { |
|
242 |
double acumulado = 0; |
|
243 |
for (int i = 0; i < stats.getAutovalues().length; i++) |
|
244 |
acumulado += stats.getAutovalues()[i]; |
|
245 |
int autova[] = new int[stats.getAutovalues().length]; |
|
246 |
int cont = stats.getAutovalues().length - 1; |
|
247 |
for (int i = 0; i < stats.getAutovalues().length; i++) { |
|
248 |
autova[i] = cont; |
|
249 |
cont--; |
|
250 |
} |
|
251 |
|
|
252 |
for (int i = stats.getAutovalues().length-1; i >= 0; i--) { |
|
253 |
getPagedTable().addRow(new Object[] {true, |
|
254 |
autova[i], |
|
255 |
stats.getAutovalues()[i], |
|
256 |
stats.getAutovalues()[i] / acumulado}); |
|
257 |
} |
|
258 |
} |
|
259 |
|
|
260 |
public int getComponentIDByObject(Object obj) { |
|
261 |
return obj == getGenerateButton() ? PrincipalComponentsSwingLibrary.GENERATE_STATIST : -1; |
|
262 |
} |
|
263 |
|
|
264 |
public void addListener(EventListener listener) { |
|
265 |
if(listener instanceof ActionListener) |
|
266 |
getGenerateButton().addActionListener((ActionListener)listener); |
|
267 |
} |
|
268 |
|
|
269 |
} |
|
0 | 270 |
org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.156/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.impl/src/main/java/org/gvsig/raster/principalcomponents/swing/impl/main/PrincipalComponentsPanelImpl.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.principalcomponents.swing.impl.main; |
|
23 |
|
|
24 |
import java.awt.BorderLayout; |
|
25 |
import java.awt.GridBagConstraints; |
|
26 |
import java.awt.GridBagLayout; |
|
27 |
import java.io.File; |
|
28 |
import java.util.EventListener; |
|
29 |
import java.util.List; |
|
30 |
|
|
31 |
import javax.swing.BorderFactory; |
|
32 |
import javax.swing.JComponent; |
|
33 |
import javax.swing.JLabel; |
|
34 |
import javax.swing.JPanel; |
|
35 |
|
|
36 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
|
37 |
import org.gvsig.i18n.Messages; |
|
38 |
import org.gvsig.raster.algorithm.BasicAPISwingPanel; |
|
39 |
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary; |
|
40 |
import org.gvsig.raster.algorithm.process.DataProcess; |
|
41 |
import org.gvsig.raster.algorithm.process.ProcessException; |
|
42 |
import org.gvsig.raster.principalcomponents.algorithm.PrincipalComponentsAlgorithmLibrary; |
|
43 |
import org.gvsig.raster.swing.RasterSwingLocator; |
|
44 |
import org.gvsig.raster.swing.RasterSwingManager; |
|
45 |
import org.gvsig.raster.swing.newlayer.CreateNewLayerPanel; |
|
46 |
import org.gvsig.raster.swing.pagedtable.ModelLoader; |
|
47 |
import org.gvsig.raster.swing.pagedtable.PagedTable; |
|
48 |
|
|
49 |
/** |
|
50 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
51 |
*/ |
|
52 |
public class PrincipalComponentsPanelImpl extends JPanel implements BasicAPISwingPanel { |
|
53 |
private static final long serialVersionUID = 1L; |
|
54 |
private String layerName = null; |
|
55 |
private CreateNewLayerPanel newLayerPanel = null; |
|
56 |
private Object inputStore = null; |
|
57 |
private PagedTable table = null; |
|
58 |
private int bandList = 0; |
|
59 |
|
|
60 |
public PrincipalComponentsPanelImpl(Object inputStore, String layerName, int bandList) { |
|
61 |
this.inputStore = inputStore; |
|
62 |
this.layerName = layerName; |
|
63 |
this.bandList = bandList; |
|
64 |
init(); |
|
65 |
} |
|
66 |
|
|
67 |
private void init() { |
|
68 |
setLayout(new GridBagLayout()); |
|
69 |
|
|
70 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
|
71 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; |
|
72 |
gridBagConstraints1.weightx = 1; |
|
73 |
gridBagConstraints1.insets = new java.awt.Insets(0, 0, 0, 0); |
|
74 |
gridBagConstraints1.gridx = 0; |
|
75 |
gridBagConstraints1.gridy = 0; |
|
76 |
add(getLayerPanel(), gridBagConstraints1); |
|
77 |
|
|
78 |
gridBagConstraints1.gridy = 2; |
|
79 |
add((JComponent)getCreateNewLayerPanel(), gridBagConstraints1); |
|
80 |
|
|
81 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; |
|
82 |
gridBagConstraints1.gridy = 1; |
|
83 |
gridBagConstraints1.weighty = 1; |
|
84 |
add(getInputsPanel(), gridBagConstraints1); |
|
85 |
} |
|
86 |
|
|
87 |
private JPanel getLayerPanel() { |
|
88 |
JPanel p = new JPanel(); |
|
89 |
p.setBorder(BorderFactory.createTitledBorder(Messages.getText("layer"))); |
|
90 |
p.setLayout(new GridBagLayout()); |
|
91 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
|
92 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; |
|
93 |
gridBagConstraints1.weightx = 1; |
|
94 |
gridBagConstraints1.insets = new java.awt.Insets(0, 0, 2, 0); |
|
95 |
|
|
96 |
gridBagConstraints1.gridx = 0; |
|
97 |
gridBagConstraints1.gridy = 0; |
|
98 |
p.add(new JLabel(layerName), gridBagConstraints1); |
|
99 |
|
|
100 |
return p; |
|
101 |
} |
|
102 |
|
|
103 |
private JPanel getInputsPanel() { |
|
104 |
JPanel p = new JPanel(); |
|
105 |
p.setBorder(BorderFactory.createTitledBorder(Messages.getText("bands"))); |
|
106 |
p.setLayout(new BorderLayout()); |
|
107 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
|
108 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; |
|
109 |
gridBagConstraints1.weightx = 1; |
|
110 |
gridBagConstraints1.weighty = 1; |
|
111 |
gridBagConstraints1.insets = new java.awt.Insets(2, 2, 2, 2); |
|
112 |
|
|
113 |
gridBagConstraints1.gridx = 0; |
|
114 |
gridBagConstraints1.gridy = 0; |
|
115 |
p.add(getPagedTable().getComponent(), BorderLayout.CENTER); |
|
116 |
|
|
117 |
return p; |
|
118 |
} |
|
119 |
|
|
120 |
public JComponent getComponent() { |
|
121 |
return this; |
|
122 |
} |
|
123 |
|
|
124 |
public PagedTable getPagedTable() { |
|
125 |
if(table == null) { |
|
126 |
RasterSwingManager manager = RasterSwingLocator.getSwingManager(); |
|
127 |
String[] columnNames = { |
|
128 |
"", |
|
129 |
Messages.getText("bands")}; |
|
130 |
int[] columnSizes = {30, -1}; |
|
131 |
|
|
132 |
BandTableModel model = new BandTableModel(columnNames); |
|
133 |
ModelLoader loader = manager.createModelLoader(model); |
|
134 |
CheckBoxColumnRenderer render = new CheckBoxColumnRenderer(null); |
|
135 |
CheckBoxColumnEditor editor = new CheckBoxColumnEditor(); |
|
136 |
loader.setRenderForColumn(0, render); |
|
137 |
loader.setCellEditorForColumn(0, editor); |
|
138 |
loader.setColumnNames(columnNames); |
|
139 |
loader.setColumnWidths(columnSizes); |
|
140 |
|
|
141 |
table = manager.createPagedTable(loader); |
|
142 |
table.showControllerTable(false); |
|
143 |
table.showMoveRowsControls(false); |
|
144 |
} |
|
145 |
return table; |
|
146 |
} |
|
147 |
|
|
148 |
public DataProcess getResult() throws ProcessException { |
|
149 |
DataProcess task = RasterBaseAlgorithmLibrary.getManager().createRasterTask(PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL); |
|
150 |
List<String> params = task.getRasterTaskInputParameters(PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL); |
|
151 |
for (int i = 0; i < params.size(); i++) { |
|
152 |
String paramName = params.get(i); |
|
153 |
Class<?> paramType = task.getParameterTypeByProcess(PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL, paramName); |
|
154 |
if(paramType == RasterDataStore[].class) { |
|
155 |
task.addParam(paramName, new RasterDataStore[]{(RasterDataStore)inputStore}); |
|
156 |
} |
|
157 |
if(paramType == String.class) { |
|
158 |
String filename = newLayerPanel.getDirectorySelected() + File.separator + newLayerPanel.getFileSelected(); |
|
159 |
if(!filename.endsWith(".tif")) |
|
160 |
filename += ".tif"; |
|
161 |
task.addParam(paramName, filename); |
|
162 |
} |
|
163 |
if(paramType == Boolean[].class) { |
|
164 |
boolean[] bands = new boolean[getPagedTable().getRowCount()]; |
|
165 |
for (int j = 0; j < getPagedTable().getRowCount(); j++) { |
|
166 |
Object obj = getPagedTable().getValueAt(j, 0); |
|
167 |
if(obj instanceof Boolean) |
|
168 |
bands[j] = ((Boolean)obj).booleanValue(); |
|
169 |
} |
|
170 |
task.addParam(paramName, bands); |
|
171 |
} |
|
172 |
} |
|
173 |
return task; |
|
174 |
} |
|
175 |
|
|
176 |
public CreateNewLayerPanel getCreateNewLayerPanel() { |
|
177 |
if(newLayerPanel == null) { |
|
178 |
newLayerPanel = RasterSwingLocator.getSwingManager().createNewLayerPanel(); |
|
179 |
} |
|
180 |
return newLayerPanel; |
|
181 |
} |
|
182 |
|
|
183 |
public void initialize() { |
|
184 |
for (int i = 0; i < bandList; i++) { |
|
185 |
getPagedTable().addRow(new Object[]{true, "B" + i}); |
|
186 |
} |
|
187 |
} |
|
188 |
|
|
189 |
public int getComponentIDByObject(Object obj) { |
|
190 |
return -1; |
|
191 |
} |
|
192 |
|
|
193 |
public void addListener(EventListener listener) { |
|
194 |
// TODO Auto-generated method stub |
|
195 |
|
|
196 |
} |
|
197 |
|
|
198 |
} |
|
0 | 199 |
org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.156/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.impl/src/main/java/org/gvsig/raster/principalcomponents/swing/impl/main/PCAMainPanelImpl.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.raster.principalcomponents.swing.impl.main; |
|
23 |
|
|
24 |
import java.awt.BorderLayout; |
|
25 |
import java.awt.GridBagConstraints; |
|
26 |
import java.awt.GridBagLayout; |
|
27 |
import java.io.File; |
|
28 |
import java.util.EventListener; |
|
29 |
import java.util.List; |
|
30 |
|
|
31 |
import javax.swing.BorderFactory; |
|
32 |
import javax.swing.JCheckBox; |
|
33 |
import javax.swing.JComponent; |
|
34 |
import javax.swing.JLabel; |
|
35 |
import javax.swing.JPanel; |
|
36 |
|
|
37 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
|
38 |
import org.gvsig.i18n.Messages; |
|
39 |
import org.gvsig.raster.algorithm.BasicAPISwingPanel; |
|
40 |
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary; |
|
41 |
import org.gvsig.raster.algorithm.process.DataProcess; |
|
42 |
import org.gvsig.raster.algorithm.process.ProcessException; |
|
43 |
import org.gvsig.raster.principalcomponents.algorithm.PrincipalComponentsAlgorithmLibrary; |
|
44 |
import org.gvsig.raster.swing.RasterSwingLocator; |
|
45 |
import org.gvsig.raster.swing.RasterSwingManager; |
|
46 |
import org.gvsig.raster.swing.newlayer.CreateNewLayerPanel; |
|
47 |
import org.gvsig.raster.swing.pagedtable.ModelLoader; |
|
48 |
import org.gvsig.raster.swing.pagedtable.PagedTable; |
|
49 |
|
|
50 |
/** |
|
51 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
52 |
*/ |
|
53 |
public class PCAMainPanelImpl extends JPanel implements BasicAPISwingPanel { |
|
54 |
private static final long serialVersionUID = 1L; |
|
55 |
private String layerName = null; |
|
56 |
private CreateNewLayerPanel newLayerPanel = null; |
|
57 |
private Object inputStore = null; |
|
58 |
private PagedTable table = null; |
|
59 |
private JCheckBox roisCheck = null; |
|
60 |
private int bandList = 0; |
|
61 |
private String roisEPSG = null; |
|
62 |
|
|
63 |
public PCAMainPanelImpl(Object inputStore, String layerName, int bandList, String roisEPSG) { |
|
64 |
this.inputStore = inputStore; |
|
65 |
this.layerName = layerName; |
|
66 |
this.bandList = bandList; |
|
67 |
this.roisEPSG = roisEPSG; |
|
68 |
init(); |
|
69 |
} |
|
70 |
|
|
71 |
private void init() { |
|
72 |
setLayout(new GridBagLayout()); |
|
73 |
|
|
74 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
|
75 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; |
|
76 |
gridBagConstraints1.weightx = 1; |
|
77 |
gridBagConstraints1.insets = new java.awt.Insets(0, 0, 0, 0); |
|
78 |
gridBagConstraints1.gridx = 0; |
|
79 |
gridBagConstraints1.gridy = 0; |
|
80 |
add(getLayerPanel(), gridBagConstraints1); |
|
81 |
|
|
82 |
gridBagConstraints1.gridy = 2; |
|
83 |
add((JComponent)getCreateNewLayerPanel(), gridBagConstraints1); |
|
84 |
|
|
85 |
if(roisEPSG != null) { |
|
86 |
gridBagConstraints1.gridy = 3; |
|
87 |
add(getROIsCheck(), gridBagConstraints1); |
|
88 |
} |
|
89 |
|
|
90 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; |
|
91 |
gridBagConstraints1.gridy = 1; |
|
92 |
gridBagConstraints1.weighty = 1; |
|
93 |
add(getInputsPanel(), gridBagConstraints1); |
|
94 |
} |
|
95 |
|
|
96 |
private JPanel getLayerPanel() { |
|
97 |
JPanel p = new JPanel(); |
|
98 |
p.setBorder(BorderFactory.createTitledBorder(Messages.getText("layer"))); |
|
99 |
p.setLayout(new GridBagLayout()); |
|
100 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
|
101 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; |
|
102 |
gridBagConstraints1.weightx = 1; |
|
103 |
gridBagConstraints1.insets = new java.awt.Insets(0, 0, 2, 0); |
|
104 |
|
|
105 |
gridBagConstraints1.gridx = 0; |
|
106 |
gridBagConstraints1.gridy = 0; |
|
107 |
p.add(new JLabel(layerName), gridBagConstraints1); |
|
108 |
|
|
109 |
return p; |
|
110 |
} |
|
111 |
|
|
112 |
private JPanel getInputsPanel() { |
|
113 |
JPanel p = new JPanel(); |
|
114 |
p.setBorder(BorderFactory.createTitledBorder(Messages.getText("bands"))); |
|
115 |
p.setLayout(new BorderLayout()); |
|
116 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
|
117 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; |
|
118 |
gridBagConstraints1.weightx = 1; |
|
119 |
gridBagConstraints1.weighty = 1; |
|
120 |
gridBagConstraints1.insets = new java.awt.Insets(2, 2, 2, 2); |
|
121 |
|
|
122 |
gridBagConstraints1.gridx = 0; |
|
123 |
gridBagConstraints1.gridy = 0; |
|
124 |
p.add(getPagedTable().getComponent(), BorderLayout.CENTER); |
|
125 |
|
|
126 |
return p; |
|
127 |
} |
|
128 |
|
|
129 |
public JComponent getComponent() { |
|
130 |
return this; |
|
131 |
} |
|
132 |
|
|
133 |
public PagedTable getPagedTable() { |
|
134 |
if(table == null) { |
|
135 |
RasterSwingManager manager = RasterSwingLocator.getSwingManager(); |
|
136 |
String[] columnNames = { |
|
137 |
"", |
|
138 |
Messages.getText("bands")}; |
|
139 |
int[] columnSizes = {30, -1}; |
|
140 |
|
|
141 |
BandTableModel model = new BandTableModel(columnNames); |
|
142 |
ModelLoader loader = manager.createModelLoader(model); |
|
143 |
CheckBoxColumnRenderer render = new CheckBoxColumnRenderer(null); |
|
144 |
CheckBoxColumnEditor editor = new CheckBoxColumnEditor(); |
|
145 |
loader.setRenderForColumn(0, render); |
|
146 |
loader.setCellEditorForColumn(0, editor); |
|
147 |
loader.setColumnNames(columnNames); |
|
148 |
loader.setColumnWidths(columnSizes); |
|
149 |
|
|
150 |
table = manager.createPagedTable(loader); |
|
151 |
table.showControllerTable(false); |
|
152 |
table.showMoveRowsControls(false); |
|
153 |
} |
|
154 |
return table; |
|
155 |
} |
|
156 |
|
|
157 |
public DataProcess getResult() throws ProcessException { |
|
158 |
DataProcess task = RasterBaseAlgorithmLibrary.getManager().createRasterTask(PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL); |
|
159 |
List<String> params = task.getRasterTaskInputParameters(PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL); |
|
160 |
for (int i = 0; i < params.size(); i++) { |
|
161 |
String paramName = params.get(i); |
|
162 |
Class<?> paramType = task.getParameterTypeByProcess(PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL, paramName); |
|
163 |
if(paramType == RasterDataStore.class) { |
|
164 |
task.addParam(paramName, (RasterDataStore)inputStore); |
|
165 |
} |
|
166 |
if(paramName.equals("PATH")) { |
|
167 |
String filename = newLayerPanel.getDirectorySelected() + File.separator + newLayerPanel.getFileSelected(); |
|
168 |
if(!filename.endsWith(".tif")) |
|
169 |
filename += ".tif"; |
|
170 |
task.addParam(paramName, filename); |
|
171 |
} |
|
172 |
if(paramType == Boolean[].class) { |
|
173 |
boolean[] bands = new boolean[getPagedTable().getRowCount()]; |
|
174 |
for (int j = 0; j < getPagedTable().getRowCount(); j++) { |
|
175 |
Object obj = getPagedTable().getValueAt(j, 0); |
|
176 |
if(obj instanceof Boolean) |
|
177 |
bands[j] = ((Boolean)obj).booleanValue(); |
|
178 |
} |
|
179 |
task.addParam(paramName, bands); |
|
180 |
} |
|
181 |
|
|
182 |
if(getROIsCheck().isSelected()) { |
|
183 |
if(paramName.equals("ROI_EPSG")) { |
|
184 |
task.addParam(paramName, roisEPSG); |
|
185 |
} |
|
186 |
} |
|
187 |
} |
|
188 |
return task; |
|
189 |
} |
|
190 |
|
|
191 |
public JCheckBox getROIsCheck() { |
|
192 |
if(roisCheck == null) { |
|
193 |
roisCheck = new JCheckBox(Messages.getText("use_rois")); |
|
194 |
} |
|
195 |
return roisCheck; |
|
196 |
} |
|
197 |
|
|
198 |
public CreateNewLayerPanel getCreateNewLayerPanel() { |
|
199 |
if(newLayerPanel == null) { |
|
200 |
newLayerPanel = RasterSwingLocator.getSwingManager().createNewLayerPanel(); |
|
201 |
} |
|
202 |
return newLayerPanel; |
|
203 |
} |
|
204 |
|
|
205 |
public void initialize() { |
|
206 |
for (int i = 0; i < bandList; i++) { |
|
207 |
getPagedTable().addRow(new Object[]{true, "B" + i}); |
|
208 |
} |
|
209 |
} |
|
210 |
|
|
211 |
public int getComponentIDByObject(Object obj) { |
|
212 |
return -1; |
|
213 |
} |
|
214 |
|
|
215 |
public void addListener(EventListener listener) { |
|
216 |
} |
|
217 |
} |
|
0 | 218 |
org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.156/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.impl/src/main/java/org/gvsig/raster/principalcomponents/swing/impl/main/CheckBoxColumnEditor.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.raster.principalcomponents.swing.impl.main; |
|
25 |
|
|
26 |
import java.awt.Component; |
|
27 |
import java.awt.event.ActionEvent; |
|
28 |
import java.awt.event.ActionListener; |
|
29 |
|
|
30 |
import javax.swing.AbstractCellEditor; |
|
31 |
import javax.swing.JCheckBox; |
|
32 |
import javax.swing.JTable; |
|
33 |
import javax.swing.SwingUtilities; |
|
34 |
import javax.swing.table.TableCellEditor; |
|
35 |
|
|
36 |
/** |
|
37 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
38 |
*/ |
|
39 |
public class CheckBoxColumnEditor extends AbstractCellEditor |
|
40 |
implements TableCellEditor { |
|
41 |
final private static long serialVersionUID = -3370601314380922368L; |
|
42 |
public JCheckBox theCheckBox; |
|
43 |
|
|
44 |
public CheckBoxColumnEditor() { |
|
45 |
super(); |
|
46 |
theCheckBox = new JCheckBox(); |
|
47 |
theCheckBox.addActionListener(new ActionListener() { |
|
48 |
public void actionPerformed(ActionEvent event) { |
|
49 |
fireEditingStopped() ; |
|
50 |
|
|
51 |
} |
|
52 |
}); |
|
53 |
} |
|
54 |
|
|
55 |
public Component getTableCellEditorComponent(JTable table, Object obj, |
|
56 |
boolean isSelected, |
|
57 |
int row, int col) { |
|
58 |
theCheckBox.setHorizontalAlignment(SwingUtilities.CENTER); |
|
59 |
|
|
60 |
Boolean lValueAsBoolean = (Boolean) obj; |
|
61 |
theCheckBox.setSelected(lValueAsBoolean.booleanValue()); |
|
62 |
|
|
63 |
return theCheckBox; |
|
64 |
} |
|
65 |
|
|
66 |
public Object getCellEditorValue() { |
|
67 |
return new Boolean(theCheckBox.isSelected()); |
|
68 |
} |
|
69 |
} |
|
0 | 70 |
org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.156/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.impl/src/main/java/org/gvsig/raster/principalcomponents/swing/impl/main/CheckBoxColumnRenderer.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.raster.principalcomponents.swing.impl.main; |
|
25 |
|
|
26 |
import java.awt.Component; |
|
27 |
import java.awt.event.ActionEvent; |
|
28 |
import java.awt.event.ActionListener; |
|
29 |
|
|
30 |
import javax.swing.JCheckBox; |
|
31 |
import javax.swing.JTable; |
|
32 |
import javax.swing.SwingConstants; |
|
33 |
import javax.swing.table.TableCellRenderer; |
|
34 |
|
|
35 |
/** |
|
36 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
37 |
*/ |
|
38 |
public class CheckBoxColumnRenderer extends JCheckBox implements TableCellRenderer { |
|
39 |
final private static long serialVersionUID = -3370601314380922368L; |
|
40 |
private ActionListener listener = null; |
Also available in: Unified diff