root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toolListeners / MapOverviewChangeZoomListener.java @ 27035
History | View | Annotate | Download (4.9 KB)
1 |
/**
|
---|---|
2 |
*
|
3 |
*/
|
4 |
package com.iver.cit.gvsig.project.documents.view.toolListeners; |
5 |
|
6 |
import java.awt.Image; |
7 |
import java.awt.event.InputEvent; |
8 |
import java.awt.event.MouseEvent; |
9 |
import java.awt.geom.Point2D; |
10 |
import java.awt.geom.Rectangle2D; |
11 |
|
12 |
import org.gvsig.fmap.geom.primitive.Envelope; |
13 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
14 |
import org.gvsig.fmap.mapcontext.ViewPort; |
15 |
import org.gvsig.fmap.mapcontrol.MapControl; |
16 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
17 |
import org.gvsig.fmap.mapcontrol.tools.Events.EnvelopeEvent; |
18 |
import org.gvsig.fmap.mapcontrol.tools.Events.MoveEvent; |
19 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.PanListener; |
20 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.RectangleListener; |
21 |
|
22 |
import com.iver.andami.PluginServices; |
23 |
import com.iver.cit.gvsig.project.documents.view.MapOverview; |
24 |
|
25 |
/**
|
26 |
* <p>Listener for changes of the zoom caused by selecting a rectangular area on the associated
|
27 |
* {@link MapOverview MapOverview} object with the first button of the mouse.</p>
|
28 |
*
|
29 |
* <p>If the kind of action was a movement on the associated object,
|
30 |
* updates the <i>extent</i> of its rectangular area.</p>
|
31 |
*
|
32 |
* <p>If the kind of action is the selection of a rectangular area, and is bigger than 3x3 pixels,
|
33 |
* applies a <i>zoom in</i> operation centering its <code>ViewPort</code> according the equivalent <i>extent</i>
|
34 |
* in map coordinates.</p>
|
35 |
*
|
36 |
* @see ViewPort
|
37 |
*
|
38 |
* @author jmvivo
|
39 |
*/
|
40 |
public class MapOverviewChangeZoomListener implements RectangleListener, PanListener { |
41 |
/**
|
42 |
* The image to display when the cursor is active.
|
43 |
*/
|
44 |
private final Image izoomin = PluginServices.getIconTheme() |
45 |
.get("cursor-zoom-in").getImage();
|
46 |
|
47 |
/**
|
48 |
* The cursor used to work with this tool listener.
|
49 |
*
|
50 |
* @see #getCursor()
|
51 |
*/
|
52 |
// private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(izoomin,new Point(16, 16), "");
|
53 |
|
54 |
/**
|
55 |
* Reference to the <code>MapControl</code> object that uses.
|
56 |
*/
|
57 |
protected MapControl mapControl;
|
58 |
|
59 |
/**
|
60 |
* <p>Creates a new listener for changes of zoom at the associated {@link MapOverview MapOverview} object.</p>
|
61 |
*
|
62 |
* @param mapControl the <code>MapControl</code> object which represents the <code>MapOverview</code>
|
63 |
*/
|
64 |
public MapOverviewChangeZoomListener(MapControl mapControl) {
|
65 |
this.mapControl=mapControl;
|
66 |
} |
67 |
|
68 |
/*
|
69 |
* (non-Javadoc)
|
70 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener#rectangle(com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent)
|
71 |
*/
|
72 |
public void rectangle(EnvelopeEvent event) throws BehaviorException { |
73 |
|
74 |
if (!checkModifiers(event.getEvent())){
|
75 |
return;
|
76 |
} |
77 |
MapOverview mov=(MapOverview) this.mapControl;
|
78 |
ViewPort vpView=mov.getAssociatedMapContext().getViewPort(); |
79 |
ViewPort vp = mov.getViewPort(); |
80 |
|
81 |
if (vp.getExtent() != null && vpView.getExtent() != null) { |
82 |
|
83 |
// Recuperamos las coordenadas del evento en px
|
84 |
Rectangle2D pxRectangle = event.getPixelCoordRect();
|
85 |
// Recuperamos las coordenadas del evento en coordenadas de la vista de localizador
|
86 |
Envelope realRectangle = event.getWorldCoordRect(); |
87 |
|
88 |
if ((pxRectangle.getWidth() < 3) && (pxRectangle.getHeight() < 3)) |
89 |
{ |
90 |
// rectangulo < 3 px no hacemos nada
|
91 |
return;
|
92 |
|
93 |
} else {
|
94 |
// Cambiamos la extension de la vista asociada al localizador
|
95 |
vpView.setEnvelope(realRectangle); |
96 |
mov.getAssociatedMapContext().invalidate(); |
97 |
vpView.setEnvelope(realRectangle); |
98 |
} |
99 |
} |
100 |
} |
101 |
|
102 |
/*
|
103 |
* (non-Javadoc)
|
104 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
|
105 |
*/
|
106 |
public Image getImageCursor() { |
107 |
return izoomin;
|
108 |
} |
109 |
|
110 |
/* (non-Javadoc)
|
111 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
112 |
*/
|
113 |
public boolean cancelDrawing() { |
114 |
return true; //??? |
115 |
} |
116 |
|
117 |
/*
|
118 |
* (non-Javadoc)
|
119 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PanListener#move(com.iver.cit.gvsig.fmap.tools.Events.MoveEvent)
|
120 |
*/
|
121 |
public void move(MoveEvent event) throws BehaviorException { |
122 |
|
123 |
|
124 |
if (!checkModifiers(event.getEvent())){
|
125 |
return;
|
126 |
} |
127 |
System.out.println("mapOvervierChangeZoom"); |
128 |
MapOverview mov=(MapOverview) this.mapControl;
|
129 |
ViewPort vpView=mov.getAssociatedMapContext().getViewPort(); |
130 |
ViewPort vp = mov.getViewPort(); |
131 |
|
132 |
if (vp.getExtent() != null && vpView.getExtent() != null) { |
133 |
|
134 |
// Creamos un recuadro con las coordenadas del raton
|
135 |
// traducidas a la del mapa
|
136 |
// Rectangle2D realRectangle = new Rectangle2D.Double();
|
137 |
Point2D p1=vp.toMapPoint(event.getFrom());
|
138 |
Point2D p2=vp.toMapPoint(event.getTo());
|
139 |
Envelope realRectangle = UtilFunctions.createEnvelope(p1.getX(),p1.getY(),p2.getX(),p2.getY()); |
140 |
// realRectangle.setFrameFromDiagonal(vp.toMapPoint(event.getFrom()),vp.toMapPoint(event.getTo()));
|
141 |
|
142 |
// Establecemos la forma
|
143 |
mov.refreshOverView(realRectangle); |
144 |
} |
145 |
|
146 |
|
147 |
|
148 |
} |
149 |
|
150 |
/**
|
151 |
* Determines if has pressed the button 1 of the mouse.
|
152 |
*/
|
153 |
private boolean checkModifiers(MouseEvent event) { |
154 |
int modifiers = event.getModifiers();
|
155 |
int keyPressedMask = InputEvent.BUTTON1_MASK; |
156 |
return ((modifiers & keyPressedMask) == keyPressedMask);
|
157 |
} |
158 |
} |