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