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