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 @ 409
History | View | Annotate | Download (3.5 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.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.tools.app.basic.RasterToolsUtil; |
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 |
* Loads the raster layer for the tool
|
72 |
* @return
|
73 |
*/
|
74 |
public boolean loadLayer() { |
75 |
if(!isActive()) {
|
76 |
RasterToolsUtil.messageBoxError(Messages.getText("layer_not_valid"), null); |
77 |
return false; |
78 |
} |
79 |
|
80 |
boolean existsRasterButNotActive = false; |
81 |
lyr = null;
|
82 |
IWindow[] windows = PluginServices.getMDIManager().getAllWindows();
|
83 |
MapContext mapCtx = null;
|
84 |
for (int i = 0; i < windows.length; i++) { |
85 |
if(windows[i] instanceof AbstractViewPanel) { |
86 |
mapCtx = ((AbstractViewPanel)windows[i]).getMapControl().getMapContext(); |
87 |
break;
|
88 |
} |
89 |
} |
90 |
|
91 |
IRasterLayer[] layers = SextanteGUI.getInputFactory().getRasterLayers();
|
92 |
for (int i = 0; i < layers.length; i++) { |
93 |
FLyrRaster l = (FLyrRaster)((FLyrRasterIRasterLayer)layers[i]).getBaseDataObject(); |
94 |
existsRasterButNotActive = true;
|
95 |
if(l.isActive() && mapCtx == l.getMapContext()) {
|
96 |
existsRasterButNotActive = false;
|
97 |
lyr = l; |
98 |
break;
|
99 |
} |
100 |
} |
101 |
|
102 |
if(existsRasterButNotActive) {
|
103 |
RasterToolsUtil.messageBoxError(Messages.getText("raster_layer_not_active"), null); |
104 |
return false; |
105 |
} |
106 |
|
107 |
return true; |
108 |
} |
109 |
|
110 |
} |