Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ZoomboxControl.java @ 546:feaf6a8881ee
Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
flys-client/trunk@2055 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 06 Jun 2011 08:21:08 +0000 |
parents | 9c2cf4811a7d |
children | f1a559d13eef |
comparison
equal
deleted
inserted
replaced
545:27fb059da15f | 546:feaf6a8881ee |
---|---|
11 import com.smartgwt.client.widgets.Canvas; | 11 import com.smartgwt.client.widgets.Canvas; |
12 import com.smartgwt.client.widgets.events.MouseDownEvent; | 12 import com.smartgwt.client.widgets.events.MouseDownEvent; |
13 import com.smartgwt.client.widgets.events.MouseDownHandler; | 13 import com.smartgwt.client.widgets.events.MouseDownHandler; |
14 import com.smartgwt.client.widgets.events.MouseMoveEvent; | 14 import com.smartgwt.client.widgets.events.MouseMoveEvent; |
15 import com.smartgwt.client.widgets.events.MouseMoveHandler; | 15 import com.smartgwt.client.widgets.events.MouseMoveHandler; |
16 import com.smartgwt.client.widgets.events.MouseOutEvent; | |
17 import com.smartgwt.client.widgets.events.MouseOutHandler; | |
16 import com.smartgwt.client.widgets.events.MouseUpEvent; | 18 import com.smartgwt.client.widgets.events.MouseUpEvent; |
17 import com.smartgwt.client.widgets.events.MouseUpHandler; | 19 import com.smartgwt.client.widgets.events.MouseUpHandler; |
18 | 20 |
19 import de.intevation.flys.client.client.event.HasZoomHandlers; | 21 import de.intevation.flys.client.client.event.HasZoomHandlers; |
20 import de.intevation.flys.client.client.event.ZoomEvent; | 22 import de.intevation.flys.client.client.event.ZoomEvent; |
31 * | 33 * |
32 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 34 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
33 */ | 35 */ |
34 public class ZoomboxControl | 36 public class ZoomboxControl |
35 extends ImgButton | 37 extends ImgButton |
36 implements MouseDownHandler, MouseUpHandler, MouseMoveHandler, HasZoomHandlers | 38 implements MouseDownHandler, MouseUpHandler, MouseMoveHandler, HasZoomHandlers, |
39 MouseOutHandler | |
37 { | 40 { |
38 protected List<ZoomHandler> handlers; | 41 protected List<ZoomHandler> handlers; |
39 | 42 |
40 protected ChartOutputTab chartTab; | 43 protected ChartOutputTab chartTab; |
41 | 44 |
62 setSize(20); | 65 setSize(20); |
63 setShowRollOver(false); | 66 setShowRollOver(false); |
64 setSelected(false); | 67 setSelected(false); |
65 | 68 |
66 chartTab.getChartPanel().addMouseDownHandler(this); | 69 chartTab.getChartPanel().addMouseDownHandler(this); |
70 chartTab.getChartPanel().addMouseOutHandler(this); | |
67 chartTab.getChartPanel().addMouseMoveHandler(this); | 71 chartTab.getChartPanel().addMouseMoveHandler(this); |
68 chartTab.getChartPanel().addMouseUpHandler(this); | 72 chartTab.getChartPanel().addMouseUpHandler(this); |
69 } | 73 } |
70 | 74 |
71 | 75 |
112 start[1] = getRelativeY(event.getY()); | 116 start[1] = getRelativeY(event.getY()); |
113 | 117 |
114 end[0] = start[0]; | 118 end[0] = start[0]; |
115 end[1] = start[1]; | 119 end[1] = start[1]; |
116 | 120 |
117 chartTab.getChartPanel().addChild(zoombox); | 121 Canvas c = getChartPanel(); |
122 c.addChild(zoombox); | |
118 | 123 |
119 positionZoombox(); | 124 positionZoombox(); |
120 } | 125 } |
121 | 126 |
122 | 127 |
156 end[1] = getRelativeY(event.getY()); | 161 end[1] = getRelativeY(event.getY()); |
157 | 162 |
158 fireZoomEvent(); | 163 fireZoomEvent(); |
159 | 164 |
160 clearZoombox(); | 165 clearZoombox(); |
161 | 166 } |
162 chartTab.getChartPanel().removeChild(zoombox); | 167 |
168 | |
169 /** | |
170 * The mouse out event is used to cancel an active zoom operation. | |
171 * | |
172 * @param event The mouse out event. | |
173 */ | |
174 public void onMouseOut(MouseOutEvent event) { | |
175 if (!isSelected() || !isMouseOut(event.getX(), event.getY())) { | |
176 return; | |
177 } | |
178 | |
179 start[0] = 0; | |
180 start[1] = 0; | |
181 end[0] = 0; | |
182 end[1] = 0; | |
183 | |
184 clearZoombox(); | |
185 } | |
186 | |
187 | |
188 /** | |
189 * Returns the chart panel. | |
190 * | |
191 * @return the chart panel. | |
192 */ | |
193 protected Canvas getChartPanel() { | |
194 return chartTab.getChartPanel(); | |
195 } | |
196 | |
197 | |
198 /** | |
199 * This method is required to check manually if the mouse pointer really | |
200 * moves out the chart area. The MouseOutEvent is also fired if the mouse | |
201 * goes down which doesn't seem to be correct. So, we gonna check this | |
202 * manually. | |
203 * | |
204 * @param x The x coordinate. | |
205 * @param y The y coordinate. | |
206 * | |
207 * @return true, if the mouse is really out of the chart area, otherwise | |
208 * false. | |
209 */ | |
210 protected boolean isMouseOut(int x, int y) { | |
211 Canvas chart = getChartPanel(); | |
212 | |
213 int left = chart.getPageLeft(); | |
214 int right = chart.getPageRight(); | |
215 int top = chart.getPageTop(); | |
216 int bottom = chart.getPageBottom(); | |
217 | |
218 if (x <= left || x >= right || y <= top || y >= bottom) { | |
219 return true; | |
220 } | |
221 | |
222 return false; | |
163 } | 223 } |
164 | 224 |
165 | 225 |
166 /** | 226 /** |
167 * Returns the X coordinate relative to the left border. | 227 * Returns the X coordinate relative to the left border. |
223 protected void clearZoombox() { | 283 protected void clearZoombox() { |
224 zoombox.setLeft(0); | 284 zoombox.setLeft(0); |
225 zoombox.setTop(0); | 285 zoombox.setTop(0); |
226 zoombox.setWidth(0); | 286 zoombox.setWidth(0); |
227 zoombox.setHeight(0); | 287 zoombox.setHeight(0); |
288 | |
289 Canvas c = getChartPanel(); | |
290 c.removeChild(zoombox); | |
228 } | 291 } |
229 | 292 |
230 | 293 |
231 /** | 294 /** |
232 * Fires a ZoomEvent to all registered listeners. | 295 * Fires a ZoomEvent to all registered listeners. |