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