changeset 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 27fb059da15f
children 95a7f9cb3d58
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ZoomboxControl.java
diffstat 2 files changed, 73 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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 <ingo@intevation.de>
+
+	* 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 <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.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<ZoomHandler> 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);
     }
 
 

http://dive4elements.wald.intevation.org