* Bug #13588 fixed - Default values of "event_handler" and "event_handler_enable... 81/15281/4
Vincent COUVERT [Fri, 26 Sep 2014 12:45:24 +0000 (14:45 +0200)]
                     were not taken into account when creating a new figure.

Change-Id: I2565f5bc8904d7a98fc6bf04175b81c633daaf1b

scilab/CHANGES_5.5.X
scilab/modules/graphics/tests/nonreg_tests/bug_13588.tst [new file with mode: 0644]
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/tab/SwingScilabCommonPanel.java
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/tab/SwingScilabDockablePanel.java
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/tab/SwingScilabStaticPanel.java
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/window/SwingScilabStaticWindow.java

index 4b7712c..3b8fc77 100644 (file)
@@ -242,6 +242,9 @@ Scilab Bug Fixes
 
 * Bug #13579 fixed - bar displayed useless warnings.
 
+* Bug #13588 fixed - Default values of "event_handler" and "event_handler_enable" properties
+                     were not taken into account when creating a new figure.
+
 
 Xcos Bug Fixes
 ==============
diff --git a/scilab/modules/graphics/tests/nonreg_tests/bug_13588.tst b/scilab/modules/graphics/tests/nonreg_tests/bug_13588.tst
new file mode 100644 (file)
index 0000000..bd33dfd
--- /dev/null
@@ -0,0 +1,34 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2014 - Scilab Enterprises - Vincent COUVERT
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- TEST WITH GRAPHIC -->
+
+// <-- INTERACTIVE TEST -->
+
+// <-- Non-regression test for bug 13588 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/13588
+//
+// <-- Short Description -->
+// default properties (git comm) of figures badly inherited.
+
+function handler(w,x,y,k)
+    disp(k)
+endfunction
+
+// When set on dockable figure
+set(gdf(),"event_handler","handler","event_handler_enable","on");
+gcf();
+// Move the mouse over the figure and check that messages are displayed in Scilab console
+// Close the figure and check that -1000 has been displayed in Scilab console
+
+// When set on non-dockable figure
+set(gdf(),"event_handler","handler","event_handler_enable","on");
+figure("Dockable", "off");
+// Move the mouse over the figure and check that messages are displayed in Scilab console
+// Close the figure and check that -1000 has been displayed in Scilab console
index 482d82d..9df70a2 100644 (file)
@@ -53,7 +53,6 @@ import java.io.IOException;
 
 import javax.imageio.ImageIO;
 import javax.swing.ImageIcon;
-import javax.swing.JLayeredPane;
 
 import org.scilab.modules.commons.gui.FindIconHelper;
 import org.scilab.modules.graphic_objects.figure.Figure;
index 863195b..693b2dc 100644 (file)
@@ -78,8 +78,6 @@ import org.scilab.modules.gui.bridge.popupmenu.SwingScilabPopupMenu;
 import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
 import org.scilab.modules.gui.bridge.radiobutton.SwingScilabRadioButton;
 import org.scilab.modules.gui.bridge.slider.SwingScilabScroll;
-import org.scilab.modules.gui.bridge.textbox.SwingScilabTextBox;
-import org.scilab.modules.gui.bridge.toolbar.SwingScilabToolBar;
 import org.scilab.modules.gui.bridge.tree.SwingScilabTree;
 import org.scilab.modules.gui.bridge.uidisplaytree.SwingScilabUiDisplayTree;
 import org.scilab.modules.gui.bridge.uitable.SwingScilabUiTable;
@@ -637,9 +635,10 @@ public class SwingScilabDockablePanel extends View implements SimpleTab, FocusLi
         if (member instanceof SwingScilabAxes) {
             if (contentCanvas == null) {
                 contentCanvas = new SwingScilabCanvas((Figure) GraphicController.getController().getObjectFromId(((SwingScilabAxes) member).getFigureId()));
-                contentCanvas.addEventHandlerKeyListener(editorEventHandler);
-                contentCanvas.addEventHandlerMouseListener(editorEventHandler);
-                contentCanvas.addEventHandlerMouseMotionListener(editorEventHandler);
+                if (eventEnabled) {
+                    editorEventHandler.setEnable(false);
+                    enableEventHandler();
+                }
 
                 layeredPane.add(contentCanvas, JLayeredPane.FRAME_CONTENT_LAYER);
 
index b6ff1d3..3f9e698 100644 (file)
@@ -39,6 +39,8 @@ import org.scilab.modules.gui.SwingViewObject;
 import org.scilab.modules.gui.SwingViewWidget;
 import org.scilab.modules.gui.bridge.canvas.SwingScilabCanvas;
 import org.scilab.modules.gui.bridge.window.SwingScilabWindow;
+import org.scilab.modules.gui.editor.EditorEventListener;
+import org.scilab.modules.gui.events.ScilabEventListener;
 import org.scilab.modules.gui.events.callback.CommonCallBack;
 import org.scilab.modules.gui.menubar.MenuBar;
 import org.scilab.modules.gui.textbox.TextBox;
@@ -56,15 +58,25 @@ public class SwingScilabStaticPanel extends SwingScilabScrollPane implements Swi
     private String parentWindowId;
     private JLayeredPane uiContentPane;
     private JLayeredPane layeredPane;
+    private boolean eventEnabled = false;
     private ComponentListener componentListener;
     private HierarchyBoundsListener ancestorListener;
 
+    /** The listener for event handling */
+    private ScilabEventListener eventHandler;
+    private EditorEventListener editorEventHandler = null;
+
     private SwingScilabCanvas contentCanvas;
     protected boolean hasLayout;
     private Dimension deltaSize = null;
+    
+    private CommonCallBack callback;
 
     public SwingScilabStaticPanel(String figureTitle, Integer figureId, Figure figure) {
         super(new JLayeredPane(), new JLayeredPane(), figure);
+
+        editorEventHandler = new EditorEventListener(figure.getIdentifier());
+
         uiContentPane = (JLayeredPane) getUIComponent();
         layeredPane = (JLayeredPane) getGlobalComponent();
         setVisible(true);
@@ -142,6 +154,28 @@ public class SwingScilabStaticPanel extends SwingScilabScrollPane implements Swi
         addComponentListener(componentListener);
     }
 
+    /**
+     * Turn on event handling.
+     */
+    private void enableEventHandler() {
+        if (contentCanvas != null) {
+            contentCanvas.addEventHandlerKeyListener(eventHandler);
+            contentCanvas.addEventHandlerMouseListener(eventHandler);
+            contentCanvas.addEventHandlerMouseMotionListener(eventHandler);
+        }
+    }
+
+    /**
+     * Turn off event handling.
+     */
+    private void disableEventHandler() {
+        if (eventHandler != null && contentCanvas != null) {
+            contentCanvas.removeEventHandlerKeyListener(eventHandler);
+            contentCanvas.removeEventHandlerMouseListener(eventHandler);
+            contentCanvas.removeEventHandlerMouseMotionListener(eventHandler);
+        }
+    }
+
     public void setId(Integer id) {
         this.id = id;
     }
@@ -184,12 +218,40 @@ public class SwingScilabStaticPanel extends SwingScilabScrollPane implements Swi
         this.toolBar = toolBar;
     }
 
-    public void setEventHandler(String eventHandler) {
+    /**
+     * Set the event handler of the Canvas
+     * @param funName the name of the Scilab function to call
+     */
+    public void setEventHandler(String funName) {
+        disableEventHandler();
+        eventHandler = new ScilabEventListener(funName, getId());
+        if (eventEnabled) {
+            editorEventHandler.setEnable(false);
+            enableEventHandler();
+        }
     }
 
-    public void setEventHandlerEnabled(boolean enabled) {
+    /**
+     * Set the status of the event handler of the Canvas
+     * @param status is true to set the event handler active
+     */
+    public void setEventHandlerEnabled(boolean status) {
+        if (status && eventEnabled) {
+            return;
+        }
+
+        if (status) {
+            editorEventHandler.setEnable(false);
+            enableEventHandler();
+            eventEnabled = true;
+        } else {
+            editorEventHandler.setEnable(true);
+            disableEventHandler();
+            eventEnabled = false;
+        }
     }
 
+
     public void setParentWindowId(String parentWindowId) {
         this.parentWindowId = parentWindowId;
         SwingScilabWindow.allScilabWindows.get(parentWindowId).setIconImage(new ImageIcon(FindIconHelper.findIcon("graphic-window", "256x256")).getImage());
@@ -202,6 +264,11 @@ public class SwingScilabStaticPanel extends SwingScilabScrollPane implements Swi
         if (member instanceof SwingScilabAxes) {
             if (contentCanvas == null) {
                 contentCanvas = new SwingScilabCanvas((Figure) GraphicController.getController().getObjectFromId(((SwingScilabAxes) member).getFigureId()));
+                if (eventEnabled) {
+                    editorEventHandler.setEnable(false);
+                    enableEventHandler();
+                }
+
                 layeredPane.add(contentCanvas, JLayeredPane.FRAME_CONTENT_LAYER);
                 setCanvas(contentCanvas);
             }
@@ -224,10 +291,13 @@ public class SwingScilabStaticPanel extends SwingScilabScrollPane implements Swi
     }
 
     public void setCallback(CommonCallBack callback) {
-        // TODO Auto-generated method stub
-
+        this.callback = callback;
     }
 
+    public CommonCallBack getCallback() {
+        return callback;
+    }
+    
     public Container getContentPane() {
         return this.getAsContainer();
     }
index 5c937da..d96626d 100644 (file)
@@ -24,6 +24,7 @@ import org.scilab.modules.action_binding.InterpreterManagement;
 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
 import org.scilab.modules.gui.bridge.tab.SwingScilabPanel;
 import org.scilab.modules.gui.bridge.tab.SwingScilabStaticPanel;
+import org.scilab.modules.gui.events.callback.CommonCallBack;
 
 public class SwingScilabStaticWindow extends SwingScilabWindow {
 
@@ -41,7 +42,12 @@ public class SwingScilabStaticWindow extends SwingScilabWindow {
                     InterpreterManagement.putCommandInScilabQueue(closeCommand);
                 } else {
                     //GraphicController.getController().deleteObject(panel.getId());
-                    GraphicController.getController().removeRelationShipAndDelete(panel.getId());
+                    CommonCallBack callback = panel.getCallback();
+                    if (callback != null) {
+                        callback.actionPerformed(null);
+                    } else {
+                        GraphicController.getController().removeRelationShipAndDelete(panel.getId());
+                    }
                 }
             }
         });