Revision 2101

View differences:

org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/tool/layerdatatype/LayerDatatypeTocMenuEntry.java
34 34
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
35 35
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel;
36 36
import org.gvsig.i18n.Messages;
37
import org.gvsig.raster.algorithm.BaseAlgorithmPanel;
38
import org.gvsig.raster.algorithm.process.ProcessException;
37
import org.gvsig.raster.algorithm.BasicAPISwingPanel;
39 38
import org.gvsig.raster.algorithm.process.DataProcess;
40 39
import org.gvsig.raster.fmap.layers.FLyrRaster;
41 40
import org.gvsig.raster.fmap.layers.ILayerState;
......
54 53
	implements IGenericToolBarMenuItem, ActionListener {
55 54
	static private LayerDatatypeTocMenuEntry       singleton              = null;
56 55
	private MainWindow                             window                 = null;
57
	private BaseAlgorithmPanel                     panel                  = null;
56
	private BasicAPISwingPanel                     panel                  = null;
58 57
	private FLyrRaster                             inputLayer             = null;
59 58
	
60 59
	/**
......
160 159
				e.getSource() == ((DefaultButtonsPanel)window).getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT)) {
161 160
			DataProcess task = null;
162 161
			try {
163
				task = panel.getProcess();
164
			} catch (ProcessException e1) {
162
				task = (DataProcess)panel.getResult();
163
			} catch (Exception e1) {
165 164
				Messages.getText("error_getting_process");
166 165
			}
167 166
			task.setActions(new ProcessEndActions(window, inputLayer));
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.swing/org.gvsig.raster.tools.algorithm.swing.api/src/main/java/org/gvsig/raster/tools/algorithm/swing/AlgorithmSwingManager.java
21 21
 */
22 22
package org.gvsig.raster.tools.algorithm.swing;
23 23

  
24
import org.gvsig.raster.algorithm.BaseAlgorithmPanel;
24
import org.gvsig.raster.algorithm.BasicAPISwingPanel;
25 25
import org.gvsig.raster.swing.RasterWindowManager;
26 26
import org.gvsig.raster.swing.newlayer.FileNameManagement;
27 27
import org.gvsig.raster.tools.algorithm.swing.maskthreshold.MaskThresholdPanel;
......
64 64
     */
65 65
    public MaskThresholdPanel createMaskThresholdPanel();
66 66
    
67
    public BaseAlgorithmPanel createLayerDatatypePanel(Object inputStore, String inputDatatype, String layerName);
67
    public BasicAPISwingPanel createLayerDatatypePanel(Object inputStore, String inputDatatype, String layerName);
68 68

  
69 69
    /**
70 70
     * Creates the panel for the tool save raster
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.swing/org.gvsig.raster.tools.algorithm.swing.impl/src/main/java/org/gvsig/raster/tools/algorithm/swing/impl/DefaultAlgorithmSwingManager.java
21 21
 */
22 22
package org.gvsig.raster.tools.algorithm.swing.impl;
23 23

  
24
import org.gvsig.raster.algorithm.BaseAlgorithmPanel;
24
import org.gvsig.raster.algorithm.BasicAPISwingPanel;
25 25
import org.gvsig.raster.swing.newlayer.FileNameManagement;
26 26
import org.gvsig.raster.tools.algorithm.swing.AlgorithmSwingManager;
27 27
import org.gvsig.raster.tools.algorithm.swing.impl.layerdatatype.LayerDatatypePanelImpl;
......
93 93
		return new MaskThresholdPanelImpl();
94 94
	}
95 95

  
96
	public BaseAlgorithmPanel createLayerDatatypePanel(Object inputStore, String inputDatatype, String layerName) {
96
	public BasicAPISwingPanel createLayerDatatypePanel(Object inputStore, String inputDatatype, String layerName) {
97 97
		return new LayerDatatypePanelImpl(inputStore, inputDatatype, layerName);
98 98
	}
99 99
	
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.swing/org.gvsig.raster.tools.algorithm.swing.impl/src/main/java/org/gvsig/raster/tools/algorithm/swing/impl/layerdatatype/LayerDatatypePanelImpl.java
24 24
import java.awt.GridBagConstraints;
25 25
import java.awt.GridBagLayout;
26 26
import java.io.File;
27
import java.util.EventListener;
27 28

  
28 29
import javax.swing.BorderFactory;
29 30
import javax.swing.JComboBox;
......
33 34

  
34 35
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
35 36
import org.gvsig.i18n.Messages;
36
import org.gvsig.raster.algorithm.BaseAlgorithmPanel;
37
import org.gvsig.raster.algorithm.BasicAPISwingPanel;
37 38
import org.gvsig.raster.algorithm.process.ProcessException;
38 39
import org.gvsig.raster.algorithm.process.DataProcess;
39 40
import org.gvsig.raster.swing.RasterSwingLocator;
......
43 44
/**
44 45
 * @author Nacho Brodin (nachobrodin@gmail.com)
45 46
 */
46
public class LayerDatatypePanelImpl extends JPanel implements BaseAlgorithmPanel {
47
public class LayerDatatypePanelImpl extends JPanel implements BasicAPISwingPanel {
47 48
	private static final long               serialVersionUID     = 1L;
48 49
	private JComboBox                       comboOutput          = null;
49 50
	private JComboBox                       comboDec2Int         = null;
......
148 149
		return this;
149 150
	}
150 151

  
151
	public DataProcess getProcess() throws ProcessException {
152
	public DataProcess getResult() throws ProcessException {
152 153
		DataProcess task = new LayerDatatypeProcess();
153 154
		task.addParam(LayerDatatypeProcess.RASTER_STORE1, inputStore);
154 155
		String filename = newLayerPanel.getDirectorySelected() + File.separator + newLayerPanel.getFileSelected();
......
220 221
		
221 222
	}
222 223

  
224
	public int getComponentIDByObject(Object obj) {
225
		return -1;
226
	}
227

  
228
	public void addListener(EventListener listener) {
229
	}
223 230
}
org.gvsig.raster.tools/trunk/templates/rasterTaskProjectTemplate/build.xml
29 29
  <property name="testdir" value="/src/test/java/org/gvsig/raster/${project}"/>
30 30
  <property name="resourcesplugindir" value="/src/main/resources-plugin"/>
31 31
  <property name="resourcesdir" value="/src/main/resources"/>
32
  <property name="traslationdir" value="${resourcesplugindir}/org/gvsig/raster/${project}"/>
32
  <property name="traslationappdir" value="${resourcesplugindir}/org/gvsig/raster/${project}"/>
33
  <property name="traslationlibdir" value="${resourcesdir}/org/gvsig/raster/${project}"/>
33 34
  <property name="metainfdir" value="${resourcesdir}/META-INF/services"/>
34 35
  <property name="imagesactiondir" value="${resourcesplugindir}/images/action"/>
35 36
  <property name="imagescursordir" value="${resourcesplugindir}/images/cursor"/>
......
51 52
  <property name="swingimpl-metainfdir" value="${base}.swing/${dirplugin}.swing.impl${metainfdir}"/>
52 53
  <property name="sextante-metainfdir" value="${base}.sextante${metainfdir}"/>
53 54
	
54
  <property name="algorithm-translationdir" value="${base}.algorithm${traslationdir}/algorithm/i18n"/>
55
  <property name="app-translationdir" value="${base}.app/${dirplugin}.app.client${traslationdir}/app/i18n"/>
56
  <property name="lib-translationdir" value="${base}.lib/${dirplugin}.lib.impl${traslationdir}/lib/impl/i18n"/>
57
  <property name="swing-translationdir" value="${base}.swing/${dirplugin}.swing.impl${traslationdir}/swing/impl/i18n"/>
58
  <property name="sextante-translationdir" value="${base}.sextante${traslationdir}/sextante/i18n"/>
55
  <property name="algorithm-translationdir" value="${base}.algorithm${traslationlibdir}/algorithm/i18n"/>
56
  <property name="app-translationdir" value="${base}.app/${dirplugin}.app.client${traslationappdir}/app/i18n"/>
57
  <property name="lib-translationdir" value="${base}.lib/${dirplugin}.lib.impl${traslationlibdir}/lib/impl/i18n"/>
58
  <property name="swing-translationdir" value="${base}.swing/${dirplugin}.swing.impl${traslationlibdir}/swing/impl/i18n"/>
59
  <property name="sextante-translationdir" value="${base}.sextante${traslationlibdir}/sextante/i18n"/>
59 60
	
60 61
  <taskdef resource="net/sf/antcontrib/antlib.xml">
61 62
  	<classpath>
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.fmap/src/main/java/org/gvsig/raster/fmap/roi/VectorialROIsReader.java
52 52
	private HashMap<String, ROI>   rois         = null;
53 53
	private Grid                   grid         = null;
54 54
	private Envelope               bbox         = null;
55
	private FeatureStore           featureStore = null; 
55
	private FeatureStore[]         featureStore = null; 
56 56

  
57 57

  
58 58
	public VectorialROIsReader(
......
64 64
		this.bbox = bbox;
65 65
		File file = new File(filename);
66 66
		if(file.exists()) {
67
			DataManager datamanager = DALLocator.getDataManager();
68
			SHPStoreParameters params = null;
69
			try {
70
				params = (SHPStoreParameters)datamanager.createStoreParameters(SHPStoreProvider.NAME);
71
				params.setCRS(projection);
72
			} catch (InitializeException e) {
73
				throw new InvalidROIsShpException(e.getMessage(), e);
74
			} catch (ProviderNotRegisteredException e) {
75
				throw new InvalidROIsShpException(e.getMessage(), e);
67
			this.featureStore = new FeatureStore[1];
68
			this.featureStore[0] = openOneROIFile(file, projection);
69
		} else { 
70
			file = new File(filename + ".shp"); 
71
			if(file.exists()) {
72
				this.featureStore = new FeatureStore[1];
73
				this.featureStore[0] = openOneROIFile(file, projection);
74
			} else {
75
				this.featureStore = openThreeROIFiles(filename, projection);
76 76
			}
77
			params.setFile(file);
78
			DataManager dataManager = DALLocator.getDataManager();
79
			try {
80
				featureStore = (FeatureStore)dataManager.openStore(params.getDataStoreName(), params);
81
			} catch (ValidateDataParametersException e) {
82
				throw new InvalidROIsShpException(e.getMessage(), e);
83
			} catch (InitializeException e) {
84
				throw new InvalidROIsShpException(e.getMessage(), e);
85
			} catch (ProviderNotRegisteredException e) {
86
				throw new InvalidROIsShpException(e.getMessage(), e);
87
			}
88
			//FLyrVect fLyrVect = (FLyrVect)LayerFactory.getInstance().createLayer("layer1", params);
89
			//featureStore = fLyrVect.getFeatureStore();
90
		} else
77
		}
78
		
79
	}
80
	
81
	private FeatureStore[] openThreeROIFiles(String filename, IProjection projection) throws InvalidROIsShpException, FileNotExistsException {
82
		FeatureStore[] featureStore = new FeatureStore[3];
83
		File file = new File(filename + "_polygons.shp");
84
		boolean existsAtLeastOne = false;
85
		if(file.exists()) {
86
			featureStore[0] = openOneROIFile(file, projection);
87
			existsAtLeastOne = true;
88
		}
89
		
90
		file = new File(filename + "_points.shp");
91
		if(file.exists()) {
92
			featureStore[1] = openOneROIFile(file, projection);
93
			existsAtLeastOne = true;
94
		}
95
		
96
		file = new File(filename + "_polylines.shp");
97
		if(file.exists()) {
98
			featureStore[2] = openOneROIFile(file, projection);
99
			existsAtLeastOne = true;
100
		}
101
		
102
		if(!existsAtLeastOne)
91 103
			throw new FileNotExistsException("file not found");
104
		return featureStore;
92 105
	}
93 106
	
107
	private FeatureStore openOneROIFile(File file, IProjection projection) throws InvalidROIsShpException {
108
		DataManager datamanager = DALLocator.getDataManager();
109
		SHPStoreParameters params = null;
110
		try {
111
			params = (SHPStoreParameters)datamanager.createStoreParameters(SHPStoreProvider.NAME);
112
			params.setCRS(projection);
113
		} catch (InitializeException e) {
114
			throw new InvalidROIsShpException(e.getMessage(), e);
115
		} catch (ProviderNotRegisteredException e) {
116
			throw new InvalidROIsShpException(e.getMessage(), e);
117
		}
118
		params.setFile(file);
119
		DataManager dataManager = DALLocator.getDataManager();
120
		try {
121
			return (FeatureStore)dataManager.openStore(params.getDataStoreName(), params);
122
		} catch (ValidateDataParametersException e) {
123
			throw new InvalidROIsShpException(e.getMessage(), e);
124
		} catch (InitializeException e) {
125
			throw new InvalidROIsShpException(e.getMessage(), e);
126
		} catch (ProviderNotRegisteredException e) {
127
			throw new InvalidROIsShpException(e.getMessage(), e);
128
		}
129
	}
130
	
94 131
	public VectorialROIsReader(
95 132
			FeatureStore featureStore, 
96 133
			Grid grid, 
......
98 135
			Envelope bbox) {
99 136
		this.grid = grid;
100 137
		this.bbox = bbox;
101
		this.featureStore = featureStore;
138
		this.featureStore = new FeatureStore[1];
139
		this.featureStore[0] = featureStore;
102 140
	}
141
	
142
	public List<ROI> read(List<ROI> existingROIs) throws InvalidROIsShpException, DataException {
143
		for (int i = 0; i < this.featureStore.length; i++) {
144
			existingROIs = read(existingROIs, this.featureStore[i]);
145
		}
146
		return existingROIs;
147
	}
103 148

  
104 149
	@SuppressWarnings("deprecation")
105
	public ArrayList<ROI> read(List<ROI> existingROIs) throws InvalidROIsShpException, DataException{
150
	public List<ROI> read(List<ROI> existingROIs, FeatureStore featureStore) throws InvalidROIsShpException, DataException {
106 151
		FeatureType featureType = featureStore.getDefaultFeatureType();
107 152
		long id = System.currentTimeMillis();
108 153

  
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/BaseAlgorithmPanel.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.algorithm;
23

  
24
import javax.swing.JComponent;
25

  
26
import org.gvsig.raster.algorithm.process.ProcessException;
27
import org.gvsig.raster.algorithm.process.DataProcess;
28

  
29
/**
30
 * Interface for panels which build an algorithm using the parameters selected
31
 * by the user
32
 * @author Nacho Brodin (nachobrodin@gmail.com)
33
 */
34
public interface BaseAlgorithmPanel {
35
	
36
	/**
37
	 * Gets the main component 
38
	 * @return
39
	 */
40
	public JComponent getComponent();
41
	
42
	/**
43
	 * Gets the process loaded with the data selected in the interface
44
	 * @return
45
	 */
46
	public DataProcess getProcess() throws ProcessException;
47
	
48
	/**
49
	 * Initialization actions.
50
	 */
51
	public void initialize();
52
}
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/BasicAPISwingPanel.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.algorithm;
23

  
24
import java.util.EventListener;
25

  
26
import javax.swing.JComponent;
27

  
28
/**
29
 * Interface for panels which build an algorithm using the parameters selected
30
 * by the user
31
 * @author Nacho Brodin (nachobrodin@gmail.com)
32
 */
33
public interface BasicAPISwingPanel {
34
	
35
	/**
36
	 * Gets the main component 
37
	 * @return
38
	 */
39
	public JComponent getComponent();
40
	
41
	/**
42
	 * Gets the process loaded with the data selected in the interface
43
	 * @return
44
	 */
45
	public Object getResult() throws Exception;
46
	
47
	/**
48
	 * Initialization actions.
49
	 */
50
	public void initialize();
51
	
52
	/**
53
	 * Gets the component ID using the object of this component. This is useful
54
	 * to know what button has been pressed in a panel. The IDs should be defined
55
	 * in the component API.
56
	 * @param obj
57
	 * @return
58
	 */
59
	public int getComponentIDByObject(Object obj);
60
	
61
	/**
62
	 * Adds a listener to the components of a panel. The EventListener could be
63
	 * any listener.
64
	 * @param listener
65
	 */
66
	public void addListener(EventListener listener);
67
}
0 68

  
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/process/DataProcess.java
60 60
	private long                time              = 0;
61 61
	private boolean             progressActive    = true;
62 62
	private IProcessActions     queueActions      = null;
63
	private Logger              logger            = LoggerFactory.getLogger(DataProcess.class.toString());
63
	protected Logger            logger            = LoggerFactory.getLogger(DataProcess.class.toString());
64 64
	private int                 percent           = 0;
65 65
	private String              processName       = null;
66 66
	
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/process/ProcessParamsManagement.java
41 41
 * @author Nacho Brodin nachobrodin@gmail.com
42 42
 */
43 43
public abstract class ProcessParamsManagement extends ProcessUtils implements IIncrementable, IncrementableListener, Runnable, Disposable {
44
	public static String                TIME                               = "Time";
45
	public static String                PROCESS                            = "Process";
46
	public static String                PROCESS_NAME                       = "ProcessName";
44
	public static String                TIME                               = "TIME";
45
	public static String                PROCESS                            = "PROCESS";
46
	public static String                PROCESS_NAME                       = "PROCESS_NAME";
47 47
	
48 48
	protected Hashtable<String, Object> taskParams                         = new Hashtable<String, Object>();
49 49
	public static final String          REGISTER_INPUT_PARAMETERS_LABEL    = "RasterProcessInputParam";
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/datastruct/ExtentImpl.java
129 129
        max = new Point2D.Double(ext.maxX(), ext.maxY());
130 130
    }
131 131
    
132
    /*
133
     * (non-Javadoc)
134
     * @see org.gvsig.fmap.dal.coverage.datastruct.Extent#encloseBoundinBoxes(org.gvsig.fmap.dal.coverage.datastruct.Extent)
135
     */
136 132
    public Extent encloseBoundinBoxes(Extent ext) {
137 133
    	Point2D pUl = new Point2D.Double(
138 134
    			Math.min(getULX(), ext.getULX()), 
......
143 139
    	return new ExtentImpl(pUl, pLr);
144 140
    }
145 141
    
146
    /*
147
     * (non-Javadoc)
148
     * @see org.gvsig.fmap.dal.coverage.datastruct.Extent#intersection(org.gvsig.fmap.dal.coverage.datastruct.Extent)
149
     */
150 142
    public Extent intersection(Extent ext) {
151 143
    	if(intersects(ext)) {
152 144
    		Point2D pUl = new Point2D.Double(
......
160 152
    	return null;
161 153
    }
162 154

  
163
    /*
164
     * (non-Javadoc)
165
     * @see org.gvsig.fmap.dal.coverage.datastruct.Extent#intersects(org.gvsig.fmap.dal.coverage.datastruct.Extent)
166
     */
167 155
    public boolean intersects(Extent ext) {
168 156
    	if (getMin().getX() > ext.getMax().getX()) 
169 157
    		return false;
......
176 164
    	return true;
177 165
    }
178 166

  
179
    /*ax
180
     * (non-Javadoc)
181
     * @see org.gvsig.fmap.dal.coverage.datastruct.Extent#getGridExtent(double)
182
     */
183 167
    public GridExtent getGridExtent(double cellSize) {
184 168
    	return new GridExtentImpl(this, cellSize);
185 169
    }
......
505 489
				rectDest.getMinY());
506 490
	}
507 491
    
508
	/*
509
	 * (non-Javadoc)
510
	 * @see org.gvsig.tools.persistence.Persistent#loadFromState(org.gvsig.tools.persistence.PersistentState)
511
	 */
512 492
	public void loadFromState(PersistentState state)
513 493
			throws PersistenceException {
514 494
		double ulx = state.getDouble("ulx");
......
538 518
    	}
539 519
	}
540 520

  
541
	/*
542
	 * (non-Javadoc)
543
	 * @see org.gvsig.tools.persistence.Persistent#saveToState(org.gvsig.tools.persistence.PersistentState)
544
	 */
545 521
	public void saveToState(PersistentState state) throws PersistenceException {
546 522
		state.set("ulx", getULX());
547 523
		state.set("uly", getULY());
......
576 552
		}
577 553
	}
578 554
	
579
	/*
580
	 * (non-Javadoc)
581
	 * @see java.lang.Object#finalize()
582
	 */
583 555
	protected void finalize() throws Throwable {
584 556
		min = null;
585 557
	    max = null;
org.gvsig.raster.principalcomponents/trunk/org.gvsig.raster.principalcomponents/org.gvsig.raster.principalcomponents.app/org.gvsig.raster.principalcomponents.app.client/src/main/java/org/gvsig/raster/principalcomponents/app/PrincipalComponentsExtension.java
177 177
			try {
178 178
				Object[] result = (Object[])componentsPanel.getResult();
179 179
				task = (DataProcess)result[0];
180
				task.setActions(this);
180
				task.setActions(new ProcessEndActions(windowComponentsPanel, lyr));
181 181
				task.init();
182 182
				task.start();
183 183
			} catch (Exception e1) {
......
188 188
	}
189 189

  
190 190
	public void end(Object param) {
191
		@SuppressWarnings("unchecked")
191 192
		HashMap<String, Object> params = (HashMap<String, Object>)param;
192 193
		String processName = (String)params.get(ProcessParamsManagement.PROCESS_NAME);
193 194
		
194 195
		//End the process to get statistics (accept main dialog)
195
		if (processName.equals(PrincipalComponentsAlgorithmLibrary.PCS_STATS_PROCESS_LABEL)) {
196
		if (processName.equals(PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL)) {
196 197
			PluginServices.getMDIManager().closeWindow(windowMainPanel);
197
			stats = (PCStatsDataStructure)params.get("PCStatsDataStructure");
198
			componentsPanel = PrincipalComponentsSwingLocator.getSwingManager().createPCAComponentsListPanel(lyr.getDataStore(), stats);
198
			stats = (PCStatsDataStructure)params.get("STATS_RESULT");
199
			String fileName = (String)params.get("PATH");
200
			boolean[] bands = (boolean[])params.get("BANDS");
201
			componentsPanel = PrincipalComponentsSwingLocator.getSwingManager().createPCAComponentsListPanel(lyr.getDataStore(), stats, fileName, bands);
199 202
			componentsPanel.addListener(this);
200 203
			windowComponentsPanel = new MainWindow(componentsPanel.getComponent(), 
201 204
    				Messages.getText("principal_components"), 
......
204 207
    		PluginServices.getMDIManager().addCentredWindow(windowComponentsPanel);
205 208
    		componentsPanel.initialize();
206 209
		}
207
		
208
		//End the process to get components (accept components dialog)
209
		if (processName.equals(PrincipalComponentsAlgorithmLibrary.PROCESS_LABEL)) {
210
			
211
		}
212 210
	}
213 211
	
214 212
	public void interrupted() {
org.gvsig.raster.principalcomponents/trunk/org.gvsig.raster.principalcomponents/org.gvsig.raster.principalcomponents.app/org.gvsig.raster.principalcomponents.app.client/src/main/java/org/gvsig/raster/principalcomponents/app/ProcessEndActions.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2011-2012 Prodevelop S.L
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., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 */
21
package org.gvsig.raster.principalcomponents.app;
22

  
23
import java.io.File;
24
import java.util.HashMap;
25

  
26
import org.gvsig.andami.PluginServices;
27
import org.gvsig.andami.ui.mdiManager.IWindow;
28
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
29
import org.gvsig.fmap.dal.DALLocator;
30
import org.gvsig.fmap.dal.DataManager;
31
import org.gvsig.fmap.dal.DataStore;
32
import org.gvsig.fmap.dal.coverage.RasterLocator;
33
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
34
import org.gvsig.fmap.dal.coverage.util.ProviderServices;
35
import org.gvsig.fmap.dal.exception.InitializeException;
36
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
37
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
38
import org.gvsig.fmap.mapcontext.MapContextLocator;
39
import org.gvsig.fmap.mapcontext.MapContextManager;
40
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
41
import org.gvsig.fmap.mapcontext.layers.FLayer;
42
import org.gvsig.fmap.mapcontext.layers.FLayers;
43
import org.gvsig.raster.algorithm.process.IProcessActions;
44
import org.gvsig.raster.algorithm.process.ProcessParamsManagement;
45
import org.gvsig.raster.principalcomponents.algorithm.PrincipalComponentsAlgorithmLibrary;
46
import org.gvsig.raster.tools.app.basic.RasterToolsUtil;
47
import org.gvsig.raster.tools.app.basic.raster.bean.endinfo.EndInfoDialog;
48
import org.gvsig.raster.util.RasterNotLoadException;
49

  
50
/**
51
 * Actions when the process finalizes or is interrupted
52
 * 
53
 * Nacho Brodin (nachobrodin@gmail.com)
54
 */
55
public class ProcessEndActions implements IProcessActions {
56
	private IWindow     window        = null;
57
	private FLayer      inputLyr      = null;
58

  
59
	/**
60
	 * Constructor
61
	 * @param window
62
	 * @param lyr
63
	 *        The input layer is only used to select the view where the new layer be loaded
64
	 */
65
	public ProcessEndActions(IWindow window, FLayer lyr) {
66
		this.window = window;
67
		this.inputLyr = lyr;
68
	}
69
	
70
	@SuppressWarnings("unchecked")
71
	public void end(Object param) {
72
		if(window != null) {
73
			PluginServices.getMDIManager().closeWindow(window);
74
			window = null;
75
		}
76
		
77
		HashMap<String, Object> params = (HashMap<String, Object>)param;
78
		String processName = (String)params.get(ProcessParamsManagement.PROCESS_NAME);
79
		
80
		//End the process to get statistics (accept main dialog)
81
		if (processName.equals(PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL)) {
82
			String fileName = (String)params.get("FILENAME");
83
			long milis = (Long)params.get("TIME");
84
			processFinalize(fileName, milis);
85
			EndInfoDialog.show(fileName, milis);
86
		}
87
	}
88
	
89
	/**
90
	 * Acciones que se realizan al finalizar de crear los recortes de imagen.
91
	 * Este m?todo es llamado por el thread TailRasterProcess al finalizar.
92
	 */
93
	private void processFinalize(String fileName, long milis) {
94
		if (!new File(fileName).exists())
95
			return;
96

  
97
		if (RasterToolsUtil.messageBoxYesOrNot("cargar_toc", this)) {
98
			try {
99
				loadLayer(fileName, fileName.substring(fileName.lastIndexOf(File.separator) + 1));
100
			} catch (RasterNotLoadException e) {
101
				RasterToolsUtil.messageBoxError("error_load_layer", e);
102
			}
103
		}
104
	}
105
	
106
	/**
107
	 * Gets the view 
108
	 * @return
109
	 */
110
	private AbstractViewPanel getView() {
111
		IWindow[] w = PluginServices.getMDIManager().getAllWindows();
112
		for (int i = 0; i < w.length; i++) {
113
			if(w[i] instanceof AbstractViewPanel) {
114
				FLayers lyrs = ((AbstractViewPanel)w[i]).getMapControl().getMapContext().getLayers();
115
				for (int j = 0; j < lyrs.getLayersCount(); j++) {
116
					FLayer lyr = lyrs.getLayer(j);
117
					if(inputLyr == lyr) {
118
						return ((AbstractViewPanel) w[i]);
119
					}
120
				}
121
			}
122
		}
123
		return null;
124
	}
125
	
126
	@SuppressWarnings("deprecation")
127
	private void loadLayer(String fileName, String layerName) throws RasterNotLoadException {
128
		if(fileName ==  null)
129
			return;
130

  
131
		//Seleccionamos la vista de gvSIG
132
		AbstractViewPanel theView = getView();
133

  
134
		theView.getMapControl().getMapContext().beginAtomicEvent();
135

  
136
		try {
137
			DataManager dataManager = DALLocator.getDataManager();
138
			
139
			ProviderServices provServ = RasterLocator.getManager().getProviderServices();
140
			RasterDataParameters storeParameters = provServ.createParameters(fileName);
141
			storeParameters.setURI(fileName);
142
			
143
			MapContextManager mcm = MapContextLocator.getMapContextManager();
144
			
145
			DataStore dataStore = null;
146
			try {
147
				dataStore = dataManager.createStore(storeParameters);
148
			} catch (ValidateDataParametersException e) {
149
				throw new RasterNotLoadException("Error al cargar la capa.");
150
			} catch (InitializeException e) {
151
				throw new RasterNotLoadException("Error al cargar la capa.");
152
			} catch (ProviderNotRegisteredException e) {
153
				throw new RasterNotLoadException("Error al cargar la capa.");
154
			}
155
			
156
			if(layerName == null) {
157
				int endIndex = fileName.lastIndexOf(".");
158
				if (endIndex < 0)
159
					endIndex = fileName.length();
160
				
161
				layerName = fileName.substring(fileName.lastIndexOf(File.separator) + 1, endIndex);
162
			}
163
			
164
			FLayer lyr = mcm.createLayer(layerName, dataStore);
165
			theView.getMapControl().getMapContext().getLayers().addLayer(lyr);
166

  
167
		} catch (LoadLayerException e) {
168
			throw new RasterNotLoadException("Error al cargar la capa.");
169
		} 
170
		theView.getMapControl().getMapContext().invalidate();
171
		theView.getMapControl().getMapContext().endAtomicEvent();
172
	}
173
	
174
	public void interrupted() {
175

  
176
    }
177
}
0 178

  
org.gvsig.raster.principalcomponents/trunk/org.gvsig.raster.principalcomponents/org.gvsig.raster.principalcomponents.algorithm/pom.xml
42 42
        </dependency>
43 43
        <dependency>
44 44
            <groupId>org.gvsig</groupId>
45
            <artifactId>org.gvsig.raster.fmap</artifactId>
46
            <scope>compile</scope>
47
        </dependency>
48
        <dependency>
49
            <groupId>org.gvsig</groupId>
45 50
            <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
46 51
            <scope>compile</scope>
47 52
        </dependency>
org.gvsig.raster.principalcomponents/trunk/org.gvsig.raster.principalcomponents/org.gvsig.raster.principalcomponents.algorithm/src/main/java/org/gvsig/raster/principalcomponents/algorithm/PCAStatisticsProcess.java
72 72
public class PCAStatisticsProcess extends DataProcess {
73 73
    public static final String 	 LAYER_ZONA_ESTUDIO 			= "LAYER_ZONA_ESTUDIO";
74 74
    public static String         BANDS 							= "BANDS";
75
    public static String         PATH 							= "PATH";
75 76
    
76
	public static String         RASTER_STORE_LIST              = "RasterStoreList";
77
	public static String         STATS_RESULT                   = "PCStatsDataStructure";
77
	public static String         RASTER_STORE_LIST              = "RASTER_STORE_LIST";
78
	public static String         STATS_RESULT                   = "STATS_RESULT";
78 79
	
79 80
	
80 81
    private VectorialROI 		 vectROI 						= null;
......
92 93
	private static Logger 		 logger    		   				= LoggerFactory.getLogger(PCAStatisticsProcess.class.getName());
93 94
    private double[][] 			 maxminmean						= null;
94 95
    private	Extent 				 extentResult					= null; 
96
    private String               path                           = null;
95 97
	 
96 98
	public static void registerParameters() {
97
		registerInputParameter(RASTER_STORE_LIST, RasterDataStore[].class, PrincipalComponentsAlgorithmLibrary.PCS_STATS_PROCESS_LABEL);
98
		registerInputParameter(BANDS, Boolean[].class, PrincipalComponentsAlgorithmLibrary.PCS_STATS_PROCESS_LABEL);
99
		registerInputParameter(RASTER_STORE_LIST, RasterDataStore[].class, PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL);
100
		registerInputParameter(BANDS, Boolean[].class, PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL);
101
		registerInputParameter(PATH, String.class, PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL);
99 102
		
100
		registerOutputParameter(STATS_RESULT, PCStatsDataStructure.class, PrincipalComponentsAlgorithmLibrary.PCS_STATS_PROCESS_LABEL);
103
		registerOutputParameter(STATS_RESULT, PCStatsDataStructure.class, PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL);
104
		registerOutputParameter(PATH, String.class, PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL);
105
		registerOutputParameter(BANDS, Boolean[].class, PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL);
101 106
	}
102 107
	
103 108
	@Override
104 109
	public void init() {
105 110
		storeList = (RasterDataStore[])getParam(RASTER_STORE_LIST);
106 111
		bands = (boolean[])getParam(BANDS);
112
		path = getStringParam(PATH);
107 113
	}
108 114
	
109 115
	public double[] getAutoValors() {
......
337 343
		
338 344
		//Object[] dataROI = new Object[]{vectROI, (int)shift[0].getX(), (int)shift[0].getY()};	
339 345
		addOutputValue(STATS_RESULT, resultStatistics);
346
		addOutputValue(PATH, path);
347
		addOutputValue(BANDS, bands);
340 348
		try {
341 349
			store.close();
342 350
		} catch (CloseException e) {
org.gvsig.raster.principalcomponents/trunk/org.gvsig.raster.principalcomponents/org.gvsig.raster.principalcomponents.algorithm/src/main/java/org/gvsig/raster/principalcomponents/algorithm/PrincipalComponentsAlgorithmLibrary.java
9 9
 * Initialization of PrincipalComponentsAlgorithmLibrary library.
10 10
 */
11 11
public class PrincipalComponentsAlgorithmLibrary extends AbstractLibrary {
12
	public static final String         PROCESS_LABEL             = "PrincipalComponentsProcess";
13
	public static final String         PCS_STATS_PROCESS_LABEL   = "StatsPrincipalComponentsProcess";
12
	public static final String         PC_PROCESS_LABEL         = "PrincipalComponentsProcess";
13
	public static final String         PC_STATS_PROCESS_LABEL   = "StatsPrincipalComponentsProcess";
14 14
	
15 15
    @Override
16 16
    protected void doInitialize() throws LibraryException {
......
20 20
    @Override
21 21
    protected void doPostInitialize() throws LibraryException {
22 22
    	//Registers the process and its parameters
23
    	RasterBaseAlgorithmLibrary.register(PCS_STATS_PROCESS_LABEL, PCAStatisticsProcess.class);
23
    	RasterBaseAlgorithmLibrary.register(PC_STATS_PROCESS_LABEL, PCAStatisticsProcess.class);
24 24
    	PCAStatisticsProcess.registerParameters();
25
    	RasterBaseAlgorithmLibrary.register(PROCESS_LABEL, PrincipalComponentsProcess.class);
25
    	RasterBaseAlgorithmLibrary.register(PC_PROCESS_LABEL, PrincipalComponentsProcess.class);
26 26
    	PrincipalComponentsProcess.registerParameters();
27 27
    	
28 28
        Messages.addResourceFamily(
org.gvsig.raster.principalcomponents/trunk/org.gvsig.raster.principalcomponents/org.gvsig.raster.principalcomponents.algorithm/src/main/java/org/gvsig/raster/principalcomponents/algorithm/PrincipalComponentsProcess.java
28 28
 * @author Nacho Brodin (nachobrodin@gmail.com)
29 29
 */
30 30
public class PrincipalComponentsProcess extends DataProcess {
31
	public static String         RASTER_STORE        = "RasterStore";
32
	public static String         PATH                = "Path";
33
	public static String         FILENAME            = "FileName";
31
	public static String          RASTER_STORE       = "RASTER_STORE";
32
	public static String          PATH               = "PATH";
33
	public static String          FILENAME           = "FILENAME";
34 34
	
35 35
	public static final String    BUFFERS            = "BUFFERS";
36 36
	public static final String    SELECTEDPCS        = "SELECTEDPCS";
......
38 38
	public static final String    DATAROI            = "DATAROI";
39 39
	public static final String    EXTENT             = "EXTENT";
40 40
	public static final String    GRAPHIC_DATA       = "GRAPHIC_DATA";
41
	public static final String    BANDS              = "BANDS";
41 42
	
42 43
	private RasterDataStore       store              = null;
43 44
	private String                filename           = null;
......
46 47
	private VectorialROI[]        dataROI            = null;
47 48
	private Extent                extentResult       = null;
48 49
	private boolean[]             selectedPCs        = null;
50
	private boolean[]             bands              = null;
49 51
	private int[]                 selectedBands      = null;
50 52
	private NoData                nodata             = null;
51 53
	
52 54
	
53 55
	public static void registerParameters() {
54
		registerInputParameter(RASTER_STORE, RasterDataStore.class, PrincipalComponentsAlgorithmLibrary.PROCESS_LABEL);
55
		registerInputParameter(PCSTATISTICS, PCStatsDataStructure.class, PrincipalComponentsAlgorithmLibrary.PROCESS_LABEL);
56
		registerInputParameter(PATH, String.class, PrincipalComponentsAlgorithmLibrary.PROCESS_LABEL);
57
		registerInputParameter(DATAROI, VectorialROI[].class, PrincipalComponentsAlgorithmLibrary.PROCESS_LABEL);
58
		registerOutputParameter(FILENAME, String.class, PrincipalComponentsAlgorithmLibrary.PROCESS_LABEL);
59
		registerOutputParameter(GRAPHIC_DATA, Double[].class, PrincipalComponentsAlgorithmLibrary.PROCESS_LABEL);
56
		registerInputParameter(RASTER_STORE, RasterDataStore.class, PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL);
57
		registerInputParameter(PCSTATISTICS, PCStatsDataStructure.class, PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL);
58
		registerInputParameter(PATH, String.class, PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL);
59
		registerInputParameter(DATAROI, VectorialROI[].class, PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL);
60
		registerInputParameter(SELECTEDPCS, Boolean[].class, PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL);
61
		registerInputParameter(BANDS, Boolean[].class, PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL);
62
		
63
		registerOutputParameter(FILENAME, String.class, PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL);
64
		registerOutputParameter(GRAPHIC_DATA, Double[].class, PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL);
60 65
	}
61 66
	
62 67
	public void init() {
63 68
		store = getParam(RASTER_STORE) != null ? (RasterDataStore)getParam(RASTER_STORE) : null;
64 69
		filename = getStringParam(PATH);
65 70
		selectedPCs = (boolean[]) getParam(SELECTEDPCS);
71
		bands = (boolean[]) getParam(BANDS);
66 72
		pcStatistics = (PCStatsDataStructure) getParam(PCSTATISTICS);
67
		dataROI = (VectorialROI[]) getParam(DATAROI);
73
		dataROI = getParam(DATAROI) != null ? (VectorialROI[]) getParam(DATAROI) :  null;
68 74
	}
69 75
	
70 76
	/**
......
100 106
	}
101 107

  
102 108
	public void process() throws ProcessInterruptedException, ProcessException {
103
		insertLineLog(Messages.getText("..."));
109
		insertLineLog(Messages.getText("processing_pc"));
104 110
		try {
105 111
			if (store == null)
106 112
				throw new PrincipalComponentsException(Messages.getText("need_a_input"));
......
122 128
			int bandCount = getNumberOfSelectedBands(selectedPCs);
123 129
			
124 130
			Buffer outputBuffer = createOutputBuffer(sourcePxBBox, bandCount);
125
			Buffer sourceBuffer = createSourceBuffer(sourcePxBBox, selectedPCs);
131
			Buffer sourceBuffer = createSourceBuffer(sourcePxBBox, bands);
126 132
			
127 133
			// Matriz Autovectores
128 134
			// Colocamos la matriz en el orden correcto:
......
154 160
						}
155 161
					}
156 162
				}
157
				updatePercent((int)(i * 100 / store.getHeight()), 100);
163
				updatePercent((int)(i * 100 / sourcePxBBox.getHeight()), 100);
158 164
			}
159 165
			
160 166
			super.exportRaster(filename, 
......
194 200
	 * @param bandsPCs
195 201
	 * @return
196 202
	 */
197
	private int getNumberOfSelectedBands(boolean[] bandsPCs) {
203
	private int getNumberOfSelectedBands(boolean[] b) {
198 204
		int bandCount = 0;
199
        for (int i = 0; i < bandsPCs.length; i++) {
200
			if(bandsPCs[i])
205
        for (int i = 0; i < b.length; i++) {
206
			if(b[i])
201 207
				bandCount++;
202 208
		}
203 209
        return bandCount;
......
250 256
	/**
251 257
	 * Gets a buffer of a raster 
252 258
     */
253
    private Buffer createSourceBuffer(Rectangle2D sourcePxBBox, boolean[] bandsPCs) throws PrincipalComponentsException {
259
    private Buffer createSourceBuffer(Rectangle2D sourcePxBBox, boolean[] bands) throws PrincipalComponentsException {
254 260
        RasterManager rManager = RasterLocator.getManager();
255 261
        RasterQuery query = rManager.createQuery();
256 262
        query.setReadOnly(true);
257 263
        
258
        query.setAllDrawableBands();
264
        int nBands = getNumberOfSelectedBands(bands);
265
        int count = 0;
266
        int[] drawableBands = new int[nBands];
267
        for (int i = 0; i < bands.length; i++) {
268
			if(bands[i]) {
269
				drawableBands[count] = i;
270
				count ++;
271
			}
272
		}
273
        
274
        query.setDrawableBands(drawableBands);
259 275
        query.setAreaOfInterest(
260 276
        		(int)sourcePxBBox.getX(), 
261 277
        		(int)sourcePxBBox.getY(), 
org.gvsig.raster.principalcomponents/trunk/org.gvsig.raster.principalcomponents/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.api/src/main/java/org/gvsig/raster/principalcomponents/swing/PrincipalComponentsSwingManager.java
17 17
public interface PrincipalComponentsSwingManager {
18 18
	public BasicAPISwingPanel createPCAMainPanel(Object inputStore, String layerName, int bandList);
19 19
	
20
	public BasicAPISwingPanel createPCAComponentsListPanel(Object inputStore, PCStatsDataStructure stats);
20
	public BasicAPISwingPanel createPCAComponentsListPanel(Object inputStore, PCStatsDataStructure stats, String fileName, boolean[] bands);
21 21
	
22 22
	public JPanel createStatisticsPanel(PCStatsDataStructure pcStatistics, boolean bandStatistics, boolean covar, boolean autovect);
23 23
}
org.gvsig.raster.principalcomponents/trunk/org.gvsig.raster.principalcomponents/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.impl/src/main/resources/org/gvsig/raster/principalcomponents/swing/impl/i18n/text.properties
4 4
var_covar=Matriz varianza-covarianza
5 5
autovector=Autovector
6 6
generate=Generar
7
stats=Estadisticas
7
stats=Estadisticas
8
use_rois=Usar regiones de inter?s de la capa
org.gvsig.raster.principalcomponents/trunk/org.gvsig.raster.principalcomponents/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.impl/src/main/resources/org/gvsig/raster/principalcomponents/swing/impl/i18n/text_en.properties
4 4
var_covar=Matrix variance-covariance
5 5
autovector=Eigenvector
6 6
generate=Generate
7
stats=Statistics
7
stats=Statistics
8
use_rois=Use regions of interest of the layer
org.gvsig.raster.principalcomponents/trunk/org.gvsig.raster.principalcomponents/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.impl/src/main/java/org/gvsig/raster/principalcomponents/swing/impl/DefaultPrincipalComponentsSwingManager.java
31 31
		return new PCAMainPanelImpl(inputStore, layerName, bandList);
32 32
	}
33 33

  
34
	public BasicAPISwingPanel createPCAComponentsListPanel(Object inputStore, PCStatsDataStructure stats) {
35
		return new PCAComponentsListPanelImpl(inputStore, stats);
34
	public BasicAPISwingPanel createPCAComponentsListPanel(Object inputStore, PCStatsDataStructure stats, String fileName, boolean[] bands) {
35
		return new PCAComponentsListPanelImpl(inputStore, stats, fileName, bands);
36 36
	}
37 37
	
38 38
	public JPanel createStatisticsPanel(PCStatsDataStructure pcStatistics, boolean bandStatistics, boolean covar, boolean autovect) {
org.gvsig.raster.principalcomponents/trunk/org.gvsig.raster.principalcomponents/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.impl/src/main/java/org/gvsig/raster/principalcomponents/swing/impl/main/PCAComponentsListPanelImpl.java
61 61
	private JRadioButton                    autovectorRadioButton    = null;
62 62
	private JButton                         generateButton           = null;
63 63
	private PCStatsDataStructure            stats                    = null;
64
	private String                          fileName                 = null;
65
	private boolean[]                       bands                    = null;
64 66
	
65
	public PCAComponentsListPanelImpl(Object inputStore, PCStatsDataStructure stats) {
67
	public PCAComponentsListPanelImpl(Object inputStore, PCStatsDataStructure stats, String fileName, boolean[] bands) {
66 68
		this.inputStore = inputStore;
67 69
		this.stats = stats;
70
		this.fileName = fileName;
71
		this.bands = bands;
68 72
		init();
69 73
	}
70 74
	
......
190 194
	}
191 195

  
192 196
	public Object getResult() throws ProcessException {
193
		DataProcess task = RasterBaseAlgorithmLibrary.getManager().createRasterTask(PrincipalComponentsAlgorithmLibrary.PROCESS_LABEL);
194
		List<String> params = task.getRasterTaskInputParameters(PrincipalComponentsAlgorithmLibrary.PROCESS_LABEL);
197
		DataProcess task = RasterBaseAlgorithmLibrary.getManager().createRasterTask(PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL);
198
		List<String> params = task.getRasterTaskInputParameters(PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL);
195 199
		for (int i = 0; i < params.size(); i++) {
196 200
			String paramName = params.get(i);
197
			Class<?> paramType = task.getParameterTypeByProcess(PrincipalComponentsAlgorithmLibrary.PROCESS_LABEL, paramName);
198
			if(paramType == RasterDataStore[].class) {
199
				task.addParam(paramName, new RasterDataStore[]{(RasterDataStore)inputStore});
201
			Class<?> paramType = task.getParameterTypeByProcess(PrincipalComponentsAlgorithmLibrary.PC_PROCESS_LABEL, paramName);
202
			if(paramType == RasterDataStore.class) {
203
				task.addParam(paramName, (RasterDataStore)inputStore);
200 204
			}
201 205
			if(paramType == Boolean[].class) {
202
				boolean[] bands = new boolean[getPagedTable().getRowCount()];
206
				boolean[] components = new boolean[getPagedTable().getRowCount()];
203 207
				for (int j = 0; j < getPagedTable().getRowCount(); j++) {
204 208
					Object obj = getPagedTable().getValueAt(j, 0);
205 209
					if(obj instanceof Boolean)
206
						bands[j] = ((Boolean)obj).booleanValue();
210
						components[j] = ((Boolean)obj).booleanValue();
207 211
				}
208
				task.addParam(paramName, bands);
212
				task.addParam(paramName, components);
209 213
			}
214
			
215
			if(paramType == PCStatsDataStructure.class) {
216
				task.addParam(paramName, stats);
217
			}
218
			
219
			if(paramType == String.class) {
220
				task.addParam(paramName, fileName);
221
			}
210 222
		}
211 223
		return new Object[]{task, getByBandRadioButton().isSelected(), getVarCovarRadioButton().isSelected(), getAutovectorRadioButton().isSelected()};
212 224
	}
org.gvsig.raster.principalcomponents/trunk/org.gvsig.raster.principalcomponents/org.gvsig.raster.principalcomponents.swing/org.gvsig.raster.principalcomponents.swing.impl/src/main/java/org/gvsig/raster/principalcomponents/swing/impl/main/PCAMainPanelImpl.java
29 29
import java.util.List;
30 30

  
31 31
import javax.swing.BorderFactory;
32
import javax.swing.JCheckBox;
32 33
import javax.swing.JComponent;
33 34
import javax.swing.JLabel;
34 35
import javax.swing.JPanel;
......
55 56
	private CreateNewLayerPanel             newLayerPanel        = null;
56 57
	private Object                          inputStore           = null;
57 58
	private PagedTable                      table                = null;
59
	private JCheckBox                       roisCheck            = null;
58 60
	private int                             bandList             = 0;
59 61
	
60 62
	public PCAMainPanelImpl(Object inputStore, String layerName, int bandList) {
......
78 80
		gridBagConstraints1.gridy = 2;
79 81
		add((JComponent)getCreateNewLayerPanel(), gridBagConstraints1);
80 82
		
83
		gridBagConstraints1.gridy = 3;
84
		add(getROIsCheck(), gridBagConstraints1);
85
		
81 86
		gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
82 87
		gridBagConstraints1.gridy = 1;
83 88
		gridBagConstraints1.weighty = 1;
......
146 151
	}
147 152

  
148 153
	public DataProcess getResult() throws ProcessException {
149
		DataProcess task = RasterBaseAlgorithmLibrary.getManager().createRasterTask(PrincipalComponentsAlgorithmLibrary.PCS_STATS_PROCESS_LABEL);
150
		List<String> params = task.getRasterTaskInputParameters(PrincipalComponentsAlgorithmLibrary.PCS_STATS_PROCESS_LABEL);
154
		DataProcess task = RasterBaseAlgorithmLibrary.getManager().createRasterTask(PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL);
155
		List<String> params = task.getRasterTaskInputParameters(PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL);
151 156
		for (int i = 0; i < params.size(); i++) {
152 157
			String paramName = params.get(i);
153
			Class<?> paramType = task.getParameterTypeByProcess(PrincipalComponentsAlgorithmLibrary.PCS_STATS_PROCESS_LABEL, paramName);
158
			Class<?> paramType = task.getParameterTypeByProcess(PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL, paramName);
154 159
			if(paramType == RasterDataStore[].class) {
155 160
				task.addParam(paramName, new RasterDataStore[]{(RasterDataStore)inputStore});
156 161
			}
......
172 177
		}
173 178
		return task;
174 179
	}
180
	
181
	public JCheckBox getROIsCheck() {
182
		if(roisCheck == null) {
183
			roisCheck = new JCheckBox(Messages.getText("use_rois"));
184
		}
185
		return roisCheck;
186
	}
175 187

  
176 188
	public CreateNewLayerPanel getCreateNewLayerPanel() {
177 189
		if(newLayerPanel == null) {

Also available in: Unified diff