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