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