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