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 | 7771 | caballero | /**
|
---|---|---|---|
2 | 9439 | caballero | *
|
3 | 7771 | caballero | */
|
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 | 21743 | vcaballero | import java.awt.geom.Point2D; |
10 | 7771 | caballero | import java.awt.geom.Rectangle2D; |
11 | |||
12 | 21743 | vcaballero | import org.gvsig.fmap.geom.primitive.Envelope; |
13 | 27022 | jpiera | import org.gvsig.fmap.geom.util.UtilFunctions; |
14 | 20994 | jmvivo | import org.gvsig.fmap.mapcontext.ViewPort; |
15 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
16 | import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
||
17 | 21743 | vcaballero | import org.gvsig.fmap.mapcontrol.tools.Events.EnvelopeEvent; |
18 | 24759 | jmvivo | import org.gvsig.fmap.mapcontrol.tools.Events.MoveEvent; |
19 | 20994 | jmvivo | import org.gvsig.fmap.mapcontrol.tools.Listeners.PanListener; |
20 | import org.gvsig.fmap.mapcontrol.tools.Listeners.RectangleListener; |
||
21 | |||
22 | 14821 | jmvivo | import com.iver.andami.PluginServices; |
23 | 7771 | caballero | import com.iver.cit.gvsig.project.documents.view.MapOverview; |
24 | |||
25 | /**
|
||
26 | 20098 | jmvivo | * <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 | 21743 | vcaballero | *
|
32 | 20098 | jmvivo | * <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 | 21743 | vcaballero | *
|
36 | 20098 | jmvivo | * @see ViewPort
|
37 | 21743 | vcaballero | *
|
38 | 7771 | caballero | * @author jmvivo
|
39 | */
|
||
40 | public class MapOverviewChangeZoomListener implements RectangleListener, PanListener { |
||
41 | 20098 | jmvivo | /**
|
42 | * The image to display when the cursor is active.
|
||
43 | */
|
||
44 | 14821 | jmvivo | private final Image izoomin = PluginServices.getIconTheme() |
45 | .get("cursor-zoom-in").getImage();
|
||
46 | 20098 | jmvivo | |
47 | /**
|
||
48 | * The cursor used to work with this tool listener.
|
||
49 | 21743 | vcaballero | *
|
50 | 20098 | jmvivo | * @see #getCursor()
|
51 | */
|
||
52 | 23642 | vcaballero | // private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(izoomin,new Point(16, 16), "");
|
53 | 20098 | jmvivo | |
54 | /**
|
||
55 | * Reference to the <code>MapControl</code> object that uses.
|
||
56 | */
|
||
57 | 7771 | caballero | protected MapControl mapControl;
|
58 | 9439 | caballero | |
59 | 7771 | caballero | /**
|
60 | 20098 | jmvivo | * <p>Creates a new listener for changes of zoom at the associated {@link MapOverview MapOverview} object.</p>
|
61 | 7771 | caballero | *
|
62 | 21743 | vcaballero | * @param mapControl the <code>MapControl</code> object which represents the <code>MapOverview</code>
|
63 | 7771 | caballero | */
|
64 | public MapOverviewChangeZoomListener(MapControl mapControl) {
|
||
65 | this.mapControl=mapControl;
|
||
66 | } |
||
67 | 9439 | caballero | |
68 | 20098 | jmvivo | /*
|
69 | * (non-Javadoc)
|
||
70 | 9439 | caballero | * @see com.iver.cit.gvsig.fmap.tools.Listeners.RectangleListener#rectangle(com.iver.cit.gvsig.fmap.tools.Events.RectangleEvent)
|
71 | 7771 | caballero | */
|
72 | 21743 | vcaballero | public void rectangle(EnvelopeEvent event) throws BehaviorException { |
73 | 9439 | caballero | |
74 | 7771 | caballero | 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 | 9439 | caballero | |
81 | 7771 | caballero | if (vp.getExtent() != null && vpView.getExtent() != null) { |
82 | 9439 | caballero | |
83 | 7771 | caballero | // 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 | 21743 | vcaballero | Envelope realRectangle = event.getWorldCoordRect(); |
87 | 9439 | caballero | |
88 | 7771 | caballero | if ((pxRectangle.getWidth() < 3) && (pxRectangle.getHeight() < 3)) |
89 | { |
||
90 | // rectangulo < 3 px no hacemos nada
|
||
91 | return;
|
||
92 | 9439 | caballero | |
93 | 7771 | caballero | } else {
|
94 | // Cambiamos la extension de la vista asociada al localizador
|
||
95 | 21501 | vcaballero | vpView.setEnvelope(realRectangle); |
96 | 12214 | jcampos | mov.getAssociatedMapContext().invalidate(); |
97 | 21501 | vcaballero | vpView.setEnvelope(realRectangle); |
98 | 7771 | caballero | } |
99 | } |
||
100 | } |
||
101 | |||
102 | 20098 | jmvivo | /*
|
103 | 7771 | caballero | * (non-Javadoc)
|
104 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
|
||
105 | 20098 | jmvivo | */
|
106 | 23642 | vcaballero | public Image getImageCursor() { |
107 | return izoomin;
|
||
108 | 7771 | caballero | } |
109 | |||
110 | /* (non-Javadoc)
|
||
111 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
||
112 | */
|
||
113 | 9439 | caballero | public boolean cancelDrawing() { |
114 | 7771 | caballero | return true; //??? |
115 | } |
||
116 | 9439 | caballero | |
117 | 20098 | jmvivo | /*
|
118 | * (non-Javadoc)
|
||
119 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.PanListener#move(com.iver.cit.gvsig.fmap.tools.Events.MoveEvent)
|
||
120 | */
|
||
121 | 7771 | caballero | public void move(MoveEvent event) throws BehaviorException { |
122 | 9439 | caballero | |
123 | |||
124 | 7771 | caballero | 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 | 9439 | caballero | ViewPort vp = mov.getViewPort(); |
131 | |||
132 | 7771 | caballero | if (vp.getExtent() != null && vpView.getExtent() != null) { |
133 | |||
134 | // Creamos un recuadro con las coordenadas del raton
|
||
135 | // traducidas a la del mapa
|
||
136 | 21743 | vcaballero | // Rectangle2D realRectangle = new Rectangle2D.Double();
|
137 | Point2D p1=vp.toMapPoint(event.getFrom());
|
||
138 | Point2D p2=vp.toMapPoint(event.getTo());
|
||
139 | 27022 | jpiera | Envelope realRectangle = UtilFunctions.createEnvelope(p1.getX(),p1.getY(),p2.getX(),p2.getY()); |
140 | 21743 | vcaballero | // realRectangle.setFrameFromDiagonal(vp.toMapPoint(event.getFrom()),vp.toMapPoint(event.getTo()));
|
141 | 9439 | caballero | |
142 | 7771 | caballero | // Establecemos la forma
|
143 | mov.refreshOverView(realRectangle); |
||
144 | } |
||
145 | 9439 | caballero | |
146 | |||
147 | |||
148 | 7771 | caballero | } |
149 | 9439 | caballero | |
150 | 21743 | vcaballero | /**
|
151 | 20098 | jmvivo | * Determines if has pressed the button 1 of the mouse.
|
152 | */
|
||
153 | 9439 | caballero | private boolean checkModifiers(MouseEvent event) { |
154 | 7771 | caballero | int modifiers = event.getModifiers();
|
155 | int keyPressedMask = InputEvent.BUTTON1_MASK; |
||
156 | return ((modifiers & keyPressedMask) == keyPressedMask);
|
||
157 | } |
||
158 | } |