gvsig-raster / org.gvsig.raster.tasseledcap / trunk / org.gvsig.raster.tasseledcap / org.gvsig.raster.tasseledcap.app.tasseledcapclient / src / main / java / org / gvsig / raster / tasseledcap / app / ProcessEndActions.java @ 2381
History | View | Annotate | Download (6.06 KB)
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 |
} |