Revision 4403

View differences:

org.gvsig.raster.reproject/tags/org.gvsig.raster.reproject-2.2.17/org.gvsig.raster.reproject.app.reprojectclient/buildNumber.properties
1
#Thu Dec 10 19:32:50 CET 2015
2
buildNumber=69
0 3

  
org.gvsig.raster.reproject/tags/org.gvsig.raster.reproject-2.2.17/org.gvsig.raster.reproject.app.reprojectclient/package.info
1
#
2
#Mon Jun 10 11:57:18 CEST 2013
3
owner=gvSIG Association
4
code=org.gvsig.raster.reproject.app.reprojectclient
5
java-version=j1_5
6
official=true
7
type=plugin
8
version=2.0.1-SNAPSHOT-12
9
state=testing
10
operating-system=all
11
dependencies=required\: org.gvsig.raster.tilecache.app -ge 2.0.0-0, required\: org.gvsig.raster.tools.app.basic -ge 2.0.0-0
12
sources-url=https\://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster.reproject/trunk/org.gvsig.raster.reproject/org.gvsig.raster.reproject.app.reprojectclient
13
web-url=http\://www.gvsig.com
14
architecture=all
15
model-version=1.0.1
16
categories=Raster
17
description=Reprojection support
18
buildNumber=12
19
gvSIG-version=2.0.0
20
name=Reprojection support
org.gvsig.raster.reproject/tags/org.gvsig.raster.reproject-2.2.17/org.gvsig.raster.reproject.app.reprojectclient/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
  </files>
17

  
18
  <fileSets>
19
    <fileSet>
20
      <directory>src/main/resources-plugin</directory>
21
      <outputDirectory>.</outputDirectory>
22
    </fileSet>
23
  </fileSets>
24

  
25

  
26
  <dependencySets>
27
    <dependencySet>
28
      <useProjectArtifact>false</useProjectArtifact>
29
	  <useTransitiveDependencies>false</useTransitiveDependencies>
30
      <outputDirectory>lib</outputDirectory>
31
      <includes> 
32
				<include>org.gvsig:org.gvsig.raster.reproject.app.reprojectclient:jar</include>
33
				<include>org.gvsig:org.gvsig.raster.reproject.algorithm:jar</include>
34
	  </includes>
35
	</dependencySet>
36
  </dependencySets>
37
</assembly>
0 38

  
org.gvsig.raster.reproject/tags/org.gvsig.raster.reproject-2.2.17/org.gvsig.raster.reproject.app.reprojectclient/src/main/java/org/gvsig/raster/reproject/app/PrepareLayerAskProjection.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.reproject.app;
23

  
24
import java.io.File;
25
import java.util.HashMap;
26
import java.util.Map;
27
import org.apache.commons.io.FilenameUtils;
28

  
29
import org.cresques.cts.IProjection;
30
import org.gvsig.app.prepareAction.PrepareContext;
31
import org.gvsig.app.prepareAction.PrepareContextView;
32
import org.gvsig.app.prepareAction.PrepareDataStoreParameters;
33
import org.gvsig.app.prepareAction.PrepareLayer;
34
import org.gvsig.fmap.crs.CRSFactory;
35
import org.gvsig.fmap.dal.DALLocator;
36
import org.gvsig.fmap.dal.DataManager;
37
import org.gvsig.fmap.dal.DataStoreParameters;
38
import org.gvsig.fmap.dal.coverage.RasterLocator;
39
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
40
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
41
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
42
import org.gvsig.fmap.dal.coverage.util.CRSUtils;
43
import org.gvsig.fmap.mapcontext.MapContextLocator;
44
import org.gvsig.fmap.mapcontext.MapContextManager;
45
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
46
import org.gvsig.fmap.mapcontext.layers.FLayer;
47
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary;
48
import org.gvsig.raster.algorithm.process.DataProcess;
49
import org.gvsig.raster.algorithm.process.IProcessActions;
50
import org.gvsig.raster.algorithm.process.ProcessException;
51
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster;
52
import org.gvsig.raster.fmap.layers.FLyrRaster;
53
import org.gvsig.raster.mainplugin.config.Configuration;
54
import org.gvsig.raster.reproject.algorithm.ReprojectProcess;
55
import org.gvsig.raster.reproject.app.preparelayer.RasterProjectionActionsDialog;
56
import org.gvsig.raster.reproject.app.preparelayer.ReprojectionQueue;
57
import org.gvsig.raster.swing.RasterSwingLibrary;
58
import org.gvsig.tools.exception.BaseException;
59
import org.slf4j.Logger;
60
import org.slf4j.LoggerFactory;
61

  
62
public class PrepareLayerAskProjection implements PrepareDataStoreParameters, PrepareLayer, IProcessActions {
63
	protected CRSUtils              crsUtil                       = RasterLocator.getManager().getCRSUtils(); 
64
	private boolean                 changeReprojectionOption      = true;
65
	private int                     lastReprojectionOption        = RasterDataParameters.NEW_PROJETION_TO_THE_LAYER;
66
	private ReprojectionQueue       queue                         = ReprojectionQueue.getSingleton();
67
	private Logger                  log                           = LoggerFactory.getLogger(PrepareLayerAskProjection.class);
68
	
69
	@SuppressWarnings("deprecation")
70
	public DataStoreParameters prepare(DataStoreParameters storeParameters,
71
			PrepareContext context) throws BaseException {
72
		if(!(storeParameters instanceof RasterDataParameters))
73
			return storeParameters;
74
		
75
		DataManager dataManager = DALLocator.getDataManager();
76
		RasterDataStore dataStore = (RasterDataStore)dataManager.createStore(storeParameters);
77
		
78
		if (Configuration.getValue("general_ask_projection", Boolean.valueOf(false)).booleanValue()) {
79
			IProjection proj = readProjection(dataStore);
80
			if(proj != null) {
81
				//((RasterDataParameters)storeParameters).setDynValue("CRS", proj);
82
				compareProjections(proj, context.getViewProjection(), dataStore);
83
			}
84
		}
85
		
86
		if(dataStore != null)
87
			dataStore.close();
88
		
89
		if(((RasterDataParameters)storeParameters).getReprojectionOption() == RasterDataParameters.NEW_PROJETION_TO_THE_LAYER) {
90
			IProjection viewProjection = context.getViewProjection();
91
			if(viewProjection != null) {
92
				((RasterDataParameters)storeParameters).setSRS(viewProjection);
93
				((RasterDataParameters)storeParameters).setSRSID(viewProjection.getAbrev());
94
			} else {
95
				((RasterDataParameters)storeParameters).setSRS(null);
96
				((RasterDataParameters)storeParameters).setSRSID(null);
97
			}
98
		}
99
			
100
		if(((RasterDataParameters)storeParameters).getReprojectionOption() == RasterDataParameters.NOT_LOAD)
101
			return null;
102
		
103
		return storeParameters;
104
	}
105
	
106
	public void post(DataStoreParameters storeParameters, PrepareContext context) {
107
		changeReprojectionOption = true;
108
	}
109
	
110
	public void pre(DataStoreParameters storeParameters, PrepareContext context) {
111
	}
112
	
113
	/**
114
	 * If this flag is true the reprojection options can be changed by the user 
115
	 * @return
116
	 */
117
	public boolean getChangeOption() {
118
		return changeReprojectionOption;
119
	}
120
	
121
	/**
122
	 * If this flag is true the reprojection options can be changed by the user 
123
	 * @param changeOption
124
	 */
125
	public void setChangeOption(boolean changeOption) {
126
		this.changeReprojectionOption = changeOption;
127
	}
128
	
129
	public FLayer prepare(FLayer layer, PrepareContextView context) {
130
		if (!(layer instanceof DefaultFLyrRaster))
131
			return layer;
132
		DefaultFLyrRaster lyrRaster = (DefaultFLyrRaster) layer;
133
		String layerName = lyrRaster.getName();
134

  
135
		RasterDataParameters params = (RasterDataParameters)lyrRaster.getDataStore().getParameters();
136
		int repOption = params.getReprojectionOption();
137
		
138
		if(repOption == RasterDataParameters.REPROJECT_DATA) {
139
			RasterDataParameters rasterParams = reproject(lyrRaster, context.getViewProjection());
140
			if(rasterParams != null) {
141
				MapContextManager mcm = MapContextLocator.getMapContextManager();
142
				try {
143
					return (DefaultFLyrRaster) mcm.createLayer(layerName, rasterParams);
144
				} catch (LoadLayerException e) {
145
					return lyrRaster;
146
				}
147
				/*DefaultFLyrRaster lyr = new DefaultFLyrRaster();
148
				DataManager dataManager = DALLocator.getDataManager();
149
				try {
150
					DataStore dataStore = dataManager.createStore(rasterParams);
151
					lyr.setName(layerName);
152
					lyr.setDataStore(dataStore);
153
					return lyr;
154
				} catch (ValidateDataParametersException e) {
155
					return lyrRaster;
156
				} catch (InitializeException e) {
157
					return lyrRaster;
158
				} catch (ProviderNotRegisteredException e) {
159
					return lyrRaster;
160
				} catch (LoadLayerException e) {
161
					return lyrRaster;
162
				}*/
163
			}
164
		} else if(repOption == RasterDataParameters.REPROJECT_VIEW) {
165
			try {
166
				if (lyrRaster != null && lyrRaster.readProjection() != null) {
167
					context.getMapControl().setProjection(lyrRaster.readProjection());
168
					lyrRaster.setVisible(true);
169
				}
170
			} catch (RasterDriverException e) {
171
				RasterSwingLibrary.messageBoxError("Error reading the projection", null, e);
172
			}
173
		} else if(repOption == RasterDataParameters.DONT_CHANGE_PROJECTION) {
174
			lyrRaster.setVisible(true);
175
			return lyrRaster;
176
		} else if(repOption == RasterDataParameters.NEW_PROJETION_TO_THE_LAYER) {
177
			IProjection proj = context.getViewProjection();
178
			if(proj != null)
179
				lyrRaster.setProjection(proj, false);
180
			lyrRaster.setVisible(true);
181
			return lyrRaster;
182
		}
183

  
184
		return lyrRaster;
185
	}
186
	
187
	private RasterDataParameters reproject(FLyrRaster lyrRaster, IProjection dstProj) {
188
		RasterDataParameters params = (RasterDataParameters)lyrRaster.getDataStore().getParameters();
189
		int repOption = params.getReprojectionOption();
190

  
191
		if(repOption == RasterDataParameters.REPROJECT_DATA) {
192
			IProjection srcProj = readProjection(lyrRaster.getDataStore());
193
			if(srcProj == null)
194
				return null;
195

  
196
			File f = new File(params.getURI());
197
                        File fdst = new File(
198
                                f.getParentFile(), 
199
                                FilenameUtils.getBaseName(f.getName()) 
200
                                        + "_" 
201
                                        + dstProj.getAbrev()
202
                                        + FilenameUtils.getExtension(f.getName())
203
                        );
204
			
205
			if(!fdst.exists()) {					
206
				DataProcess process = null;
207
				try {
208
					process = RasterBaseAlgorithmLibrary.getManager().createRasterTask("RasterReprojectionProcess");
209
				} catch (ProcessException e1) {
210
					RasterSwingLibrary.messageBoxError("error_creating_algorithm", null, e1);
211
					return params;
212
				}
213
				process.setActions(this);
214
				process.addParam(ReprojectProcess.RASTER_STORE, lyrRaster.getDataStore());
215
				process.addParam(ReprojectProcess.SIZEX, 0); //Calculo autom?tico de tama?o
216
				process.addParam(ReprojectProcess.SIZEY, 0);
217
				process.addParam(ReprojectProcess.PATH, fdst.toURI());
218
				process.addParam(ReprojectProcess.SRC_PROJECTION, srcProj);
219
				process.addParam(ReprojectProcess.DST_PROJECTION, dstProj);
220
				process.addParam(ReprojectProcess.CELLSIZE, lyrRaster.getDataStore().getCellSize());
221

  
222
				//Despierta la cola que reproyecta im?genes
223
				synchronized (queue) {
224
					queue.add(process, this);	
225
					queue.notify();
226
				}
227

  
228
				//Se suspende hasta que la cola haya terminado
229
				try {
230
					synchronized (this) {
231
						this.wait();
232
					}
233
				} catch (InterruptedException e) {
234
				}
235

  
236
				if(process.getResult() != null) {
237
					HashMap<String, Object> map = (HashMap<String, Object>)process.getResult();
238
					String filename = (String)map.get(ReprojectProcess.FILENAME);
239
					params.setURI(new File(filename).toURI());
240
					return params;
241
				}
242
			} else {
243
				params.setURI(fdst.toURI());
244
				return params;
245
			}
246

  
247
		} else if(repOption == RasterDataParameters.REPROJECT_VIEW) {
248
			//Esto se cambia en el prepare que tiene acceso al mapcontrol. Este prepare es a nivel de datos
249
		} 
250
		return null;
251
	}
252

  
253
	public void end(Object param) {
254
		
255
	}
256

  
257
	/**
258
	 * Compares two projections and show a dialog to the user to make a decision
259
	 * @param lyrProj
260
	 * @param viewProj
261
	 */
262
	private void compareProjections(IProjection lyrProj, IProjection viewProj, RasterDataStore dataStore) {
263
		if(!getChangeOption() || lyrProj == null || viewProj == null) {
264
			((RasterDataParameters)dataStore.getParameters()).setReprojectionOption(lastReprojectionOption);
265
			return;
266
		}
267

  
268
		/*
269
		 * Si las proyecciones de vista y raster son distintas se lanza el
270
		 * dialogo de selecci?n de opciones. Este dialogo solo se lanza en caso
271
		 * de que el checkbox de aplicar a todos los ficheros no haya sido
272
		 * marcado. En este caso para el resto de ficheros de esa selecci?n se
273
		 * har? la misma acci?n que se hizo para el primero.
274
		 */
275
		if (!viewProj.getAbrev().endsWith(lyrProj.getAbrev())) {
276
			String layerName = dataStore.getName().substring(dataStore.getName().lastIndexOf(File.separator) + 1, dataStore.getName().length());
277
			RasterProjectionActionsDialog dialog = new RasterProjectionActionsDialog(
278
					dataStore.isReproyectable(), layerName, RasterDataParameters.REPROJECT_VIEW);
279
			if (dialog != null) {
280
				lastReprojectionOption = dialog.getRasterProjectionActionsPanel().getSelection();
281
				((RasterDataParameters)dataStore.getParameters()).setReprojectionOption(lastReprojectionOption);
282
				setChangeOption(!dialog.getChangeProjectionOption());
283
			}
284
		}
285
	}
286
	
287
	/**
288
	 * Reads the projection from a DataStore
289
	 * @param dataStore
290
	 * @return
291
	 * @throws RasterDriverException
292
	 */
293
	@SuppressWarnings("deprecation")
294
	private IProjection readProjection(RasterDataStore dataStore) {
295
		try {
296
			crsUtil.setCRSFactory(CRSFactory.cp);
297
			if( dataStore == null )
298
				return null;
299
			return crsUtil.convertWktToIProjection(dataStore.getWktProjection());
300
		} catch (Exception e) {
301
			//Si ha habido alg?n problema con la conversi?n metemos un log y que devuelva null 
302
			log.info("Problems converting from WKT to IProjection", e);
303
		} catch (Error e) {
304
			log.info("Problems converting from WKT to IProjection", e);
305
		}
306
		return null;
307
	}
308

  
309
	public String getDescription() {
310
		return "Prepare projection for Raster Layer";
311
	}
312

  
313
	public String getName() {
314
		return "PrepareRasterLayerProjection";
315
	}
316

  
317
	public Object create() {
318
		return this;
319
	}
320

  
321
	public Object create(Object[] args) {
322
		return this;
323
	}
324

  
325
	@SuppressWarnings("rawtypes")
326
	public Object create(Map args) {
327
		return this;
328
	}
329

  
330
	public void interrupted() {
331
	}
332
	
333
	public void updateProgress(int current, int total) {
334
		
335
	}
336
}
0 337

  
org.gvsig.raster.reproject/tags/org.gvsig.raster.reproject-2.2.17/org.gvsig.raster.reproject.app.reprojectclient/src/main/java/org/gvsig/raster/reproject/app/ReprojectExtension.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.reproject.app;
23

  
24
import org.gvsig.andami.IconThemeHelper;
25
import org.gvsig.andami.PluginServices;
26
import org.gvsig.andami.plugins.Extension;
27
import org.gvsig.andami.ui.mdiManager.IWindow;
28
import org.gvsig.app.ApplicationLocator;
29
import org.gvsig.app.ApplicationManager;
30
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
31
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
32
import org.gvsig.fmap.mapcontext.layers.FLayer;
33
import org.gvsig.fmap.mapcontext.layers.FLayers;
34
import org.gvsig.raster.fmap.layers.FLyrRaster;
35
import org.gvsig.raster.fmap.layers.ILayerState;
36
import org.gvsig.raster.fmap.layers.IRasterLayerActions;
37
import org.gvsig.raster.reproject.app.toolbox.ToolboxReprojectLoader;
38
import org.gvsig.tools.ToolsLocator;
39
import org.gvsig.tools.extensionpoint.ExtensionBuilder;
40
import org.gvsig.tools.extensionpoint.ExtensionPoint;
41
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
42

  
43
/**
44
 * Extension for adding grid netcdf support to gvSIG.
45
 * @author Nacho Brodin (nachobrodin@gmail.com)
46
 */
47
public class ReprojectExtension extends Extension {
48
	private ExtensionPoint      genericToolBarMenuExtensionPoint  = null;
49
	private static String       action                            = "Reproject";
50

  
51
	public void initialize() {
52
		IconThemeHelper.registerIcon("action", "tools-raster-reproject", this);
53
		
54
		ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
55
		ExtensionPoint point = extensionPoints.add("GenericToolBarMenu");
56
		point.append(action, "", ReprojectTocMenuEntry.getSingleton());
57
		
58
		ApplicationManager appGvSigMan = ApplicationLocator.getManager();
59
		appGvSigMan.registerPrepareOpenLayer(new PrepareLayerAskProjection());
60
		appGvSigMan.registerPrepareOpenDataStoreParameters(new PrepareLayerAskProjection());
61
	}
62
	
63
	public void postInitialize() {
64
		new ToolboxReprojectLoader().registerTool();
65
	}
66

  
67
	public void execute(String actionCommand) {
68
		//Las entradas en GenericToolBarModule est?n registradas con la misma etiqueta que la del actionCommand
69
		//De esta forma pueden recuperarse los TocMenuEntry del punto de extensi?n y ejecutar la acci?n a
70
		//trav?s de este.
71
		ExtensionBuilder ext = getGenericToolBarMenuExtensionPoint().get(actionCommand).getBuilder();
72
		if(ext != null && ext instanceof AbstractTocContextMenuAction) {
73
			IWindow w = PluginServices.getMDIManager().getActiveWindow();
74
			if(w instanceof AbstractViewPanel) {
75
				FLayers lyrs = ((AbstractViewPanel)w).getMapControl().getMapContext().getLayers();
76
				FLayer[] actives = lyrs.getActives();
77
				((AbstractTocContextMenuAction)ext).execute(null, actives);
78
			}
79
		}
80
	}
81

  
82
	public boolean isEnabled() {
83
		IWindow w = PluginServices.getMDIManager().getActiveWindow();
84
		if(w instanceof AbstractViewPanel) {
85
			FLayers lyrs = ((AbstractViewPanel)w).getMapControl().getMapContext().getLayers();
86
			FLayer[] actives = lyrs.getActives();
87
			if(actives != null && actives.length > 0) {
88
				for (int i = 0; i < actives.length; i++) {
89
					if(actives[i] instanceof FLyrRaster && ((ILayerState)actives[i]).isOpen()) {
90
						return true;
91
					}
92
				}
93
			}
94
		}
95
		return false;
96
	}
97

  
98
	public boolean isVisible() {
99
		IWindow w = PluginServices.getMDIManager().getActiveWindow();
100
		if(w instanceof AbstractViewPanel) {
101
			FLayers lyrs = ((AbstractViewPanel)w).getMapControl().getMapContext().getLayers();
102
			FLayer[] actives = lyrs.getActives();
103
			if(actives != null && actives.length > 0) {
104
				for (int i = 0; i < actives.length; i++) {
105
					if(actives[i] instanceof FLyrRaster && 
106
						((IRasterLayerActions)actives[i]).isActionEnabled(IRasterLayerActions.REPROJECT)) {
107
						return true;
108
					}
109
				}
110
			}
111
		}
112
		return false;
113
	}
114
	
115
	public ExtensionPoint getGenericToolBarMenuExtensionPoint() {
116
		if(genericToolBarMenuExtensionPoint == null) {
117
			ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
118
			genericToolBarMenuExtensionPoint = extensionPoints.get("GenericToolBarMenu");
119
		}
120
		return genericToolBarMenuExtensionPoint;
121
	}
122
}
0 123

  
org.gvsig.raster.reproject/tags/org.gvsig.raster.reproject-2.2.17/org.gvsig.raster.reproject.app.reprojectclient/src/main/java/org/gvsig/raster/reproject/app/ReprojectTocMenuEntry.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.reproject.app;
23

  
24
import javax.swing.Icon;
25

  
26
import java.awt.Dimension;
27

  
28
import org.gvsig.andami.IconThemeHelper;
29
import org.gvsig.andami.PluginServices;
30
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
31
import org.gvsig.app.project.documents.view.toc.ITocItem;
32
import org.gvsig.fmap.mapcontext.layers.FLayer;
33
import org.gvsig.i18n.Messages;
34
import org.gvsig.raster.fmap.layers.FLyrRaster;
35
import org.gvsig.raster.fmap.layers.IRasterLayerActions;
36
import org.gvsig.raster.mainplugin.toolbar.IGenericToolBarMenuItem;
37
import org.gvsig.raster.reproject.algorithm.RasterReprojectionSwingLocator;
38
import org.gvsig.raster.reproject.algorithm.swing.api.RasterReprojectionPanel;
39
import org.gvsig.raster.reproject.algorithm.swing.api.ReprojectionPanelDataModel;
40

  
41

  
42
/**
43
 * @author Nacho Brodin (nachobrodin@gmail.com)
44
 */
45
public class ReprojectTocMenuEntry extends AbstractTocContextMenuAction 
46
	implements IGenericToolBarMenuItem {
47
	static private ReprojectTocMenuEntry    singleton        = null;
48
	private ReprojectListener               listener         = null;
49

  
50
	public String getGroup() {
51
		return "GeoRaster";
52
	}
53

  
54
	public int getGroupOrder() {
55
		return 10;
56
	}
57

  
58
	public int getOrder() {
59
		return 10;
60
	}
61

  
62
	public String getText() {
63
		return Messages.getText("toc_reproject");
64
	}
65
	
66
	/**
67
	 * Devuelve un objeto unico a dicha clase
68
	 * @return
69
	 */
70
	static public ReprojectTocMenuEntry getSingleton() {
71
		if (singleton == null)
72
			singleton = new ReprojectTocMenuEntry();
73
		return singleton;
74
	}
75

  
76
	public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
77
		return true;
78
	}
79

  
80
	public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
81
		if ((selectedItems == null) || (selectedItems.length != 1))
82
			return false;
83

  
84
		if (!(selectedItems[0] instanceof IRasterLayerActions))
85
			return false;
86

  
87
		return ((IRasterLayerActions) selectedItems[0]).isActionEnabled(IRasterLayerActions.REPROJECT);
88
	}
89

  
90
	/**
91
	 * M?todo que se ejecuta cuando se pulsa la entrada en el men? contextual del TOC 
92
	 * correspondiente a "Zoom a la resoluci?n del raster". Aqu? se crear? el mapTool si 
93
	 * no se ha hecho antes y se cargar?.
94
	 */
95
	public void execute(ITocItem item, FLayer[] selectedItems) {
96
		if (selectedItems.length == 1) {
97
			FLayer lyr = selectedItems[0];
98
			if (lyr instanceof FLyrRaster) {
99
				ReprojectionPanelDataModel dataModel = new ReprojectionPanelDataModelImpl((FLyrRaster)lyr);
100
				RasterReprojectionPanel reprojectPanel = RasterReprojectionSwingLocator.getSwingManager().createRasterReprojectPanel(dataModel);
101
				Dimension dimension = reprojectPanel.getComponent().getPreferredSize();
102
				
103
				ReprojectWindow window = new ReprojectWindow(reprojectPanel.getComponent(), Messages.getText("reprojection"), dimension.width, dimension.height);
104
				listener = new ReprojectListener(lyr, dataModel, window, reprojectPanel);
105
				reprojectPanel.addButtonsListener(listener);
106
				PluginServices.getMDIManager().addCentredWindow(window);
107
			}
108
		}
109
	}
110
	
111
	public Icon getIcon() {
112
		return IconThemeHelper.getImageIcon("tools-raster-reproject");
113
	}
114

  
115
	public void interrupted() {
116
		
117
	}
118
}
0 119

  
org.gvsig.raster.reproject/tags/org.gvsig.raster.reproject-2.2.17/org.gvsig.raster.reproject.app.reprojectclient/src/main/java/org/gvsig/raster/reproject/app/preparelayer/RasterProjectionActionsDialog.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.reproject.app.preparelayer;
23

  
24
import java.awt.BorderLayout;
25
import java.awt.Point;
26
import java.awt.event.ActionEvent;
27
import java.awt.event.ActionListener;
28

  
29
import javax.swing.JPanel;
30

  
31
import org.gvsig.andami.PluginServices;
32
import org.gvsig.andami.ui.mdiManager.IWindow;
33
import org.gvsig.andami.ui.mdiManager.IWindowListener;
34
import org.gvsig.andami.ui.mdiManager.WindowInfo;
35
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
36
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
37
import org.gvsig.raster.mainplugin.RasterMainPluginUtils;
38

  
39
/**
40
 * Dialogo de opciones de sobre la proyecci?n de la capa raster y la vista.
41
 *
42
 * @author Nacho Brodin nachobrodin@gmail.com
43
 */
44
public class RasterProjectionActionsDialog extends JPanel implements IWindow, IWindowListener, ActionListener {
45
	private static final long            serialVersionUID       = 6954391896451933337L;
46
	private RasterProjectionActionsPanel panel                  = null;
47
	private Point                        posWindow              = null;
48
	private int                          widthWindow            = 390;
49
	private int                          heightWindow           = 260;
50
	private boolean                      layerIsReprojectable   = true;
51
	private String                       layerName              = null;
52
	private int                          defaultAction          = RasterDataParameters.NEW_PROJETION_TO_THE_LAYER;
53

  
54
	/**
55
	 * Constructor.
56
	 */
57
	public RasterProjectionActionsDialog(boolean layerIsReprojectable, String layerName, int defaultAction) {
58
		this.layerIsReprojectable = layerIsReprojectable;
59
		this.layerName = layerName;
60
		this.defaultAction = defaultAction;
61
		BorderLayout bl = new BorderLayout();
62
		bl.setHgap(2);
63
		bl.setVgap(2);
64
		setLayout(bl);
65
		add(getRasterProjectionActionsPanel(), BorderLayout.CENTER);
66
		getRasterProjectionActionsPanel().getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT).addActionListener(this);
67
		getRasterProjectionActionsPanel().getButtonsPanel().getButton(ButtonsPanel.BUTTON_CANCEL).addActionListener(this);
68
		getRasterProjectionActionsPanel().getCheckOption().addActionListener(this);
69
		posWindow = RasterMainPluginUtils.iwindowPosition(widthWindow, heightWindow);
70
		PluginServices.getMDIManager().addWindow(this);
71
	}
72
	
73
	public WindowInfo getWindowInfo() {
74
		WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE);
75
		m_viewinfo.setTitle(PluginServices.getText(this, "options"));
76
		m_viewinfo.setHeight(heightWindow);
77
		m_viewinfo.setWidth(widthWindow);
78
		if (posWindow != null) {
79
			m_viewinfo.setX((int) posWindow.getX());
80
			m_viewinfo.setY((int) posWindow.getY());
81
		}
82
		return m_viewinfo;
83
	}
84

  
85
	/**
86
	 * Obtiene el panel con las opciones de proyecci?n
87
	 * @return RasterProjectionActionsPanel
88
	 */
89
	public RasterProjectionActionsPanel getRasterProjectionActionsPanel() {
90
		if (panel == null) {
91
			panel = new RasterProjectionActionsPanel(layerIsReprojectable, layerName, defaultAction);
92
		}
93
		return panel;
94
	}
95

  
96
	/**
97
	 * Obtiene la selecci?n del panel
98
	 * @return entero con la selecci?n. Esta representada por las constantes de la
99
	 *         clase RasterReprojectionPanel.
100
	 */
101
	public int getSelection() {
102
		return getRasterProjectionActionsPanel().getSelection();
103
	}
104
	
105
	/**
106
	 * Obtiene la selecci?n del panel
107
	 * @return entero con la selecci?n. Esta representada por las constantes de la
108
	 *         clase RasterReprojectionPanel.
109
	 */
110
	public boolean getChangeProjectionOption() {
111
		return getRasterProjectionActionsPanel().getCheckOption().isSelected();
112
	}
113

  
114
	public void actionPerformed(ActionEvent e) {
115
		if (e.getSource() == getRasterProjectionActionsPanel().getCheckOption()) {
116
			return;
117
		}
118
		PluginServices.getMDIManager().closeWindow(this);
119
	}
120

  
121
	public void windowClosed() {}
122

  
123
	public void windowActivated() {}
124

  
125
	public Object getWindowProfile() {
126
		return WindowInfo.DIALOG_PROFILE;
127
	}
128
}
0 129

  
org.gvsig.raster.reproject/tags/org.gvsig.raster.reproject-2.2.17/org.gvsig.raster.reproject.app.reprojectclient/src/main/java/org/gvsig/raster/reproject/app/preparelayer/RasterProjectionActionsPanel.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.reproject.app.preparelayer;
23

  
24
import java.awt.BorderLayout;
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27

  
28
import javax.swing.ButtonGroup;
29
import javax.swing.JCheckBox;
30
import javax.swing.JLabel;
31
import javax.swing.JPanel;
32
import javax.swing.JRadioButton;
33

  
34
import org.gvsig.andami.PluginServices;
35
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
36
import org.gvsig.i18n.Messages;
37
import org.gvsig.raster.swing.basepanel.AbstractButtonsPanel;
38
import org.gvsig.raster.swing.basepanel.IButtonsPanel;
39

  
40
/**
41
 * Obtiene el panel con las opciones a realizar con la proyecci?n. Nos ofrece
42
 * las siguientes posibilidades:
43
 * <UL>
44
 * <LI>Cambiar la proyecci?n de la vista</LI>
45
 * <LI>Reproyectar el raster</LI>
46
 * <LI>Ignorar la proyecci?n del raster y cargar</LI>
47
 * <LI>No cargar</LI>
48
 * </UL>
49
 * 
50
 * @author Nacho Brodin nachobrodin@gmail.com
51
 */
52
public class RasterProjectionActionsPanel extends AbstractButtonsPanel {
53
	private static final long serialVersionUID = -3868504818382448187L;
54

  
55
	private JPanel        buttonsPanel           = null;
56
	private ButtonGroup   group                  = new ButtonGroup();
57
	private JRadioButton  changeViewProjection   = null;
58
	private JRadioButton  reproject              = null;
59
	private JRadioButton  ignoreRasterProjection = null;
60
	private JRadioButton  notLoad                = null;
61
	private JRadioButton  onTheFly               = null;
62
	private JCheckBox     allfiles               = null;
63
	private boolean       layerIsReprojectable   = true;
64
	
65
	/**
66
	 * Constructor. Llama al inicializador de componentes gr?ficos.
67
	 */
68
	public RasterProjectionActionsPanel(boolean layerIsReprojectable, String layerName, int defaultAction) {
69
		super(IButtonsPanel.BUTTONS_ACCEPTCANCEL);
70
		this.layerIsReprojectable = layerIsReprojectable;
71
		init(layerName);
72
		setSelection(defaultAction);
73
	}
74
	
75
	/**
76
	 * Inicializaci?n de componentes gr?ficos.
77
	 */
78
	public void init(String lyrName) {
79
		BorderLayout bl = new BorderLayout();
80
		bl.setVgap(5);
81
		setLayout(bl);
82
		add(new JLabel("<html><b>" + lyrName + "</b><BR><BR>" + Messages.getText("dif_proj") + "</html>"), BorderLayout.NORTH);
83
		add(getButtonsActionPanel(), BorderLayout.CENTER);
84
		add(getCheckOption(), BorderLayout.SOUTH);
85
	}
86
		
87
	/**
88
	 * Obtiene el panel con los botones se selecci?n de opci?n.
89
	 * @return JPanel
90
	 */
91
	private JPanel getButtonsActionPanel() {
92
		if (buttonsPanel == null) {
93
			buttonsPanel = new JPanel();
94
			buttonsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, Messages.getText("proj_options"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
95

  
96
			group.add(getIgnoreRasterProjectionButton());
97
			group.add(getChangeViewProjectionButton());
98
			group.add(getReprojectButton());
99
			group.add(getNotLoadButton());
100
			group.add(getOnTheFlyButton());
101

  
102
			buttonsPanel.setLayout(new GridBagLayout());
103
			GridBagConstraints gbc = new GridBagConstraints();
104
			gbc.insets = new java.awt.Insets(0, 5, 5, 0);
105
			
106
			gbc.gridx = 0;
107
			gbc.gridy = 0;
108
			gbc.weightx = 1;
109
			gbc.anchor = GridBagConstraints.WEST;
110
			buttonsPanel.add(getIgnoreRasterProjectionButton(), gbc);
111
			
112
			gbc.gridy = 1;
113
			buttonsPanel.add(getReprojectButton(), gbc);
114
			
115
			gbc.gridy = 2;
116
			buttonsPanel.add(getChangeViewProjectionButton(), gbc);
117
			
118
			gbc.gridy = 3;
119
			buttonsPanel.add(getNotLoadButton(), gbc);
120
			
121
			gbc.gridy = 4;
122
			buttonsPanel.add(getOnTheFlyButton(), gbc);
123
		}
124
		return buttonsPanel;
125
	}
126
	
127
	/**
128
	 * Obtiene el bot?n de cambio de projecci?n de la vista
129
	 * @return
130
	 */
131
	private JRadioButton getChangeViewProjectionButton() {
132
		if(changeViewProjection == null) {
133
			changeViewProjection = new JRadioButton(Messages.getText("change_view_proj"));
134
			
135
			/*IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow();
136
			if (activeWindow instanceof AbstractViewPanel) {		
137
				AbstractViewPanel activeView = (org.gvsig.app.project.documents.view.gui.AbstractViewPanel) activeWindow;
138
				if (activeView.getMapControl().getMapContext().getLayers().getLayersCount() >= 1)
139
					changeViewProjection.setEnabled(false);
140
			}*/
141
		}
142
		return changeViewProjection;
143
	}
144
	
145
	/**
146
	 * Obtiene el bot?n de cambio de reproyecci?n
147
	 * @return
148
	 */
149
	private JRadioButton getReprojectButton() {
150
		if(reproject == null) {
151
			reproject = new JRadioButton(Messages.getText("reproject"));
152
			reproject.setEnabled(layerIsReprojectable);
153
		}
154
		return reproject;
155
	}
156
	
157
	/**
158
	 * Obtiene el bot?n de ignorar la proyecci?n del raster
159
	 * @return
160
	 */
161
	private JRadioButton getIgnoreRasterProjectionButton() {
162
		if(ignoreRasterProjection == null) {
163
			ignoreRasterProjection = new JRadioButton(Messages.getText("ignore_raster_proj"));
164
		}
165
		return ignoreRasterProjection;
166
	}
167
	
168
	/**
169
	 * Obtiene el bot?n de no cargar el raster.
170
	 * @return
171
	 */
172
	private JRadioButton getNotLoadButton() {
173
		if(notLoad == null) {
174
			notLoad = new JRadioButton(Messages.getText("not_load"));
175
		}
176
		return notLoad;
177
	}
178
	
179
	/**
180
	 * Gets the button to reproject on the fly
181
	 * @return
182
	 */
183
	private JRadioButton getOnTheFlyButton() {
184
		if(onTheFly == null) {
185
			onTheFly = new JRadioButton(Messages.getText("reproject_on_the_fly") + " (Not implemented yet)");
186
			onTheFly.setEnabled(false);
187
		}
188
		return onTheFly;
189
	}
190
	
191
	/**
192
	 * Obtiene la selecci?n del panel
193
	 * @return entero con la selecci?n. Esta representada por las constantes de FileOpenRaster.
194
	 */
195
	public int getSelection() {
196
		if (getChangeViewProjectionButton().isSelected())
197
			return RasterDataParameters.REPROJECT_VIEW;
198
		if (getReprojectButton().isSelected())
199
			return RasterDataParameters.REPROJECT_DATA;
200
		if (getIgnoreRasterProjectionButton().isSelected())
201
			return RasterDataParameters.NEW_PROJETION_TO_THE_LAYER;
202
		if (getNotLoadButton().isSelected())
203
			return RasterDataParameters.NOT_LOAD;
204
		if (getOnTheFlyButton().isSelected())
205
			return RasterDataParameters.ON_THE_FLY;
206
		return RasterDataParameters.NEW_PROJETION_TO_THE_LAYER;
207
	}
208
	
209
	/**
210
	 * Asigna una selecci?n de opci?n
211
	 * @param entero con la selecci?n. Esta representada por las constantes de FileOpenRaster.
212
	 */
213
	public void setSelection(int value) {
214
		if (value == RasterDataParameters.NEW_PROJETION_TO_THE_LAYER)
215
			getIgnoreRasterProjectionButton().setSelected(true);
216
		if (value == RasterDataParameters.REPROJECT_DATA)
217
			getReprojectButton().setSelected(true);
218
		if (value == RasterDataParameters.REPROJECT_VIEW)
219
			getChangeViewProjectionButton().setSelected(true);
220
		if (value == RasterDataParameters.NOT_LOAD)
221
			getNotLoadButton().setSelected(true);
222
		if (value == RasterDataParameters.ON_THE_FLY)
223
			getOnTheFlyButton().setSelected(true);
224
	}
225
	
226
	/**
227
	 * Obtiene el check con la opci?n de aplicar a todos los ficheros
228
	 * @return
229
	 */
230
	public JCheckBox getCheckOption() {
231
		if (allfiles == null)
232
			allfiles = new JCheckBox(PluginServices.getText(this, "apply_all"));
233
		return allfiles;
234
	}
235
} 
0 236

  
org.gvsig.raster.reproject/tags/org.gvsig.raster.reproject-2.2.17/org.gvsig.raster.reproject.app.reprojectclient/src/main/java/org/gvsig/raster/reproject/app/preparelayer/ReprojectionQueue.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.reproject.app.preparelayer;
23

  
24
import org.gvsig.fmap.dal.coverage.RasterLocator;
25
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
26
import org.gvsig.raster.algorithm.process.IProcessActions;
27
import org.gvsig.raster.algorithm.process.ProcessException;
28
import org.gvsig.raster.algorithm.process.DataProcess;
29
import org.gvsig.raster.util.Queue;
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32

  
33
/**
34
 * Cola de procesos de ejecuci?n exclusiva. Los procesos de esta lista se ir?n ejecutando
35
 * por orden de llegada impidiendo que se ejecuten dos al mismo tiempo.
36
 * 
37
 * 16/05/2008
38
 * @author Nacho Brodin nachobrodin@gmail.com
39
 */
40
public class ReprojectionQueue extends Thread {
41
	private Queue                     queue                       = new Queue();
42
	private DataProcess             executionProcess            = null;
43
	static private ReprojectionQueue  singleton                   = null;
44
	private Logger                    logger                      = LoggerFactory.getLogger(ReprojectionQueue.class.toString());
45
	
46
	/**
47
	 * Devuelve una instancia al unico objeto de UniqueProcessQueue que puede existir.
48
	 * @return
49
	 */
50
	static public ReprojectionQueue getSingleton() {
51
		if(singleton == null) {
52
			singleton = new ReprojectionQueue();
53
			synchronized (singleton) {
54
				singleton.start();
55
			}
56
		}
57
		return singleton;
58
	}
59
	
60
	public void run() {
61
		//Cuando arranca el thread se duerme porque la cola est? vacia
62
		synchronized (this) {
63
			try {
64
				wait();
65
			} catch (InterruptedException e) {
66
			}
67
		}
68
		
69
		while(true) {
70
			if(queue.size() >= 1) {
71
				Object[] obj = (Object[])queue.get();
72
				executionProcess = ((DataProcess) obj[0]);
73
				if (executionProcess != null) {
74
					executionProcess.showIncrementableWindow();
75
					try {
76
						executionProcess.execute();
77
					} catch (ProcessInterruptedException e) {
78
					} catch (ProcessException e) {
79
						logger.debug(RasterLocator.getManager().getRasterUtils().getTrace(e));
80
					}
81
					executionProcess.getIncrementableTask().processFinalize();
82
					
83
					//Despierta el objeto que llam? cuando termina el calculo
84
					//para que pueda recoger los resultados
85
					synchronized (obj[1]) {
86
						obj[1].notify();	
87
					}
88
					
89
					//Cuando la cola est? vacia se suspende el hilo.
90
					if(queue.size() <= 0) {
91
						synchronized (this) {
92
							try {
93
								this.wait();
94
							} catch (InterruptedException e) {
95
							}
96
						}
97
					}
98
						
99
				}
100
			}
101
		}
102
	}	
103
	
104
	/**
105
	 * A?ade un proceso a la cola.
106
	 * @param id Identificador del proceso
107
	 * @param process Proceso
108
	 * @throws InterruptedException 
109
	 */
110
	public synchronized void add(DataProcess process, IProcessActions obj) {
111
		queue.put(new Object[]{process, obj});
112
	}
113

  
114
}
0 115

  
org.gvsig.raster.reproject/tags/org.gvsig.raster.reproject-2.2.17/org.gvsig.raster.reproject.app.reprojectclient/src/main/java/org/gvsig/raster/reproject/app/FileNameManagementImpl.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.reproject.app;
23

  
24
import java.util.ArrayList;
25
import java.util.List;
26

  
27
import org.gvsig.fmap.dal.coverage.RasterLocator;
28
import org.gvsig.fmap.dal.coverage.util.FileUtils;
29
import org.gvsig.raster.swing.newlayer.FileNameManagement;
30

  
31
/**
32
 * @author Nacho Brodin (nachobrodin@gmail.com)
33
 */
34
public class FileNameManagementImpl implements FileNameManagement {
35
	private FileUtils fileUtils = RasterLocator.getManager().getFileUtils();
36
	
37
	/*
38
	 * (non-Javadoc)
39
	 * @see org.gvsig.raster.swing.newlayer.FileNameManagement#getDefaultFilePath()
40
	 */
41
	public String getDefaultFilePath() {
42
		return System.getProperty("user.home");
43
	}
44

  
45
	/*
46
	 * (non-Javadoc)
47
	 * @see org.gvsig.raster.swing.newlayer.FileNameManagement#getPrefixSupported()
48
	 */
49
	public List<String> getPrefixSupported() {
50
		List<String> list = new ArrayList<String>();
51
		list.add("tif");
52
		return list;
53
	}
54

  
55
	/*
56
	 * (non-Javadoc)
57
	 * @see org.gvsig.raster.swing.newlayer.FileNameManagement#getUniqueLayerName()
58
	 */
59
	public String getUniqueLayerName() {
60
		return fileUtils.getOnlyLayerName();
61
	}
62

  
63
	/*
64
	 * (non-Javadoc)
65
	 * @see org.gvsig.raster.swing.newlayer.FileNameManagement#usesUniqueLayerName()
66
	 */
67
	public void usesUniqueLayerName() {
68
		fileUtils.usesOnlyLayerName();
69
	}
70

  
71
}
0 72

  
org.gvsig.raster.reproject/tags/org.gvsig.raster.reproject-2.2.17/org.gvsig.raster.reproject.app.reprojectclient/src/main/java/org/gvsig/raster/reproject/app/ReprojectionPanelDataModelImpl.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.reproject.app;
23

  
24
import java.awt.geom.Point2D;
25
import java.util.ArrayList;
26
import java.util.List;
27

  
28
import org.cresques.cts.ICoordTrans;
29
import org.cresques.cts.IProjection;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.andami.ui.mdiManager.IWindow;
32
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
33
import org.gvsig.fmap.crs.CRSFactory;
34
import org.gvsig.fmap.dal.coverage.RasterLocator;
35
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
36
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
37
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
38
import org.gvsig.fmap.mapcontext.MapContext;
39
import org.gvsig.fmap.mapcontext.layers.FLayers;
40
import org.gvsig.raster.fmap.layers.FLyrRaster;
41
import org.gvsig.raster.reproject.algorithm.ReprojectProcess;
42
import org.gvsig.raster.reproject.algorithm.swing.api.ReprojectionPanelDataModel;
43

  
44
/**
45
 * Data model for the panel of reprojection
46
 * @author Nacho Brodin (nachobrodin@gmail.com)
47
 */
48
public class ReprojectionPanelDataModelImpl implements ReprojectionPanelDataModel {
49
	private double               cellSize                 = 0;
50
	private IProjection          dstProjection            = null;
51
	private IProjection          srcProjection            = null;
52
	private List<String>         interpolationMethodList  = null;
53
	private int                  interpolationMethod      = 0;
54
	private String               layerName                = null;
55
	private int[]                size                     = new int[]{0, 0};
56
	private FLyrRaster           lyr                      = null;
57
	private Extent               newBbox                  = null;
58
	
59
	public ReprojectionPanelDataModelImpl(FLyrRaster lyr) {
60
		this.lyr = lyr;
61
		cellSize = lyr.getDataStore().getCellSize();
62
		try {
63
			srcProjection = lyr.readProjection();
64
		} catch (RasterDriverException e) {
65
			srcProjection = getViewProjection(lyr);
66
		}
67
		if (srcProjection == null) 
68
			srcProjection = getViewProjection(lyr);
69
		if (srcProjection == null)
70
			srcProjection = CRSFactory.getCRS("EPSG:23030");
71

  
72
		dstProjection = srcProjection;
73
		
74
		layerName = lyr.getName();
75
		size = new int[]{(int)lyr.getDataStore().getWidth(), 
76
						 (int)lyr.getDataStore().getHeight()};
77
		
78
		interpolationMethod = -1;
79
		interpolationMethodList = new ArrayList<String>();
80
		for (int i = 0; i < ReprojectProcess.INTERP_METHODS.length; i++) {
81
			interpolationMethodList.add(ReprojectProcess.INTERP_METHODS[i]);
82
		}
83
		//updateValues(lyr.getDataStore());
84
	}
85
	
86
	/**
87
	 * Gets the projection of the view
88
	 * @param lyr
89
	 * @return
90
	 */
91
	private IProjection getViewProjection(FLyrRaster lyr) {
92
		IWindow[] w = PluginServices.getMDIManager().getAllWindows();
93
		for (int i = 0; i < w.length; i++) {
94
			if(w[i] instanceof AbstractViewPanel) {
95
				MapContext mapContext = ((AbstractViewPanel)w[i]).getMapControl().getMapContext();
96
				FLayers lyrs = mapContext.getLayers();
97
				for (int j = 0; j < lyrs.getLayersCount(); j++) {
98
					if(lyrs.getLayer(j) == lyr) {
99
						return ((AbstractViewPanel)w[i]).getProjection();
100
					}
101
				}
102
			}
103
		}
104
		return null;
105
	}
106
	
107
	private void updateValues(RasterDataStore store) {
108
		//      d1x                 d2x
109
		//   ---------           ---------
110
		//   |  p1x  |           |  p2x  |
111
		//d1y|p1y    |        d2y|p2y    |
112
		//   |       |           |       |
113
		//   ---------           ---------
114
		
115
		ICoordTrans transf = srcProjection.getCT(dstProjection);
116
		Extent bbox = store.getExtent();
117
		Point2D ul = new Point2D.Double(bbox.getULX(), bbox.getULY());
118
		Point2D lr = new Point2D.Double(bbox.getLRX(), bbox.getLRY());
119
		if(transf == null)
120
			return;
121
		ul = transf.convert(ul, ul);
122
		lr = transf.convert(lr, lr);
123
		newBbox = RasterLocator.getManager().getDataStructFactory().createExtent(ul, lr);
124
		
125
		//System.out.println("Old BBox: " + bbox.toString());
126
		//System.out.println("New BBox: " + newBbox.toString());
127
		//System.out.println("Old Pixel Size: " + store.getCellSize());
128
		
129
		//double p1x = store.getWidth();
130
		//double p1y = store.getHeight();
131
		//System.out.println("Old WxH: " + p1x + " " + p1y + " --- " + (p1x / p1y) + "  " + (p1y / p1x));
132
		
133
		//long nPixels = (long)(store.getWidth() * store.getHeight());
134
		double sumSideOldBBox = bbox.width() + bbox.height();
135
		double sumSideNewBBox = newBbox.width() + newBbox.height();
136
		double d1x = (bbox.width() * 100) / sumSideOldBBox; 
137
		double d1y = (bbox.height() * 100) / sumSideOldBBox;
138
		double d2x = (newBbox.width() * 100) / sumSideNewBBox;
139
		double d2y = (newBbox.height() * 100) / sumSideNewBBox;
140
		//System.out.println("Old nPixels: " + nPixels);
141
		//System.out.println("d1x: " + d1x + " d1y: " + d1y + " d2x: " + d2x + " d2y: " + d2y);
142
		double p2y = (store.getHeight() * d2y) / d1y;
143
		double p2x = (store.getWidth() * d2x) / d1x;
144
		//long newNPixels = (long)(p2x * p2y);
145
		//System.out.println("New nPixels: " + newNPixels);
146
		//System.out.println("New WxH: " + p2x + " " + p2y + " --- " + (p2x / p2y) + "  " + (p2y / p2x));
147
		double newCellSize = newBbox.width() / p2x;
148
		
149
		size[0] = (int)Math.round(p2x);
150
		size[1] = (int)Math.round(p2y);
151
		cellSize = newCellSize;
152
		//double newCellSizeY = newBbox.height() / p2y;
153
		//System.out.println("New Pixel Size: " + newCellSize + " " + newCellSizeY);
154
	}
155
	
156
	public double getCellSize() {
157
		return cellSize;
158
	}
159

  
160
	public IProjection getDstProjection() {
161
		return dstProjection;
162
	}
163

  
164
	public List<String> getInterpolationMethodList() {
165
		return interpolationMethodList;
166
	}
167

  
168
	public int getInterpolationMethodSelected() {
169
		return interpolationMethod;
170
	}
171

  
172
	public String getLayerName() {
173
		return layerName;
174
	}
175

  
176
	public int[] getSize() {
177
		return size;
178
	}
179

  
180
	public IProjection getSrcProjection() {
181
		return srcProjection;
182
	}
183

  
184
	public void setCellSize(double cellSize) {
185
		this.cellSize = cellSize;
186
		size[0] = (int)(newBbox.width() / cellSize);
187
		size[1] = (int)(newBbox.height() / cellSize);
188
	}
189

  
190
	public void setDstProjection(IProjection dst) {
191
		this.dstProjection = dst;
192
		updateValues(lyr.getDataStore());
193
	}
194
	
195
	public void setSrcProjection(IProjection src) {
196
		this.srcProjection = src;
197
		updateValues(lyr.getDataStore());
198
	}
199

  
200
	public void setInterpolationMethodList(List<String> list) {
201
		this.interpolationMethodList = list;
202
	}
203

  
204
	public void setInterpolationMethodSelected(int method) {
205
		this.interpolationMethod = method;
206
	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff