482d82d199f23071b160ddf850ebc96a39dc097e
[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 import javax.swing.JLayeredPane;
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                 if (oldFigureSize.getWidth() != 0 && oldFigureSize.getHeight() != 0 && ((oldFigureSize.getWidth() != size[0]) || (oldFigureSize.getHeight() != size[1]))
144                         && ((Boolean) GraphicController.getController().getProperty(component.getId(), __GO_AUTORESIZE__))) {
145                     figure.setDims(new Size(size[0], size[1]));
146                     figure.validate();
147                     GraphicController.getController().setProperty(component.getId(), __GO_AXES_SIZE__, new Integer[] { figure.getContentPane().getWidth(), figure.getContentPane().getHeight() });
148
149                 }
150                 break;
151             }
152             case __GO_POSITION__:
153                 Integer[] position = (Integer[]) value;
154                 SwingScilabWindow.allScilabWindows.get(component.getParentWindowId()).setPosition(new Position(position[0], position[1]));
155                 break;
156             case __GO_AXES_SIZE__:
157                 Integer[] axesSize = (Integer[]) value;
158                 Dimension oldAxesSize = component.getContentPane().getSize();
159                 if (oldAxesSize.getWidth() != 0 && oldAxesSize.getHeight() != 0 && ((oldAxesSize.getWidth() != axesSize[0]) || (oldAxesSize.getHeight() != axesSize[1]))
160                         && ((Boolean) GraphicController.getController().getProperty(component.getId(), __GO_AUTORESIZE__))) {
161                     // TODO manage tabs when there are docked (do not change the window size if more than one tab docked)
162                     int deltaX = axesSize[0] - (int) oldAxesSize.getWidth();
163                     int deltaY = axesSize[1] - (int) oldAxesSize.getHeight();
164                     Size parentWindowSize = SwingScilabWindow.allScilabWindows.get(component.getParentWindowId()).getDims();
165                     SwingScilabWindow.allScilabWindows.get(component.getParentWindowId()).setDims(new Size(parentWindowSize.getWidth() + deltaX, parentWindowSize.getHeight() + deltaY));
166                     GraphicController.getController().setProperty(component.getId(), __GO_SIZE__, new Integer[] { parentWindowSize.getWidth() + deltaX, parentWindowSize.getHeight() + deltaY});
167                 }
168                 break;
169             case __GO_INFO_MESSAGE__:
170                 if (component.getInfoBar() != null) {
171                     component.getInfoBar().setText((String) value);
172                 }
173                 break;
174             case __GO_EVENTHANDLER_ENABLE__:
175                 Boolean enabled = (Boolean) GraphicController.getController().getProperty(component.getId(), __GO_EVENTHANDLER_ENABLE__);
176                 component.setEventHandlerEnabled(enabled);
177                 break;
178             case __GO_EVENTHANDLER_NAME__:
179                 String eventHandlerName = (String) GraphicController.getController().getProperty(component.getId(), __GO_EVENTHANDLER_NAME__);
180                 component.setEventHandler(eventHandlerName);
181                 break;
182             case __GO_VISIBLE__:
183                 component.getContentPane().setVisible((Boolean) value);
184                 if (component.getParentWindow().getNbDockedObjects() == 1) {
185                     component.getParentWindow().setVisible((Boolean) value);
186                 }
187                 break;
188             case __GO_INFOBAR_VISIBLE__: {
189                 component.disableResizeEvent();
190                 Integer[] oldSize = (Integer[]) GraphicController.getController().getProperty(component.getId(), __GO_AXES_SIZE__);
191                 component.getInfoBar().setVisible((Boolean) value);
192                 SwingScilabWindow parentWindow = SwingScilabWindow.allScilabWindows.get(component.getParentWindowId());
193                 parentWindow.validate();
194                 GraphicController.getController().setProperty(component.getId(), __GO_AXES_SIZE__, oldSize);
195                 component.enableResizeEvent();
196                 break;
197             }
198             case __GO_TOOLBAR_VISIBLE__: {
199                 component.disableResizeEvent();
200                 Integer[] oldSize = (Integer[]) GraphicController.getController().getProperty(component.getId(), __GO_AXES_SIZE__);
201                 component.getToolBar().setVisible((Boolean) value);
202                 SwingScilabWindow parentWindow = SwingScilabWindow.allScilabWindows.get(component.getParentWindowId());
203                 parentWindow.validate();
204                 GraphicController.getController().setProperty(component.getId(), __GO_AXES_SIZE__, oldSize);
205                 component.enableResizeEvent();
206                 break;
207             }
208             case __GO_MENUBAR_VISIBLE__: {
209                 component.disableResizeEvent();
210                 Integer[] oldSize = (Integer[]) GraphicController.getController().getProperty(component.getId(), __GO_AXES_SIZE__);
211                 component.getMenuBar().setVisible((Boolean) value);
212                 SwingScilabWindow parentWindow = SwingScilabWindow.allScilabWindows.get(component.getParentWindowId());
213                 parentWindow.validate();
214                 GraphicController.getController().setProperty(component.getId(), __GO_AXES_SIZE__, oldSize);
215                 component.enableResizeEvent();
216                 break;
217             }
218             case __GO_RESIZE__:
219                 component.getParentWindow().setResizable((Boolean) value);
220                 //on some cases, set resizable can change frame size. ( L&F, Window Manager, ... )
221                 //so force set of axes_size.
222                 SwingScilabCommonPanel.update(component, __GO_AXES_SIZE__, GraphicController.getController().getProperty(component.getId(), __GO_AXES_SIZE__));
223
224                 break;
225             case __GO_LAYOUT__:
226                 LayoutType newLayout = LayoutType.intToEnum((Integer) value);
227
228                 component.getWidgetPane().invalidate();
229
230                 switch (newLayout) {
231                     case BORDER: {
232                         Integer[] padding = (Integer[]) GraphicController.getController().getProperty(component.getId(), __GO_BORDER_OPT_PADDING__);
233                         component.getWidgetPane().setLayout(new BorderLayout(padding[0], padding[1]));
234                         component.setHasLayout(true);
235                         break;
236                     }
237                     case GRIDBAG: {
238                         component.getWidgetPane().setLayout(new GridBagLayout());
239                         component.setHasLayout(true);
240                         break;
241                     }
242                     case GRID: {
243                         Integer[] padding = (Integer[]) GraphicController.getController().getProperty(component.getId(), __GO_GRID_OPT_PADDING__);
244                         Integer[] grid = (Integer[]) GraphicController.getController().getProperty(component.getId(), __GO_GRID_OPT_GRID__);
245                         Integer[] localGrid = new Integer[] { 0, 0 };
246                         localGrid[0] = grid[0];
247                         localGrid[1] = grid[1];
248
249                         if (localGrid[0] == 0 && localGrid[1] == 0) {
250                             localGrid[0] = 1;
251                         }
252
253                         component.getWidgetPane().setLayout(new GridLayout(localGrid[0], localGrid[1], padding[0], padding[1]));
254                         component.setHasLayout(true);
255                         break;
256                     }
257                     case NONE:
258                     default:
259                         component.getWidgetPane().setLayout(null);
260                         component.setHasLayout(false);
261                         break;
262                 }
263
264                 component.getWidgetPane().validate();
265
266                 break;
267             case __GO_GRID_OPT_PADDING__:
268             case __GO_GRID_OPT_GRID__: {
269                 Integer layout = (Integer) GraphicController.getController().getProperty(component.getId(), __GO_LAYOUT__);
270                 LayoutType layoutType = LayoutType.intToEnum(layout);
271
272                 if (layoutType != LayoutType.GRID) {
273                     break;
274                 }
275
276                 Integer[] padding = (Integer[]) GraphicController.getController().getProperty(component.getId(), __GO_GRID_OPT_PADDING__);
277
278                 Integer[] grid = (Integer[]) GraphicController.getController().getProperty(component.getId(), __GO_GRID_OPT_GRID__);
279                 Integer[] localGrid = new Integer[] { 0, 0 };
280                 localGrid[0] = grid[0];
281                 localGrid[1] = grid[1];
282
283                 if (localGrid[0] == 0 && localGrid[1] == 0) {
284                     localGrid[0] = 1;
285                 }
286
287                 component.getWidgetPane().invalidate();
288
289                 GridLayout gl = (GridLayout)component.getWidgetPane().getLayout();
290                 gl.setRows(localGrid[0]);
291                 gl.setColumns(localGrid[1]);
292                 gl.setHgap(padding[0]);
293                 gl.setVgap(padding[1]);
294
295                 component.getWidgetPane().validate();
296
297                 break;
298             }
299             case __GO_BORDER_OPT_PADDING__: {
300                 Integer layout = (Integer) GraphicController.getController().getProperty(component.getId(), __GO_LAYOUT__);
301                 LayoutType layoutType = LayoutType.intToEnum(layout);
302
303                 if (layoutType != LayoutType.BORDER) {
304                     break;
305                 }
306
307                 component.getWidgetPane().invalidate();
308
309                 Integer[] padding = (Integer[])value;
310                 BorderLayout bl = (BorderLayout)component.getWidgetPane().getLayout();
311                 bl.setHgap(padding[0]);
312                 bl.setVgap(padding[1]);
313
314
315                 component.getWidgetPane().validate();
316
317                 break;
318             }
319             case __GO_UI_ICON__: {
320                 File file = new File((String) value);
321                 if (file.exists() == false) {
322                     String filename = FindIconHelper.findImage((String) value);
323                     file = new File(filename);
324                 }
325
326                 try {
327                     BufferedImage icon = ImageIO.read(file);
328                     component.getParentWindow().setIconImage(new ImageIcon(icon).getImage());
329                 } catch (IOException e) {
330                 }
331                 break;
332             }
333             case __GO_COLORMAP__: {
334                 // Force background
335                 Figure figure = (Figure) GraphicController.getController().getObjectFromId(component.getId());
336                 component.setFigureBackground(ColorFactory.createColor(figure.getColorMap(), figure.getBackground()));
337                 break;
338             }
339             case __GO_BACKGROUND__: {
340                 Figure figure = (Figure) GraphicController.getController().getObjectFromId(component.getId());
341                 component.setFigureBackground(ColorFactory.createColor(figure.getColorMap(), (Integer) value));
342                 break;
343             }
344         }
345     }
346
347     /**
348      * Update the title of the Tab
349      * @param figureName figure_name property
350      * @param figureId figure_id property
351      */
352     private static void updateTitle(SwingScilabPanel component, String figureName, Integer figureId) {
353         if ((figureName != null) && (figureId != null)) {
354             String figureTitle = figureName.replaceFirst("%d", figureId.toString());
355             component.setName(figureTitle);
356         }
357     }
358
359     /**
360      * Update the menus callbacks when they are linked to the figure ID
361      * @param children the children UID
362      * @param parentFigureId the figure ID
363      */
364     private static void updateChildrenCallbacks(Integer[] children, int parentFigureId) {
365         for (int kChild = 0; kChild < children.length; kChild++) {
366             Integer childType = (Integer) GraphicController.getController().getProperty(children[kChild], __GO_TYPE__);
367             if (childType != null && (childType == __GO_UIMENU__ || childType == __GO_UIPARENTMENU__ || childType == __GO_UICHILDMENU__ || childType == __GO_UICHECKEDMENU__)) {
368                 String cb = (String) GraphicController.getController().getProperty(children[kChild], __GO_CALLBACK__);
369                 SwingView.getFromId(children[kChild]).update(__GO_CALLBACK__, replaceFigureID(cb, parentFigureId));
370                 Integer[] menuChildren = (Integer[]) GraphicController.getController().getProperty(children[kChild], __GO_CHILDREN__);
371                 updateChildrenCallbacks(menuChildren, parentFigureId);
372             }
373         }
374     }
375
376     /**
377      * Replace pattern [SCILAB_FIGURE_ID] by the figure index
378      * @param initialString string read in XML file
379      * @param parentFigureId the figure ID
380      * @return callback string
381      */
382     private static String replaceFigureID(String initialString, Integer parentFigureId) {
383         return initialString.replaceAll("\\[SCILAB_FIGURE_ID\\]", Integer.toString(parentFigureId));
384     }
385
386     /**
387      * Add a SwingViewObject (from SwingView.java) to container and returns its
388      * index
389      * @param member the member to add
390      */
391     protected static void addMember(SwingScilabPanel component, SwingViewObject member) {
392         //member.get
393         Uicontrol uicontrol = (Uicontrol) GraphicModel.getModel().getObjectFromId(member.getId());
394         if (component.getWidgetPane().getLayout() instanceof BorderLayout) {
395             switch (uicontrol.getBorderPositionAsEnum()) {
396                 case BOTTOM:
397                     component.getWidgetPane().add((Component) member, BorderLayout.SOUTH);
398                     break;
399                 case TOP:
400                     component.getWidgetPane().add((Component) member, BorderLayout.NORTH);
401                     break;
402                 case LEFT:
403                     component.getWidgetPane().add((Component) member, BorderLayout.WEST);
404                     break;
405                 case RIGHT:
406                     component.getWidgetPane().add((Component) member, BorderLayout.EAST);
407                     break;
408                 case CENTER:
409                     component.getWidgetPane().add((Component) member, BorderLayout.CENTER);
410                     break;
411                 default:
412                     break;
413             }
414
415             Integer[] preferredSize = uicontrol.getBorderPreferredSize();
416             if (preferredSize[0].equals(-1) == false && preferredSize[1].equals(-1) == false) {
417                 ((Component) member).setPreferredSize(new Dimension(preferredSize[0], preferredSize[1]));
418             }
419         } else if (component.getWidgetPane().getLayout() instanceof GridBagLayout) {
420             GridBagConstraints constraints = new GridBagConstraints();
421
422             // Grid
423             Integer[] grid = uicontrol.getGridBagGrid();
424             constraints.gridx = grid[0];
425             constraints.gridy = grid[1];
426             constraints.gridwidth = grid[2];
427             constraints.gridheight = grid[3];
428
429             // Weight
430             Double[] weight = uicontrol.getGridBagWeight();
431             constraints.weightx = weight[0];
432             constraints.weighty = weight[1];
433
434             // Anchor
435             switch (uicontrol.getGridBagAnchorAsEnum()) {
436                 case RIGHT:
437                     constraints.anchor = GridBagConstraints.EAST;
438                     break;
439                 case UPPER:
440                     constraints.anchor = GridBagConstraints.NORTH;
441                     break;
442                 case LOWER:
443                     constraints.anchor = GridBagConstraints.SOUTH;
444                     break;
445                 case LOWER_RIGHT:
446                     constraints.anchor = GridBagConstraints.SOUTHEAST;
447                     break;
448                 case LOWER_LEFT:
449                     constraints.anchor = GridBagConstraints.SOUTHWEST;
450                     break;
451                 case LEFT:
452                     constraints.anchor = GridBagConstraints.WEST;
453                     break;
454                 case UPPER_RIGHT:
455                     constraints.anchor = GridBagConstraints.NORTHEAST;
456                     break;
457                 case UPPER_LEFT:
458                     constraints.anchor = GridBagConstraints.NORTHWEST;
459                     break;
460                 case CENTER:
461                 default:
462                     constraints.anchor = GridBagConstraints.CENTER;
463                     break;
464             }
465
466             // Fill
467             switch (uicontrol.getGridBagFillAsEnum()) {
468                 case BOTH:
469                     constraints.fill = GridBagConstraints.BOTH;
470                     break;
471                 case HORIZONTAL:
472                     constraints.fill = GridBagConstraints.HORIZONTAL;
473                     break;
474                 case VERTICAL:
475                     constraints.fill = GridBagConstraints.VERTICAL;
476                     break;
477                 case NONE:
478                 default:
479                     constraints.fill = GridBagConstraints.NONE;
480                     break;
481             }
482
483             // Insets
484             Double[] margins = uicontrol.getMargins();
485             constraints.insets = new Insets(margins[0].intValue(), margins[1].intValue(), margins[2].intValue(), margins[3].intValue());
486
487             // Padding
488             Integer[] padding = uicontrol.getGridBagPadding();
489             constraints.ipadx = padding[0];
490             constraints.ipady = padding[1];
491
492             Integer[] preferredSize = uicontrol.getGridBagPreferredSize();
493             if (preferredSize[0].equals(-1) == false && preferredSize[1].equals(-1) == false) {
494                 ((Component) member).setPreferredSize(new Dimension(preferredSize[0], preferredSize[1]));
495             }
496
497             component.getWidgetPane().add((Component) member, constraints);
498             component.getWidgetPane().revalidate();
499         } else {
500             if (member instanceof SwingScilabScrollableFrame || member instanceof SwingScilabFrame) {
501                 component.getWidgetPane().add((Component) member, 0);
502             } else {
503                 component.getWidgetPane().add((Component) member, 0);
504             }
505         }
506     }
507
508     protected static void removeMember(SwingScilabPanel component, SwingViewObject member) {
509         component.getWidgetPane().remove((Component) member);
510     }
511 }