gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.app / org.gvsig.geoprocess.app.tool / src / main / java / org / gvsig / geoprocess / app / tool / AbstractToolboxAction.java @ 403
History | View | Annotate | Download (3.04 KB)
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.geoprocess.app.tool; |
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.layers.FLayers; |
31 |
import org.gvsig.geoprocess.lib.sextante.dataObjects.FLyrRasterIRasterLayer; |
32 |
import org.gvsig.i18n.Messages; |
33 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
34 |
import org.gvsig.raster.tools.app.basic.RasterToolsUtil; |
35 |
|
36 |
import es.unex.sextante.dataObjects.IRasterLayer; |
37 |
import es.unex.sextante.gui.core.SextanteGUI; |
38 |
import es.unex.sextante.gui.core.ToolboxAction; |
39 |
|
40 |
/**
|
41 |
* Base class for toolBox actions
|
42 |
*
|
43 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
44 |
*/
|
45 |
public abstract class AbstractToolboxAction extends ToolboxAction { |
46 |
protected FLyrRaster lyr = null; |
47 |
|
48 |
@Override
|
49 |
public String getGroup() { |
50 |
return Messages.getText("group_tools"); |
51 |
} |
52 |
|
53 |
|
54 |
@Override
|
55 |
public boolean isActive() { |
56 |
IWindow[] windows = PluginServices.getMDIManager().getAllWindows();
|
57 |
for (int i = 0; i < windows.length; i++) { |
58 |
if(windows[i] instanceof AbstractViewPanel) { |
59 |
FLayers lyrs = ((AbstractViewPanel)windows[i]).getMapControl().getMapContext().getLayers(); |
60 |
for (int j = 0; j < lyrs.getLayersCount(); j++) { |
61 |
if(lyrs.getLayer(j) instanceof FLyrRaster) |
62 |
return true; |
63 |
} |
64 |
} |
65 |
} |
66 |
return false; |
67 |
} |
68 |
|
69 |
/**
|
70 |
* Loads the raster layer for the tool
|
71 |
* @return
|
72 |
*/
|
73 |
public boolean loadLayer() { |
74 |
if(!isActive())
|
75 |
return false; |
76 |
|
77 |
boolean existsRasterButNotActive = false; |
78 |
lyr = null;
|
79 |
IRasterLayer[] layers = SextanteGUI.getInputFactory().getRasterLayers();
|
80 |
for (int i = 0; i < layers.length; i++) { |
81 |
FLyrRaster l = (FLyrRaster)((FLyrRasterIRasterLayer)layers[i]).getBaseDataObject(); |
82 |
existsRasterButNotActive = true;
|
83 |
if(l.isActive()) {
|
84 |
existsRasterButNotActive = false;
|
85 |
lyr = l; |
86 |
break;
|
87 |
} |
88 |
} |
89 |
|
90 |
if(existsRasterButNotActive) {
|
91 |
RasterToolsUtil.messageBoxError(Messages.getText("raster_layer_not_active"), null); |
92 |
return false; |
93 |
} |
94 |
|
95 |
return true; |
96 |
} |
97 |
|
98 |
} |