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