gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / geolocation / behavior / GeoRasterBehavior.java @ 2480
History | View | Annotate | Download (7.67 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 |
*/
|
22 |
package org.gvsig.raster.tools.app.basic.tool.geolocation.behavior; |
23 |
|
24 |
import java.awt.Image; |
25 |
import java.awt.event.MouseEvent; |
26 |
import java.awt.event.MouseWheelEvent; |
27 |
|
28 |
import org.gvsig.andami.IconThemeHelper; |
29 |
import org.gvsig.andami.PluginServices; |
30 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
31 |
import org.gvsig.app.project.documents.view.gui.IView; |
32 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
33 |
import org.gvsig.fmap.mapcontrol.MapControl; |
34 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
35 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
36 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
37 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.PanListener; |
38 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener; |
39 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
40 |
|
41 |
|
42 |
|
43 |
/**
|
44 |
* Behavior que espera un listener de tipo GeoMoveListener.
|
45 |
* Nacho Brodin (nachobrodin@gmail.com)
|
46 |
*
|
47 |
*/
|
48 |
public class GeoRasterBehavior extends Behavior { |
49 |
private Image curImage = null; |
50 |
private Image notValid = IconThemeHelper.getImage("not-valid-cursor"); |
51 |
private IView theView = null; |
52 |
private TransformationBehavior[] behavior = new TransformationBehavior[4]; |
53 |
private FLyrRaster lyr = null; |
54 |
|
55 |
/**
|
56 |
* Crea un nuevo GeoRasterBehavior.
|
57 |
*
|
58 |
* @param zili listener.
|
59 |
* @param windowIO
|
60 |
*/
|
61 |
public GeoRasterBehavior(PanListener zili, ITransformIO windowIO) {
|
62 |
curImage = zili.getImageCursor(); |
63 |
behavior[0] = new TranslateBehavior(this, curImage, windowIO); |
64 |
behavior[1] = new ScaleBehavior(this, curImage, windowIO); |
65 |
behavior[2] = new RotationBehavior(this, curImage, windowIO); |
66 |
behavior[3] = new ShearBehavior(this, curImage, windowIO); |
67 |
} |
68 |
|
69 |
/**
|
70 |
* Crea un nuevo RectangleBehavior.
|
71 |
*
|
72 |
* @param zili listener.
|
73 |
*/
|
74 |
public GeoRasterBehavior(PanListener zili, ITransformIO windowIO, FLyrRaster lyr) {
|
75 |
this(zili, windowIO);
|
76 |
this.lyr = lyr;
|
77 |
} |
78 |
|
79 |
/**
|
80 |
* Asigna la capa raster
|
81 |
* @param lyr
|
82 |
*/
|
83 |
public void setLayer(FLyrRaster lyr) { |
84 |
this.lyr = lyr;
|
85 |
} |
86 |
|
87 |
/**
|
88 |
* Asigna el objeto externo para variar la transformaci?n
|
89 |
* @param gld
|
90 |
*/
|
91 |
public void setITransformIO(ITransformIO gld) { |
92 |
for (int i = 0; i < behavior.length; i++) |
93 |
behavior[i].setITransformIO(gld); |
94 |
} |
95 |
|
96 |
/**
|
97 |
* Funci?n que carga la capa si todav?a no lo est?.
|
98 |
*/
|
99 |
public FLyrRaster getLayer() {
|
100 |
//Cuando cargamos desde el men? contextual la capa es asignada de forma fija
|
101 |
if(lyr != null) |
102 |
return lyr;
|
103 |
|
104 |
//Cuando cargamos desde la barra hay que buscar la capa activa.
|
105 |
|
106 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
107 |
if(w instanceof IView) { |
108 |
theView = (IView)w; |
109 |
FLayers lyrs = theView.getMapControl().getMapContext().getLayers(); |
110 |
for (int i = 0; i < lyrs.getActives().length; i++) |
111 |
if(lyrs.getActives()[i] instanceof FLyrRaster) |
112 |
return (FLyrRaster)lyrs.getActives()[i];
|
113 |
} |
114 |
return null; |
115 |
} |
116 |
|
117 |
/**
|
118 |
* Coloca el cursor del rat?n con el icono adecuado cuando entra dentro de la
|
119 |
* imagen.
|
120 |
*/
|
121 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
122 |
behavior[0].setActiveTool(false); |
123 |
behavior[1].setActiveTool(false); |
124 |
behavior[2].setActiveTool(false); |
125 |
behavior[3].setActiveTool(false); |
126 |
if(!behavior[1].mouseMoved(e)) |
127 |
if(!behavior[0].mouseMoved(e)) |
128 |
if(!behavior[2].mouseMoved(e)) |
129 |
if(!behavior[3].mouseMoved(e)); |
130 |
} |
131 |
|
132 |
/**
|
133 |
* Si no est? activo el cursor por defecto capturamos el punto
|
134 |
* seleccionado en coordenadas del mundo real.
|
135 |
*/
|
136 |
public void mousePressed(MouseEvent e) throws BehaviorException { |
137 |
if(behavior[1].isActiveTool()) |
138 |
behavior[1].mousePressed(e);
|
139 |
else if(behavior[0].isActiveTool()) |
140 |
behavior[0].mousePressed(e);
|
141 |
else if(behavior[2].isActiveTool()) |
142 |
behavior[2].mousePressed(e);
|
143 |
else if(behavior[3].isActiveTool()) |
144 |
behavior[3].mousePressed(e);
|
145 |
} |
146 |
|
147 |
/**
|
148 |
* Cuando soltamos el bot?n del rat?n desplazamos la imagen a la posici?n
|
149 |
* de destino calculando el extent nuevamente.
|
150 |
*/
|
151 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
152 |
if(behavior[1].isActiveTool()) |
153 |
behavior[1].mouseReleased(e);
|
154 |
else if(behavior[0].isActiveTool()) |
155 |
behavior[0].mouseReleased(e);
|
156 |
else if(behavior[2].isActiveTool()) |
157 |
behavior[2].mouseReleased(e);
|
158 |
else if(behavior[3].isActiveTool()) |
159 |
behavior[3].mouseReleased(e);
|
160 |
} |
161 |
|
162 |
/**
|
163 |
* Funci?n de pintado del canvas.Pintamos un marco a la imagen para saber
|
164 |
* donde la movemos.
|
165 |
*/
|
166 |
public void paintComponent(MapControlDrawer mapControlDrawer) { |
167 |
super.paintComponent(mapControlDrawer);
|
168 |
if(behavior[1].isActiveTool()) |
169 |
behavior[1].paintComponent(mapControlDrawer);
|
170 |
else if(behavior[0].isActiveTool()) |
171 |
behavior[0].paintComponent(mapControlDrawer);
|
172 |
else if(behavior[2].isActiveTool()) |
173 |
behavior[2].paintComponent(mapControlDrawer);
|
174 |
else if(behavior[3].isActiveTool()) |
175 |
behavior[3].paintComponent(mapControlDrawer);
|
176 |
} |
177 |
|
178 |
/**
|
179 |
* Esta funci?n repinta el canvas si se est? arrasrtando la imagen para
|
180 |
* poder ver el marco de arrastre.
|
181 |
*/
|
182 |
public void mouseDragged(MouseEvent e) throws BehaviorException { |
183 |
if(behavior[1].isActiveTool()) |
184 |
behavior[1].mouseDragged(e);
|
185 |
else if(behavior[0].isActiveTool()) |
186 |
behavior[0].mouseDragged(e);
|
187 |
else if(behavior[2].isActiveTool()) |
188 |
behavior[2].mouseDragged(e);
|
189 |
else if(behavior[3].isActiveTool()) |
190 |
behavior[3].mouseDragged(e);
|
191 |
} |
192 |
|
193 |
/* (non-Javadoc)
|
194 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
|
195 |
*/
|
196 |
public ToolListener getListener() {
|
197 |
return null; |
198 |
} |
199 |
/* (non-Javadoc)
|
200 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getMapControl()
|
201 |
*/
|
202 |
public MapControl getMapControl() {
|
203 |
return super.getMapControl(); |
204 |
} |
205 |
/* (non-Javadoc)
|
206 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseClicked(java.awt.event.MouseEvent)
|
207 |
*/
|
208 |
public void mouseClicked(MouseEvent e) throws BehaviorException { |
209 |
super.mouseClicked(e);
|
210 |
} |
211 |
|
212 |
/* (non-Javadoc)
|
213 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseEntered(java.awt.event.MouseEvent)
|
214 |
*/
|
215 |
public void mouseEntered(MouseEvent e) throws BehaviorException { |
216 |
super.mouseEntered(e);
|
217 |
} |
218 |
/* (non-Javadoc)
|
219 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseExited(java.awt.event.MouseEvent)
|
220 |
*/
|
221 |
public void mouseExited(MouseEvent e) throws BehaviorException { |
222 |
super.mouseExited(e);
|
223 |
} |
224 |
|
225 |
/* (non-Javadoc)
|
226 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseWheelMoved(java.awt.event.MouseWheelEvent)
|
227 |
*/
|
228 |
public void mouseWheelMoved(MouseWheelEvent e) throws BehaviorException { |
229 |
super.mouseWheelMoved(e);
|
230 |
} |
231 |
|
232 |
/* (non-Javadoc)
|
233 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#setMapControl(com.iver.cit.gvsig.fmap.MapControl)
|
234 |
*/
|
235 |
public void setMapControl(MapControl mc) { |
236 |
super.setMapControl(mc);
|
237 |
} |
238 |
|
239 |
public void setCursorImage(Image cursor) { |
240 |
this.curImage = cursor;
|
241 |
} |
242 |
|
243 |
public Image getImageCursor() { |
244 |
return this.curImage; |
245 |
} |
246 |
|
247 |
public void resetDefaultCursor() { |
248 |
this.curImage = notValid;
|
249 |
} |
250 |
} |