svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / fmap / tools / Behavior / GeoRedimBehavior.java @ 5818
History | View | Annotate | Download (19.6 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 com.iver.cit.gvsig.fmap.tools.Behavior; |
20 |
|
21 |
import java.awt.Color; |
22 |
import java.awt.Component; |
23 |
import java.awt.Graphics; |
24 |
import java.awt.Image; |
25 |
import java.awt.Point; |
26 |
import java.awt.Rectangle; |
27 |
import java.awt.Toolkit; |
28 |
import java.awt.event.MouseEvent; |
29 |
import java.awt.geom.Point2D; |
30 |
import java.awt.geom.Rectangle2D; |
31 |
import java.awt.image.BufferedImage; |
32 |
|
33 |
import javax.swing.ImageIcon; |
34 |
import javax.swing.JOptionPane; |
35 |
|
36 |
import org.cresques.px.Extent; |
37 |
import org.gvsig.georeferencing.gui.dialog.GeoreferencingDialog; |
38 |
|
39 |
import com.iver.andami.PluginServices; |
40 |
import com.iver.cit.gvsig.fmap.MapControl; |
41 |
import com.iver.cit.gvsig.fmap.ViewPort; |
42 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
43 |
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster; |
44 |
import com.iver.cit.gvsig.fmap.layers.GeoPoint; |
45 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
46 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
47 |
import com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener; |
48 |
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener; |
49 |
|
50 |
|
51 |
/**
|
52 |
* Behaviour que espera un listener de tipo RedimListener.
|
53 |
* Nacho Brodin (brodin_ign@gva.es)
|
54 |
*
|
55 |
*/
|
56 |
public class GeoRedimBehavior extends Behavior { |
57 |
//Params
|
58 |
private int WIDTH_BORDER = 25; |
59 |
private int LONG_CORNER = 35; |
60 |
private Color rectangleColor = Color.RED; |
61 |
|
62 |
private RectangleListener listener;
|
63 |
|
64 |
private final Image iconHoriz = new ImageIcon(getClass().getClassLoader().getResource( |
65 |
"images/FlechaHorizCursor.gif")).getImage();
|
66 |
private final Image iconVert = new ImageIcon(getClass().getClassLoader().getResource( |
67 |
"images/FlechaVertCursor.gif")).getImage();
|
68 |
private final Image iconInclDer = new ImageIcon(getClass().getClassLoader().getResource( |
69 |
"images/FlechaInclDerCursor.gif")).getImage();
|
70 |
private final Image iconInclIzq = new ImageIcon(getClass().getClassLoader().getResource( |
71 |
"images/FlechaInclIzqCursor.gif")).getImage();
|
72 |
private final Image defaultCursor = new ImageIcon(getClass().getClassLoader().getResource( |
73 |
"images/ZoomInCursor.gif")).getImage();
|
74 |
|
75 |
/**
|
76 |
* Cada elemento del vector corresponde a un tipo de icono que
|
77 |
* estar? a true si est? activo y a false si no lo est?.
|
78 |
* horizontal, vertical, inclinado derecha, inclinado izquierda
|
79 |
*/
|
80 |
private boolean[] iconActive = {false, false, false, false}; |
81 |
private Point2D ul = null; |
82 |
private Point2D lr = null; |
83 |
private Point2D tmpUl = null; |
84 |
private Point2D tmpLr = null; |
85 |
|
86 |
/**
|
87 |
* Variable que si est? a true permite que se pinte el marco de la imagen. Se activa al
|
88 |
* comenzar el redimensionado y se desactiva al terminar
|
89 |
*/
|
90 |
private boolean isResizable = false; |
91 |
|
92 |
/**
|
93 |
* Cada elemento corresponde a la acivaci?n de redimensionado en una
|
94 |
* direcci?n que estar? activa a true.
|
95 |
* vertical derecha, vertical izquierda, horizontal arriba, horizontal abajo,
|
96 |
* inclinado
|
97 |
*/
|
98 |
private boolean[] redimActive = new boolean[8]; |
99 |
private Point2D pointInit = null; |
100 |
private Rectangle2D rectInit = null; |
101 |
private FLyrGeoRaster lyrGeoRaster = null; |
102 |
private com.iver.cit.gvsig.gui.View theView = null; |
103 |
|
104 |
|
105 |
/**
|
106 |
* Crea un nuevo RectangleBehavior.
|
107 |
*
|
108 |
* @param zili listener.
|
109 |
*/
|
110 |
public GeoRedimBehavior(RectangleListener zili) {
|
111 |
listener = zili; |
112 |
for(int i=0; i<redimActive.length;i++) |
113 |
redimActive[i] = false;
|
114 |
} |
115 |
|
116 |
/**
|
117 |
* Funci?n que carga la capa si todav?a no lo est?.
|
118 |
*/
|
119 |
private void loadLayer() throws InstantiationException, ClassCastException{ |
120 |
//Cargamos la capa
|
121 |
|
122 |
theView = (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView(); |
123 |
for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
124 |
FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i); |
125 |
if( lyr instanceof FLyrGeoRaster && |
126 |
lyr.getName().startsWith("*"))
|
127 |
this.lyrGeoRaster = (FLyrGeoRaster)lyr;
|
128 |
} |
129 |
if(lyrGeoRaster == null) |
130 |
throw new InstantiationException("No se ha podido cargar la capa de georreferenciaci?n"); |
131 |
} |
132 |
|
133 |
|
134 |
/**
|
135 |
* Cuando se produce un evento de pintado dibujamos el marco de la imagen para
|
136 |
* que el usuario pueda seleccionar y redimensionar.
|
137 |
*/
|
138 |
public void paintComponent(Graphics g) { |
139 |
BufferedImage img = getMapControl().getImage();
|
140 |
g.drawImage(img, 0, 0, null); |
141 |
g.setColor(rectangleColor); |
142 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
143 |
try{
|
144 |
loadLayer(); |
145 |
Rectangle r = new Rectangle(); |
146 |
|
147 |
if(tmpLr == null || tmpUl == null){ |
148 |
ul = vp.fromMapPoint(lyrGeoRaster.getAssignExtent().getMin().getX(), lyrGeoRaster.getAssignExtent().getMin().getY()); |
149 |
lr = vp.fromMapPoint(lyrGeoRaster.getAssignExtent().getMax().getX(), lyrGeoRaster.getAssignExtent().getMax().getY()); |
150 |
r.setFrameFromDiagonal(ul, lr); |
151 |
}else
|
152 |
r.setFrameFromDiagonal(tmpUl, tmpLr); |
153 |
if(isResizable)
|
154 |
g.drawRect(r.x, r.y, r.width, r.height); |
155 |
}catch(InstantiationException exc){ |
156 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
157 |
PluginServices.getText(this, "error_capa_puntos")); |
158 |
}catch(ClassCastException exc){ |
159 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
160 |
PluginServices.getText(this, "error_capa_puntos")); |
161 |
} |
162 |
|
163 |
} |
164 |
|
165 |
/**
|
166 |
* Reimplementaci?n del m?todo mousePressed de Behavior. Cuando se pulsa
|
167 |
* estando sobre el marco de la imagen activamos la posibilidad de arrastrar
|
168 |
* para redimensionar la imagen.
|
169 |
*
|
170 |
* @param e MouseEvent
|
171 |
*/
|
172 |
public void mousePressed(MouseEvent e) { |
173 |
if (e.getButton() == MouseEvent.BUTTON1) { |
174 |
isResizable = true;
|
175 |
try{
|
176 |
loadLayer(); |
177 |
}catch(InstantiationException exc){ |
178 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
179 |
PluginServices.getText(this, "error_capa_puntos")); |
180 |
return;
|
181 |
}catch(ClassCastException exc){ |
182 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
183 |
PluginServices.getText(this, "error_capa_puntos")); |
184 |
return;
|
185 |
} |
186 |
|
187 |
tmpUl = ul; |
188 |
tmpLr = lr; |
189 |
|
190 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
191 |
double wcX = vp.toMapPoint(e.getX(), e.getY()).getX();
|
192 |
double wcY = vp.toMapPoint(e.getX(), e.getY()).getY();
|
193 |
|
194 |
double minX = lyrGeoRaster.getAssignExtent().getMin().getX();
|
195 |
double minY = lyrGeoRaster.getAssignExtent().getMin().getY();
|
196 |
double maxX = lyrGeoRaster.getAssignExtent().getMax().getX();
|
197 |
double maxY = lyrGeoRaster.getAssignExtent().getMax().getY();
|
198 |
|
199 |
if(iconActive[0]){//Estirar en horizontal activado |
200 |
if(wcX > (maxX - WIDTH_BORDER) && wcX < maxX)
|
201 |
redimActive[0] = true; |
202 |
if(wcX < (minX + WIDTH_BORDER) && wcX > minX)
|
203 |
redimActive[1] = true; |
204 |
} |
205 |
if(iconActive[1]){//Estirar en vertical activado |
206 |
if(wcY > (maxY - WIDTH_BORDER) && wcY < maxY)
|
207 |
redimActive[3] = true; |
208 |
if(wcY < (minY + WIDTH_BORDER) && wcY > minY)
|
209 |
redimActive[2] = true; |
210 |
} |
211 |
if(iconActive[2]){ //Estirar en oblicuo derecha activado |
212 |
if((wcX > (maxX - WIDTH_BORDER) && wcX < maxX) || (wcY < (minY + WIDTH_BORDER) && wcY > minY))
|
213 |
redimActive[4] = true; //System.out.println("LR"); |
214 |
|
215 |
if((wcX < (minX + WIDTH_BORDER) && wcX > minX) || (wcY > (maxY - WIDTH_BORDER) && wcY < maxY))
|
216 |
redimActive[5] = true;//System.out.println("UL"); |
217 |
//pointInit = e.getPoint();
|
218 |
//rectInit = new Rectangle2D.Double(tmpUl.getX(), tmpUl.getY(), tmpLr.getX() - tmpUl.getX(), tmpLr.getY() - tmpUl.getY());
|
219 |
} |
220 |
if(iconActive[3]){ //Estirar en oblicuo izquierda activado |
221 |
if((wcX > (maxX - WIDTH_BORDER) && wcX < maxX) || (wcY > (maxY - WIDTH_BORDER) && wcY < maxY))
|
222 |
redimActive[6] = true;//System.out.println("UR"); |
223 |
|
224 |
if((wcX < (minX + WIDTH_BORDER) && wcX > minX) || (wcY < (minY + WIDTH_BORDER) && wcY > minY))
|
225 |
redimActive[7] = true;//System.out.println("LL"); |
226 |
} |
227 |
} |
228 |
|
229 |
if (listener.cancelDrawing())
|
230 |
getMapControl().cancelDrawing(); |
231 |
} |
232 |
|
233 |
/**
|
234 |
* Reimplementaci?n del m?todo mouseReleased de Behavior. Desactivamos
|
235 |
* los flags de redimensionado y a partir de la selecci?n del usuario
|
236 |
* creamos un nuevo extent para la imagen. Con este extent creamos una nueva
|
237 |
* capa que sustituir? a la anterior.
|
238 |
*
|
239 |
* @param e MouseEvent
|
240 |
*
|
241 |
* @throws BehaviorException Excepci?n lanzada cuando el Behavior.
|
242 |
*/
|
243 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
244 |
|
245 |
if (e.getButton() == MouseEvent.BUTTON1 && isResizable) { |
246 |
//Desactivamos los flags de redimensionado
|
247 |
for(int i=0;i<redimActive.length;i++) |
248 |
redimActive[i] = false;
|
249 |
//Asignamos el nuevo extent a la imagen
|
250 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
251 |
Extent ext = new Extent(vp.toMapPoint((int)tmpUl.getX(), (int)tmpUl.getY()).getX(), |
252 |
vp.toMapPoint((int)tmpUl.getX(), (int)tmpUl.getY()).getY(), |
253 |
vp.toMapPoint((int)tmpLr.getX(), (int)tmpLr.getY()).getX(), |
254 |
vp.toMapPoint((int)tmpLr.getX(), (int)tmpLr.getY()).getY()); |
255 |
|
256 |
|
257 |
if(this.lyrGeoRaster != null){ |
258 |
|
259 |
((FLyrGeoRaster)getMapControl().getMapContext().getLayers().getLayer(lyrGeoRaster.getName())).setAssignExtent(ext); |
260 |
|
261 |
//Si la capa tiene puntos de control hacemos un update de estos
|
262 |
//a su posici?n para que se actualicen los controles
|
263 |
for(int i=0; i<lyrGeoRaster.getFLyrPoints().getCountPoints(); i++){ |
264 |
Point2D center = lyrGeoRaster.img2World(lyrGeoRaster.getFLyrPoints().getPoint(i).pixelPoint);
|
265 |
lyrGeoRaster.getFLyrPoints().setMiniExtent( i, |
266 |
center, |
267 |
//lyrGeoRaster.getGeoDialog().getZoomControlLeft().getCanvas().initViewPort(vp, center, lyrGeoRaster.getFLyrPoints().getPoint(i).leftViewPort),
|
268 |
lyrGeoRaster.getGeoDialog().getLeftInitViewport(vp, center, lyrGeoRaster.getFLyrPoints().getPoint(i).leftViewPort, 1),
|
269 |
false);
|
270 |
if(i == lyrGeoRaster.getGeoDialog().getSelectedPoint())
|
271 |
lyrGeoRaster.updateData(i + 1, lyrGeoRaster.getFLyrPoints().getPoint(i).pixelPoint, null, theView); |
272 |
} |
273 |
theView.getMapControl().getMapContext().invalidate(); |
274 |
|
275 |
tmpUl = null;
|
276 |
tmpLr = null;
|
277 |
|
278 |
} |
279 |
isResizable = false;
|
280 |
} |
281 |
} |
282 |
|
283 |
/**
|
284 |
* Al arrastrar cuando se ha pulsado sobre el marco de la imagen recalculamos
|
285 |
* el marco de la imagen
|
286 |
*
|
287 |
* @param e MouseEvent
|
288 |
*/
|
289 |
public void mouseDragged(MouseEvent e) { |
290 |
double longLadoX = Math.abs(tmpLr.getX() - tmpUl.getX()); |
291 |
double longLadoY = Math.abs(tmpLr.getY() - tmpUl.getY()); |
292 |
double coordCentro = 0D; |
293 |
|
294 |
//Guardamos los puntos iniciales para poder reponerlos si excedemos el tama?o m?nimo
|
295 |
Point2D antUl = tmpUl;
|
296 |
Point2D antLr = tmpLr;
|
297 |
|
298 |
coordCentro = tmpLr.getY() + (Math.abs(tmpLr.getY() - tmpUl.getY()) / 2); |
299 |
if(redimActive[0]){//vertical derecha |
300 |
double newLadoX = (e.getX() - tmpUl.getX());
|
301 |
double newLadoY = (newLadoX * longLadoY) / longLadoX;
|
302 |
tmpUl = new Point2D.Double(tmpUl.getX(), coordCentro + (newLadoY/2)); |
303 |
tmpLr = new Point2D.Double(e.getX(), coordCentro - (newLadoY/2)); |
304 |
} |
305 |
if(redimActive[1]){//vertical izquierda |
306 |
double newLadoX = (e.getX() - tmpLr.getX());
|
307 |
double newLadoY = (newLadoX * longLadoY) / longLadoX;
|
308 |
tmpLr = new Point2D.Double(tmpLr.getX(), coordCentro + (newLadoY/2)); |
309 |
tmpUl = new Point2D.Double(e.getX(), coordCentro - (newLadoY/2)); |
310 |
} |
311 |
|
312 |
coordCentro = tmpLr.getX() - (Math.abs(tmpLr.getX() - tmpUl.getX()) / 2); |
313 |
if(redimActive[2]){//horizontal abajo |
314 |
double newLadoY = (e.getY() - tmpLr.getY());
|
315 |
double newLadoX = (newLadoY * longLadoX) / longLadoY;
|
316 |
tmpLr = new Point2D.Double(coordCentro + (newLadoX/2), tmpLr.getY()); |
317 |
tmpUl = new Point2D.Double(coordCentro - (newLadoX/2), e.getY()); |
318 |
} |
319 |
if(redimActive[3]){//horizontal arriba |
320 |
double newLadoY = (e.getY() - tmpUl.getY());
|
321 |
double newLadoX = (newLadoY * longLadoX) / longLadoY;
|
322 |
tmpUl = new Point2D.Double(coordCentro + (newLadoX/2), tmpUl.getY()); |
323 |
tmpLr = new Point2D.Double(coordCentro - (newLadoX/2), e.getY()); |
324 |
} |
325 |
if(redimActive[4]){//Esquina inferior derecha |
326 |
double rel = longLadoX / longLadoY;
|
327 |
double difY = (tmpUl.getY() - e.getY());
|
328 |
double difX = (tmpLr.getX() - e.getX());
|
329 |
if(difX > difY){
|
330 |
difY = difX / rel; |
331 |
}else
|
332 |
difX = difY * rel; |
333 |
tmpUl = new Point2D.Double(tmpUl.getX(), tmpUl.getY() - difY); |
334 |
tmpLr = new Point2D.Double(tmpLr.getX() - difX, tmpLr.getY()); |
335 |
} |
336 |
if(redimActive[5]){//Esquina superior izquierda |
337 |
double rel = longLadoX / longLadoY;
|
338 |
double difY = -(tmpLr.getY() + e.getY());
|
339 |
double difX = (tmpUl.getX() - e.getX());
|
340 |
if(difX > difY){
|
341 |
difY = difX / rel; |
342 |
}else
|
343 |
difX = difY * rel; |
344 |
tmpUl = new Point2D.Double(tmpUl.getX() - difX, tmpUl.getY()); |
345 |
tmpLr = new Point2D.Double(tmpLr.getX(), tmpLr.getY() - difY); |
346 |
} |
347 |
if(redimActive[6]){//Esquina superior derecha |
348 |
double rel = longLadoX / longLadoY;
|
349 |
double difY = -(tmpLr.getY() + e.getY());
|
350 |
double difX = (tmpLr.getX() - e.getX());
|
351 |
if(difX > difY){
|
352 |
difY = difX / rel; |
353 |
}else
|
354 |
difX = difY * rel; |
355 |
tmpUl = new Point2D.Double(tmpUl.getX(), tmpUl.getY()); |
356 |
tmpLr = new Point2D.Double(tmpLr.getX() - difX, tmpLr.getY() + difY); |
357 |
} |
358 |
if(redimActive[7]){//Esquina inferior izquierda |
359 |
double rel = longLadoX / longLadoY;
|
360 |
double difY = -(tmpLr.getY() + e.getY());
|
361 |
double difX = (tmpUl.getX() - e.getX());
|
362 |
if(difX > difY){
|
363 |
difY = difX / rel; |
364 |
}else
|
365 |
difX = difY * rel; |
366 |
tmpUl = new Point2D.Double(tmpUl.getX() - difX, tmpUl.getY() + difY); |
367 |
tmpLr = new Point2D.Double(tmpLr.getX(), tmpLr.getY()); |
368 |
} |
369 |
/*if(redimActive[4]){//inclinado
|
370 |
double distX = (e.getX() - pointInit.getX());
|
371 |
double distY = (e.getY() - pointInit.getY());
|
372 |
double incrLadoX = 0D, incrLadoY = 0D;
|
373 |
|
374 |
if(longLadoY <= longLadoX){
|
375 |
incrLadoX = distX;
|
376 |
incrLadoY = (incrLadoX * longLadoY) / longLadoX;
|
377 |
}else{
|
378 |
incrLadoY = distY;
|
379 |
incrLadoX = (incrLadoY * longLadoX) / longLadoY;
|
380 |
}
|
381 |
if(distX > 0 && e.getX() > lr.getX()){
|
382 |
tmpUl = new Point2D.Double(rectInit.getMinX() - Math.abs(incrLadoX), rectInit.getMinY() + Math.abs(incrLadoY));
|
383 |
tmpLr = new Point2D.Double(rectInit.getMaxX() + Math.abs(incrLadoX), rectInit.getMaxY() - Math.abs(incrLadoY));
|
384 |
}else if(distX < 0 && e.getX() < ul.getX()){
|
385 |
tmpUl = new Point2D.Double(rectInit.getMinX() - Math.abs(incrLadoX), rectInit.getMinY() + Math.abs(incrLadoY));
|
386 |
tmpLr = new Point2D.Double(rectInit.getMaxX() + Math.abs(incrLadoX), rectInit.getMaxY() - Math.abs(incrLadoY));
|
387 |
}else if(distX > 0 && e.getX() < lr.getX() && e.getX() > ul.getX()){
|
388 |
tmpUl = new Point2D.Double(rectInit.getMinX() + Math.abs(incrLadoX), rectInit.getMinY() - Math.abs(incrLadoY));
|
389 |
tmpLr = new Point2D.Double(rectInit.getMaxX() - Math.abs(incrLadoX), rectInit.getMaxY() + Math.abs(incrLadoY));
|
390 |
}else if(distX < 0 && e.getX() < lr.getX() && e.getX() > ul.getX()){
|
391 |
tmpUl = new Point2D.Double(rectInit.getMinX() + Math.abs(incrLadoX), rectInit.getMinY() - Math.abs(incrLadoY));
|
392 |
tmpLr = new Point2D.Double(rectInit.getMaxX() - Math.abs(incrLadoX), rectInit.getMaxY() + Math.abs(incrLadoY));
|
393 |
}
|
394 |
}*/
|
395 |
//A partir de un tama?o m?nimo no reducimos m?s
|
396 |
if((tmpLr.getX() - tmpUl.getX()) < 25 || (tmpUl.getY() - tmpLr.getY()) < 25){ |
397 |
tmpUl = antUl; |
398 |
tmpLr = antLr; |
399 |
} |
400 |
|
401 |
getMapControl().repaint(); |
402 |
} |
403 |
|
404 |
/**
|
405 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#setListener(org.gvsig.georeferencing.fmap.tools.ToolListener)
|
406 |
*/
|
407 |
public void setListener(ToolListener listener) { |
408 |
this.listener = (RectangleListener) listener;
|
409 |
} |
410 |
|
411 |
/**
|
412 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener()
|
413 |
*/
|
414 |
public ToolListener getListener() {
|
415 |
return listener;
|
416 |
} |
417 |
|
418 |
/**
|
419 |
* Cuando movemos el rat?n detecta si estamos en el marco de la
|
420 |
* imagen y pone el icono del cursor del rat?n adecuado.
|
421 |
*/
|
422 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
423 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
424 |
|
425 |
try{
|
426 |
loadLayer(); |
427 |
}catch(InstantiationException exc){ |
428 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
429 |
PluginServices.getText(this, "error_capa_puntos")); |
430 |
return;
|
431 |
}catch(ClassCastException exc){ |
432 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
433 |
PluginServices.getText(this, "error_capa_puntos")); |
434 |
return;
|
435 |
} |
436 |
|
437 |
double wcX = vp.toMapPoint(e.getX(), e.getY()).getX();
|
438 |
double wcY = vp.toMapPoint(e.getX(), e.getY()).getY();
|
439 |
|
440 |
double minX = lyrGeoRaster.getAssignExtent().getMin().getX();
|
441 |
double minY = lyrGeoRaster.getAssignExtent().getMin().getY();
|
442 |
double maxX = lyrGeoRaster.getAssignExtent().getMax().getX();
|
443 |
double maxY = lyrGeoRaster.getAssignExtent().getMax().getY();
|
444 |
|
445 |
//Calculamos el borde sobre el cual cambiar? el puntero del rat?n y la longitud de la esquina
|
446 |
|
447 |
WIDTH_BORDER = (int)Math.round((maxX - minX) * 0.02); |
448 |
LONG_CORNER = (int)Math.round((maxX - minX) * 0.03); |
449 |
if(WIDTH_BORDER < 15) |
450 |
WIDTH_BORDER = 15;
|
451 |
if(LONG_CORNER < 20) |
452 |
LONG_CORNER = 20;
|
453 |
|
454 |
int iconPosActive = -1; |
455 |
|
456 |
//Flecha horizontal
|
457 |
if( ((wcX > minX && wcX < minX + WIDTH_BORDER) ||
|
458 |
(wcX < maxX && wcX > maxX - WIDTH_BORDER )) && |
459 |
(wcY < (maxY - LONG_CORNER)) && |
460 |
(wcY > (minY + LONG_CORNER))){ |
461 |
getMapControl().setCursor(Toolkit.getDefaultToolkit().createCustomCursor(iconHoriz, new Point(16, 16), "")); |
462 |
iconPosActive = 0;
|
463 |
|
464 |
}else{
|
465 |
//Flecha Vertical
|
466 |
if( ((wcY > minY && wcY < minY + WIDTH_BORDER) ||
|
467 |
(wcY < maxY && wcY > maxY - WIDTH_BORDER )) && |
468 |
(wcX < (maxX - LONG_CORNER)) && |
469 |
(wcX > (minX + LONG_CORNER))){ |
470 |
getMapControl().setCursor(Toolkit.getDefaultToolkit().createCustomCursor(iconVert, new Point(16, 16), "")); |
471 |
iconPosActive = 1;
|
472 |
}else{
|
473 |
//Flecha oblicua derecha
|
474 |
if((wcX > (maxX - LONG_CORNER) && wcX < maxX &&
|
475 |
wcY < (minY + LONG_CORNER) && wcY > minY) || |
476 |
(wcX > minX && wcX < (minX + LONG_CORNER) && |
477 |
wcY < maxY && wcY > (maxY - LONG_CORNER))){ |
478 |
getMapControl().setCursor(Toolkit.getDefaultToolkit().createCustomCursor(iconInclIzq, new Point(16, 16), "")); |
479 |
iconPosActive = 2;
|
480 |
}else{
|
481 |
//Flecha oblicua izquierda
|
482 |
if((wcX > minX && wcX < (minX + LONG_CORNER) &&
|
483 |
wcY < (minY + LONG_CORNER) && wcY > minY) || |
484 |
(wcX > (maxX - LONG_CORNER) && wcX < maxX && |
485 |
wcY > (maxY - LONG_CORNER) && wcY < maxY)){ |
486 |
getMapControl().setCursor(Toolkit.getDefaultToolkit().createCustomCursor(iconInclDer, new Point(16, 16), "")); |
487 |
iconPosActive = 3;
|
488 |
}else{
|
489 |
getMapControl().setCursor(Toolkit.getDefaultToolkit().createCustomCursor(defaultCursor, new Point(16, 16), "")); |
490 |
iconPosActive = -1;
|
491 |
} |
492 |
} |
493 |
} |
494 |
} |
495 |
|
496 |
//Ponemos a true el incono activado y a false el resto
|
497 |
for(int i=0;i<iconActive.length;i++){ |
498 |
if(i==iconPosActive)
|
499 |
iconActive[i] = true;
|
500 |
else
|
501 |
iconActive[i] = false;
|
502 |
} |
503 |
getMapControl().repaint(); |
504 |
} |
505 |
|
506 |
} |