fix figure dimension
[scilab.git] / scilab / modules / gui / src / java / org / scilab / modules / gui / bridge / tab / SwingScilabCommonPanel.java
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2014 - Scilab Enterprises - Bruno JOFRET
4  * Copyright (C) 2015 - Scilab Enterprises - Anais AUBERT
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.1-en.txt
11  *
12  */
13 package org.scilab.modules.gui.bridge.tab;
14
15 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_AUTORESIZE__;
16 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_AXES_SIZE__;
17 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_BACKGROUND__;
18 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_BORDER_OPT_PADDING__;
19 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CALLBACK__;
20 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CHILDREN__;
21 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_COLORMAP__;
22 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_EVENTHANDLER_ENABLE__;
23 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_EVENTHANDLER_NAME__;
24 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_GRID_OPT_GRID__;
25 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_GRID_OPT_PADDING__;
26 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_ID__;
27 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_INFOBAR_VISIBLE__;
28 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_INFO_MESSAGE__;
29 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_LAYOUT__;
30 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_MENUBAR_VISIBLE__;
31 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_NAME__;
32 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_POSITION__;
33 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_RESIZE__;
34 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_SIZE__;
35 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TOOLBAR_VISIBLE__;
36 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TYPE__;
37 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UICHECKEDMENU__;
38 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UICHILDMENU__;
39 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UIMENU__;
40 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UIPARENTMENU__;
41 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_ICON__;
42 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_VISIBLE__;
43
44 import java.awt.BorderLayout;
45 import java.awt.Component;
46 import java.awt.Dimension;
47 import java.awt.GridBagConstraints;
48 import java.awt.GridBagLayout;
49 import java.awt.GridLayout;
50 import java.awt.Insets;
51 import java.awt.image.BufferedImage;
52 import java.io.File;
53 import java.io.IOException;
54
55 import javax.imageio.ImageIO;
56 import javax.swing.ImageIcon;
57
58 import org.scilab.modules.commons.gui.FindIconHelper;
59 import org.scilab.modules.graphic_objects.figure.Figure;
60 import org.scilab.modules.graphic_objects.figure.Figure.BarType;
61 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
62 import org.scilab.modules.graphic_objects.graphicModel.GraphicModel;
63 import org.scilab.modules.graphic_objects.uicontrol.Uicontrol;
64 import org.scilab.modules.graphic_objects.utils.LayoutType;
65 import org.scilab.modules.gui.SwingView;
66 import org.scilab.modules.gui.SwingViewObject;
67 import org.scilab.modules.gui.bridge.frame.SwingScilabFrame;
68 import org.scilab.modules.gui.bridge.frame.SwingScilabScrollableFrame;
69 import org.scilab.modules.gui.bridge.window.SwingScilabWindow;
70 import org.scilab.modules.gui.events.callback.ScilabCloseCallBack;
71 import org.scilab.modules.gui.toolbar.ToolBar;
72 import org.scilab.modules.gui.utils.Position;
73 import org.scilab.modules.gui.utils.Size;
74 import org.scilab.modules.gui.utils.ToolBarBuilder;
75 import org.scilab.modules.renderer.JoGLView.util.ColorFactory;
76
77 public class SwingScilabCommonPanel {
78
79     public static final String GRAPHICS_TOOLBAR_DESCRIPTOR = System.getenv("SCI") + "/modules/gui/etc/graphics_toolbar.xml";
80
81     /**
82      * Update the tab after a modification of its properties
83      * @param property the property name
84      * @param value the property value
85      * @see org.scilab.modules.gui.SwingViewObject#update(java.lang.String,
86      * java.lang.Object)
87      */
88     protected static void update(SwingScilabPanel component, int property, Object value) {
89         String name;
90         Integer figureId;
91         switch (property) {
92             case __GO_NAME__:
93                 name = ((String) value);
94                 figureId = (Integer) GraphicController.getController().getProperty(component.getId(), __GO_ID__);
95                 updateTitle(component, name, figureId);
96                 break;
97             case __GO_ID__:
98                 /* Update title */
99                 figureId = ((Integer) value);
100                 Figure localFigure = (Figure) GraphicController.getController().getObjectFromId(component.getId());
101                 name = localFigure.getName();
102                 updateTitle(component, name, figureId);
103
104                 /** Update tool bar */
105                 if (localFigure.getToolbarAsEnum() == BarType.FIGURE) {
106                     SwingScilabWindow parentWindow = SwingScilabWindow.allScilabWindows.get(component.getParentWindowId());
107
108                     boolean currentVisible = component.getToolBar().isVisible();
109
110                     //only if toolbar is visible
111                     if (currentVisible) {
112                         //keep current delta between figure size and axes size
113                         component.storeSizeDelta();
114                     }
115
116                     ToolBar toolbar = ToolBarBuilder.buildToolBar(GRAPHICS_TOOLBAR_DESCRIPTOR, figureId);
117                     toolbar.setVisible(currentVisible);
118                     component.setToolBar(toolbar);
119                     parentWindow.addToolBar(toolbar);
120                     //force redraw to get good value on contentpane.getHeight
121                     parentWindow.validate();
122
123                     if (currentVisible) {
124                         //apply stored delta to new axes size
125                         component.applyDeltaSize();
126                     }
127                 }
128
129                 /* Update callback */
130                 String closingCommand = "if (get_figure_handle(" + figureId + ") <> []) then" + "  if (get(get_figure_handle(" + figureId + "), 'event_handler_enable') == 'on') then"
131                                         + "    execstr(get(get_figure_handle(" + figureId + "), 'event_handler')+'(" + figureId + ", -1, -1, -1000)', 'errcatch', 'm');" + "  end;" + "  delete(get_figure_handle("
132                                         + figureId + "));" + "end;";
133                 component.setCallback(null);
134                 component.setCallback(ScilabCloseCallBack.create(component.getId(), closingCommand));
135                 /* Update menus callback */
136                 Integer[] children = (Integer[]) GraphicController.getController().getProperty(component.getId(), __GO_CHILDREN__);
137                 updateChildrenCallbacks(children, figureId);
138                 break;
139             case __GO_SIZE__: {
140                 Integer[] size = (Integer[]) value;
141                 SwingScilabWindow figure = SwingScilabWindow.allScilabWindows.get(component.getParentWindowId());
142                 Size oldFigureSize = figure.getDims();
143
144                 if (oldFigureSize.getWidth() != 0 && oldFigureSize.getHeight() != 0 && ((oldFigureSize.getWidth() != size[0]) || (oldFigureSize.getHeight() != size[1]))
145                         && ((Boolean) GraphicController.getController().getProperty(component.getId(), __GO_AUTORESIZE__))) {
146                     figure.setDims(new Size(size[0], size[1]));
147                     figure.validate();
148                     // Axes are resized by resize event: SwingScilabDockablePanel::componentResized or SwingScilabStaticPanel::componentResized
149                     // ==> NO NEED TO FORCE RESIZE
150                     // GraphicController.getController().setProperty(component.getId(), __GO_AXES_SIZE__, new Integer[] { figure.getContentPane().getWidth(), figure.getContentPane().getHeight() });
151
152                 }
153                 break;
154             }
155             case __GO_POSITION__:
156                 Integer[] position = (Integer[]) value;
157                 SwingScilabWindow.allScilabWindows.get(component.getParentWindowId()).setPosition(new Position(position[0], position[1]));
158                 break;
159             case __GO_AXES_SIZE__:
160                 Integer[] axesSize = (Integer[]) value;
161                 Dimension oldAxesSize = component.getContentPane().getSize();
162                 if (oldAxesSize.getWidth() != 0 && oldAxesSize.getHeight() != 0 && ((oldAxesSize.getWidth() != axesSize[0]) || (oldAxesSize.getHeight() != axesSize[1]))
163                         && ((Boolean) GraphicController.getController().getProperty(component.getId(), __GO_AUTORESIZE__))) {
164                     // TODO manage tabs when there are docked (do not change the window size if more than one tab docked)
165                     int deltaX = axesSize[0] - (int) oldAxesSize.getWidth();
166                     int deltaY = axesSize[1] - (int) oldAxesSize.getHeight();
167                     Size parentWindowSize = SwingScilabWindow.allScilabWindows.get(component.getParentWindowId()).getDims();
168                     SwingScilabWindow.allScilabWindows.get(component.getParentWindowId()).setDims(new Size(parentWindowSize.getWidth() + deltaX, parentWindowSize.getHeight() + deltaY));
169                     GraphicController.getController().setProperty(component.getId(), __GO_SIZE__, new Integer[] { parentWindowSize.getWidth() + deltaX, parentWindowSize.getHeight() + deltaY});
170                 }
171                 break;
172             case __GO_INFO_MESSAGE__:
173                 if (component.getInfoBar() != null) {
174                     component.getInfoBar().setText((String) value);
175                 }
176                 break;
177             case __GO_EVENTHANDLER_ENABLE__:
178                 Boolean enabled = (Boolean) GraphicController.getController().getProperty(component.getId(), __GO_EVENTHANDLER_ENABLE__);
179                 component.setEventHandlerEnabled(enabled);
180                 break;
181             case __GO_EVENTHANDLER_NAME__:
182                 String eventHandlerName = (String) GraphicController.getController().getProperty(component.getId(), __GO_EVENTHANDLER_NAME__);
183                 component.setEventHandler(eventHandlerName);
184                 break;
185             case __GO_VISIBLE__:
186                 component.getContentPane().setVisible((Boolean) value);
187                 if (component.getParentWindow().getNbDockedObjects() == 1) {
188                     component.getParentWindow().setVisible((Boolean) value);
189                 }
190                 break;
191             case __GO_INFOBAR_VISIBLE__: {
192                 component.disableResizeEvent();
193                 Integer[] oldSize = (Integer[]) GraphicController.getController().getProperty(component.getId(), __GO_AXES_SIZE__);
194                 component.getInfoBar().setVisible((Boolean) value);
195                 SwingScilabWindow parentWindow = SwingScilabWindow.allScilabWindows.get(component.getParentWindowId());
196                 parentWindow.validate();
197                 GraphicController.getController().setProperty(component.getId(), __GO_AXES_SIZE__, oldSize);
198                 component.enableResizeEvent();
199                 break;
200             }
201             case __GO_TOOLBAR_VISIBLE__: {
202                 component.disableResizeEvent();
203                 Integer[] oldSize = (Integer[]) GraphicController.getController().getProperty(component.getId(), __GO_AXES_SIZE__);
204                 component.getToolBar().setVisible((Boolean) value);
205                 SwingScilabWindow parentWindow = SwingScilabWindow.allScilabWindows.get(component.getParentWindowId());
206                 parentWindow.validate();
207                 GraphicController.getController().setProperty(component.getId(), __GO_AXES_SIZE__, oldSize);
208                 component.enableResizeEvent();
209                 break;
210             }
211             case __GO_MENUBAR_VISIBLE__: {
212                 component.disableResizeEvent();
213                 Integer[] oldSize = (Integer[]) GraphicController.getController().getProperty(component.getId(), __GO_AXES_SIZE__);
214                 component.getMenuBar().setVisible((Boolean) value);
215                 SwingScilabWindow parentWindow = SwingScilabWindow.allScilabWindows.get(component.getParentWindowId());
216                 parentWindow.validate();
217                 GraphicController.getController().setProperty(component.getId(), __GO_AXES_SIZE__, oldSize);
218                 component.enableResizeEvent();
219                 break;
220             }
221             case __GO_RESIZE__:
222                 component.getParentWindow().setResizable((Boolean) value);
223                 //on some cases, set resizable can change frame size. ( L&F, Window Manager, ... )
224                 //so force set of axes_size.
225                 SwingScilabCommonPanel.update(component, __GO_AXES_SIZE__, GraphicController.getController().getProperty(component.getId(), __GO_AXES_SIZE__));
226
227                 break;
228             case __GO_LAYOUT__:
229                 LayoutType newLayout = LayoutType.intToEnum((Integer) value);
230
231                 component.getWidgetPane().invalidate();
232
233                 switch (newLayout) {
234                     case BORDER: {
235                         Integer[] padding = (Integer[]) GraphicController.getController().getProperty(component.getId(), __GO_BORDER_OPT_PADDING__);
236                         component.getWidgetPane().setLayout(new BorderLayout(padding[0], padding[1]));
237                         component.setHasLayout(true);
238                         break;
239                     }
240                     case GRIDBAG: {
241                         component.getWidgetPane().setLayout(new GridBagLayout());
242                         component.setHasLayout(true);
243                         break;
244                     }
245                     case GRID: {
246                         Integer[] padding = (Integer[]) GraphicController.getController().getProperty(component.getId(), __GO_GRID_OPT_PADDING__);
247                         Integer[] grid = (Integer[]) GraphicController.getController().getProperty(component.getId(), __GO_GRID_OPT_GRID__);
248                         Integer[] localGrid = new Integer[] { 0, 0 };
249                         localGrid[0] = grid[0];
250                         localGrid[1] = grid[1];
251
252                         if (localGrid[0] == 0 && localGrid[1] == 0) {
253                             localGrid[0] = 1;
254                         }
255
256                         component.getWidgetPane().setLayout(new GridLayout(localGrid[0], localGrid[1], padding[0], padding[1]));
257                         component.setHasLayout(true);
258                         break;
259                     }
260                     case NONE:
261                     default:
262                         component.getWidgetPane().setLayout(null);
263                         component.setHasLayout(false);
264                         break;
265                 }
266
267                 component.getWidgetPane().validate();
268
269                 break;
270             case __GO_GRID_OPT_PADDING__:
271             case __GO_GRID_OPT_GRID__: {
272                 Integer layout = (Integer) GraphicController.getController().getProperty(component.getId(), __GO_LAYOUT__);
273                 LayoutType layoutType = LayoutType.intToEnum(layout);
274
275                 if (layoutType != LayoutType.GRID) {
276                     break;
277                 }
278
279                 Integer[] padding = (Integer[]) GraphicController.getController().getProperty(component.getId(), __GO_GRID_OPT_PADDING__);
280
281                 Integer[] grid = (Integer[]) GraphicController.getController().getProperty(component.getId(), __GO_GRID_OPT_GRID__);
282                 Integer[] localGrid = new Integer[] { 0, 0 };
283                 localGrid[0] = grid[0];
284                 localGrid[1] = grid[1];
285
286                 if (localGrid[0] == 0 && localGrid[1] == 0) {
287                     localGrid[0] = 1;
288                 }
289
290                 component.getWidgetPane().invalidate();
291
292                 GridLayout gl = (GridLayout)component.getWidgetPane().getLayout();
293                 gl.setRows(localGrid[0]);
294                 gl.setColumns(localGrid[1]);
295                 gl.setHgap(padding[0]);
296                 gl.setVgap(padding[1]);
297
298                 component.getWidgetPane().validate();
299
300                 break;
301             }
302             case __GO_BORDER_OPT_PADDING__: {
303                 Integer layout = (Integer) GraphicController.getController().getProperty(component.getId(), __GO_LAYOUT__);
304                 LayoutType layoutType = LayoutType.intToEnum(layout);
305
306                 if (layoutType != LayoutType.BORDER) {
307                     break;
308                 }
309
310                 component.getWidgetPane().invalidate();
311
312                 Integer[] padding = (Integer[])value;
313                 BorderLayout bl = (BorderLayout)component.getWidgetPane().getLayout();
314                 bl.setHgap(padding[0]);
315                 bl.setVgap(padding[1]);
316
317
318                 component.getWidgetPane().validate();
319
320                 break;
321             }
322             case __GO_UI_ICON__: {
323                 File file = new File((String) value);
324                 if (file.exists() == false) {
325                     String filename = FindIconHelper.findImage((String) value);
326                     file = new File(filename);
327                 }
328
329                 try {
330                     BufferedImage icon = ImageIO.read(file);
331                     component.getParentWindow().setIconImage(new ImageIcon(icon).getImage());
332                 } catch (IOException e) {
333                 }
334                 break;
335             }
336             case __GO_COLORMAP__: {
337                 // Force background
338                 Figure figure = (Figure) GraphicController.getController().getObjectFromId(component.getId());
339                 component.setFigureBackground(ColorFactory.createColor(figure.getColorMap(), figure.getBackground()));
340                 break;
341             }
342             case __GO_BACKGROUND__: {
343                 Figure figure = (Figure) GraphicController.getController().getObjectFromId(component.getId());
344                 component.setFigureBackground(ColorFactory.createColor(figure.getColorMap(), (Integer) value));
345                 break;
346             }
347         }
348     }
349
350     /**
351      * Update the title of the Tab
352      * @param figureName figure_name property
353      * @param figureId figure_id property
354      */
355     private static void updateTitle(SwingScilabPanel component, String figureName, Integer figureId) {
356         if ((figureName != null) && (figureId != null)) {
357             String figureTitle = figureName.replaceFirst("%d", figureId.toString());
358             component.setName(figureTitle);
359         }
360     }
361
362     /**
363      * Update the menus callbacks when they are linked to the figure ID
364      * @param children the children UID
365      * @param parentFigureId the figure ID
366      */
367     private static void updateChildrenCallbacks(Integer[] children, int parentFigureId) {
368         for (int kChild = 0; kChild < children.length; kChild++) {
369             Integer childType = (Integer) GraphicController.getController().getProperty(children[kChild], __GO_TYPE__);
370             if (childType != null && (childType == __GO_UIMENU__ || childType == __GO_UIPARENTMENU__ || childType == __GO_UICHILDMENU__ || childType == __GO_UICHECKEDMENU__)) {
371                 String cb = (String) GraphicController.getController().getProperty(children[kChild], __GO_CALLBACK__);
372                 SwingView.getFromId(children[kChild]).update(__GO_CALLBACK__, replaceFigureID(cb, parentFigureId));
373                 Integer[] menuChildren = (Integer[]) GraphicController.getController().getProperty(children[kChild], __GO_CHILDREN__);
374                 updateChildrenCallbacks(menuChildren, parentFigureId);
375             }
376         }
377     }
378
379     /**
380      * Replace pattern [SCILAB_FIGURE_ID] by the figure index
381      * @param initialString string read in XML file
382      * @param parentFigureId the figure ID
383      * @return callback string
384      */
385     private static String replaceFigureID(String initialString, Integer parentFigureId) {
386         return initialString.replaceAll("\\[SCILAB_FIGURE_ID\\]", Integer.toString(parentFigureId));
387     }
388
389     /**
390      * Add a SwingViewObject (from SwingView.java) to container and returns its
391      * index
392      * @param member the member to add
393      */
394     protected static void addMember(SwingScilabPanel component, SwingViewObject member) {
395         //member.get
396         Uicontrol uicontrol = (Uicontrol) GraphicModel.getModel().getObjectFromId(member.getId());
397         if (component.getWidgetPane().getLayout() instanceof BorderLayout) {
398             switch (uicontrol.getBorderPositionAsEnum()) {
399                 case BOTTOM:
400                     component.getWidgetPane().add((Component) member, BorderLayout.SOUTH);
401                     break;
402                 case TOP:
403                     component.getWidgetPane().add((Component) member, BorderLayout.NORTH);
404                     break;
405                 case LEFT:
406                     component.getWidgetPane().add((Component) member, BorderLayout.WEST);
407                     break;
408                 case RIGHT:
409                     component.getWidgetPane().add((Component) member, BorderLayout.EAST);
410                     break;
411                 case CENTER:
412                     component.getWidgetPane().add((Component) member, BorderLayout.CENTER);
413                     break;
414                 default:
415                     break;
416             }
417
418             Integer[] preferredSize = uicontrol.getBorderPreferredSize();
419             if (preferredSize[0].equals(-1) == false && preferredSize[1].equals(-1) == false) {
420                 ((Component) member).setPreferredSize(new Dimension(preferredSize[0], preferredSize[1]));
421             }
422         } else if (component.getWidgetPane().getLayout() instanceof GridBagLayout) {
423             GridBagConstraints constraints = new GridBagConstraints();
424
425             // Grid
426             Integer[] grid = uicontrol.getGridBagGrid();
427             constraints.gridx = grid[0];
428             constraints.gridy = grid[1];
429             constraints.gridwidth = grid[2];
430             constraints.gridheight = grid[3];
431
432             // Weight
433             Double[] weight = uicontrol.getGridBagWeight();
434             constraints.weightx = weight[0];
435             constraints.weighty = weight[1];
436
437             // Anchor
438             switch (uicontrol.getGridBagAnchorAsEnum()) {
439                 case RIGHT:
440                     constraints.anchor = GridBagConstraints.EAST;
441                     break;
442                 case UPPER:
443                     constraints.anchor = GridBagConstraints.NORTH;
444                     break;
445                 case LOWER:
446                     constraints.anchor = GridBagConstraints.SOUTH;
447                     break;
448                 case LOWER_RIGHT:
449                     constraints.anchor = GridBagConstraints.SOUTHEAST;
450                     break;
451                 case LOWER_LEFT:
452                     constraints.anchor = GridBagConstraints.SOUTHWEST;
453                     break;
454                 case LEFT:
455                     constraints.anchor = GridBagConstraints.WEST;
456                     break;
457                 case UPPER_RIGHT:
458                     constraints.anchor = GridBagConstraints.NORTHEAST;
459                     break;
460                 case UPPER_LEFT:
461                     constraints.anchor = GridBagConstraints.NORTHWEST;
462                     break;
463                 case CENTER:
464                 default:
465                     constraints.anchor = GridBagConstraints.CENTER;
466                     break;
467             }
468
469             // Fill
470             switch (uicontrol.getGridBagFillAsEnum()) {
471                 case BOTH:
472                     constraints.fill = GridBagConstraints.BOTH;
473                     break;
474                 case HORIZONTAL:
475                     constraints.fill = GridBagConstraints.HORIZONTAL;
476                     break;
477                 case VERTICAL:
478                     constraints.fill = GridBagConstraints.VERTICAL;
479                     break;
480                 case NONE:
481                 default:
482                     constraints.fill = GridBagConstraints.NONE;
483                     break;
484             }
485
486             // Insets
487             Double[] margins = uicontrol.getMargins();
488             constraints.insets = new Insets(margins[0].intValue(), margins[1].intValue(), margins[2].intValue(), margins[3].intValue());
489
490             // Padding
491             Integer[] padding = uicontrol.getGridBagPadding();
492             constraints.ipadx = padding[0];
493             constraints.ipady = padding[1];
494
495             Integer[] preferredSize = uicontrol.getGridBagPreferredSize();
496             if (preferredSize[0].equals(-1) == false && preferredSize[1].equals(-1) == false) {
497                 ((Component) member).setPreferredSize(new Dimension(preferredSize[0], preferredSize[1]));
498             }
499
500             component.getWidgetPane().add((Component) member, constraints);
501             component.getWidgetPane().revalidate();
502         } else {
503             if (member instanceof SwingScilabScrollableFrame || member instanceof SwingScilabFrame) {
504                 component.getWidgetPane().add((Component) member, 0);
505             } else {
506                 component.getWidgetPane().add((Component) member, 0);
507             }
508         }
509     }
510
511     protected static void removeMember(SwingScilabPanel component, SwingViewObject member) {
512         component.getWidgetPane().remove((Component) member);
513     }
514 }