* Bug #11685 fixed - gcbo variable was not defined when executing functions set
[scilab.git] / scilab / modules / gui / src / java / org / scilab / modules / gui / graphicWindow / PanelLayout.java
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2010 - DIGITEO - Pierre Lando
4  * Copyright (C) 2010 - Scilab Enterprises - Bruno JOFRET
5  *
6  * This file must be used under the terms of the CeCILL.
7  * This source file is licensed as described in the file COPYING, which
8  * you should have received as part of this distribution.  The terms
9  * are also available at
10  * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
11  */
12 package org.scilab.modules.gui.graphicWindow;
13
14 import java.awt.Component;
15 import java.awt.Container;
16 import java.awt.Dimension;
17 import java.awt.LayoutManager;
18 import java.io.Serializable;
19
20 import org.scilab.modules.action_binding.InterpreterManagement;
21 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
22 import org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties;
23 import org.scilab.modules.gui.SwingViewObject;
24 import org.scilab.modules.gui.bridge.canvas.SwingScilabCanvas;
25
26 /**
27  * @author Pierre Lando
28  */
29 @SuppressWarnings(value = { "serial" })
30 public class PanelLayout implements LayoutManager, Serializable {
31
32     public static final String GL_CANVAS = "GL_CANVAS";
33     public static final String UI_CONTROL = "UI_CONTROL";
34     private Component canvas;
35
36     @Override
37     public void addLayoutComponent(String name, Component comp) {
38         if (GL_CANVAS.equals(name)) {
39             canvas = comp;
40         }
41     }
42
43     @Override
44     public void removeLayoutComponent(Component comp) {
45     }
46
47     @Override
48     public Dimension preferredLayoutSize(Container parent) {
49         return new Dimension(0, 0);
50     }
51
52     @Override
53     public Dimension minimumLayoutSize(Container parent) {
54         return new Dimension(0, 0);
55     }
56
57     @Override
58     public void layoutContainer(Container parent) {
59         for (Component child : parent.getComponents()) {
60             if (child.equals(canvas)) {
61                 canvas.setBounds(0, 0, parent.getWidth(), parent.getHeight());
62                 parent.setComponentZOrder(child, parent.getComponentCount() - 1);
63             }
64
65             String figureIdentifier = ((SwingScilabCanvas) parent).getFigure().getIdentifier();
66             String resizeFcn = (String) GraphicController.getController().getProperty(figureIdentifier, GraphicObjectProperties.__GO_RESIZEFCN__);
67             if (resizeFcn != null && !resizeFcn.equals("")) {
68                 String resizeCommand = "if exists(\"gcbo\") then %oldgcbo = gcbo; end;"
69                                        + "gcbo = getcallbackobject(\"" + figureIdentifier + "\");"
70                                        + resizeFcn
71                                        + ";if exists(\"%oldgcbo\") then gcbo = %oldgcbo; else clear gcbo; end;";
72                 InterpreterManagement.requestScilabExec(resizeCommand);
73             }
74
75             /* Here you can perform the layout of UI object. */
76             if (child instanceof SwingViewObject) {
77                 String id = ((SwingViewObject) child).getId();
78                 ((SwingViewObject) child).update(GraphicObjectProperties.__GO_POSITION__,
79                                                  GraphicController.getController().getProperty(id, GraphicObjectProperties.__GO_POSITION__));
80             }
81         }
82     }
83 }