Revision 8239

View differences:

org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.64/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.api/src/main/java/org/gvsig/raster/principalcomponents/swing/PrincipalComponentsSwingLibrary.java
1
package org.gvsig.raster.principalcomponents.swing;
2

  
3
import org.gvsig.tools.library.AbstractLibrary;
4
import org.gvsig.tools.library.LibraryException;
5
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
6

  
7
/**
8
 * Library for API initialization and configuration.
9
 * 
10
 * @author gvSIG team
11
 * @version $Id$
12
 */
13
public class PrincipalComponentsSwingLibrary extends AbstractLibrary {
14
	public static int 	GENERATE_STATIST 	   = 1026;
15
	
16
    @Override
17
    protected void doInitialize() throws LibraryException {
18
    }
19

  
20
    @Override
21
    protected void doPostInitialize() throws LibraryException {
22
        // Validate there is any implementation registered.
23
    	PrincipalComponentsSwingManager manager = PrincipalComponentsSwingLocator.getSwingManager();
24
        if (manager == null) {
25
            throw new ReferenceNotRegisteredException(
26
            		PrincipalComponentsSwingLocator.SWING_MANAGER_NAME, 
27
            		PrincipalComponentsSwingLocator.getInstance());
28
        }
29
    }
30

  
31
}
0 32

  
org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.64/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.api/src/main/java/org/gvsig/raster/principalcomponents/swing/PrincipalComponentsSwingManager.java
1
package org.gvsig.raster.principalcomponents.swing;
2

  
3
import javax.swing.JPanel;
4

  
5
import org.gvsig.raster.algorithm.BasicAPISwingPanel;
6
import org.gvsig.raster.principalcomponents.algorithm.PCStatsDataStructure;
7

  
8
/**
9
 * This class is responsible of the management of the library's business logic.
10
 * It is the library's main entry point, and provides all the services to manage
11
 * {@link PrincipalComponentsService}s.
12
 * 
13
 * @see PrincipalComponentsService
14
 * @author gvSIG team
15
 * @version $Id$
16
 */
17
public interface PrincipalComponentsSwingManager {
18
	public BasicAPISwingPanel createPCAMainPanel(
19
			Object inputStore, 
20
			String layerName, 
21
			int bandList, 
22
			String roisEPSG);
23
	
24
	public BasicAPISwingPanel createPCAComponentsListPanel(
25
			Object inputStore, 
26
			PCStatsDataStructure stats, 
27
			String fileName, 
28
			boolean[] bands, 
29
			String roisEPSG);
30
	
31
	public JPanel createStatisticsPanel(
32
			PCStatsDataStructure pcStatistics, 
33
			boolean bandStatistics, 
34
			boolean covar, 
35
			boolean autovect);
36
}
0 37

  
org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.64/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.api/src/main/java/org/gvsig/raster/principalcomponents/swing/PrincipalComponentsSwingLocator.java
1
package org.gvsig.raster.principalcomponents.swing;
2

  
3
import org.gvsig.tools.locator.BaseLocator;
4

  
5
/**
6
 * This locator is the entry point for the Raster library, providing
7
 * access to all Raster services through the {@link PrincipalComponentsManager}
8
 * .
9
 * 
10
 * @author gvSIG team
11
 * @version $Id$
12
 */
13
public class PrincipalComponentsSwingLocator extends BaseLocator {
14
    /**
15
     * Validation swing manager name.
16
     */
17
    public static final String SWING_MANAGER_NAME =
18
        "PrincipalComponents.swing.manager";
19

  
20
    /**
21
     * Validation swing manager description.
22
     */
23
    public static final String SWING_MANAGER_DESCRIPTION =
24
        "PrincipalComponents UIManager";
25

  
26
    private static final String LOCATOR_NAME = "PrincipalComponents.swing.locator";
27

  
28
    /**
29
     * Unique instance.
30
     */
31
    private static final PrincipalComponentsSwingLocator INSTANCE =
32
        new PrincipalComponentsSwingLocator();
33

  
34
    /**
35
     * Return the singleton instance.
36
     * 
37
     * @return the singleton instance
38
     */
39
    public static PrincipalComponentsSwingLocator getInstance() {
40
        return INSTANCE;
41
    }
42

  
43
    /**
44
     * Return the Locator's name
45
     * 
46
     * @return a String with the Locator's name
47
     */
48
    public final String getLocatorName() {
49
        return LOCATOR_NAME;
50
    }
51

  
52
    /**
53
     * Registers the Class implementing the PersistenceManager interface.
54
     * 
55
     * @param clazz
56
     *            implementing the PersistenceManager interface
57
     */
58
    public static void registerSwingManager(
59
        Class<? extends PrincipalComponentsSwingManager> clazz) {
60
        getInstance().register(SWING_MANAGER_NAME, SWING_MANAGER_DESCRIPTION, clazz);
61
    }
62

  
63
    /**
64
     * Gets the instance of the {@link ScriptingUIManager} registered.
65
     * 
66
     * @return {@link ScriptingUIManager}
67
     */
68
    public static PrincipalComponentsSwingManager getSwingManager() {
69
        return (PrincipalComponentsSwingManager) getInstance().get(SWING_MANAGER_NAME);
70
    }
71
}
0 72

  
org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.64/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.api/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.principalcomponents.swing.PrincipalComponentsSwingLibrary
0 2

  
org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.64/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.api/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.api</artifactId>
5
	<packaging>jar</packaging>
6
	<name>org.gvsig.raster.principalcomponents.swing.api</name>
7
	<parent>
8
		<groupId>org.gvsig</groupId>
9
		<artifactId>org.gvsig.raster.principalcomponents.swing</artifactId>
10
		<version>2.2.64</version>
11
	</parent>
12
	<dependencies>
13
		<dependency>
14
            <groupId>org.gvsig</groupId>
15
            <artifactId>org.gvsig.tools.lib</artifactId>      
16
            <scope>compile</scope>
17
        </dependency> 
18
        <dependency>
19
            <groupId>org.gvsig</groupId>
20
            <artifactId>org.gvsig.fmap.mapcontext.api</artifactId>
21
            <scope>compile</scope>
22
        </dependency>
23
        <dependency>
24
            <groupId>org.gvsig</groupId>
25
            <artifactId>org.gvsig.fmap.mapcontext.impl</artifactId>
26
            <scope>runtime</scope>
27
        </dependency>
28
        <dependency>
29
            <groupId>org.gvsig</groupId>
30
            <artifactId>org.gvsig.i18n</artifactId>
31
            <scope>compile</scope>
32
        </dependency>
33
	</dependencies>
34
</project>
0 35

  
org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.64/org.gvsig.raster.principalcomponents.swing/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/xsd/maven-4.0.0.xsd">
3

  
4
	<modelVersion>4.0.0</modelVersion>
5
	<artifactId>org.gvsig.raster.principalcomponents.swing</artifactId>
6
	<packaging>pom</packaging>
7
	<name>org.gvsig.raster.principalcomponents.swing</name>
8
	<parent>
9
		<groupId>org.gvsig</groupId>
10
		<artifactId>org.gvsig.raster.principalcomponents</artifactId>
11
		<version>2.2.64</version>
12
	</parent>
13
	<dependencies>
14
		<dependency>
15
			<groupId>org.gvsig</groupId>
16
			<artifactId>org.gvsig.andami</artifactId>
17
                        <scope>compile</scope>
18
		</dependency>
19
		<dependency>
20
			<groupId>org.gvsig</groupId>
21
			<artifactId>org.gvsig.ui</artifactId>
22
                        <scope>compile</scope>
23
		</dependency>
24
               <dependency>
25
                  <groupId>org.gvsig</groupId>
26
                  <artifactId>org.gvsig.raster.algorithm</artifactId>           
27
                  <scope>compile</scope>
28
              </dependency>
29
               <dependency>
30
                  <groupId>org.gvsig</groupId>
31
                  <artifactId>org.gvsig.raster.swing.api</artifactId>           
32
                  <scope>compile</scope>
33
              </dependency>
34
               <dependency>
35
                  <groupId>org.gvsig</groupId>
36
                  <artifactId>org.gvsig.raster.swing.impl</artifactId>           
37
                  <scope>runtime</scope>
38
              </dependency>
39
              <dependency>
40
			      <groupId>org.gvsig</groupId>
41
			      <artifactId>org.gvsig.raster.principalcomponents.algorithm</artifactId>
42
			      <scope>compile</scope>
43
		      </dependency>
44
	</dependencies>
45
	<modules>
46
		<module>org.gvsig.raster.principalcomponents.swing.api</module>
47
		<module>org.gvsig.raster.principalcomponents.swing.impl</module>
48
	</modules>
49
</project>
50

  
0 51

  
org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.64/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.impl/src/main/resources-plugin/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
0 8

  
org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.64/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.impl/src/main/resources-plugin/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
0 8

  
org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.64/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.64/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.64/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.64/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.impl/src/main/java/org/gvsig/raster/principalcomponents/swing/impl/main/ComponentsTableModel.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 javax.swing.table.DefaultTableModel;
27

  
28
import org.gvsig.raster.swing.pagedtable.TableModel;
29
/**
30
 * Model for the list of components
31
 * 
32
 * @author Nacho Brodin (nachobrodin@gmail.com)
33
 */
34
public class ComponentsTableModel extends DefaultTableModel implements TableModel {
35
	final private static long serialVersionUID = -3370601314380922368L;
36
	private int               nColumns         = 0;
37

  
38
	public ComponentsTableModel(String[] columnNames) {
39
		super(new Object[0][columnNames.length], columnNames);
40
		this.nColumns = columnNames.length;
41
	}
42

  
43
	public Class<?> getColumnClass(int c) {
44
		return String.class;
45
	}
46

  
47
	public void setValueAt(Object value, int row, int col) {
48
		super.setValueAt(value, row, col);
49
	}
50

  
51
	public void addNew() {
52
		Object[] line = new Object[nColumns];
53
		line[0] = new Boolean(true);
54
		for (int i = 0; i < nColumns; i++)
55
			line[i] = new String("");
56
		super.addRow(line);
57
	}
58

  
59
	public Object[] getNewLine() {
60
		Object[] o = new Object[nColumns];
61
		o[0] = new Boolean(true);
62
		for (int i = 1; i < nColumns; i++)
63
			o[i] = "";
64
		return o;
65
	}
66

  
67
	public void addNewLine() {
68
		// TODO Auto-generated method stub
69
		
70
	}
71
}
0 72

  
org.gvsig.raster.principalcomponents/tags/org.gvsig.raster.principalcomponents-2.2.64/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.64/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

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff