Revision 2010

View differences:

org.gvsig.raster.reproject/tags/buildNumber_41/org.gvsig.raster.reproject.app.reprojectclient/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Wed May 15 12:24:42 CEST 2013
3
buildNumber=41
0 4

  
org.gvsig.raster.reproject/tags/buildNumber_41/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/buildNumber_41/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
				<!-- 
35
				Ojo! no incluir estos ya que los pone app.basic
36
				<include>org.gvsig:org.gvsig.raster.tools.algorithm.base:jar</include>
37
				<include>org.gvsig:org.gvsig.raster.tools.algorithm.swing.api:jar</include>
38
				<include>org.gvsig:org.gvsig.raster.tools.algorithm.swing.impl:jar</include>
39
				-->
40
	  </includes>
41
	</dependencySet>
42
  </dependencySets>
43
</assembly>
0 44

  
org.gvsig.raster.reproject/tags/buildNumber_41/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/buildNumber_41/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
	}
207

  
208
	public void setLayerName(String layerName) {
209
		this.layerName = layerName;
210
	}
211

  
212
	public void setSize(int w, int h) {
213
		this.size = new int[]{w, h};
214
	}
215
}
0 216

  
org.gvsig.raster.reproject/tags/buildNumber_41/org.gvsig.raster.reproject.app.reprojectclient/src/main/java/org/gvsig/raster/reproject/app/ReprojectListener.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.Component;
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27
import java.io.File;
28
import java.util.HashMap;
29

  
30
import javax.swing.JOptionPane;
31

  
32
import org.cresques.cts.IProjection;
33
import org.gvsig.andami.PluginServices;
34
import org.gvsig.andami.ui.mdiManager.IWindow;
35
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
36
import org.gvsig.fmap.mapcontext.layers.FLayer;
37
import org.gvsig.fmap.mapcontext.layers.FLayers;
38
import org.gvsig.i18n.Messages;
39
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary;
40
import org.gvsig.raster.algorithm.process.IProcessActions;
41
import org.gvsig.raster.algorithm.process.ProcessException;
42
import org.gvsig.raster.algorithm.process.RasterProcess;
43
import org.gvsig.raster.fmap.layers.FLyrRaster;
44
import org.gvsig.raster.reproject.algorithm.ReprojectProcess;
45
import org.gvsig.raster.reproject.algorithm.swing.api.RasterReprojectionPanel;
46
import org.gvsig.raster.reproject.algorithm.swing.api.ReprojectionPanelDataModel;
47
import org.gvsig.raster.tools.algorithm.swing.reproject.RasterReprojectPanel;
48
import org.gvsig.raster.tools.app.basic.RasterToolsUtil;
49
import org.gvsig.raster.tools.app.basic.raster.bean.endinfo.EndInfoDialog;
50
import org.gvsig.raster.util.RasterNotLoadException;
51

  
52

  
53
/**
54
 * Actions for the reprojection panel
55
 * 
56
 * @author Nacho Brodin (nachobrodin@gmail.com)
57
 */
58
public class ReprojectListener implements ActionListener, IProcessActions {
59
	private RasterReprojectionPanel            reprojectPanel   = null;
60
	private FLayer                             lyr              = null;
61
	private ReprojectionPanelDataModel         dataModel        = null;
62
	private ReprojectWindow                    window           = null;
63

  
64
	public ReprojectListener(FLayer lyr, ReprojectionPanelDataModel dataModel, ReprojectWindow window, RasterReprojectionPanel reprojectPanel) {
65
		this.lyr = lyr;
66
		this.dataModel = dataModel;
67
		this.window = window;
68
		this.reprojectPanel = reprojectPanel;
69
	}
70

  
71
	public void actionPerformed(ActionEvent e) {
72
		if(reprojectPanel.getObjectSelected(e.getSource()) == RasterReprojectPanel.BUTTON_ACCEPT) {
73
			double cellsize = dataModel.getCellSize();
74
			int w = dataModel.getSize()[0];
75
			int h = dataModel.getSize()[1];
76
			IProjection srcPrj = dataModel.getSrcProjection();
77
			IProjection dstPrj = dataModel.getDstProjection();
78
			
79
			if(cellsize <= 0 || w <= 0 || h <= 0) {
80
				messageBoxError("wrong_size");
81
				return;
82
			}
83
			
84
			if(srcPrj == null || dstPrj == null) {
85
				messageBoxError("wrong_projection");
86
				return;
87
			}
88
			
89
			RasterProcess process;
90
			try {
91
				process = RasterBaseAlgorithmLibrary.getManager().createRasterTask("RasterReprojectionProcess");
92
			} catch (ProcessException e1) {
93
				messageBoxError("error_creating_algorithm");
94
				return;
95
			}
96
			
97
			String path = getPath();
98
			if(path == null)
99
				return;
100
			
101
			process.setActions(this);
102
			process.addParam(ReprojectProcess.RASTER_STORE, ((FLyrRaster)lyr).getDataStore());
103
			process.addParam(ReprojectProcess.SIZEX, w);
104
			process.addParam(ReprojectProcess.SIZEY, h);
105
			process.addParam(ReprojectProcess.PATH, path);
106
			process.addParam(ReprojectProcess.SRC_PROJECTION, dataModel.getSrcProjection());
107
			process.addParam(ReprojectProcess.DST_PROJECTION, dataModel.getDstProjection());
108
			process.addParam(ReprojectProcess.CELLSIZE, dataModel.getCellSize());
109
			process.addParam(ReprojectProcess.INTERPOLATION, dataModel.getInterpolationMethodSelected());
110
			process.start();
111
			
112
		}
113
		if(reprojectPanel.getObjectSelected(e.getSource()) == RasterReprojectPanel.BUTTON_CANCEL) {
114
			if(window != null) {
115
				PluginServices.getMDIManager().closeWindow(window);
116
				window = null;
117
			}
118
		}
119
	}
120
	
121
	/**
122
	 * Gets the path to the file
123
	 * @return
124
	 */
125
	private String getPath() {
126
		String file = reprojectPanel.getFileSelected();
127
		if(file == null || file.equals("") || !file.matches("[a-zA-Z0-9_]*")) {
128
			messageBoxError(
129
					Messages.getText("file_name_not_valid") + 
130
					"\n" + file + "\n " + 
131
					Messages.getText("valid_characters") + 
132
					" a-zA-Z0-9_");
133
			return null;
134
		}
135
		
136
		if(!file.endsWith(".tif"))
137
			file += ".tif";
138
		String dir = reprojectPanel.getDirectorySelected();
139
		if(!new File(dir).exists()) {
140
			messageBoxError("directory_does_not_exists");
141
			return null;
142
		}
143
		
144
		if(new File(dir + File.separator + file).exists()) {
145
			if(!RasterToolsUtil.messageBoxYesOrNot(
146
					Messages.getText("file_exists") + 
147
					"\n " + (dir + File.separator + file) + "\n " + 
148
					Messages.getText("overwrite"), null))
149
			return null;
150
		}
151
		return (dir + File.separator + file);
152
	}
153
	
154
	/**
155
	 * Shows an error dialog with a text and a accept button 
156
	 * @param msg Message to show in the dialog
157
	 * @param parentWindow Parent window
158
	 */
159
	public static void messageBoxError(String msg) {
160
		String string = Messages.getText("accept");
161
		Object[] options = {string};
162
		JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(),
163
					"<html>" + Messages.getText(msg).replaceAll("\n", "<br>") + "</html>",
164
					Messages.getText("confirmacion"),
165
					JOptionPane.OK_OPTION,
166
					JOptionPane.ERROR_MESSAGE,
167
					null,
168
					options,
169
					string);
170
	}
171

  
172
	@SuppressWarnings("unchecked")
173
	public void end(Object params) {
174
		if(window != null) {
175
			PluginServices.getMDIManager().closeWindow(window);
176
			window = null;
177
		}
178
		if(params instanceof HashMap<?, ?>) {
179
			HashMap<String, Object>  map = (HashMap<String, Object>) params;
180
			String fName = (String)map.get(ReprojectProcess.FILENAME);
181
			long milis = (Long)map.get(ReprojectProcess.TIME);
182
			processFinalize(fName, milis);
183
			EndInfoDialog.show(fName, milis);
184
		}
185

  
186
	}
187
	
188
	/**
189
	 * Acciones que se realizan al finalizar de crear los recortes de imagen.
190
	 * Este m?todo es llamado por el thread TailRasterProcess al finalizar.
191
	 */
192
	private void processFinalize(String fileName, long milis) {
193
		if (!new File(fileName).exists())
194
			return;
195

  
196
		String viewName = getViewName();
197
		if(viewName != null) {
198
			if (RasterToolsUtil.messageBoxYesOrNot("cargar_toc", this)) {
199
				try {
200
					RasterToolsUtil.loadLayer(viewName, fileName, null);
201
				} catch (RasterNotLoadException e) {
202
					messageBoxError("error_load_layer");
203
				}
204
			}
205
		}
206
	}
207
	
208
	/**
209
	 * Gets the view 
210
	 * @return
211
	 */
212
	private String getViewName() {
213
		IWindow[] w = PluginServices.getMDIManager().getAllWindows();
214
		for (int i = 0; i < w.length; i++) {
215
			if(w[i] instanceof AbstractViewPanel) {
216
				FLayers lyrs = ((AbstractViewPanel)w[i]).getMapControl().getMapContext().getLayers();
217
				for (int j = 0; j < lyrs.getLayersCount(); j++) {
218
					FLayer lyr = lyrs.getLayer(j);
219
					if(this.lyr == lyr) {
220
						return PluginServices.getMDIManager().getWindowInfo((AbstractViewPanel) w[i]).getTitle();
221
					}
222
				}
223
			}
224
		}
225
		return null;
226
	}
227

  
228
	public void interrupted() {
229
	}
230
}
0 231

  
org.gvsig.raster.reproject/tags/buildNumber_41/org.gvsig.raster.reproject.app.reprojectclient/src/main/java/org/gvsig/raster/reproject/app/ReprojectWindow.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.reproject.app;
22

  
23
import java.awt.BorderLayout;
24

  
25
import javax.swing.JComponent;
26
import javax.swing.JPanel;
27

  
28
import org.gvsig.andami.ui.mdiManager.IWindow;
29
import org.gvsig.andami.ui.mdiManager.WindowInfo;
30

  
31

  
32
/**
33
 * @author Nacho Brodin (nachobrodin@gmail.com)
34
 */
35
public class ReprojectWindow extends JPanel implements IWindow {
36
    
37
    private static final long serialVersionUID = -4401123724140025094L;
38

  
39
    private WindowInfo info;
40

  
41
    private Object profile = WindowInfo.EDITOR_PROFILE;
42

  
43
    public ReprojectWindow(JComponent panel, String title, int w, int h) {
44
        this.setLayout(new BorderLayout());
45
        add(panel, BorderLayout.CENTER);
46

  
47
        info = new WindowInfo(WindowInfo.PALETTE | WindowInfo.RESIZABLE);
48
        info.setTitle(title);
49
        info.setWidth(w);
50
        info.setHeight(h);
51
    }
52

  
53
    public WindowInfo getWindowInfo() {
54
        return info;
55
    }
56

  
57
    public Object getWindowProfile() {
58
        return profile;
59
    }
60
}
0 61

  
org.gvsig.raster.reproject/tags/buildNumber_41/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

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

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

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

  
172
		return lyrRaster;
173
	}
174
	
175
	@SuppressWarnings("unchecked")
176
	private RasterDataParameters reproject(FLyrRaster lyrRaster, IProjection dstProj) {
177
		RasterDataParameters params = (RasterDataParameters)lyrRaster.getDataStore().getParameters();
178
		int repOption = params.getReprojectionOption();
179

  
180
		if(repOption == RasterDataParameters.REPROJECT_DATA) {
181
			try {
182
				IProjection srcProj = readProjection(lyrRaster.getDataStore());
183
				if(srcProj == null)
184
					return null;
185

  
186
				String uri = params.getURI();
187
				uri = uri.substring(0, uri.lastIndexOf(".")) + "_" + dstProj.getAbrev() + uri.substring(uri.lastIndexOf("."));
188
				uri = uri.replace(':', '_');
189

  
190
				if(!new File(uri).exists()) {					
191
					RasterProcess process = null;
192
					try {
193
						process = RasterBaseAlgorithmLibrary.getManager().createRasterTask("RasterReprojectionProcess");
194
					} catch (ProcessException e1) {
195
						RasterToolsUtil.messageBoxError("error_creating_algorithm", null, e1);
196
						return params;
197
					}
198
					process.setActions(this);
199
					process.addParam(ReprojectProcess.RASTER_STORE, lyrRaster.getDataStore());
200
					process.addParam(ReprojectProcess.SIZEX, 0); //Calculo autom?tico de tama?o
201
					process.addParam(ReprojectProcess.SIZEY, 0);
202
					process.addParam(ReprojectProcess.PATH, uri);
203
					process.addParam(ReprojectProcess.SRC_PROJECTION, srcProj);
204
					process.addParam(ReprojectProcess.DST_PROJECTION, dstProj);
205
					process.addParam(ReprojectProcess.CELLSIZE, lyrRaster.getDataStore().getCellSize());
206

  
207
					//Despierta la cola que reproyecta im?genes
208
					synchronized (queue) {
209
						queue.add(process, this);	
210
						queue.notify();
211
					}
212

  
213
					//Se suspende hasta que la cola haya terminado
214
					try {
215
						synchronized (this) {
216
							this.wait();
217
						}
218
					} catch (InterruptedException e) {
219
					}
220
					
221
					if(process.getResult() != null) {
222
						HashMap<String, Object> map = (HashMap<String, Object>)process.getResult();
223
						String filename = (String)map.get(ReprojectProcess.FILENAME);
224
						params.setURI(filename);
225
						return params;
226
					}
227
				} else {
228
					params.setURI(uri);
229
					return params;
230
				}
231
				
232
			} catch (RasterDriverException e) {
233
				RasterToolsUtil.messageBoxError("Error creating layer", null, e);
234
			} 
235
		} else if(repOption == RasterDataParameters.REPROJECT_VIEW) {
236
			//Esto se cambia en el prepare que tiene acceso al mapcontrol. Este prepare es a nivel de datos
237
		} 
238
		return null;
239
	}
240

  
241
	public void end(Object param) {
242
		
243
	}
244

  
245
	/**
246
	 * Compares two projections and show a dialog to the user to make a decision
247
	 * @param lyrProj
248
	 * @param viewProj
249
	 */
250
	private void compareProjections(IProjection lyrProj, IProjection viewProj, RasterDataStore dataStore) {
251
		if(!getChangeOption() || lyrProj == null || viewProj == null) {
252
			((RasterDataParameters)dataStore.getParameters()).setReprojectionOption(lastReprojectionOption);
253
			return;
254
		}
255

  
256
		/*
257
		 * Si las proyecciones de vista y raster son distintas se lanza el
258
		 * dialogo de selecci?n de opciones. Este dialogo solo se lanza en caso
259
		 * de que el checkbox de aplicar a todos los ficheros no haya sido
260
		 * marcado. En este caso para el resto de ficheros de esa selecci?n se
261
		 * har? la misma acci?n que se hizo para el primero.
262
		 */
263
		if (!viewProj.getAbrev().endsWith(lyrProj.getAbrev())) {
264
			String layerName = dataStore.getName().substring(dataStore.getName().lastIndexOf(File.separator) + 1, dataStore.getName().length());
265
			RasterProjectionActionsDialog dialog = new RasterProjectionActionsDialog(
266
					dataStore.isReproyectable(), layerName, RasterDataParameters.REPROJECT_VIEW);
267
			if (dialog != null) {
268
				lastReprojectionOption = dialog.getRasterProjectionActionsPanel().getSelection();
269
				((RasterDataParameters)dataStore.getParameters()).setReprojectionOption(lastReprojectionOption);
270
				setChangeOption(!dialog.getChangeProjectionOption());
271
			}
272
		}
273
	}
274
	
275
	/**
276
	 * Reads the projection from a DataStore
277
	 * @param dataStore
278
	 * @return
279
	 * @throws RasterDriverException
280
	 */
281
	private IProjection readProjection(RasterDataStore dataStore) throws RasterDriverException {
282
		try {
283
			crsUtil.setCRSFactory(CRSFactory.cp);
284
			if( dataStore == null )
285
				return null;
286
			return crsUtil.convertWktToIProjection(dataStore.getWktProjection());
287
		} catch (Exception e) {
288
			throw new RasterDriverException("Problems converting from WKT to IProjection", e);
289
		} catch (Error e) {
290
			e.printStackTrace();
291
			return null;
292
		}
293
	}
294

  
295
	public String getDescription() {
296
		return "Prepare projection for Raster Layer";
297
	}
298

  
299
	public String getName() {
300
		return "PrepareRasterLayerProjection";
301
	}
302

  
303
	public Object create() {
304
		return this;
305
	}
306

  
307
	public Object create(Object[] args) {
308
		return this;
309
	}
310

  
311
	@SuppressWarnings("unchecked")
312
	public Object create(Map args) {
313
		return this;
314
	}
315

  
316
	public void interrupted() {
317
	}
318
}
0 319

  
org.gvsig.raster.reproject/tags/buildNumber_41/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.tools.ToolsLocator;
38
import org.gvsig.tools.extensionpoint.ExtensionBuilder;
39
import org.gvsig.tools.extensionpoint.ExtensionPoint;
40
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
41

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

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

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

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

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

  
org.gvsig.raster.reproject/tags/buildNumber_41/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 org.gvsig.andami.IconThemeHelper;
27
import org.gvsig.andami.PluginServices;
28
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
29
import org.gvsig.app.project.documents.view.toc.ITocItem;
30
import org.gvsig.fmap.mapcontext.layers.FLayer;
31
import org.gvsig.i18n.Messages;
32
import org.gvsig.raster.fmap.layers.FLyrRaster;
33
import org.gvsig.raster.fmap.layers.IRasterLayerActions;
34
import org.gvsig.raster.reproject.algorithm.RasterReprojectionSwingLocator;
35
import org.gvsig.raster.reproject.algorithm.swing.api.RasterReprojectionPanel;
36
import org.gvsig.raster.reproject.algorithm.swing.api.ReprojectionPanelDataModel;
37
import org.gvsig.raster.swing.newlayer.FileNameManagement;
38
import org.gvsig.raster.tools.app.basic.raster.gui.IGenericToolBarMenuItem;
39

  
40

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

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

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

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

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

  
75
	/*
76
	 *  (non-Javadoc)
77
	 * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#isEnabled(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
78
	 */
79
	public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
80
		return true;
81
	}
82

  
83
	/*
84
	 *  (non-Javadoc)
85
	 * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#isVisible(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
86
	 */
87
	public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
88
		if ((selectedItems == null) || (selectedItems.length != 1))
89
			return false;
90

  
91
		if (!(selectedItems[0] instanceof IRasterLayerActions))
92
			return false;
93

  
94
		return ((IRasterLayerActions) selectedItems[0]).isActionEnabled(IRasterLayerActions.REPROJECT);
95
	}
96

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

  
122
	public void interrupted() {
123
		
124
	}
125
}
0 126

  
org.gvsig.raster.reproject/tags/buildNumber_41/org.gvsig.raster.reproject.app.reprojectclient/src/main/resources-plugin/text.properties
1
reproject_layer=Reproyectar
2
reprojection=Reproyecci?n
3
wrong_size=Tama?o incorrecto en la imagen de salida
4
wrong_projection=Proyecci?n incorrecta
5
error_creating_algorithm=Error construyendo el objeto algoritmo
6
directory_does_not_exists=El directorio de destino no existe
7
file_name_not_valid=Nombre de fichero no v?lido
8
file_exists=El fichero de salida existe
9
overwrite=Quieres sobreescribirlo?
10
valid_characters=Caracteres validos
0 11

  
org.gvsig.raster.reproject/tags/buildNumber_41/org.gvsig.raster.reproject.app.reprojectclient/src/main/resources-plugin/text_en.properties
1
reproject_layer=Reproject
2
reprojection=Reprojection
3
wrong_size=Wrong size in output image
4
wrong_projection=Wrong projection
5
error_creating_algorithm=Error building the algorithm object
6
directory_does_not_exists=The destination directory does not exists
7
file_name_not_valid=File name not valid
8
file_exists=The output file exists
9
overwrite=Do you want overwrite it?
10
valid_characters=Valid characters
0 11

  
org.gvsig.raster.reproject/tags/buildNumber_41/org.gvsig.raster.reproject.app.reprojectclient/src/main/resources-plugin/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<plugin-config>
3
	<depends plugin-name="org.gvsig.raster.tools.app.basic" />
4
	<resourceBundle name="text"/>
5
	<libraries library-dir="lib"/>
6
	<extensions>
7
		<extension class-name="org.gvsig.raster.reproject.app.ReprojectExtension"
8
			description="Reproject plugin for raster" 
9
			active="true" 
10
			priority="1">
11
			
12
			<menu text="Layer/reproject_layer"
13
				name="raster-tools-reproject-layer"/>
14
				
15
			<action 
16
        		name="raster-tools-reproject-layer"
17
        		label="reproject_layer"
18
        		tooltip="reproject_layer"
19
        		action-command="Reproject" 
20
        		icon="tools-raster-reproject"
21
        		position="0"
22
        		accelerator="Ctrl+Alt+R"
23
        	/>
24
				
25
		</extension>	
26
	</extensions>
27
</plugin-config>
0 28

  
org.gvsig.raster.reproject/tags/buildNumber_41/org.gvsig.raster.reproject.app.reprojectclient/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<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">
4
	<modelVersion>4.0.0</modelVersion>
5
	<artifactId>org.gvsig.raster.reproject.app.reprojectclient</artifactId>
6
	<packaging>jar</packaging>
7
	<name>Reprojection support</name>
8
	<description>Reprojection support</description>
9
	
10
    <parent>
11
        <groupId>org.gvsig</groupId>
12
        <artifactId>org.gvsig.raster.reproject</artifactId>
13
        <version>2.1.0-SNAPSHOT</version>
14
    </parent>
15
    
16
    <dependencies>
17
	    <dependency>
18
            <groupId>org.gvsig</groupId>
19
            <artifactId>org.gvsig.raster.lib.api</artifactId>
20
            <scope>compile</scope>
21
        </dependency>
22
		 <dependency>
23
            <groupId>org.gvsig</groupId>
24
            <artifactId>org.gvsig.ui</artifactId>
25
            <scope>compile</scope>
26
        </dependency>
27
		<dependency>
28
            <groupId>org.gvsig</groupId>
29
            <artifactId>org.gvsig.raster.algorithm</artifactId>
30
        </dependency>
31
        <dependency>
32
            <groupId>org.gvsig</groupId>
33
            <artifactId>org.gvsig.raster.reproject.algorithm</artifactId>
34
        </dependency>
35
        <dependency>
36
			<groupId>org.gvsig</groupId>
37
			<artifactId>org.gvsig.raster.fmap</artifactId>
38
            <scope>compile</scope>
39
		</dependency>
40
		<dependency>
41
			<groupId>org.gvsig</groupId>
42
			<artifactId>org.gvsig.app.mainplugin</artifactId>
43
            <scope>compile</scope>
44
		</dependency>
45
		<dependency>
46
			<groupId>org.gvsig</groupId>
47
			<artifactId>org.gvsig.raster.tools.app.basic</artifactId>
48
            <scope>compile</scope>
49
		</dependency>
50
         <dependency>
51
            <groupId>org.gvsig</groupId>
52
            <artifactId>org.gvsig.fmap.control</artifactId>
53
            <scope>compile</scope>
54
        </dependency>
55
         <dependency>
56
            <groupId>org.gvsig</groupId>
57
            <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
58
            <scope>compile</scope>
59
        </dependency>
60
        <dependency>
61
            <groupId>org.gvsig</groupId>
62
            <artifactId>org.gvsig.andami</artifactId>
63
            <scope>compile</scope>
64
        </dependency>
65
        <dependency>
66
            <groupId>org.gvsig</groupId>
67
            <artifactId>org.gvsig.i18n</artifactId>
68
            <scope>compile</scope>
69
        </dependency>
70
        <dependency>
71
            <groupId>org.gvsig</groupId>
72
            <artifactId>org.gvsig.tools.lib</artifactId>
73
            <scope>compile</scope>
74
        </dependency>
75
        
76
        
77
        <dependency>
78
            <groupId>org.gvsig</groupId>
79
            <artifactId>org.gvsig.fmap.dal.api</artifactId>
80
            <scope>compile</scope>
81
        </dependency>
82
        <dependency>
83
            <groupId>org.gvsig</groupId>
84
            <artifactId>org.gvsig.fmap.dal.impl</artifactId>
85
            <scope>compile</scope>
86
        </dependency>
87
        <dependency>
88
            <groupId>org.gvsig</groupId>
89
            <artifactId>org.gvsig.fmap.dal.spi</artifactId>
90
            <scope>compile</scope>
91
        </dependency>
92
        <dependency>
93
            <groupId>org.gvsig</groupId>
94
            <artifactId>org.gvsig.fmap.mapcontext.api</artifactId>
95
            <scope>compile</scope>
96
        </dependency>
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff