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