Bug 4677 fixed: xclick did not return correct mouse position on keyboard event 76/13276/2
Calixte DENIZET [Fri, 29 Nov 2013 13:13:18 +0000 (14:13 +0100)]
Change-Id: I2a1a7c85c2045c12743da6940e7e8f4763d22d2b

scilab/CHANGES_5.5.X
scilab/modules/gui/src/java/org/scilab/modules/gui/events/GlobalEventFilter.java
scilab/modules/gui/src/java/org/scilab/modules/gui/events/Jxclick.java
scilab/modules/gui/src/java/org/scilab/modules/gui/events/Jxgetmouse.java

index 7a04eb1..e68207c 100644 (file)
@@ -41,6 +41,8 @@ Scilab Bug Fixes
 
 * Bug #4649 fixed - License issue in the xs2ppm help page fixed.
 
+* Bug #4677 fixed - xclick did not return correct mouse position on keyboard event.
+
 * Bug #4965 fixed - Setting links property for a handle of type legend did not work.
 
 * Bug #5016 fixed - condestsp could return different results when repeated calls were performed.
index bedcfff..8bc9e14 100644 (file)
@@ -43,12 +43,12 @@ public class GlobalEventFilter {
      * @param figureUID Scilab ID of the figure where the even occurred
      * @param isControlDown : is CTRL key modifier activated.
      */
-    public static void filterKey(int keyPressed, Integer figureUID, boolean isControlDown) {
+    public static void filterKey(int keyPressed, Integer figureUID, boolean isControlDown, Component source) {
         synchronized (ClickInfos.getInstance()) {
             ClickInfos.getInstance().setMouseButtonNumber(SciTranslator.javaKey2Scilab(keyPressed, isControlDown));
             ClickInfos.getInstance().setWindowID(figureUID);
-            ClickInfos.getInstance().setXCoordinate(MouseInfo.getPointerInfo().getLocation().x);
-            ClickInfos.getInstance().setYCoordinate(MouseInfo.getPointerInfo().getLocation().y);
+            ClickInfos.getInstance().setXCoordinate(MouseInfo.getPointerInfo().getLocation().x - source.getLocationOnScreen().getX());
+            ClickInfos.getInstance().setYCoordinate(MouseInfo.getPointerInfo().getLocation().y - source.getLocationOnScreen().getY());
             ClickInfos.getInstance().notify();
         }
     }
@@ -102,19 +102,11 @@ public class GlobalEventFilter {
                 );
                 ClickInfos.getInstance().setWindowID(axesUID);
                 try {
-                    ClickInfos.getInstance().setXCoordinate(mouseEvent.getX()
-                                                            + ((Component) mouseEvent.getSource()).getLocationOnScreen().getX()
-                                                            - ((Component) mouseEvent.getSource()).getLocationOnScreen().getX());
-                    ClickInfos.getInstance().setYCoordinate(mouseEvent.getY()
-                                                            + ((Component) mouseEvent.getSource()).getLocationOnScreen().getY()
-                                                            - ((Component) mouseEvent.getSource()).getLocationOnScreen().getY());
+                    ClickInfos.getInstance().setXCoordinate(mouseEvent.getX());
+                    ClickInfos.getInstance().setYCoordinate(mouseEvent.getY());
                 } catch (Exception e) {
-                    ClickInfos.getInstance().setXCoordinate(mouseEvent.getX()
-                                                            + ((Component) mouseEvent.getSource()).getX()
-                                                            - ((Component) mouseEvent.getSource()).getX());
-                    ClickInfos.getInstance().setYCoordinate(mouseEvent.getY()
-                                                            + ((Component) mouseEvent.getSource()).getY()
-                                                            - ((Component) mouseEvent.getSource()).getY());
+                    ClickInfos.getInstance().setXCoordinate(mouseEvent.getX());
+                    ClickInfos.getInstance().setYCoordinate(mouseEvent.getY());
                 } finally {
                     ClickInfos.getInstance().notify();
                 }
index 8f41722..92c71af 100644 (file)
@@ -124,11 +124,8 @@ public final class Jxclick {
                 }
             }
         } else if (keyEvent.getID() == KeyEvent.KEY_TYPED) {
-            if (keyEvent.getSource() != null
-                    && keyEvent.getSource() instanceof SwingScilabCanvas) {
-                if (GlobalEventWatcher.isActivated()) {
-                    GlobalEventFilter.filterKey(keyChar, GlobalEventWatcher.getAxesUID(), keyEvent.isControlDown());
-                }
+            if (keyEvent.getSource() instanceof SwingScilabCanvas && GlobalEventWatcher.isActivated()) {
+                GlobalEventFilter.filterKey(keyChar, GlobalEventWatcher.getAxesUID(), keyEvent.isControlDown(), (SwingScilabCanvas) keyEvent.getSource());
             }
         }
     }
index fda750d..9478bfa 100644 (file)
@@ -119,8 +119,6 @@ public final class Jxgetmouse {
         return ClickInfos.getInstance().getWindowID();
     }
 
-
-
     /**
      * Manage xgetmouse behaviour for keyboard entry.
      * 1 - Key has been pressed.
@@ -144,22 +142,22 @@ public final class Jxgetmouse {
                 }
             }
             isControlDown = keyEvent.isControlDown();
-        } else if (keyEvent.getSource() != null
-                   && keyEvent.getSource() instanceof SwingScilabCanvas) {
+        } else if (keyEvent.getSource() instanceof SwingScilabCanvas) {
             /* Now we have have to be sure we are in a Canvas. */
             /*
              * If a RELEASED is seen use -keyChar
              */
             if (keyEvent.getID() == KeyEvent.KEY_RELEASED) {
-                GlobalEventFilter.filterKey(-keyChar, GlobalEventWatcher.getAxesUID(), isControlDown);
+                GlobalEventFilter.filterKey(-keyChar, GlobalEventWatcher.getAxesUID(), isControlDown, (SwingScilabCanvas) keyEvent.getSource());
             } else if (keyEvent.getID() == KeyEvent.KEY_TYPED) {
                 /*
                  * Or If a TYPED is seen use keyChar
                  */
-                GlobalEventFilter.filterKey(keyChar, GlobalEventWatcher.getAxesUID(), isControlDown);
+                GlobalEventFilter.filterKey(keyChar, GlobalEventWatcher.getAxesUID(), isControlDown, (SwingScilabCanvas) keyEvent.getSource());
             }
         }
     }
+
     /**
      * Manage xgetmouse behaviour for mouse entry.
      *
@@ -182,7 +180,4 @@ public final class Jxgetmouse {
             GlobalEventFilter.filterMouse(mouseEvent, axesUID, scilabMouseAction, false);
         }
     }
-
-
 }
-