diff flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/PanControl.java @ 553:c5fc3fa02edb

The MouseOut event will now finish a current pan operation. flys-client/trunk@2067 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 07 Jun 2011 13:58:38 +0000
parents 13c7f90917fc
children ea2191b1299d
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/PanControl.java	Tue Jun 07 13:26:24 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/PanControl.java	Tue Jun 07 13:58:38 2011 +0000
@@ -8,6 +8,7 @@
 import com.smartgwt.client.types.Overflow;
 import com.smartgwt.client.types.SelectionType;
 import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Img;
 import com.smartgwt.client.widgets.ImgButton;
 import com.smartgwt.client.widgets.events.MouseDownEvent;
 import com.smartgwt.client.widgets.events.MouseDownHandler;
@@ -147,7 +148,52 @@
      * @param event The mouse out event.
      */
     public void onMouseOut(MouseOutEvent event) {
-        // TODO Cancel dragging if mouse pointer leaves chart area
+        int x = event.getX();
+        int y = event.getY();
+
+        if (!isSelected() || !isMouseOut(x, y) || start[0] == -1) {
+            return;
+        }
+
+        Canvas parent = chartTab.getChartPanel().getParentElement();
+        parent.setOverflow(Overflow.AUTO);
+
+        fireOnPan();
+
+        start[0] = -1;
+        start[1] = -1;
+    }
+
+
+    /**
+     * 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 = chartTab.getChartPanel();
+
+        if (chart instanceof Img) {
+            chart = chart.getParentElement();
+        }
+
+        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;
     }
 
 

http://dive4elements.wald.intevation.org