Revision 5246

View differences:

org.gvsig.raster.reproject/tags/org.gvsig.raster.reproject-2.2.28/org.gvsig.raster.reproject.app.reprojectclient/buildNumber.properties
1
#Wed Feb 17 00:44:15 CET 2016
2
buildNumber=80
0 3

  
org.gvsig.raster.reproject/tags/org.gvsig.raster.reproject-2.2.28/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.28/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.mainplugin" />
4
	
5
	<depends plugin-name="org.gvsig.geoprocess.app.mainplugin" optional="true" />
6
	<depends plugin-name="org.gvsig.geoprocess.app.algorithm" optional="true" />
7
	
8
	<resourceBundle name="text"/>
9
	<libraries library-dir="lib"/>
10
	<extensions>
11
		<extension class-name="org.gvsig.raster.reproject.app.ReprojectExtension"
12
			description="Reproject plugin for raster" 
13
			active="true" 
14
			priority="1">
15
			
16
			<menu text="Layer/transformaciones_geograficas/reproject_layer"
17
				name="raster-tools-reproject-layer"/>
18
				
19
			<action 
20
        		name="raster-tools-reproject-layer"
21
        		label="reproject_layer"
22
        		tooltip="reproject_layer"
23
        		action-command="Reproject" 
24
        		icon="tools-raster-reproject"
25
        		position="000601800"
26
        		accelerator="Ctrl+Alt+R"
27
        	/>
28
				
29
		</extension>	
30
	</extensions>
31
</plugin-config>
0 32

  
org.gvsig.raster.reproject/tags/org.gvsig.raster.reproject-2.2.28/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
11
toc_reproject=Reproyectar capa
12
dif_proj_with_projections=La proyecci\u00f3n del raster seleccionado no coincide con la de la vista.
13
view_proj=Proyecci\u00f3n de la vista
14
layer_proj=Proyecci\u00f3n de la capa
0 15

  
org.gvsig.raster.reproject/tags/org.gvsig.raster.reproject-2.2.28/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
11
toc_reproject=Reproject layer
12
dif_proj_with_projections=Projection of selected raster is diferent<br>that view projection.
13
view_proj=View projection
14
layer_proj=View projection
0 15

  
org.gvsig.raster.reproject/tags/org.gvsig.raster.reproject-2.2.28/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.28/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/org.gvsig.raster.reproject-2.2.28/org.gvsig.raster.reproject.app.reprojectclient/src/main/java/org/gvsig/raster/reproject/app/toolbox/ReprojectToolboxAction.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25

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

  
28
import javax.swing.ImageIcon;
29

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

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

  
55
	@Override
56
	public String getName() {
57
		return Messages.getText("reproject_layer");
58
	}
59

  
60
	public ImageIcon getIcon() {
61
		return (ImageIcon)ReprojectTocMenuEntry.getSingleton().getIcon();
62
	}
63
	
64
	public boolean isPluginInstalled() {
65
		try {
66
			ReprojectTocMenuEntry.getSingleton();
67
		} catch(Exception e) {
68
			return false;
69
		} catch(Error e) {
70
			return false;
71
		}
72
		return true;
73
	}
74
}
0 75

  
org.gvsig.raster.reproject/tags/org.gvsig.raster.reproject-2.2.28/org.gvsig.raster.reproject.app.reprojectclient/src/main/java/org/gvsig/raster/reproject/app/toolbox/AbstractToolboxAction.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.raster.reproject.app.toolbox;
26

  
27
import org.gvsig.andami.PluginServices;
28
import org.gvsig.andami.ui.mdiManager.IWindow;
29
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
30
import org.gvsig.fmap.mapcontext.MapContext;
31
import org.gvsig.fmap.mapcontext.layers.FLayers;
32
import org.gvsig.geoprocess.lib.sextante.dataObjects.FLyrRasterIRasterLayer;
33
import org.gvsig.i18n.Messages;
34
import org.gvsig.raster.fmap.layers.FLyrRaster;
35
import org.gvsig.raster.swing.RasterSwingLibrary;
36

  
37
import es.unex.sextante.dataObjects.IRasterLayer;
38
import es.unex.sextante.gui.core.SextanteGUI;
39
import es.unex.sextante.gui.core.ToolboxAction;
40

  
41
/**
42
 * Base class for toolBox actions
43
 *
44
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
45
 */
46
public abstract class AbstractToolboxAction extends ToolboxAction {
47
	protected FLyrRaster             lyr = null;
48

  
49
	@Override
50
	public String getGroup() {
51
		return Messages.getText("group_tools");
52
	}
53

  
54

  
55
	@Override
56
	public boolean isActive() {
57
		IWindow[] windows = PluginServices.getMDIManager().getAllWindows();
58
		for (int i = 0; i < windows.length; i++) {
59
			if(windows[i] instanceof AbstractViewPanel) {
60
				FLayers lyrs = ((AbstractViewPanel)windows[i]).getMapControl().getMapContext().getLayers();
61
				for (int j = 0; j < lyrs.getLayersCount(); j++) {
62
					if(lyrs.getLayer(j) instanceof FLyrRaster)
63
						return true;
64
				}
65
			}
66
		}
67
		return false;
68
	}
69

  
70
	/**
71
	 * Returns true if the plugin which gives the functionality is installed
72
	 * in gvSIG
73
	 * @return
74
	 */
75
	public abstract boolean isPluginInstalled();
76

  
77
	/**
78
	 * Loads the raster layer for the tool
79
	 * @return
80
	 */
81
	public boolean loadLayer() {
82
		if(!isPluginInstalled()) {
83
			RasterSwingLibrary.messageBoxError(Messages.getText("plugin_not_installed"), null);
84
			return false;
85
		}
86

  
87
		if(!isActive()) {
88
			RasterSwingLibrary.messageBoxError(Messages.getText("layer_not_valid"), null);
89
			return false;
90
		}
91

  
92
		boolean existsRasterButNotActive = false;
93
		lyr = null;
94
		IWindow[] windows = PluginServices.getMDIManager().getOrderedWindows();
95
		MapContext mapCtx = null;
96
		for (int i = 0; i < windows.length; i++) {
97
			if(windows[i] instanceof AbstractViewPanel) {
98
				mapCtx = ((AbstractViewPanel)windows[i]).getMapControl().getMapContext();
99
				break;
100
			}
101
		}
102

  
103
		IRasterLayer[] layers = SextanteGUI.getInputFactory().getRasterLayers();
104
		for (int i = 0; i < layers.length; i++) {
105
			FLyrRaster l = (FLyrRaster)((FLyrRasterIRasterLayer)layers[i]).getBaseDataObject();
106
			existsRasterButNotActive = true;
107
			if(l.isActive() && mapCtx == l.getMapContext()) {
108
				existsRasterButNotActive = false;
109
				lyr = l;
110
				break;
111
			}
112
		}
113

  
114
		if(existsRasterButNotActive) {
115
			RasterSwingLibrary.messageBoxError(Messages.getText("raster_layer_not_active"), null);
116
			return false;
117
		}
118

  
119
		return true;
120
	}
121

  
122
}
0 123

  
org.gvsig.raster.reproject/tags/org.gvsig.raster.reproject-2.2.28/org.gvsig.raster.reproject.app.reprojectclient/src/main/java/org/gvsig/raster/reproject/app/toolbox/ToolboxReprojectLoader.java
1
package org.gvsig.raster.reproject.app.toolbox;
2

  
3
import java.lang.reflect.Constructor;
4
import java.lang.reflect.InvocationTargetException;
5

  
6
import org.slf4j.Logger;
7
import org.slf4j.LoggerFactory;
8

  
9
/**
10
 * Loader for this tool in the toolbox dialog
11
 * 
12
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
13
 */
14
public class ToolboxReprojectLoader {
15
	private Logger log      = LoggerFactory.getLogger(ToolboxReprojectLoader.class); 
16
	private String errorMsg = "The reprojection tool are not been added in the toolbox";
17

  
18
	public void registerTool() {
19
		try {
20
			Class<?> c = Class.forName("org.gvsig.raster.reproject.app.toolbox.ReprojectToolboxAction");
21
			Constructor<?> constructor = c.getConstructor();
22
			constructor.newInstance();
23
		} catch (ClassNotFoundException e) {
24
			log.info(errorMsg, e);
25
		} catch (SecurityException e) {
26
			log.info(errorMsg, e);
27
		} catch (NoSuchMethodException e) {
28
			log.info(errorMsg, e);
29
		} catch (IllegalArgumentException e) {
30
			log.info(errorMsg, e);
31
		} catch (InstantiationException e) {
32
			log.info(errorMsg, e);
33
		} catch (IllegalAccessException e) {
34
			log.info(errorMsg, e);
35
		} catch (InvocationTargetException e) {
36
			log.info(errorMsg, e);
37
		} catch (NoClassDefFoundError e) {
38
			log.info("Geoprocess are not installed." + errorMsg, e);
39
		}
40
	}
41

  
42
}
0 43

  
org.gvsig.raster.reproject/tags/org.gvsig.raster.reproject-2.2.28/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 =
198
                new File(FilenameUtils.removeExtension(f.getAbsolutePath()) + "_"
199
                    + dstProj.getAbrev().replace(":", "_")+ "." + FilenameUtils.getExtension(f.getName()));
200

  
201
			if(!fdst.exists()) {
202
				DataProcess process = null;
203
				try {
204
					process = RasterBaseAlgorithmLibrary.getManager().createRasterTask("RasterReprojectionProcess");
205
				} catch (ProcessException e1) {
206
					RasterSwingLibrary.messageBoxError("error_creating_algorithm", null, e1);
207
					return params;
208
				}
209
				process.setActions(this);
210
				process.addParam(ReprojectProcess.RASTER_STORE, lyrRaster.getDataStore());
211
				process.addParam(ReprojectProcess.SIZEX, 0); //Calculo autom?tico de tama?o
212
				process.addParam(ReprojectProcess.SIZEY, 0);
213
				process.addParam(ReprojectProcess.PATH, fdst.getAbsolutePath());
214
				process.addParam(ReprojectProcess.SRC_PROJECTION, srcProj);
215
				process.addParam(ReprojectProcess.DST_PROJECTION, dstProj);
216
				process.addParam(ReprojectProcess.CELLSIZE, lyrRaster.getDataStore().getCellSize());
217

  
218
				//Despierta la cola que reproyecta im?genes
219
				synchronized (queue) {
220
					queue.add(process, this);
221
					queue.notify();
222
				}
223

  
224
				//Se suspende hasta que la cola haya terminado
225
				try {
226
					synchronized (this) {
227
						this.wait();
228
					}
229
				} catch (InterruptedException e) {
230
				}
231

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

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

  
249
	public void end(Object param) {
250

  
251
	}
252

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

  
264
		/*
265
		 * Si las proyecciones de vista y raster son distintas se lanza el
266
		 * dialogo de selecci?n de opciones. Este dialogo solo se lanza en caso
267
		 * de que el checkbox de aplicar a todos los ficheros no haya sido
268
		 * marcado. En este caso para el resto de ficheros de esa selecci?n se
269
		 * har? la misma acci?n que se hizo para el primero.
270
		 */
271
		if (!viewProj.getAbrev().endsWith(lyrProj.getAbrev())) {
272
			String layerName = dataStore.getName().substring(dataStore.getName().lastIndexOf(File.separator) + 1, dataStore.getName().length());
273
			RasterProjectionActionsDialog dialog = new RasterProjectionActionsDialog(
274
					dataStore.isReproyectable(), layerName, RasterDataParameters.REPROJECT_VIEW, viewProj, lyrProj);
275
			if (dialog != null) {
276
				lastReprojectionOption = dialog.getRasterProjectionActionsPanel().getSelection();
277
				((RasterDataParameters)dataStore.getParameters()).setReprojectionOption(lastReprojectionOption);
278
				setChangeOption(!dialog.getChangeProjectionOption());
279
			}
280
		}
281
	}
282

  
283
	/**
284
	 * Reads the projection from a DataStore
285
	 * @param dataStore
286
	 * @return
287
	 * @throws RasterDriverException
288
	 */
289
	@SuppressWarnings("deprecation")
290
	private IProjection readProjection(RasterDataStore dataStore) {
291
		try {
292
			crsUtil.setCRSFactory(CRSFactory.cp);
293
			if( dataStore == null )
294
				return null;
295
			return crsUtil.convertWktToIProjection(dataStore.getWktProjection());
296
		} catch (Exception e) {
297
			//Si ha habido alg?n problema con la conversi?n metemos un log y que devuelva null
298
			log.info("Problems converting from WKT to IProjection", e);
299
		} catch (Error e) {
300
			log.info("Problems converting from WKT to IProjection", e);
301
		}
302
		return null;
303
	}
304

  
305
	public String getDescription() {
306
		return "Prepare projection for Raster Layer";
307
	}
308

  
309
	public String getName() {
310
		return "PrepareRasterLayerProjection";
311
	}
312

  
313
	public Object create() {
314
		return this;
315
	}
316

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

  
321
	@SuppressWarnings("rawtypes")
322
	public Object create(Map args) {
323
		return this;
324
	}
325

  
326
	public void interrupted() {
327
	}
328

  
329
	public void updateProgress(int current, int total) {
330

  
331
	}
332
}
0 333

  
org.gvsig.raster.reproject/tags/org.gvsig.raster.reproject-2.2.28/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.28/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.28/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.28/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.cresques.cts.IProjection;
32

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

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

  
58
	   /**
59
     * Constructor.
60
     */
61
    public RasterProjectionActionsDialog(boolean layerIsReprojectable, String layerName, int defaultAction) {
62
        this(layerIsReprojectable, layerName, defaultAction, null, null);
63
    }
64
	/**
65
	 * Constructor.
66
	 */
67
	public RasterProjectionActionsDialog(boolean layerIsReprojectable, String layerName, int defaultAction, IProjection viewProj, IProjection layerProj) {
68
	    this.viewProj = viewProj;
69
	    this.layerProj = layerProj;
70
		this.layerIsReprojectable = layerIsReprojectable;
71
		this.layerName = layerName;
72
		this.defaultAction = defaultAction;
73
		BorderLayout bl = new BorderLayout();
74
		bl.setHgap(2);
75
		bl.setVgap(2);
76
		setLayout(bl);
77
		add(getRasterProjectionActionsPanel(), BorderLayout.CENTER);
78
		getRasterProjectionActionsPanel().getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT).addActionListener(this);
79
		getRasterProjectionActionsPanel().getButtonsPanel().getButton(ButtonsPanel.BUTTON_CANCEL).addActionListener(this);
80
		getRasterProjectionActionsPanel().getCheckOption().addActionListener(this);
81
		posWindow = RasterMainPluginUtils.iwindowPosition(widthWindow, heightWindow);
82
		PluginServices.getMDIManager().addWindow(this);
83
	}
84

  
85
	public WindowInfo getWindowInfo() {
86
		WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE);
87
		m_viewinfo.setTitle(PluginServices.getText(this, "options"));
88
		m_viewinfo.setHeight(heightWindow);
89
		m_viewinfo.setWidth(widthWindow);
90
		if (posWindow != null) {
91
			m_viewinfo.setX((int) posWindow.getX());
92
			m_viewinfo.setY((int) posWindow.getY());
93
		}
94
		return m_viewinfo;
95
	}
96

  
97
	/**
98
	 * Obtiene el panel con las opciones de proyecci?n
99
	 * @return RasterProjectionActionsPanel
100
	 */
101
	public RasterProjectionActionsPanel getRasterProjectionActionsPanel() {
102
		if (panel == null) {
103
			panel = new RasterProjectionActionsPanel(layerIsReprojectable, layerName, defaultAction, viewProj, layerProj);
104
		}
105
		return panel;
106
	}
107

  
108
	/**
109
	 * Obtiene la selecci?n del panel
110
	 * @return entero con la selecci?n. Esta representada por las constantes de la
111
	 *         clase RasterReprojectionPanel.
112
	 */
113
	public int getSelection() {
114
		return getRasterProjectionActionsPanel().getSelection();
115
	}
116

  
117
	/**
118
	 * Obtiene la selecci?n del panel
119
	 * @return entero con la selecci?n. Esta representada por las constantes de la
120
	 *         clase RasterReprojectionPanel.
121
	 */
122
	public boolean getChangeProjectionOption() {
123
		return getRasterProjectionActionsPanel().getCheckOption().isSelected();
124
	}
125

  
126
	public void actionPerformed(ActionEvent e) {
127
		if (e.getSource() == getRasterProjectionActionsPanel().getCheckOption()) {
128
			return;
129
		}
130
		PluginServices.getMDIManager().closeWindow(this);
131
	}
132

  
133
	public void windowClosed() {}
134

  
135
	public void windowActivated() {}
136

  
137
	public Object getWindowProfile() {
138
		return WindowInfo.DIALOG_PROFILE;
139
	}
140
}
0 141

  
org.gvsig.raster.reproject/tags/org.gvsig.raster.reproject-2.2.28/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.cresques.cts.IProjection;
35

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

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

  
57
	private JPanel        buttonsPanel           = null;
58
	private ButtonGroup   group                  = new ButtonGroup();
59
	private JRadioButton  changeViewProjection   = null;
60
	private JRadioButton  reproject              = null;
61
	private JRadioButton  ignoreRasterProjection = null;
62
	private JRadioButton  notLoad                = null;
63
	private JRadioButton  onTheFly               = null;
64
	private JCheckBox     allfiles               = null;
65
	private boolean       layerIsReprojectable   = true;
66

  
67
    private IProjection viewProj = null;
68

  
69
    private IProjection layerProj = null;
70

  
71

  
72
	/**
73
	 * Constructor. Llama al inicializador de componentes gr?ficos.
74
	 */
75
	public RasterProjectionActionsPanel(boolean layerIsReprojectable, String layerName, int defaultAction) {
76
	    this(layerIsReprojectable, layerName, defaultAction, null, null);
77
	}
78

  
79
	   /**
80
     * Constructor. Llama al inicializador de componentes gr?ficos.
81
     */
82
    public RasterProjectionActionsPanel(boolean layerIsReprojectable, String layerName, int defaultAction, IProjection viewProj, IProjection layerProj) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff