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