root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / RasterBarToolsModule.java @ 15765
History | View | Annotate | Download (5.08 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.rastertools; |
20 |
|
21 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
22 |
import org.gvsig.fmap.raster.layers.IRasterLayerActions; |
23 |
import org.gvsig.rastertools.geolocation.behavior.GeoRasterBehavior; |
24 |
import org.gvsig.rastertools.geolocation.listener.GeorefPanListener; |
25 |
import org.gvsig.rastertools.geolocation.ui.GeoLocationDialog; |
26 |
|
27 |
import com.iver.andami.PluginServices; |
28 |
import com.iver.andami.plugins.Extension; |
29 |
import com.iver.andami.ui.mdiManager.IWindow; |
30 |
import com.iver.cit.gvsig.fmap.MapContext; |
31 |
import com.iver.cit.gvsig.fmap.MapControl; |
32 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
33 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
34 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
35 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior; |
36 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
37 |
import com.iver.cit.gvsig.project.documents.view.gui.IView; |
38 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
39 |
import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener; |
40 |
/**
|
41 |
* Extensi?n con las herramientas del men? que contienen usos especificos para capas
|
42 |
* raster. Estas no apareceran si la capa seleccionada del TOC no es raster.
|
43 |
*
|
44 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
45 |
*/
|
46 |
public class RasterBarToolsModule extends Extension{ |
47 |
private GeoLocationDialog gld = null; |
48 |
/*
|
49 |
* (non-Javadoc)
|
50 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
51 |
*/
|
52 |
public void execute(String actionCommand) { |
53 |
View theView = (View) PluginServices.getMDIManager().getActiveWindow(); |
54 |
MapControl mapCtrl = theView.getMapControl(); |
55 |
|
56 |
// Listener de eventos de movimiento que pone las coordenadas del rat?n en
|
57 |
// la barra de estado
|
58 |
StatusBarListener sbl = new StatusBarListener(mapCtrl);
|
59 |
|
60 |
if (actionCommand.equals("GEO_PAN")) { |
61 |
boolean isOpen = false; |
62 |
|
63 |
//Comprobamos si no hay capas activas. En este caso no lanzamos la ventana ni activamos la tool
|
64 |
IWindow[] win = PluginServices.getMDIManager().getAllWindows();
|
65 |
for (int i = 0; i < win.length; i++) { |
66 |
if (win[i] instanceof IView) { |
67 |
FLayers lyrs = ((IView)win[i]).getMapControl().getMapContext().getLayers(); |
68 |
FLayer[] actives = lyrs.getActives();
|
69 |
if(actives == null || actives.length == 0) |
70 |
return;
|
71 |
} |
72 |
if(win[i] instanceof GeoLocationDialog) |
73 |
isOpen = true;
|
74 |
} |
75 |
if(gld == null) |
76 |
gld = new GeoLocationDialog();
|
77 |
if(!isOpen) {
|
78 |
gld.calcPosition(); |
79 |
PluginServices.getMDIManager().addWindow(gld); |
80 |
} |
81 |
gld.init(mapCtrl); |
82 |
loadGeoPanListener(mapCtrl, sbl, gld); |
83 |
mapCtrl.setTool("geoPan");
|
84 |
} |
85 |
|
86 |
} |
87 |
|
88 |
/**
|
89 |
* Carga el listener de selecci?n de raster en el MapControl.
|
90 |
*/
|
91 |
private void loadGeoPanListener(MapControl mapCtrl, StatusBarListener sbl, GeoLocationDialog gld) { |
92 |
if (mapCtrl.getNamesMapTools().get("geoPan") == null) { |
93 |
GeorefPanListener pl = new GeorefPanListener(mapCtrl);
|
94 |
GeoRasterBehavior mb = new GeoRasterBehavior(pl, gld);
|
95 |
mapCtrl.addMapTool("geoPan", new Behavior[]{mb, new MouseMovementBehavior(sbl)}); |
96 |
|
97 |
} |
98 |
} |
99 |
|
100 |
/*
|
101 |
* (non-Javadoc)
|
102 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
103 |
*/
|
104 |
public void initialize() { |
105 |
registerIcons(); |
106 |
} |
107 |
|
108 |
private void registerIcons(){ |
109 |
PluginServices.getIconTheme().register( |
110 |
"forward-icon",
|
111 |
this.getClass().getClassLoader().getResource("images/forward.png") |
112 |
); |
113 |
PluginServices.getIconTheme().register( |
114 |
"backwardward-icon",
|
115 |
this.getClass().getClassLoader().getResource("images/backward.png") |
116 |
); |
117 |
} |
118 |
|
119 |
/*
|
120 |
* (non-Javadoc)
|
121 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
122 |
*/
|
123 |
public boolean isEnabled() { |
124 |
return true; |
125 |
} |
126 |
|
127 |
/**
|
128 |
* Mostramos el control si hay alguna capa cargada.
|
129 |
*/
|
130 |
public boolean isVisible() { |
131 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
132 |
if (f == null) |
133 |
return false; |
134 |
|
135 |
if (f instanceof View) { |
136 |
View vista = (View) f; |
137 |
IProjectView model = vista.getModel(); |
138 |
MapContext mapa = model.getMapContext(); |
139 |
if (mapa.getLayers().getLayersCount() > 0) { |
140 |
if( mapa.getLayers().getActives().length == 1 && |
141 |
mapa.getLayers().getActives()[0] instanceof FLyrRasterSE && |
142 |
((FLyrRasterSE)mapa.getLayers().getActives()[0]).isActionEnabled(IRasterLayerActions.FLYRASTER_BAR_TOOLS))
|
143 |
return true; |
144 |
} |
145 |
} |
146 |
|
147 |
return false; |
148 |
} |
149 |
} |