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