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