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