reduce depth search to find figure during closing
[scilab.git] / scilab / modules / gui / src / java / org / scilab / modules / gui / bridge / tab / SwingScilabCommonPanel.java
index 8e54da0..77b8287 100644 (file)
@@ -1,12 +1,16 @@
 /*
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2014 - Scilab Enterprises - Bruno JOFRET
+ * Copyright (C) 2015 - Scilab Enterprises - Anais AUBERT
  *
- * This file must be used under the terms of the CeCILL.
- * This source file is licensed as described in the file COPYING, which
- * you should have received as part of this distribution.  The terms
- * are also available at
- * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+ * This file was originally licensed under the terms of the CeCILL v2.1,
+ * and continues to be available under such terms.
+ * For more information, see the COPYING file which you should have received
+ * along with this program.
  *
  */
 package org.scilab.modules.gui.bridge.tab;
@@ -53,7 +57,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;
@@ -127,9 +130,15 @@ public class SwingScilabCommonPanel {
                 }
 
                 /* 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;";
+                String closingCommand =   "%closing_fig = findobj('figure_id', " + figureId + ", '-flat');"
+                                        + "if (%closing_fig <> []) then"
+                                        + "    if (get(%closing_fig, 'event_handler_enable') == 'on') then"
+                                        + "        execstr(get(%closing_fig, 'event_handler')+'(" + figureId + ", -1, -1, -1000)', 'errcatch', 'm');"
+                                        + "    end;"
+                                        + "    delete(%closing_fig);"
+                                        + "end;"
+                                        + "clear('%closing_fig');";
+
                 component.setCallback(null);
                 component.setCallback(ScilabCloseCallBack.create(component.getId(), closingCommand));
                 /* Update menus callback */
@@ -140,11 +149,14 @@ public class SwingScilabCommonPanel {
                 Integer[] size = (Integer[]) value;
                 SwingScilabWindow figure = SwingScilabWindow.allScilabWindows.get(component.getParentWindowId());
                 Size oldFigureSize = figure.getDims();
+
                 if (oldFigureSize.getWidth() != 0 && oldFigureSize.getHeight() != 0 && ((oldFigureSize.getWidth() != size[0]) || (oldFigureSize.getHeight() != size[1]))
                         && ((Boolean) GraphicController.getController().getProperty(component.getId(), __GO_AUTORESIZE__))) {
                     figure.setDims(new Size(size[0], size[1]));
                     figure.validate();
-                    GraphicController.getController().setProperty(component.getId(), __GO_AXES_SIZE__, new Integer[] { figure.getContentPane().getWidth(), figure.getContentPane().getHeight() });
+                    // Axes are resized by resize event: SwingScilabDockablePanel::componentResized or SwingScilabStaticPanel::componentResized
+                    // ==> NO NEED TO FORCE RESIZE
+                    // GraphicController.getController().setProperty(component.getId(), __GO_AXES_SIZE__, new Integer[] { figure.getContentPane().getWidth(), figure.getContentPane().getHeight() });
 
                 }
                 break;
@@ -184,6 +196,14 @@ public class SwingScilabCommonPanel {
                 if (component.getParentWindow().getNbDockedObjects() == 1) {
                     component.getParentWindow().setVisible((Boolean) value);
                 }
+
+                //de-iconify windows
+                if((Boolean)value == true) {
+                    int state = component.getParentWindow().getExtendedState();
+                    if((state & SwingScilabWindow.ICONIFIED) == SwingScilabWindow.ICONIFIED) {
+                        component.getParentWindow().setExtendedState(state - SwingScilabWindow.ICONIFIED);
+                    }
+                }
                 break;
             case __GO_INFOBAR_VISIBLE__: {
                 component.disableResizeEvent();
@@ -217,9 +237,16 @@ public class SwingScilabCommonPanel {
             }
             case __GO_RESIZE__:
                 component.getParentWindow().setResizable((Boolean) value);
+                //on some cases, set resizable can change frame size. ( L&F, Window Manager, ... )
+                //so force set of axes_size.
+                SwingScilabCommonPanel.update(component, __GO_AXES_SIZE__, GraphicController.getController().getProperty(component.getId(), __GO_AXES_SIZE__));
+
                 break;
             case __GO_LAYOUT__:
                 LayoutType newLayout = LayoutType.intToEnum((Integer) value);
+
+                component.getWidgetPane().invalidate();
+
                 switch (newLayout) {
                     case BORDER: {
                         Integer[] padding = (Integer[]) GraphicController.getController().getProperty(component.getId(), __GO_BORDER_OPT_PADDING__);
@@ -253,6 +280,9 @@ public class SwingScilabCommonPanel {
                         component.setHasLayout(false);
                         break;
                 }
+
+                component.getWidgetPane().validate();
+
                 break;
             case __GO_GRID_OPT_PADDING__:
             case __GO_GRID_OPT_GRID__: {
@@ -274,7 +304,16 @@ public class SwingScilabCommonPanel {
                     localGrid[0] = 1;
                 }
 
-                component.getWidgetPane().setLayout(new GridLayout(localGrid[0], localGrid[1], padding[0], padding[1]));
+                component.getWidgetPane().invalidate();
+
+                GridLayout gl = (GridLayout)component.getWidgetPane().getLayout();
+                gl.setRows(localGrid[0]);
+                gl.setColumns(localGrid[1]);
+                gl.setHgap(padding[0]);
+                gl.setVgap(padding[1]);
+
+                component.getWidgetPane().validate();
+
                 break;
             }
             case __GO_BORDER_OPT_PADDING__: {
@@ -285,8 +324,16 @@ public class SwingScilabCommonPanel {
                     break;
                 }
 
-                Integer[] padding = (Integer[]) GraphicController.getController().getProperty(component.getId(), __GO_BORDER_OPT_PADDING__);
-                component.getWidgetPane().setLayout(new BorderLayout(padding[0], padding[1]));
+                component.getWidgetPane().invalidate();
+
+                Integer[] padding = (Integer[])value;
+                BorderLayout bl = (BorderLayout)component.getWidgetPane().getLayout();
+                bl.setHgap(padding[0]);
+                bl.setVgap(padding[1]);
+
+
+                component.getWidgetPane().validate();
+
                 break;
             }
             case __GO_UI_ICON__: {
@@ -471,9 +518,9 @@ public class SwingScilabCommonPanel {
             component.getWidgetPane().revalidate();
         } else {
             if (member instanceof SwingScilabScrollableFrame || member instanceof SwingScilabFrame) {
-                component.getWidgetPane().add((Component) member, JLayeredPane.FRAME_CONTENT_LAYER);
+                component.getWidgetPane().add((Component) member, 0);
             } else {
-                component.getWidgetPane().add((Component) member, JLayeredPane.DEFAULT_LAYER + 1);
+                component.getWidgetPane().add((Component) member, 0);
             }
         }
     }