Bug 12990 fixed: GED features conflict with figure events 88/13088/2
Calixte DENIZET [Wed, 6 Nov 2013 10:35:08 +0000 (11:35 +0100)]
Change-Id: I2ae2626829d619d15e32d9b1c4718a5bef2fbbd8

scilab/CHANGES_5.5.X
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/tab/SwingScilabTab.java
scilab/modules/gui/src/java/org/scilab/modules/gui/editor/EditorEventListener.java
scilab/modules/gui/src/java/org/scilab/modules/gui/events/GlobalEventWatcher.java
scilab/modules/gui/src/java/org/scilab/modules/gui/events/Jxgetmouse.java
scilab/modules/gui/tests/nonreg_tests/bug_12990.tst [new file with mode: 0644]

index 9660e37..33a6c66 100644 (file)
@@ -92,6 +92,8 @@ Scilab Bug Fixes
 
 * Bug #12979 fixed - exportUI did not work with vectorial export.
 
+* Bug #12990 fixed - GED features conflicted with figure events.
+
 * Bug #13000 fixed - []./int8(3) and on int8(3)./[] led to an endless recursive.
 
 * Bug #13003 fixed - String to enum converter added to Java external objects.
index fae1be9..324d4bf 100644 (file)
@@ -299,7 +299,7 @@ public class SwingScilabTab extends View implements SwingViewObject, SimpleTab,
 
             public void ancestorMoved(HierarchyEvent e) {
                 if (e.getChanged() instanceof SwingScilabWindow) {
-                    Position parentPosition =  SwingScilabWindow.allScilabWindows.get(parentWindowId).getPosition();
+                    Position parentPosition = SwingScilabWindow.allScilabWindows.get(parentWindowId).getPosition();
                     Integer[] newPosition = new Integer[] {parentPosition.getX(), parentPosition.getY()};
                     GraphicController.getController().setProperty(id, __GO_POSITION__, newPosition);
                 }
@@ -317,7 +317,7 @@ public class SwingScilabTab extends View implements SwingViewObject, SimpleTab,
                 /* Update the figure_size property */
                 Size parentSize =  SwingScilabWindow.allScilabWindows.get(parentWindowId).getDims();
                 Integer[] newSize = new Integer[] {parentSize.getWidth(), parentSize.getHeight()};
-                
+
                 GraphicController.getController().setProperty(id, __GO_SIZE__, newSize);
 
                 Boolean autoreSize = (Boolean) GraphicController.getController().getProperty(id, __GO_AUTORESIZE__);
@@ -335,7 +335,7 @@ public class SwingScilabTab extends View implements SwingViewObject, SimpleTab,
             public void componentHidden(ComponentEvent arg0) {
             }
         });
-        
+
         /* Manage closerequestfcn */
         ClosingOperationsManager.registerClosingOperation(SwingScilabTab.this, new ClosingOperationsManager.ClosingOperation() {
 
@@ -1323,6 +1323,7 @@ public class SwingScilabTab extends View implements SwingViewObject, SimpleTab,
         disableEventHandler();
         eventHandler = new ScilabEventListener(funName, getId());
         if (eventEnabled) {
+            editorEventHandler.setEnable(false);
             enableEventHandler();
         }
     }
@@ -1337,9 +1338,11 @@ public class SwingScilabTab extends View implements SwingViewObject, SimpleTab,
         }
 
         if (status) {
+            editorEventHandler.setEnable(false);
             enableEventHandler();
             eventEnabled = true;
         } else {
+            editorEventHandler.setEnable(true);
             disableEventHandler();
             eventEnabled = false;
         }
@@ -1424,89 +1427,88 @@ public class SwingScilabTab extends View implements SwingViewObject, SimpleTab,
         String name;
         Integer figureId;
         switch (property) {
-        case  __GO_NAME__ :
-            name = ((String) value);
-            figureId = (Integer) GraphicController.getController().getProperty(getId(), __GO_ID__);
-            updateTitle(name, figureId);
-            break;
-        case __GO_ID__ :
-            /* Update title */
-            figureId = ((Integer) value);
-            name = (String) GraphicController.getController().getProperty(getId(), __GO_NAME__);
-            updateTitle(name, figureId);
-
-            /** Update tool bar */
-            setToolBar(ToolBarBuilder.buildToolBar(GRAPHICS_TOOLBAR_DESCRIPTOR, figureId));
-            SwingScilabWindow parentWindow = SwingScilabWindow.allScilabWindows.get(getParentWindowId());
-            parentWindow.addToolBar(getToolBar());
-
-            /* Update callback */
-            String closingCommand =
-                "if (get_figure_handle(" + figureId + ") <> []) then"
-                +      "  if (get(get_figure_handle(" + figureId + "), 'event_handler_enable') == 'on') then"
-                +      "    execstr(get(get_figure_handle(" + figureId + "), 'event_handler')+'(" + figureId + ", -1, -1, -1000)', 'errcatch', 'm');"
-                +      "  end;"
-                +      "  delete(get_figure_handle(" + figureId + "));"
-                +      "end;";
-            setCallback(null);
-            setCallback(ScilabCloseCallBack.create(getId(), closingCommand));
-            /* Update menus callback */
-            Integer[] children = (Integer[]) GraphicController.getController().getProperty(getId(), __GO_CHILDREN__);
-            updateChildrenCallbacks(children, figureId);
-            break;
-        case __GO_SIZE__ :
-            Integer[] size = (Integer[]) value;
-            SwingScilabWindow figure = SwingScilabWindow.allScilabWindows.get(parentWindowId);
-            Size oldFigureSize = figure.getDims();
-            figure.setDims(new Size(size[0], size[1]));
-            int deltaFigureX = size[0] - (int) oldFigureSize.getWidth();
-            int deltaFigureY = size[1] - (int) oldFigureSize.getHeight();
-            if ( oldFigureSize.getWidth() != 0 && oldFigureSize.getHeight() != 0
-                    && ((oldFigureSize.getWidth() != size[0]) || (oldFigureSize.getHeight() != size[1]))
-                    && ((Boolean) GraphicController.getController().getProperty(getId(), __GO_AUTORESIZE__))
-                    ) {
-                Integer[] axesSize = (Integer[]) GraphicController.getController().getProperty(getId(), __GO_AXES_SIZE__);
-                Integer[] newAxesSize = {axesSize[0] + deltaFigureX, axesSize[1] + deltaFigureY};
-                GraphicController.getController().setProperty(getId(), __GO_AXES_SIZE__, newAxesSize);  
-            }
-            break;
-        case __GO_POSITION__ :
-            Integer[] position = (Integer[]) value;
-            SwingScilabWindow.allScilabWindows.get(parentWindowId).setPosition(new Position(position[0], position[1]));
-            break;
-        case __GO_AXES_SIZE__ :
-            Integer[] axesSize = (Integer[]) value;
-            Dimension oldAxesSize = getContentPane().getSize();
-            if ( oldAxesSize.getWidth() != 0 && oldAxesSize.getHeight() != 0
-                    && ((oldAxesSize.getWidth() != axesSize[0]) || (oldAxesSize.getHeight() != axesSize[1]))
-                    && ((Boolean) GraphicController.getController().getProperty(getId(), __GO_AUTORESIZE__))
-                    ) {
-                // TODO manage tabs when there are docked (do not change the window size if more than one tab docked)
-                int deltaX = axesSize[0] - (int) oldAxesSize.getWidth();
-                int deltaY = axesSize[1] - (int) oldAxesSize.getHeight();
-                Size parentWindowSize = SwingScilabWindow.allScilabWindows.get(parentWindowId).getDims();
-                SwingScilabWindow.allScilabWindows.get(parentWindowId).setDims(
+            case  __GO_NAME__ :
+                name = ((String) value);
+                figureId = (Integer) GraphicController.getController().getProperty(getId(), __GO_ID__);
+                updateTitle(name, figureId);
+                break;
+            case __GO_ID__ :
+                /* Update title */
+                figureId = ((Integer) value);
+                name = (String) GraphicController.getController().getProperty(getId(), __GO_NAME__);
+                updateTitle(name, figureId);
+
+                /** Update tool bar */
+                setToolBar(ToolBarBuilder.buildToolBar(GRAPHICS_TOOLBAR_DESCRIPTOR, figureId));
+                SwingScilabWindow parentWindow = SwingScilabWindow.allScilabWindows.get(getParentWindowId());
+
+                /* Update callback */
+                String closingCommand =
+                    "if (get_figure_handle(" + figureId + ") <> []) then"
+                    +      "  if (get(get_figure_handle(" + figureId + "), 'event_handler_enable') == 'on') then"
+                    +      "    execstr(get(get_figure_handle(" + figureId + "), 'event_handler')+'(" + figureId + ", -1, -1, -1000)', 'errcatch', 'm');"
+                    +      "  end;"
+                    +      "  delete(get_figure_handle(" + figureId + "));"
+                    +      "end;";
+                setCallback(null);
+                setCallback(ScilabCloseCallBack.create(getId(), closingCommand));
+                /* Update menus callback */
+                Integer[] children = (Integer[]) GraphicController.getController().getProperty(getId(), __GO_CHILDREN__);
+                updateChildrenCallbacks(children, figureId);
+                break;
+            case __GO_SIZE__ :
+                Integer[] size = (Integer[]) value;
+                SwingScilabWindow figure = SwingScilabWindow.allScilabWindows.get(parentWindowId);
+                Size oldFigureSize = figure.getDims();
+                figure.setDims(new Size(size[0], size[1]));
+                int deltaFigureX = size[0] - (int) oldFigureSize.getWidth();
+                int deltaFigureY = size[1] - (int) oldFigureSize.getHeight();
+                if ( oldFigureSize.getWidth() != 0 && oldFigureSize.getHeight() != 0
+                        && ((oldFigureSize.getWidth() != size[0]) || (oldFigureSize.getHeight() != size[1]))
+                        && ((Boolean) GraphicController.getController().getProperty(getId(), __GO_AUTORESIZE__))
+                   ) {
+                    Integer[] axesSize = (Integer[]) GraphicController.getController().getProperty(getId(), __GO_AXES_SIZE__);
+                    Integer[] newAxesSize = {axesSize[0] + deltaFigureX, axesSize[1] + deltaFigureY};
+                    GraphicController.getController().setProperty(getId(), __GO_AXES_SIZE__, newAxesSize);
+                }
+                break;
+            case __GO_POSITION__ :
+                Integer[] position = (Integer[]) value;
+                SwingScilabWindow.allScilabWindows.get(parentWindowId).setPosition(new Position(position[0], position[1]));
+                break;
+            case __GO_AXES_SIZE__ :
+                Integer[] axesSize = (Integer[]) value;
+                Dimension oldAxesSize = getContentPane().getSize();
+                if ( oldAxesSize.getWidth() != 0 && oldAxesSize.getHeight() != 0
+                        && ((oldAxesSize.getWidth() != axesSize[0]) || (oldAxesSize.getHeight() != axesSize[1]))
+                        && ((Boolean) GraphicController.getController().getProperty(getId(), __GO_AUTORESIZE__))
+                   ) {
+                    // TODO manage tabs when there are docked (do not change the window size if more than one tab docked)
+                    int deltaX = axesSize[0] - (int) oldAxesSize.getWidth();
+                    int deltaY = axesSize[1] - (int) oldAxesSize.getHeight();
+                    Size parentWindowSize = SwingScilabWindow.allScilabWindows.get(parentWindowId).getDims();
+                    SwingScilabWindow.allScilabWindows.get(parentWindowId).setDims(
                         new Size(parentWindowSize.getWidth() + deltaX, parentWindowSize.getHeight() + deltaY));
-                Integer figureSize[] = {parentWindowSize.getWidth() + deltaX, parentWindowSize.getHeight() + deltaY};
-                GraphicController.getController().setProperty(getId(), __GO_SIZE__, figureSize);
-            }
-            break;
-        case __GO_INFO_MESSAGE__ :
-            if (getInfoBar() != null) {
-                getInfoBar().setText((String) value);
-            }
-            break;
-        case __GO_EVENTHANDLER_ENABLE__ :
-            Boolean enabled = (Boolean) GraphicController.getController().getProperty(getId(), __GO_EVENTHANDLER_ENABLE__);
-            setEventHandlerEnabled(enabled);
-            break;
-        case __GO_EVENTHANDLER_NAME__ :
-            String eventHandlerName = (String) GraphicController.getController().getProperty(getId(), __GO_EVENTHANDLER_NAME__);
-            setEventHandler(eventHandlerName);
-            break;
-        case __GO_VISIBLE__ :
-            layerdPane.setVisible((Boolean) value);
-            break;
+                    Integer figureSize[] = {parentWindowSize.getWidth() + deltaX, parentWindowSize.getHeight() + deltaY};
+                    GraphicController.getController().setProperty(getId(), __GO_SIZE__, figureSize);
+                }
+                break;
+            case __GO_INFO_MESSAGE__ :
+                if (getInfoBar() != null) {
+                    getInfoBar().setText((String) value);
+                }
+                break;
+            case __GO_EVENTHANDLER_ENABLE__ :
+                Boolean enabled = (Boolean) GraphicController.getController().getProperty(getId(), __GO_EVENTHANDLER_ENABLE__);
+                setEventHandlerEnabled(enabled);
+                break;
+            case __GO_EVENTHANDLER_NAME__ :
+                String eventHandlerName = (String) GraphicController.getController().getProperty(getId(), __GO_EVENTHANDLER_NAME__);
+                setEventHandler(eventHandlerName);
+                break;
+            case __GO_VISIBLE__ :
+                layerdPane.setVisible((Boolean) value);
+                break;
         }
     }
 
@@ -1519,10 +1521,10 @@ public class SwingScilabTab extends View implements SwingViewObject, SimpleTab,
         for (int kChild = 0; kChild < children.length; kChild++) {
             Integer childType = (Integer) GraphicController.getController().getProperty(children[kChild], __GO_TYPE__);
             if (childType != null && (
-                    childType == __GO_UIMENU__
-                    || childType == __GO_UIPARENTMENU__
-                    || childType == __GO_UICHILDMENU__
-                    || childType == __GO_UICHECKEDMENU__)) {
+                        childType == __GO_UIMENU__
+                        || childType == __GO_UIPARENTMENU__
+                        || childType == __GO_UICHILDMENU__
+                        || childType == __GO_UICHECKEDMENU__)) {
                 String cb = (String) GraphicController.getController().getProperty(children[kChild], __GO_CALLBACK__);
                 SwingView.getFromId(children[kChild]).update(__GO_CALLBACK__, replaceFigureID(cb, parentFigureId));
                 Integer[] menuChildren = (Integer[]) GraphicController.getController().getProperty(children[kChild], __GO_CHILDREN__);
@@ -1588,6 +1590,7 @@ public class SwingScilabTab extends View implements SwingViewObject, SimpleTab,
             contentCanvas.removeEventHandlerKeyListener(eventHandler);
             contentCanvas.removeEventHandlerMouseListener(eventHandler);
             contentCanvas.removeEventHandlerMouseMotionListener(eventHandler);
+            eventHandler = null;
         }
     }
 }
index cdd0998..996d828 100644 (file)
@@ -31,6 +31,7 @@ import org.scilab.modules.gui.datatip.DatatipManager;
 import org.scilab.modules.gui.editor.Editor;
 import org.scilab.modules.gui.editor.EditorManager;
 import org.scilab.modules.gui.editor.EntityPicker;
+import org.scilab.modules.gui.events.GlobalEventWatcher;
 
 import org.scilab.modules.gui.ged.Inspector;
 import org.scilab.modules.gui.ged.SwapObject;
@@ -39,14 +40,14 @@ import org.scilab.modules.gui.plotbrowser.PlotBrowser;
 
 
 /**
-* Event listener for the figure editor.
-*
-*
-* @author Caio Souza <caioc2bolado@gmail.com>
-* @author Pedro Souza <bygrandao@gmail.com>
-*
-* @since 2012-06-01
-*/
+ * Event listener for the figure editor.
+ *
+ *
+ * @author Caio Souza <caioc2bolado@gmail.com>
+ * @author Pedro Souza <bygrandao@gmail.com>
+ *
+ * @since 2012-06-01
+ */
 
 public class EditorEventListener implements KeyListener, MouseListener, MouseMotionListener {
 
@@ -60,10 +61,10 @@ public class EditorEventListener implements KeyListener, MouseListener, MouseMot
     Integer[] lastClick = new Integer[2];
     boolean changeOrientation = false;
 
-
     Editor editor;
     boolean isInRotation = false;
     boolean isLeftButtonPressed = false;
+    boolean enabled = false;
 
     public EditorEventListener(Integer uid) {
         windowUid = uid;
@@ -72,21 +73,25 @@ public class EditorEventListener implements KeyListener, MouseListener, MouseMot
         datatipManagerMode = DatatipManager.newDatatipManagerMode(uid);
     }
 
+    public void setEnable(boolean enabled) {
+        this.enabled = enabled;
+    }
+
     public void onExit() {
         EditorManager.deleteEditor(editor.getFigureUid());
         DatatipManager.deleteDatatipManager(windowUid);
     }
 
     public void keyPressed(KeyEvent arg0) {
-
-        editor.onKeyPressed(arg0);
-
-        if (datatipManagerMode.isEnabled()) {
-            if (datatipManagerMode.getSelectedTip() != null) {
-                if (arg0.getKeyCode() == KeyEvent.VK_RIGHT) {
-                    DatatipMove.moveRight(datatipManagerMode.getSelectedTip());
-                } else if (arg0.getKeyCode() == KeyEvent.VK_LEFT) {
-                    DatatipMove.moveLeft(datatipManagerMode.getSelectedTip());
+        if (enabled && !GlobalEventWatcher.isActivated()) {
+            editor.onKeyPressed(arg0);
+            if (datatipManagerMode.isEnabled()) {
+                if (datatipManagerMode.getSelectedTip() != null) {
+                    if (arg0.getKeyCode() == KeyEvent.VK_RIGHT) {
+                        DatatipMove.moveRight(datatipManagerMode.getSelectedTip());
+                    } else if (arg0.getKeyCode() == KeyEvent.VK_LEFT) {
+                        DatatipMove.moveLeft(datatipManagerMode.getSelectedTip());
+                    }
                 }
             }
         }
@@ -116,11 +121,8 @@ public class EditorEventListener implements KeyListener, MouseListener, MouseMot
      * @param arg0 MouseEvent
      */
     public void mousePressed(MouseEvent arg0) {
-
-        if (arg0.getButton() == 1) {
-
+        if (enabled && !GlobalEventWatcher.isActivated() && arg0.getButton() == 1) {
             isLeftButtonPressed = true;
-
             if (!datatipManagerMode.isEnabled()) {
                 editor.onLeftMouseDown(arg0);
 
@@ -153,26 +155,26 @@ public class EditorEventListener implements KeyListener, MouseListener, MouseMot
      * @param arg0 MouseEvent
      */
     public void mouseReleased(MouseEvent arg0) {
-
-        if (!datatipManagerMode.isEnabled()) {
-
-            if (arg0.getButton() == 3) {
-                if (!isInRotation) {
-                    editor.onRightMouseClick(arg0);
+        if (enabled && !GlobalEventWatcher.isActivated()) {
+            if (!datatipManagerMode.isEnabled()) {
+                if (arg0.getButton() == 3) {
+                    if (!isInRotation) {
+                        editor.onRightMouseClick(arg0);
+                    }
+                } else if (arg0.getButton() == 1) {
+                    editor.onLeftMouseRelease(arg0);
                 }
-            } else if (arg0.getButton() == 1) {
-                editor.onLeftMouseRelease(arg0);
-            }
 
-        } else {
-            if (arg0.getButton() == 3 && !isInRotation) {
-                datatipManagerMode.pickAndDelete(arg0.getX(), arg0.getY());
+            } else {
+                if (arg0.getButton() == 3 && !isInRotation) {
+                    datatipManagerMode.pickAndDelete(arg0.getX(), arg0.getY());
+                }
             }
+            isInRotation = false;
+            isLeftButtonPressed = false;
+            changeOrientation = false;
+            editor.setUpdateDrag(true);
         }
-        isInRotation = false;
-        isLeftButtonPressed = false;
-        changeOrientation = false;
-        editor.setUpdateDrag(true);
     }
 
     /**
@@ -181,24 +183,25 @@ public class EditorEventListener implements KeyListener, MouseListener, MouseMot
      * drag/ change datatip orientation
      */
     public void mouseDragged(MouseEvent arg0) {
+        if (enabled && !GlobalEventWatcher.isActivated()) {
+            if (!datatipManagerMode.isEnabled()) {
 
-        if (!datatipManagerMode.isEnabled()) {
-
-            if (isLeftButtonPressed) {
-                editor.onMouseDragged(arg0);
+                if (isLeftButtonPressed) {
+                    editor.onMouseDragged(arg0);
 
+                } else {
+                    isInRotation = true;
+                }
             } else {
-                isInRotation = true;
-            }
-        } else {
-            if (changeOrientation) {
-                Integer[] curClick = {arg0.getX(), arg0.getY()};
-                DatatipOrientation.setOrientation(lastDatatip, lastClick, curClick);
-            } else if (datatipManagerMode.getSelectedTip() != null && isLeftButtonPressed) {
-                DatatipDrag.dragDatatip(datatipManagerMode.getSelectedTip(), arg0.getX(), arg0.getY());
+                if (changeOrientation) {
+                    Integer[] curClick = {arg0.getX(), arg0.getY()};
+                    DatatipOrientation.setOrientation(lastDatatip, lastClick, curClick);
+                } else if (datatipManagerMode.getSelectedTip() != null && isLeftButtonPressed) {
+                    DatatipDrag.dragDatatip(datatipManagerMode.getSelectedTip(), arg0.getX(), arg0.getY());
+                }
             }
+            editor.setUpdateDrag(false);
         }
-        editor.setUpdateDrag(false);
     }
 
     public void mouseMoved(MouseEvent arg0) {
index f3c6a97..5e6ebee 100644 (file)
@@ -102,7 +102,7 @@ public final class GlobalEventWatcher {
         catchingCallback = true;
     }
 
-    public static void disableableCatchingCallback() {
+    public static void disableCatchingCallback() {
         catchingCallback = false;
     }
 
index ab14347..fda750d 100644 (file)
@@ -73,7 +73,7 @@ public final class Jxgetmouse {
          */
         GlobalEventWatcher.enable(new GlobalMouseEventWatcher(eventMask) {
             public void mouseEventFilter(MouseEvent mouseEvent,
-            Integer axesUID, int scilabMouseAction, boolean isControlDown) {
+                                         Integer axesUID, int scilabMouseAction, boolean isControlDown) {
                 mouseActionFilter(mouseEvent, axesUID, scilabMouseAction, isControlDown);
             }
         });
@@ -81,7 +81,7 @@ public final class Jxgetmouse {
         /*
          *  Force xgetmouse not to catch/disable callback execution.
          */
-        GlobalEventWatcher.disableableCatchingCallback();
+        GlobalEventWatcher.disableCatchingCallback();
 
         synchronized (ClickInfos.getInstance()) {
             try {
diff --git a/scilab/modules/gui/tests/nonreg_tests/bug_12990.tst b/scilab/modules/gui/tests/nonreg_tests/bug_12990.tst
new file mode 100644 (file)
index 0000000..251e578
--- /dev/null
@@ -0,0 +1,42 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Calixte DENIZET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- INTERACTIVE TEST -->
+//
+// <-- Non-regression test for bug 12990 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/12990
+//
+// <-- Short Description -->
+// GED features conflict with figure events
+
+scf();
+plot([1,2], [1,2]);
+
+// right click must not imply popupmenu
+xclick()
+
+// left click on the curve must not select it
+xclick()
+
+function my_eventhandler(win, x, y, ibut)
+    if ibut==-1000 then return,end
+    [x,y]=xchange(x,y,"i2f")
+    xinfo(msprintf("Event code %d at mouse position is (%f,%f)",ibut,x,y))
+endfunction
+
+seteventhandler("my_eventhandler");
+
+// Left click on the curve must not select it
+// Right click must not imply popupmenu
+
+// Disable the event handler
+seteventhandler("");
+
+// Left click on the curve must select it
+// Right click must imply popupmenu