# HG changeset patch # User Ingo Weinzierl # Date 1307348468 0 # Node ID feaf6a8881eec837d0832b881d819c2f35ab399c # Parent 27fb059da15fc41a76904705b355f25f7d89a5fc 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 diff -r 27fb059da15f -r feaf6a8881ee flys-client/ChangeLog --- a/flys-client/ChangeLog Fri Jun 03 12:19:34 2011 +0000 +++ b/flys-client/ChangeLog Mon Jun 06 08:21:08 2011 +0000 @@ -1,3 +1,10 @@ +2011-06-06 Ingo Weinzierl + + * src/main/java/de/intevation/flys/client/client/ui/chart/ZoomboxControl.java: + Added a handler that listens to mouse out events. If the mouse moves out + of the chart area, the current zoom operation is canceled. The zoombox + and the coordinates are reset. + 2011-06-03 Ingo Weinzierl * src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java: diff -r 27fb059da15f -r feaf6a8881ee flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ZoomboxControl.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ZoomboxControl.java Fri Jun 03 12:19:34 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ZoomboxControl.java Mon Jun 06 08:21:08 2011 +0000 @@ -13,6 +13,8 @@ import com.smartgwt.client.widgets.events.MouseDownHandler; import com.smartgwt.client.widgets.events.MouseMoveEvent; import com.smartgwt.client.widgets.events.MouseMoveHandler; +import com.smartgwt.client.widgets.events.MouseOutEvent; +import com.smartgwt.client.widgets.events.MouseOutHandler; import com.smartgwt.client.widgets.events.MouseUpEvent; import com.smartgwt.client.widgets.events.MouseUpHandler; @@ -33,7 +35,8 @@ */ public class ZoomboxControl extends ImgButton -implements MouseDownHandler, MouseUpHandler, MouseMoveHandler, HasZoomHandlers +implements MouseDownHandler, MouseUpHandler, MouseMoveHandler, HasZoomHandlers, + MouseOutHandler { protected List handlers; @@ -64,6 +67,7 @@ setSelected(false); chartTab.getChartPanel().addMouseDownHandler(this); + chartTab.getChartPanel().addMouseOutHandler(this); chartTab.getChartPanel().addMouseMoveHandler(this); chartTab.getChartPanel().addMouseUpHandler(this); } @@ -114,7 +118,8 @@ end[0] = start[0]; end[1] = start[1]; - chartTab.getChartPanel().addChild(zoombox); + Canvas c = getChartPanel(); + c.addChild(zoombox); positionZoombox(); } @@ -158,8 +163,63 @@ fireZoomEvent(); clearZoombox(); + } - chartTab.getChartPanel().removeChild(zoombox); + + /** + * The mouse out event is used to cancel an active zoom operation. + * + * @param event The mouse out event. + */ + public void onMouseOut(MouseOutEvent event) { + if (!isSelected() || !isMouseOut(event.getX(), event.getY())) { + return; + } + + start[0] = 0; + start[1] = 0; + end[0] = 0; + end[1] = 0; + + clearZoombox(); + } + + + /** + * Returns the chart panel. + * + * @return the chart panel. + */ + protected Canvas getChartPanel() { + return chartTab.getChartPanel(); + } + + + /** + * This method is required to check manually if the mouse pointer really + * moves out the chart area. The MouseOutEvent is also fired if the mouse + * goes down which doesn't seem to be correct. So, we gonna check this + * manually. + * + * @param x The x coordinate. + * @param y The y coordinate. + * + * @return true, if the mouse is really out of the chart area, otherwise + * false. + */ + protected boolean isMouseOut(int x, int y) { + Canvas chart = getChartPanel(); + + int left = chart.getPageLeft(); + int right = chart.getPageRight(); + int top = chart.getPageTop(); + int bottom = chart.getPageBottom(); + + if (x <= left || x >= right || y <= top || y >= bottom) { + return true; + } + + return false; } @@ -225,6 +285,9 @@ zoombox.setTop(0); zoombox.setWidth(0); zoombox.setHeight(0); + + Canvas c = getChartPanel(); + c.removeChild(zoombox); }