Revision 2389

View differences:

org.gvsig.raster.reproject/branches/org.gvsig.raster.reproject_dataaccess_refactoring/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/branches/org.gvsig.raster.reproject_dataaccess_refactoring/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().getAllWindows();
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/branches/org.gvsig.raster.reproject_dataaccess_refactoring/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

  

Also available in: Unified diff