Revision 2405

View differences:

org.gvsig.raster.tasseledcap/tags/gvSIGv2_1_0_Build_2218/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
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
	<modelVersion>4.0.0</modelVersion>
4
	<artifactId>org.gvsig.raster.tasseledcap</artifactId>
5
	<packaging>pom</packaging>
6
	<version>2.2.0-SNAPSHOT</version>
7
	<name>org.gvsig.raster.tasseledcap</name>
8
	<description></description>
9
	<inceptionYear>2011</inceptionYear>
10
	<parent>
11
      <groupId>org.gvsig</groupId>
12
      <artifactId>org.gvsig.desktop</artifactId>
13
      <version>2.0.22</version>
14
    </parent>
15
    <scm>
16
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.tasseledcap/trunk/org.gvsig.raster.tasseledcap</connection>
17
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.tasseledcap/trunk/org.gvsig.raster.tasseledcap</developerConnection>
18
        <url>https://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster.tasseledcap/trunk/org.gvsig.raster.tasseledcap</url>
19
    </scm>
20
    <build>
21
        <plugins>
22
            <plugin>
23
                <groupId>org.apache.maven.plugins</groupId>
24
                <artifactId>maven-release-plugin</artifactId>
25
                <configuration>
26
                    <tagBase>https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.tasseledcap/tags/</tagBase>
27
                    <goals>deploy</goals>
28
                </configuration>
29
            </plugin>
30
        </plugins>
31
    </build>
32
    		
33
	<dependencyManagement>
34
		<dependencies>
35
			<dependency>
36
				<groupId>org.gvsig</groupId>
37
				<artifactId>org.gvsig.raster.mainplugin</artifactId>
38
				<version>2.2.0-SNAPSHOT</version>
39
			</dependency>
40
			<dependency>
41
				<groupId>org.gvsig.legacy</groupId>
42
				<artifactId>jama</artifactId>
43
				<version>1.0.3</version>
44
			</dependency>
45
			<dependency>
46
				<groupId>org.gvsig</groupId>
47
				<artifactId>org.gvsig.raster.tasseledcap.lib.api</artifactId>
48
				<version>2.2.0-SNAPSHOT</version>
49
			</dependency>
50
			<dependency>
51
				<groupId>org.gvsig</groupId>
52
				<artifactId>org.gvsig.raster.tasseledcap.lib.impl</artifactId>
53
				<version>2.2.0-SNAPSHOT</version>
54
			</dependency>
55
			<dependency>
56
				<groupId>org.gvsig</groupId>
57
				<artifactId>org.gvsig.raster.tasseledcap.swing.api</artifactId>
58
				<version>2.2.0-SNAPSHOT</version>
59
			</dependency>
60
			<dependency>
61
				<groupId>org.gvsig</groupId>
62
				<artifactId>org.gvsig.raster.tasseledcap.swing.impl</artifactId>
63
				<version>2.2.0-SNAPSHOT</version>
64
			</dependency>
65
			<dependency>
66
				<groupId>org.gvsig</groupId>
67
				<artifactId>org.gvsig.raster.tasseledcap.algorithm</artifactId>
68
				<version>2.2.0-SNAPSHOT</version>
69
			</dependency>
70
			<dependency>
71
            	<groupId>org.gvsig</groupId>
72
            	<artifactId>org.gvsig.raster.swing.api</artifactId>           
73
            	<version>2.2.0-SNAPSHOT</version>
74
        	</dependency> 
75
       		<dependency>
76
            	<groupId>org.gvsig</groupId>
77
            	<artifactId>org.gvsig.raster.swing.impl</artifactId>           
78
            	<version>2.2.0-SNAPSHOT</version>
79
        	</dependency>
80
			<dependency>
81
	            <groupId>org.gvsig</groupId>
82
	            <artifactId>org.gvsig.raster.lib.api</artifactId>
83
	            <version>2.2.0-SNAPSHOT</version>
84
	        </dependency>
85
	        <dependency>
86
	            <groupId>org.gvsig</groupId>
87
	            <artifactId>org.gvsig.raster.lib.impl</artifactId>
88
	            <version>2.2.0-SNAPSHOT</version>
89
	        </dependency>
90
			<dependency>
91
				<groupId>org.gvsig</groupId>
92
				<artifactId>org.gvsig.raster.fmap</artifactId>
93
				<version>2.2.0-SNAPSHOT</version>
94
			</dependency>
95
			<dependency>
96
				<groupId>org.gvsig</groupId>
97
				<artifactId>org.gvsig.raster.algorithm</artifactId>
98
				<version>2.2.0-SNAPSHOT</version>
99
			</dependency>
100
			<dependency>
101
		    	<groupId>org.gvsig</groupId>
102
   				<artifactId>org.gvsig.geoprocess.algorithm.base</artifactId>
103
            	<version>2.1.0-SNAPSHOT</version>
104
   			</dependency>
105
   			<dependency>
106
				<groupId>org.gvsig</groupId>
107
				<artifactId>org.gvsig.geoprocess.lib.sextante</artifactId>
108
				<version>2.1.0-SNAPSHOT</version>
109
			</dependency>
110
			<dependency>
111
				<groupId>org.gvsig</groupId>
112
				<artifactId>org.gvsig.geoprocess.app.mainplugin</artifactId>
113
				<version>2.1.0-SNAPSHOT</version>
114
			</dependency>
115
   			<dependency>
116
				<groupId>org.gvsig</groupId>
117
				<artifactId>org.gvsig.raster.tasseledcap.toolbox.algorithm</artifactId>
118
				<version>2.2.0-SNAPSHOT</version>
119
			</dependency>
120
		</dependencies>
121
	</dependencyManagement>
122
	<modules>
123
		<module>org.gvsig.raster.tasseledcap.algorithm</module>
124
		<module>org.gvsig.raster.tasseledcap.toolbox.algorithm</module>
125
		<module>org.gvsig.raster.tasseledcap.swing</module>
126
		<module>org.gvsig.raster.tasseledcap.app.tasseledcapclient</module>
127
	</modules>
128
</project>
0 129

  
org.gvsig.raster.tasseledcap/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.tasseledcap.algorithm/src/main/java/org/gvsig/raster/tasseledcap/algorithm/TasseledCapAlgorithmLibrary.java
1
package org.gvsig.raster.tasseledcap.algorithm;
2

  
3
import org.gvsig.i18n.Messages;
4
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary;
5
import org.gvsig.tools.library.AbstractLibrary;
6
import org.gvsig.tools.library.LibraryException;
7

  
8
/**
9
 * Initialization of PrincipalComponentsAlgorithmLibrary library.
10
 */
11
public class TasseledCapAlgorithmLibrary extends AbstractLibrary {
12
	public static final String         TASSELEDCAP_PROCESS_LABEL         = "TasseledCapProcess";
13
	
14
    @Override
15
    protected void doInitialize() throws LibraryException {
16
        // Nothing to do
17
    }
18

  
19
    @Override
20
    protected void doPostInitialize() throws LibraryException {
21
    	//Registers the process and its parameters
22
    	RasterBaseAlgorithmLibrary.register(TASSELEDCAP_PROCESS_LABEL, TasseledCapProcess.class);
23
    	TasseledCapProcess.registerParameters();
24
    	
25
        Messages.addResourceFamily(
26
            "org.gvsig.raster.tasseledcap.algorithm", 
27
            TasseledCapAlgorithmLibrary.class.getClassLoader(), 
28
            TasseledCapAlgorithmLibrary.class.getClass().getName());
29
        //registerGeoProcess(new RasterReprojectAlgorithmLibrary());
30
        
31
        Messages.addResourceFamily("org.gvsig.raster.tasseledcap.algorithm.i18n.text",
32
        		TasseledCapAlgorithmLibrary.class.getClassLoader(),
33
        		TasseledCapAlgorithmLibrary.class.getClass().getName()); 
34
    }
35
}
0 36

  
org.gvsig.raster.tasseledcap/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.tasseledcap.algorithm/src/main/java/org/gvsig/raster/tasseledcap/algorithm/TasseledCapException.java
1
package org.gvsig.raster.tasseledcap.algorithm;
2

  
3
import org.gvsig.raster.algorithm.process.ProcessException;
4

  
5

  
6
/**
7
 * This exception is thrown if happen problems processing data with this algorithm.
8
 */
9
public class TasseledCapException extends ProcessException {
10
	private static final long serialVersionUID = -3022090543908771484L;
11
	
12
	public TasseledCapException(String msg){
13
		super(msg);
14
	}
15
	
16
	public TasseledCapException(String msg, Throwable e){
17
		super(msg, e);
18
	}
19
}
0 20

  
org.gvsig.raster.tasseledcap/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.tasseledcap.algorithm/src/main/java/org/gvsig/raster/tasseledcap/algorithm/TasseledCapProcess.java
1
package org.gvsig.raster.tasseledcap.algorithm;
2

  
3
import java.awt.geom.Rectangle2D;
4
import java.util.List;
5

  
6
import org.gvsig.fmap.dal.coverage.RasterLocator;
7
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
8
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
9
import org.gvsig.fmap.dal.coverage.datastruct.NoData;
10
import org.gvsig.fmap.dal.coverage.exception.CloneException;
11
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
12
import org.gvsig.fmap.dal.coverage.exception.ROIException;
13
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
14
import org.gvsig.i18n.Messages;
15
import org.gvsig.raster.algorithm.process.DataProcess;
16
import org.gvsig.raster.algorithm.process.ProcessException;
17
import org.gvsig.raster.roi.ROI;
18

  
19
/**
20
 * Tasseled Cab Process 
21
 * @author Nacho Brodin (nachobrodin@gmail.com)
22
 */
23
public class TasseledCapProcess extends DataProcess {
24
	public static int             LANDSAT_MS         = 0;
25
	public static int             LANDSAT_TM         = 1;
26
	public static int             LANDSAT_ETM        = 2;
27
	
28
	public static String          RASTER_STORE       = "RASTER_STORE";
29
	public static String          PATH               = "PATH";
30
	public static String          FILENAME           = "FILENAME";
31
	public static String          LANDSAT_TYPE       = "LANDSAT_TYPE";
32
	
33
	public static final String    BUFFERS            = "BUFFERS";
34
	public static final String    GRAPHIC_DATA       = "GRAPHIC_DATA";
35
	public static final String    BANDS              = "BANDS";
36
	
37
	private RasterDataStore       store              = null;
38
	private String                filename           = null;
39
	
40
	private List<ROI>             rois               = null;
41
	private Extent                extentResult       = null;
42
	private boolean[]             bands              = null;
43
	private NoData                nodata             = null;
44
	private double                matrixParams[][]   = null;
45
	private int                   type               = LANDSAT_MS;
46
	
47
	// MATRICES DE COEFICIENTES PARA CADA TRANSFORMACI?N
48
	double LandSatMS[][] = {
49
			/*   Brillo de suelo       */ 	{0.433, 0.632, 0.586, 0.264   },
50
			/*	 Indice de Verdor      */	{-0.290, -0.562, 0.600, 0.491 },
51
			/*	 Indice de Senescencia */   {-0.829,  0.522, -0.039, 0.194},
52
			/*	 Cuarta                */	{0.223,  0.012,  -0.543, 0.810}		
53
	};
54

  
55
	double LandSatTM[][] = { 
56
			/*   Brillo    */ 	{0.33183,  0.33121,  0.55177,  0.42514,  0.48087, 0.25252  		},
57
			/*	 Verdor    */	{-0.24717,  -0.16263,  -0.40639,  0.85468,  0.05493,  -0.11749	},
58
			/*	 Tercera   */	{0.13929,  0.22490,  0.40359,  0.25178,  -0.70133, -0.45732  	},	
59
	};
60

  
61
	double LandSatETM[][] = {
62
			/*   Brightness */ 	{0.3561,  0.3972,  0.3904,  0.6966,  0.2286,  0.1596     },
63
			/*	 Greenness 	*/	{-0.3344,  -0.3544,  -0.4556,  0.6966,  -0.0242,  -0.2630},
64
			/*	 Vetness 	*/	{0.2626,  0.2141,  0.0926,  0.0656,  -0.7629, -0.5388    },	
65
			/*	 Fourth 	*/	{0.0805,  -0.0498,  0.1950, -0.1327, 0.5752,  -0.7775    },
66
			/*	 Fifth 		*/	{-0.7252,  -0.0202,  0.6683,  0.0631,  -0.1494,  -0.0274 },
67
			/*	 Sixth 		*/	{0.4000,  -0.8172,  0.3832,  0.0602,  -0.1095,  -0.0985	 }
68
	};
69

  
70
	
71
	public static void registerParameters() {
72
		registerInputParameter(RASTER_STORE, RasterDataStore.class, TasseledCapAlgorithmLibrary.TASSELEDCAP_PROCESS_LABEL);
73
		registerInputParameter(PATH, String.class, TasseledCapAlgorithmLibrary.TASSELEDCAP_PROCESS_LABEL);
74
		registerInputParameter(BANDS, Boolean[].class, TasseledCapAlgorithmLibrary.TASSELEDCAP_PROCESS_LABEL);
75
		registerInputParameter(LANDSAT_TYPE, Integer.class, TasseledCapAlgorithmLibrary.TASSELEDCAP_PROCESS_LABEL);
76
		
77
		registerOutputParameter(FILENAME, String.class, TasseledCapAlgorithmLibrary.TASSELEDCAP_PROCESS_LABEL);
78
		registerOutputParameter(GRAPHIC_DATA, Double[].class, TasseledCapAlgorithmLibrary.TASSELEDCAP_PROCESS_LABEL);
79
	}
80
	
81
	public void init() {
82
		store = getParam(RASTER_STORE) != null ? (RasterDataStore)getParam(RASTER_STORE) : null;
83
		filename = getStringParam(PATH);
84
		bands = (boolean[]) getParam(BANDS);
85
		type = getIntParam(LANDSAT_TYPE);
86
	}
87

  
88
	private boolean loadCoefMatrix(int type) {
89
		switch (type) {
90
		case 0:
91
			matrixParams = LandSatMS;
92
			if(getNumberOfOutputBands(bands) != 4) {
93
				return false;
94
			}
95
			break;	
96
		case 1:
97
			matrixParams = LandSatTM;	
98
			if(getNumberOfOutputBands(bands) != 6) {
99
				return false;
100
			}
101
			break;
102
		case 2:
103
			matrixParams = LandSatETM;	
104
			if(getNumberOfOutputBands(bands) != 6) {
105
				return false;
106
			}
107
			break;
108
		}	
109
		return true;
110
	}
111

  
112
	public void process() throws ProcessInterruptedException, ProcessException {
113
		insertLineLog(Messages.getText("processing_tc"));
114
		if (store == null) {
115
			throw new TasseledCapException(Messages.getText("need_a_input"));
116
		}
117

  
118
		if(!loadCoefMatrix(type)) {
119
			throw new TasseledCapException(Messages.getText("wrong_number_of_bands"));
120
		}
121

  
122
		if(getROIEPSG() != null) {
123
			try {
124
				rois = store.getRois(getROIEPSG());
125
			} catch (ROIException e2) {
126
				logger.error(Messages.getText("error_getting_rois"), e2);
127
			}
128
		}
129

  
130
		try {
131
			store = ((RasterDataStore)store).cloneDataStore();
132
		} catch (CloneException e) {
133
			new TasseledCapException("Error cloning the input DataStore", e);
134
		}
135

  
136
		extentResult = getExtentResult(getOutputWindow(), rois, store);
137
		Rectangle2D sourcePxBBox = getSourcePxBox(extentResult, store);
138

  
139
		double cellSize = store.getCellSize();
140

  
141
		nodata = RasterLocator.getManager().getDataStructFactory().createDefaultNoData(1, Buffer.TYPE_DOUBLE);
142
		double nodataValue = nodata.getValue().doubleValue();
143

  
144
		Buffer outputBuffer = createOutputBuffer((int)sourcePxBBox.getWidth(), (int)sourcePxBBox.getHeight(), matrixParams.length, Buffer.TYPE_FLOAT);
145
		Buffer sourceBuffer = createSourceBuffer(store, sourcePxBBox, bands);
146

  
147

  
148
		insertLineLog(Messages.getText("writting_in_buffer"));
149
		float resultValue = 0;
150

  
151
		for (int i = 0; i < sourceBuffer.getHeight(); i++) {
152
			for (int j = 0; j < sourceBuffer.getWidth(); j++) {
153
				if (isInsideOfROI(j, i, rois, extentResult)) {
154
					for (int coef = 0; coef < matrixParams.length; coef++) {
155
						for(int band = 0; band < matrixParams[0].length; band++) {	
156
							resultValue += getValue(sourceBuffer, i, j, band, coef);
157
						}
158
						outputBuffer.setElem(i, j, coef, resultValue);
159
						resultValue = 0;
160
					}
161
				} else {
162
					for (int iBand = 0; iBand < outputBuffer.getBandCount(); iBand++) {
163
						outputBuffer.setElem(i, j, iBand, (float)nodataValue);
164
					}
165
				}
166
			}
167
			updatePercent((int)(i * 100 / sourcePxBBox.getHeight()), 100);
168
		}
169

  
170
		super.exportRaster(filename, 
171
				outputBuffer, 
172
				cellSize, 
173
				extentResult.getULX(), 
174
				extentResult.getULY(),
175
				nodata);
176

  
177
		addOutputValue(FILENAME, filename);
178
		addOutputValue(GRAPHIC_DATA, filename);
179
	}
180

  
181
	/**
182
	 * Gets the number of the selected bands
183
	 * @param bandsPCs
184
	 * @return
185
	 */
186
	private int getNumberOfOutputBands(boolean[] b) {
187
		int bandCount = 0;
188
        for (int i = 0; i < b.length; i++) {
189
			if(b[i])
190
				bandCount++;
191
		}
192
        return bandCount;
193
	}
194
	
195
	private float getValue(Buffer sourceBuffer, int i, int j, int band, int coef) {
196
		if (sourceBuffer.getDataType() == Buffer.TYPE_BYTE) {
197
			return (float)((sourceBuffer.getElemByte(i, j, band) & 0xff) * matrixParams[coef][band]);
198
		}
199
		if (sourceBuffer.getDataType() == Buffer.TYPE_SHORT) {
200
			return (float)(sourceBuffer.getElemShort(i, j, band) * matrixParams[coef][band]);
201
		}
202
		if (sourceBuffer.getDataType() == Buffer.TYPE_INT) {
203
			return (float)(sourceBuffer.getElemInt(i, j, band) * matrixParams[coef][band]);
204
		}
205
		if (sourceBuffer.getDataType() == Buffer.TYPE_FLOAT) {
206
			return (float)(sourceBuffer.getElemFloat(i, j, band) * matrixParams[coef][band]);
207
		}
208
		if (sourceBuffer.getDataType() == Buffer.TYPE_DOUBLE) {
209
			return (float)(sourceBuffer.getElemDouble(i, j, band) * matrixParams[coef][band]);
210
		}
211
		return nodata.getValue().floatValue();
212
	}
213
	
214
	public String getTitle() {
215
		return Messages.getText("tasseled_cap");
216
	}
217
}
0 218

  
org.gvsig.raster.tasseledcap/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.tasseledcap.algorithm/src/main/resources-plugin/org/gvsig/raster/tasseledcap/algorithm/i18n/text.properties
1
layers_dont_intersect=Las capas no intersectan
2
roi_not_inside=La zona de estudio no esta contenida en la extensi?n de las capas
3
preparing_buffers=Preparando buffers
0 4

  
org.gvsig.raster.tasseledcap/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.tasseledcap.algorithm/src/main/resources-plugin/org/gvsig/raster/tasseledcap/algorithm/i18n/text_en.properties
1
layers_dont_intersect=Layers do not intersect
2
roi_not_inside=The region of interest are not inside the extension of the layers
3
preparing_buffers=Preparing buffers
0 4

  
org.gvsig.raster.tasseledcap/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.tasseledcap.algorithm/src/main/resources/org/gvsig/raster/tasseledcap/algorithm/i18n/text.properties
1
layers_dont_intersect=Las capas no intersectan
2
roi_not_inside=La zona de estudio no esta contenida en la extensi?n de las capas
3
preparing_buffers=Preparando buffers
4
writting_in_buffer=Escribiendo en buffer de salida
5
processing_tc=Procesando Tasseled Cap
6
tasseled_cap=Tasseled Cap
7
type=Tipo
8

  
0 9

  
org.gvsig.raster.tasseledcap/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.tasseledcap.algorithm/src/main/resources/org/gvsig/raster/tasseledcap/algorithm/i18n/text_en.properties
1
layers_dont_intersect=Layers do not intersect
2
roi_not_inside=The region of interest are not inside the extension of the layers
3
preparing_buffers=Preparing buffers
4
writting_in_buffer=Writing in the output buffer
5
processing_tc=Procesando Tasseled Cap
6
tasseled_cap=Tasseled Cap
7
type=Type
0 8

  
org.gvsig.raster.tasseledcap/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.tasseledcap.algorithm/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.tasseledcap.algorithm.TasseledCapAlgorithmLibrary
org.gvsig.raster.tasseledcap/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.tasseledcap.algorithm/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.tasseledcap.algorithm</artifactId>
5
	<packaging>jar</packaging>
6
	<name>org.gvsig.raster.tasseledcap.algorithm</name>
7
	<parent>
8
		<groupId>org.gvsig</groupId>
9
		<artifactId>org.gvsig.raster.tasseledcap</artifactId>
10
		<version>2.2.0-SNAPSHOT</version>
11
	</parent>
12
    <dependencies>
13
		<dependency>
14
			<groupId>org.gvsig</groupId>
15
			<artifactId>org.gvsig.raster.algorithm</artifactId>
16
            <scope>compile</scope>
17
		</dependency>
18
		<dependency>
19
            <groupId>org.gvsig</groupId>
20
            <artifactId>org.gvsig.i18n</artifactId>
21
            <scope>compile</scope>
22
        </dependency>
23
        <dependency>
24
            <groupId>org.gvsig</groupId>
25
            <artifactId>org.gvsig.tools.lib</artifactId>
26
            <scope>compile</scope>
27
        </dependency>
28
        <dependency>
29
            <groupId>org.gvsig</groupId>
30
            <artifactId>org.gvsig.ui</artifactId>
31
            <scope>compile</scope>
32
        </dependency>
33
        		<dependency>
34
			<groupId>org.gvsig</groupId>
35
			<artifactId>org.gvsig.raster.lib.api</artifactId>
36
            <scope>compile</scope>
37
		</dependency>
38
        <dependency>
39
            <groupId>org.gvsig</groupId>
40
            <artifactId>org.gvsig.raster.lib.impl</artifactId>
41
            <scope>compile</scope>
42
        </dependency>
43
        <dependency>
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>
50
            <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
51
            <scope>compile</scope>
52
        </dependency>
53
        
54
        <dependency>
55
            <groupId>org.gvsig</groupId>
56
            <artifactId>org.gvsig.fmap.geometry.api</artifactId>
57
            <scope>compile</scope>
58
        </dependency>
59
        <dependency>
60
            <groupId>org.gvsig</groupId>
61
            <artifactId>org.gvsig.fmap.geometry.impl</artifactId>
62
            <scope>runtime</scope>
63
        </dependency>
64
        <dependency>
65
            <groupId>org.gvsig</groupId>
66
            <artifactId>org.gvsig.compat.api</artifactId>
67
            <scope>compile</scope>
68
        </dependency>
69
        <dependency>
70
            <groupId>org.gvsig</groupId>
71
            <artifactId>org.gvsig.compat.se</artifactId>
72
            <scope>compile</scope>
73
        </dependency>
74
        <dependency>
75
            <groupId>org.gvsig</groupId>
76
            <artifactId>org.gvsig.projection.api</artifactId>
77
            <scope>compile</scope>
78
        </dependency>
79
        <dependency>
80
            <groupId>org.gvsig</groupId>
81
            <artifactId>org.gvsig.projection.cresques.impl</artifactId>
82
            <scope>runtime</scope>
83
        </dependency>
84
        <dependency>
85
            <groupId>org.gvsig</groupId>
86
            <artifactId>org.gvsig.fmap.dal.api</artifactId>
87
            <scope>compile</scope>
88
        </dependency>
89
        <dependency>
90
            <groupId>org.gvsig</groupId>
91
            <artifactId>org.gvsig.fmap.dal.impl</artifactId>
92
            <scope>compile</scope>
93
        </dependency>
94
        <dependency>
95
            <groupId>org.gvsig</groupId>
96
            <artifactId>org.gvsig.fmap.dal.file.lib</artifactId>
97
            <scope>compile</scope>
98
        </dependency>
99
        <dependency>
100
            <groupId>org.gvsig</groupId>
101
            <artifactId>org.gvsig.fmap.dal.spi</artifactId>
102
            <scope>compile</scope>
103
        </dependency>
104
        <dependency>
105
			<groupId>org.gvsig.legacy</groupId>
106
			<artifactId>jama</artifactId>
107
			<scope>compile</scope>
108
		</dependency>
109
	</dependencies>
110
</project>
0 111

  
org.gvsig.raster.tasseledcap/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.tasseledcap.app.tasseledcapclient/src/main/assembly/gvsig-plugin-package.xml
1
<assembly>
2
  <id>gvsig-plugin-package</id>
3
  <formats>
4
    <format>zip</format>
5
  </formats>
6
  <baseDirectory>${project.artifactId}</baseDirectory>
7
  <includeBaseDirectory>true</includeBaseDirectory>
8
  <files>
9
    <file>
10
      <source>target/${project.artifactId}-${project.version}.jar</source>
11
      <outputDirectory>lib</outputDirectory>
12
    </file>
13
    <file>
14
      <source>target/package.info</source>
15
    </file>
16
    <!-- <file>
17
      <source>${user.home}/.m2/repository/org/gvsig/org.gvsig.raster.tasseledcap.toolbox.algorithm/${project.version}/org.gvsig.raster.tasseledcap.toolbox.algorithm-${project.version}.jar</source>
18
      <outputDirectory>install/files</outputDirectory>
19
    </file>-->
20
  </files>
21

  
22
  <fileSets>
23
    <fileSet>
24
      <directory>src/main/resources-plugin</directory>
25
      <outputDirectory>.</outputDirectory>
26
    </fileSet>
27
  </fileSets>
28

  
29

  
30
  <dependencySets>
31
    <dependencySet>
32
      <useProjectArtifact>false</useProjectArtifact>
33
	  <useTransitiveDependencies>false</useTransitiveDependencies>
34
      <outputDirectory>lib</outputDirectory>
35
      <includes> 
36
			<include>org.gvsig:org.gvsig.raster.tasseledcap.app.tasseledcapclient:jar</include>
37
			<include>org.gvsig:org.gvsig.raster.tasseledcap.lib.api:jar</include>
38
			<include>org.gvsig:org.gvsig.raster.tasseledcap.lib.impl:jar</include>
39
			<include>org.gvsig:org.gvsig.raster.tasseledcap.swing.api:jar</include>
40
			<include>org.gvsig:org.gvsig.raster.tasseledcap.swing.impl:jar</include>
41
			<include>org.gvsig:org.gvsig.raster.tasseledcap.algorithm:jar</include>
42
			<include>org.gvsig:org.gvsig.raster.tasseledcap.toolbox.algorithm:jar</include>
43
	  </includes>
44
	</dependencySet>
45
  </dependencySets>
46
</assembly>
0 47

  
org.gvsig.raster.tasseledcap/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.tasseledcap.app.tasseledcapclient/src/main/java/org/gvsig/raster/tasseledcap/app/MainWindow.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.tasseledcap.app;
22

  
23
import java.awt.BorderLayout;
24
import java.awt.event.ActionEvent;
25
import java.awt.event.ActionListener;
26

  
27
import javax.swing.JComponent;
28

  
29
import org.gvsig.andami.PluginServices;
30
import org.gvsig.andami.ui.mdiManager.IWindow;
31
import org.gvsig.andami.ui.mdiManager.WindowInfo;
32
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
33
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel;
34

  
35

  
36
/**
37
 * Basic frame for a gvSIG <code>IWindow</code> object. This frame adds buttons 
38
 * of Cancel, Accept and others.
39
 * 
40
 * @author Nacho Brodin (nachobrodin@gmail.com)
41
 */
42
public class MainWindow extends DefaultButtonsPanel implements IWindow, ActionListener {
43
    
44
    private static final long  serialVersionUID = -4401123724140025094L;
45
    private ActionListener     listener         = null;
46
    private WindowInfo         info             = null;
47

  
48
    private Object profile = WindowInfo.EDITOR_PROFILE;
49

  
50
    public MainWindow(JComponent panel, String title, int w, int h, ActionListener actionListener) {
51
    	this.listener = actionListener;
52
    	
53
    	setLayout(new BorderLayout());
54
		add(panel, BorderLayout.CENTER);
55

  
56
		getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).setVisible(false);
57
        getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT).addActionListener(this);
58
        getButtonsPanel().getButton(ButtonsPanel.BUTTON_CANCEL).addActionListener(this);
59
        
60
        info = new WindowInfo(WindowInfo.PALETTE | WindowInfo.RESIZABLE);
61
        info.setTitle(title);
62
        info.setWidth(w);
63
        info.setHeight(h);
64
    }
65
    
66
    public MainWindow(JComponent panel, String title, int w, int h, ActionListener actionListener, boolean closeButton) {
67
    	this.listener = actionListener;
68
    	
69
    	setLayout(new BorderLayout());
70
		add(panel, BorderLayout.CENTER);
71

  
72
		getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).setVisible(false);
73
		
74
		if(closeButton) {
75
			getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT).setVisible(false);
76
			getButtonsPanel().getButton(ButtonsPanel.BUTTON_CANCEL).setVisible(false);
77
			getButtonsPanel().addClose();
78
			getButtonsPanel().getButton(ButtonsPanel.BUTTON_CLOSE).addActionListener(this);
79
		} else {
80
			getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT).addActionListener(this);
81
			getButtonsPanel().getButton(ButtonsPanel.BUTTON_CANCEL).addActionListener(this);
82
		}
83
        
84
        info = new WindowInfo(WindowInfo.PALETTE | WindowInfo.RESIZABLE);
85
        info.setTitle(title);
86
        info.setWidth(w);
87
        info.setHeight(h);
88
    }
89

  
90
    public WindowInfo getWindowInfo() {
91
        return info;
92
    }
93

  
94
    public Object getWindowProfile() {
95
        return profile;
96
    }
97

  
98
    public void actionPerformed(ActionEvent e) {
99
    	if(e.getSource() == getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT)) {
100
    		listener.actionPerformed(e);
101
    		PluginServices.getMDIManager().closeWindow(this);
102
    	}
103
    	
104
    	if(e.getSource() == getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY)) {
105
    		listener.actionPerformed(e);
106
    	}
107
    	
108
    	if(e.getSource() == getButtonsPanel().getButton(ButtonsPanel.BUTTON_CANCEL)) {
109
    		PluginServices.getMDIManager().closeWindow(this);
110
    	}
111
    	
112
    	if(e.getSource() == getButtonsPanel().getButton(ButtonsPanel.BUTTON_CLOSE)) {
113
    		PluginServices.getMDIManager().closeWindow(this);
114
    	}
115
    }
116
}
0 117

  
org.gvsig.raster.tasseledcap/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.tasseledcap.app.tasseledcapclient/src/main/java/org/gvsig/raster/tasseledcap/app/TasseledCapExtension.java
1
package org.gvsig.raster.tasseledcap.app;
2

  
3
import java.awt.event.ActionEvent;
4
import java.awt.event.ActionListener;
5

  
6
import org.gvsig.andami.IconThemeHelper;
7
import org.gvsig.andami.PluginServices;
8
import org.gvsig.andami.plugins.Extension;
9
import org.gvsig.andami.ui.mdiManager.IWindow;
10
import org.gvsig.app.project.documents.view.gui.IView;
11
import org.gvsig.fmap.mapcontext.layers.FLayer;
12
import org.gvsig.fmap.mapcontrol.MapControl;
13
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
14
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel;
15
import org.gvsig.i18n.Messages;
16
import org.gvsig.raster.algorithm.BasicAPISwingPanel;
17
import org.gvsig.raster.algorithm.process.DataProcess;
18
import org.gvsig.raster.fmap.layers.FLyrRaster;
19
import org.gvsig.raster.swing.RasterSwingLibrary;
20
import org.gvsig.raster.tasseledcap.app.toolbox.ToolboxTasseledCapLoader;
21
import org.gvsig.raster.tasseledcap.swing.TasseledCapSwingLocator;
22
import org.gvsig.tools.ToolsLocator;
23
import org.gvsig.tools.extensionpoint.ExtensionPoint;
24
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
25

  
26

  
27
public class TasseledCapExtension extends Extension implements ActionListener {
28
    private BasicAPISwingPanel   mainPanel              = null;
29
    private MainWindow           windowMainPanel        = null;
30
    private FLyrRaster           lyr                    = null; 
31
    
32
    public void initialize() {
33
    	
34
    	// Adds an entry to the TOC's floating menu to those layers defined in this extension
35
    	
36
		//ExtensionPoint exPoint = ToolsLocator.getExtensionPointManager().add("My_TocActions");
37
		//exPoint.append("MyMenuEntry", "", new PrincipalComponentsTocMenuEntry());
38

  
39
        // Adds a new tab to the "add layer" dialog
40
    	
41
    	//AddLayer.addWizard(PrincipalComponentsWizard.class);
42
    	
43
    	// Adds a new button in the raster bar
44
    	// TODO: Remove for providers
45
		ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
46
		ExtensionPoint point = extensionPoints.add("GenericToolBarMenu");
47
		point.append("TasseledCap", "", TasseledCapTocMenuEntry.getSingleton());
48
		TasseledCapTocMenuEntry.setExtension(this);
49
    	
50
        Messages.addResourceFamily("org.gvsig.raster.tasseledcap.app.i18n.text",
51
        		TasseledCapExtension.class.getClassLoader(),
52
        		TasseledCapExtension.class.getClass().getName()); 
53

  
54
    	initilizeIcons();
55
    }
56
    
57
	public void postInitialize() {
58
		new ToolboxTasseledCapLoader().registerTool();
59
	}
60

  
61
    public void execute(String actionCommand) {
62
    	if (actionCommand.compareTo("TasseledCap") == 0) {
63
    		lyr = getSelectedLayer();
64
    		if(lyr == null) {
65
    			RasterSwingLibrary.messageBoxError(Messages.getText("layer_not_found"), null);
66
    			return;
67
    		}
68
    		
69
			String defaultROIEPSG = getFirstMapCtrl().getProjection().getAbrev();
70
			
71
    		mainPanel = TasseledCapSwingLocator.getSwingManager().createTasseledCapMainPanel(
72
    				lyr.getDataStore(),
73
    				lyr.getName(),
74
    				lyr.getDataStore().getBandCount(),
75
    				defaultROIEPSG);
76
    		
77
    		windowMainPanel = new MainWindow(mainPanel.getComponent(), 
78
    				Messages.getText("tasseled_cab"), 
79
    				400, 420, 
80
    				this);
81
    		
82
    		PluginServices.getMDIManager().addCentredWindow(windowMainPanel);
83
    		
84
    		mainPanel.initialize();
85
    	}
86
    }
87
    
88
	/**
89
	 * Gets the Mapcontrol for the first view found.
90
	 * @return
91
	 */
92
    private MapControl getFirstMapCtrl() {
93
    	IWindow[] windowList = PluginServices.getMDIManager().getAllWindows();
94
    	for (int i = 0; i < windowList.length; i++) {
95
    		if(windowList[i] instanceof IView) {
96
    			return ((IView)windowList[i]).getMapControl();
97
    		}
98
    	}		
99
    	return null;
100
    }
101

  
102
    /**
103
     * Gets the selected and valid layer
104
     * @return
105
	 */
106
	private FLyrRaster getSelectedLayer() {
107
		FLayer[] lyrList = getFirstMapCtrl().getMapContext().getLayers().getActives();
108
		for (int i = 0; i < lyrList.length; i++) {
109
			if(lyrList[i] instanceof FLyrRaster)
110
				return (FLyrRaster)lyrList[i];
111
		}
112
		return null; 
113
	}
114

  
115
    public boolean isEnabled() {
116
        return false;
117
    }
118

  
119
    public boolean isVisible() {
120
        return false;
121
    }
122

  
123
    void initilizeIcons(){
124
		IconThemeHelper.registerIcon(null, "tasseled-cab", this);
125
		IconThemeHelper.registerIcon(null, "gvsig-icon", this);
126
		IconThemeHelper.registerIcon(null, "gvsig-icon16x16", this);
127
    }
128

  
129
	public void actionPerformed(ActionEvent e) {
130
		//ACCEPT MAIN PANEL 
131
		if( e.getSource() == ((DefaultButtonsPanel)windowMainPanel).getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY) ||
132
			e.getSource() == ((DefaultButtonsPanel)windowMainPanel).getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT)) {
133
			DataProcess task = null;
134
			try {
135
				task = (DataProcess)mainPanel.getResult();
136
			} catch (Exception e1) {
137
				RasterSwingLibrary.messageBoxError(Messages.getText("problems_creating_process"), null);
138
				return;
139
			}
140
			task.setActions(new ProcessEndActions(windowMainPanel, lyr));
141
			task.init();
142
			task.start();
143
		}
144
	}
145

  
146
	public void interrupted() {
147
		
148
	}
149
	
150
	public void updateProgress(int current, int total) {
151
		
152
	}
153
}
0 154

  
org.gvsig.raster.tasseledcap/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.tasseledcap.app.tasseledcapclient/src/main/java/org/gvsig/raster/tasseledcap/app/TasseledCapTocMenuEntry.java
1
package org.gvsig.raster.tasseledcap.app;
2

  
3
import javax.swing.Icon;
4

  
5
import org.gvsig.andami.IconThemeHelper;
6
import org.gvsig.andami.plugins.Extension;
7
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
8
import org.gvsig.app.project.documents.view.toc.ITocItem;
9
import org.gvsig.fmap.mapcontext.layers.FLayer;
10
import org.gvsig.i18n.Messages;
11
import org.gvsig.raster.fmap.layers.FLyrRaster;
12
import org.gvsig.raster.fmap.layers.ILayerState;
13
import org.gvsig.raster.fmap.layers.IRasterLayerActions;
14
import org.gvsig.raster.mainplugin.toolbar.IGenericToolBarMenuItem;
15

  
16
public class TasseledCapTocMenuEntry extends AbstractTocContextMenuAction implements IGenericToolBarMenuItem {
17
	static private TasseledCapTocMenuEntry singleton  = null;
18
	private static Extension                     extension  = null;
19
	
20
	
21
	public static void setExtension(Extension ext) {
22
		extension = ext;
23
	}
24

  
25
	private TasseledCapTocMenuEntry() {}
26

  
27
	static public TasseledCapTocMenuEntry getSingleton() {
28
		if (singleton == null)
29
			singleton = new TasseledCapTocMenuEntry();
30
		return singleton;
31
	}
32
	
33
	public String getGroup() {
34
		return "Multispectral";
35
	}
36

  
37
	public int getGroupOrder() {
38
		return 55;
39
	}
40

  
41
	public int getOrder() {
42
		return 0;
43
	}
44

  
45
	public String getText() {
46
		return Messages.getText("tasseledcap");
47
	}
48

  
49
	public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
50
		if ((selectedItems == null) || (selectedItems.length != 1))
51
			return false;
52

  
53
		if (!(selectedItems[0] instanceof ILayerState))
54
			return false;
55

  
56
		if (!((ILayerState) selectedItems[0]).isOpen())
57
			return false;
58
		
59
		if(((FLyrRaster) selectedItems[0]).getRender().getFilterList().get("colortable") != null)
60
			return false;
61
		
62
		if(((FLyrRaster) selectedItems[0]).getDataStore().getBandCount() < 4)
63
			return false;
64

  
65
		return true;
66
	}
67

  
68
	public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
69
		if ((selectedItems == null) || (selectedItems.length != 1))
70
			return false;
71

  
72
		if (!(selectedItems[0] instanceof IRasterLayerActions))
73
			return false;
74
		
75
		return ((IRasterLayerActions) selectedItems[0]).isActionEnabled(IRasterLayerActions.ENHANCED);
76
	}
77

  
78
	public void execute(ITocItem item, FLayer[] selectedItems) {
79
		extension.execute("TasseledCap");
80
	}
81
	
82
	public Icon getIcon() {
83
		return IconThemeHelper.getImageIcon("tasseled-cab");
84
	}
85
	
86
}
0 87

  
org.gvsig.raster.tasseledcap/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.tasseledcap.app.tasseledcapclient/src/main/java/org/gvsig/raster/tasseledcap/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.tasseledcap.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.tasseledcap.algorithm.TasseledCapAlgorithmLibrary;
46
import org.gvsig.raster.swing.RasterSwingLibrary;
47
import org.gvsig.raster.swing.RasterSwingLocator;
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 
81
		if (processName.equals(TasseledCapAlgorithmLibrary.TASSELEDCAP_PROCESS_LABEL)) {
82
			String fileName = (String)params.get("FILENAME");
83
			long milis = (Long)params.get("TIME");
84
			processFinalize(fileName, milis);
85
			RasterSwingLocator.getSwingManager().showSummaryProcessDialog(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 (fileName == null || !new File(fileName).exists())
95
			return;
96

  
97
		if (RasterSwingLibrary.messageBoxYesOrNot("cargar_toc", null)) {
98
			try {
99
				loadLayer(fileName, fileName.substring(fileName.lastIndexOf(File.separator) + 1));
100
			} catch (RasterNotLoadException e) {
101
				RasterSwingLibrary.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
	
178
	public void updateProgress(int current, int total) {
179
		
180
	}
181
}
0 182

  
org.gvsig.raster.tasseledcap/tags/gvSIGv2_1_0_Build_2218/org.gvsig.raster.tasseledcap.app.tasseledcapclient/src/main/java/org/gvsig/raster/tasseledcap/app/toolbox/TasseledCapToolboxAction.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 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

  
25

  
26
package org.gvsig.raster.tasseledcap.app.toolbox;
27

  
28
import javax.swing.ImageIcon;
29

  
30
import org.gvsig.andami.IconThemeHelper;
31
import org.gvsig.fmap.mapcontext.layers.FLayer;
32
import org.gvsig.geoprocess.sextante.gui.core.GUIFactory;
33
import org.gvsig.i18n.Messages;
34
import org.gvsig.raster.tasseledcap.app.TasseledCapTocMenuEntry;
35

  
36
/**
37
 * Input in Sextante framework for Tasseled Cap tool
38
 * 
39
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
40
 */
41
public class TasseledCapToolboxAction extends AbstractToolboxAction {
42
	
43
	public TasseledCapToolboxAction() {
44
		ImageIcon ico = IconThemeHelper.getImageIcon("gvsig-icon16x16");
45
		GUIFactory.registerExternalTool(Messages.getText("gv_tools"), ico, this);
46
	}
47
	
48
	@Override
49
	public String getGroup() {
50
		return Messages.getText("multispectral");
51
	}
52
	
53
	@Override
54
	public void execute() {
55
		if(!super.loadLayer())
56
			return;
57
		TasseledCapTocMenuEntry.getSingleton().execute(null, new FLayer[]{lyr}); 
58
	}
59

  
60
	@Override
61
	public String getName() {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff