svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / geolocation / behavior / GeoRasterBehavior.java @ 12610
History | View | Annotate | Download (6.51 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 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.geolocation.behavior; |
20 |
|
21 |
import java.awt.Cursor; |
22 |
import java.awt.Graphics; |
23 |
import java.awt.Graphics2D; |
24 |
import java.awt.event.MouseEvent; |
25 |
import java.awt.event.MouseWheelEvent; |
26 |
import java.awt.geom.Point2D; |
27 |
import java.awt.geom.Rectangle2D; |
28 |
|
29 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
30 |
import org.gvsig.raster.datastruct.Extent; |
31 |
import org.gvsig.raster.util.RasterUtilities; |
32 |
|
33 |
import com.iver.andami.PluginServices; |
34 |
import com.iver.andami.ui.mdiManager.IWindow; |
35 |
import com.iver.cit.gvsig.fmap.MapControl; |
36 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
37 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
38 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
39 |
import com.iver.cit.gvsig.fmap.tools.Listeners.PanListener; |
40 |
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener; |
41 |
import com.iver.cit.gvsig.project.documents.view.gui.IView; |
42 |
|
43 |
|
44 |
/**
|
45 |
* Behaviour que espera un listener de tipo GeoMoveListener.
|
46 |
* Nacho Brodin (nachobrodin@gmail.com)
|
47 |
*
|
48 |
*/
|
49 |
public class GeoRasterBehavior extends Behavior { |
50 |
private Cursor cur = null; |
51 |
private IView theView = null; |
52 |
private TranslateBehavior translate = null; |
53 |
private ScaleBehavior scale = null; |
54 |
|
55 |
/**
|
56 |
* Crea un nuevo RectangleBehavior.
|
57 |
*
|
58 |
* @param zili listener.
|
59 |
*/
|
60 |
public GeoRasterBehavior(PanListener zili) {
|
61 |
cur = zili.getCursor(); |
62 |
translate = new TranslateBehavior(this, cur); |
63 |
scale = new ScaleBehavior(this, cur); |
64 |
} |
65 |
|
66 |
/**
|
67 |
* Funci?n que carga la capa si todav?a no lo est?.
|
68 |
*/
|
69 |
public FLyrRasterSE getLayer() {
|
70 |
//Cargamos la capa
|
71 |
|
72 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
73 |
if(w instanceof IView) { |
74 |
theView = (IView)w; |
75 |
FLayers lyrs = theView.getMapControl().getMapContext().getLayers(); |
76 |
for (int i = 0; i < lyrs.getActives().length; i++) { |
77 |
if(lyrs.getActives()[i] instanceof FLyrRasterSE) |
78 |
return (FLyrRasterSE)lyrs.getActives()[i];
|
79 |
} |
80 |
} |
81 |
return null; |
82 |
} |
83 |
|
84 |
/**
|
85 |
* Coloca el cursor del rat?n con el icono adecuado cuando entra dentro de la
|
86 |
* imagen.
|
87 |
*/
|
88 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
89 |
scale.setActiveTool(false);
|
90 |
translate.setActiveTool(false);
|
91 |
if(!scale.mouseMoved(e))
|
92 |
if(!translate.mouseMoved(e));
|
93 |
} |
94 |
|
95 |
/**
|
96 |
* Obtiene el cursor actual
|
97 |
*/
|
98 |
public Cursor getCursor() { |
99 |
return this.cur; |
100 |
} |
101 |
|
102 |
/**
|
103 |
* Si no est? activo el cursor por defecto capturamos el punto
|
104 |
* seleccionado en coordenadas del mundo real.
|
105 |
*/
|
106 |
public void mousePressed(MouseEvent e) throws BehaviorException { |
107 |
/*Graphics2D g = (Graphics2D)getMapControl().getGraphics();
|
108 |
FLyrRasterSE lyr = getLayer();
|
109 |
if(lyr != null) {
|
110 |
Rectangle2D extent = lyr.getFullExtent();
|
111 |
Point2D p1 = getMapControl().getViewPort().fromMapPoint(extent.getMinX(), extent.getMaxY());
|
112 |
Point2D p2 = getMapControl().getViewPort().fromMapPoint(extent.getMaxX(), extent.getMinY());
|
113 |
Extent ex = RasterUtilities.calculateAdjustedView( new Extent(p1, p2),
|
114 |
new Extent( getMapControl().getViewPort().getAdjustedExtent().getMinX(),
|
115 |
getMapControl().getViewPort().getAdjustedExtent().getMaxY(),
|
116 |
getMapControl().getViewPort().getAdjustedExtent().getMaxX(),
|
117 |
getMapControl().getViewPort().getAdjustedExtent().getMinY()));*/
|
118 |
|
119 |
if(scale.isActiveTool())
|
120 |
scale.mousePressed(e); |
121 |
else
|
122 |
if(translate.isActiveTool())
|
123 |
translate.mousePressed(e); |
124 |
|
125 |
} |
126 |
|
127 |
/**
|
128 |
* Cuando soltamos el bot?n del rat?n desplazamos la imagen a la posici?n
|
129 |
* de destino calculando el extent nuevamente.
|
130 |
*/
|
131 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
132 |
if(scale.isActiveTool())
|
133 |
scale.mouseReleased(e); |
134 |
else
|
135 |
if(translate.isActiveTool())
|
136 |
translate.mouseReleased(e); |
137 |
} |
138 |
|
139 |
/**
|
140 |
* Funci?n de pintado del canvas.Pintamos un marco a la imagen para saber
|
141 |
* donde la movemos.
|
142 |
*/
|
143 |
public void paintComponent(Graphics g) { |
144 |
super.paintComponent(g);
|
145 |
if(scale.isActiveTool())
|
146 |
scale.paintComponent(g); |
147 |
else
|
148 |
if(translate.isActiveTool())
|
149 |
translate.paintComponent(g); |
150 |
} |
151 |
|
152 |
/**
|
153 |
* Esta funci?n repinta el canvas si se est? arrasrtando la imagen para
|
154 |
* poder ver el marco de arrastre.
|
155 |
*/
|
156 |
public void mouseDragged(MouseEvent e) throws BehaviorException { |
157 |
if(scale.isActiveTool())
|
158 |
scale.mouseDragged(e); |
159 |
else
|
160 |
if(translate.isActiveTool())
|
161 |
translate.mouseDragged(e); |
162 |
} |
163 |
|
164 |
/* (non-Javadoc)
|
165 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
|
166 |
*/
|
167 |
public ToolListener getListener() {
|
168 |
return null; |
169 |
} |
170 |
/* (non-Javadoc)
|
171 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getMapControl()
|
172 |
*/
|
173 |
public MapControl getMapControl() {
|
174 |
return super.getMapControl(); |
175 |
} |
176 |
/* (non-Javadoc)
|
177 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseClicked(java.awt.event.MouseEvent)
|
178 |
*/
|
179 |
public void mouseClicked(MouseEvent e) throws BehaviorException { |
180 |
super.mouseClicked(e);
|
181 |
} |
182 |
|
183 |
/* (non-Javadoc)
|
184 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseEntered(java.awt.event.MouseEvent)
|
185 |
*/
|
186 |
public void mouseEntered(MouseEvent e) throws BehaviorException { |
187 |
super.mouseEntered(e);
|
188 |
} |
189 |
/* (non-Javadoc)
|
190 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseExited(java.awt.event.MouseEvent)
|
191 |
*/
|
192 |
public void mouseExited(MouseEvent e) throws BehaviorException { |
193 |
super.mouseExited(e);
|
194 |
} |
195 |
|
196 |
/* (non-Javadoc)
|
197 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseWheelMoved(java.awt.event.MouseWheelEvent)
|
198 |
*/
|
199 |
public void mouseWheelMoved(MouseWheelEvent e) throws BehaviorException { |
200 |
super.mouseWheelMoved(e);
|
201 |
} |
202 |
|
203 |
/* (non-Javadoc)
|
204 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#setMapControl(com.iver.cit.gvsig.fmap.MapControl)
|
205 |
*/
|
206 |
public void setMapControl(MapControl mc) { |
207 |
super.setMapControl(mc);
|
208 |
} |
209 |
|
210 |
} |