root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / toolListeners / MapOverviewChangeZoomListener.java @ 7304
History | View | Annotate | Download (3.88 KB)
1 |
/**
|
---|---|
2 |
*
|
3 |
*/
|
4 |
package com.iver.cit.gvsig.gui.toolListeners; |
5 |
|
6 |
import java.awt.Cursor; |
7 |
import java.awt.Event; |
8 |
import java.awt.Image; |
9 |
import java.awt.Point; |
10 |
import java.awt.Toolkit; |
11 |
import java.awt.event.InputEvent; |
12 |
import java.awt.event.MouseEvent; |
13 |
import java.awt.geom.Point2D; |
14 |
import java.awt.geom.Rectangle2D; |
15 |
|
16 |
import javax.swing.ImageIcon; |
17 |
|
18 |
import com.iver.cit.gvsig.fmap.MapControl; |
19 |
import com.iver.cit.gvsig.fmap.ViewPort; |
20 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
21 |
import com.iver.cit.gvsig.fmap.tools.ZoomInListenerImpl; |
22 |
import com.iver.cit.gvsig.fmap.tools.Events.MoveEvent; |
23 |
import com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent; |
24 |
import com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener; |
25 |
import com.iver.cit.gvsig.fmap.tools.Listeners.PanListener; |
26 |
import com.iver.cit.gvsig.project.documents.view.MapOverview; |
27 |
|
28 |
/**
|
29 |
* @author jmvivo
|
30 |
*
|
31 |
*/
|
32 |
|
33 |
|
34 |
|
35 |
public class MapOverviewChangeZoomListener implements RectangleListener, PanListener { |
36 |
private final Image izoomin = new ImageIcon(MapControl.class.getResource( |
37 |
"images/ZoomInCursor.gif")).getImage();
|
38 |
private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(izoomin,new Point(16, 16), ""); |
39 |
protected MapControl mapControl;
|
40 |
|
41 |
/**
|
42 |
* Crea un nuevo MapOverviewChangeZoomListener.
|
43 |
*
|
44 |
* @param mapControl Control de mapa asociado
|
45 |
*/
|
46 |
public MapOverviewChangeZoomListener(MapControl mapControl) {
|
47 |
this.mapControl=mapControl;
|
48 |
} |
49 |
|
50 |
/**
|
51 |
* Cambia el zoom. Es llamado cuando finaliza de
|
52 |
* pintar el recuadro
|
53 |
*
|
54 |
*
|
55 |
*
|
56 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener#rectangle(com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent)
|
57 |
*/
|
58 |
public void rectangle(RectangleEvent event) throws BehaviorException { |
59 |
|
60 |
if (!checkModifiers(event.getEvent())){
|
61 |
return;
|
62 |
} |
63 |
MapOverview mov=(MapOverview) this.mapControl;
|
64 |
ViewPort vpView=mov.getAssociatedMapContext().getViewPort(); |
65 |
ViewPort vp = mov.getViewPort(); |
66 |
|
67 |
if (vp.getExtent() != null && vpView.getExtent() != null) { |
68 |
|
69 |
// Recuperamos las coordenadas del evento en px
|
70 |
Rectangle2D pxRectangle = event.getPixelCoordRect();
|
71 |
// Recuperamos las coordenadas del evento en coordenadas de la vista de localizador
|
72 |
Rectangle2D realRectangle = event.getWorldCoordRect();
|
73 |
|
74 |
if ((pxRectangle.getWidth() < 3) && (pxRectangle.getHeight() < 3)) |
75 |
{ |
76 |
// rectangulo < 3 px no hacemos nada
|
77 |
return;
|
78 |
|
79 |
} else {
|
80 |
// Cambiamos la extension de la vista asociada al localizador
|
81 |
vpView.setExtent(realRectangle); |
82 |
} |
83 |
|
84 |
} |
85 |
|
86 |
|
87 |
} |
88 |
|
89 |
/**
|
90 |
* (non-Javadoc)
|
91 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
|
92 |
**/
|
93 |
public Cursor getCursor() { |
94 |
return this.cur; |
95 |
} |
96 |
|
97 |
/* (non-Javadoc)
|
98 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
99 |
*/
|
100 |
public boolean cancelDrawing() { |
101 |
return true; //??? |
102 |
} |
103 |
|
104 |
/**
|
105 |
* Es llamado mientras se hace del 'Dragg' del
|
106 |
* raton. Pinta el recuadro de la forma.
|
107 |
**/
|
108 |
public void move(MoveEvent event) throws BehaviorException { |
109 |
|
110 |
|
111 |
if (!checkModifiers(event.getEvent())){
|
112 |
return;
|
113 |
} |
114 |
System.out.println("mapOvervierChangeZoom"); |
115 |
MapOverview mov=(MapOverview) this.mapControl;
|
116 |
ViewPort vpView=mov.getAssociatedMapContext().getViewPort(); |
117 |
ViewPort vp = mov.getViewPort(); |
118 |
|
119 |
if (vp.getExtent() != null && vpView.getExtent() != null) { |
120 |
|
121 |
// Creamos un recuadro con las coordenadas del raton
|
122 |
// traducidas a la del mapa
|
123 |
Rectangle2D realRectangle = new Rectangle2D.Double(); |
124 |
realRectangle.setFrameFromDiagonal(vp.toMapPoint(event.getFrom()),vp.toMapPoint(event.getTo())); |
125 |
|
126 |
// Establecemos la forma
|
127 |
mov.refreshOverView(realRectangle); |
128 |
} |
129 |
|
130 |
|
131 |
|
132 |
} |
133 |
|
134 |
/**
|
135 |
* Comprueba que el estado de los botones
|
136 |
* sea el deseado para esta herramienta.
|
137 |
**/
|
138 |
private boolean checkModifiers(MouseEvent event) { |
139 |
int modifiers = event.getModifiers();
|
140 |
int keyPressedMask = InputEvent.BUTTON1_MASK; |
141 |
return ((modifiers & keyPressedMask) == keyPressedMask);
|
142 |
} |
143 |
|
144 |
} |