gvsig-raster / org.gvsig.raster.reproject / trunk / org.gvsig.raster.reproject / org.gvsig.raster.reproject.app.reprojectclient / src / main / java / org / gvsig / raster / reproject / app / toolbox / AbstractToolboxAction.java @ 5469
History | View | Annotate | Download (3.86 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.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 |
* @return Returns true if the plugin which gives the functionality is installed
|
72 |
* in gvSIG
|
73 |
*/
|
74 |
public abstract boolean isPluginInstalled(); |
75 |
|
76 |
/**
|
77 |
* Loads the raster layer for the tool
|
78 |
* @return true if layer load is successfully, otherwise fasle
|
79 |
*/
|
80 |
public boolean loadLayer() { |
81 |
if(!isPluginInstalled()) {
|
82 |
RasterSwingLibrary.messageBoxError(Messages.getText("plugin_not_installed"), null); |
83 |
return false; |
84 |
} |
85 |
|
86 |
if(!isActive()) {
|
87 |
RasterSwingLibrary.messageBoxError(Messages.getText("layer_not_valid"), null); |
88 |
return false; |
89 |
} |
90 |
|
91 |
boolean existsRasterButNotActive = false; |
92 |
lyr = null;
|
93 |
IWindow[] windows = PluginServices.getMDIManager().getOrderedWindows();
|
94 |
MapContext mapCtx = null;
|
95 |
for (int i = 0; i < windows.length; i++) { |
96 |
if(windows[i] instanceof AbstractViewPanel) { |
97 |
mapCtx = ((AbstractViewPanel)windows[i]).getMapControl().getMapContext(); |
98 |
break;
|
99 |
} |
100 |
} |
101 |
|
102 |
IRasterLayer[] layers = SextanteGUI.getInputFactory().getRasterLayers();
|
103 |
for (int i = 0; i < layers.length; i++) { |
104 |
FLyrRaster l = (FLyrRaster)((FLyrRasterIRasterLayer)layers[i]).getBaseDataObject(); |
105 |
existsRasterButNotActive = true;
|
106 |
if(l.isActive() && mapCtx == l.getMapContext()) {
|
107 |
existsRasterButNotActive = false;
|
108 |
lyr = l; |
109 |
break;
|
110 |
} |
111 |
} |
112 |
|
113 |
if(existsRasterButNotActive) {
|
114 |
RasterSwingLibrary.messageBoxError(Messages.getText("raster_layer_not_active"), null); |
115 |
return false; |
116 |
} |
117 |
|
118 |
return true; |
119 |
} |
120 |
|
121 |
} |