2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2011 - DIGITEO - Bruno JOFRET
4 * Copyright (C) 2011 - DIGITEO - Vincent COUVERT
6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at
10 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
13 package org.scilab.modules.gui;
15 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_AXES_SIZE__;
16 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_AXES__;
17 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CALLBACKTYPE__;
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_CONSOLE__;
21 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_FIGURE__;
22 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_IMMEDIATE_DRAWING__;
23 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_LAYOUT__;
24 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_PARENT__;
25 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_POSITION__;
26 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_PROGRESSIONBAR__;
27 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_SIZE__;
28 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_STYLE__;
29 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TYPE__;
30 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UICHECKEDMENU__;
31 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UICHILDMENU__;
32 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UICONTEXTMENU__;
33 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UICONTROL__;
34 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UIMENU__;
35 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UIPARENTMENU__;
36 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_BACKGROUNDCOLOR__;
37 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_CHECKBOX__;
38 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_CHECKED__;
39 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_EDIT__;
40 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_SPINNER__;
41 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_ENABLE__;
42 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTANGLE__;
43 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTNAME__;
44 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTSIZE__;
45 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTUNITS__;
46 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FONTWEIGHT__;
47 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FOREGROUNDCOLOR__;
48 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME_BORDER__;
49 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_FRAME__;
50 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_HORIZONTALALIGNMENT__;
51 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_ICON__;
52 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_IMAGE__;
53 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_LABEL__;
54 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_LAYER__;
55 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_LISTBOX__;
56 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_MAX__;
57 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_MIN__;
58 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_POPUPMENU__;
59 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_PUSHBUTTON__;
60 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_RADIOBUTTON__;
61 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_RELIEF__;
62 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_SCROLLABLE__;
63 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_SEPARATOR__;
64 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_SLIDER__;
65 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_STRING__;
66 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_TABLE__;
67 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_TAB__;
68 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_TEXT__;
69 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_VERTICALALIGNMENT__;
70 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_VALID__;
71 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_VISIBLE__;
72 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_WAITBAR__;
73 import static org.scilab.modules.gui.utils.Debug.DEBUG;
75 import java.awt.Component;
76 import java.awt.Container;
77 import java.awt.GraphicsEnvironment;
78 import java.lang.reflect.InvocationTargetException;
79 import java.util.Arrays;
80 import java.util.Collections;
81 import java.util.HashMap;
82 import java.util.HashSet;
85 import java.util.UUID;
87 import javax.media.opengl.GL;
88 import javax.media.opengl.GLCapabilities;
89 import javax.media.opengl.GLProfile;
90 import javax.media.opengl.awt.GLCanvas;
91 import javax.swing.JComponent;
92 import javax.swing.JSeparator;
93 import javax.swing.SwingUtilities;
95 import org.flexdock.docking.Dockable;
96 import org.flexdock.docking.DockingManager;
97 import org.flexdock.docking.activation.ActiveDockableTracker;
98 import org.scilab.modules.graphic_export.Driver;
99 import org.scilab.modules.graphic_objects.DataLoader;
100 import org.scilab.modules.graphic_objects.console.Console;
101 import org.scilab.modules.graphic_objects.figure.Figure;
102 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
103 import org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties;
104 import org.scilab.modules.graphic_objects.graphicView.GraphicView;
105 import org.scilab.modules.gui.bridge.checkbox.SwingScilabCheckBox;
106 import org.scilab.modules.gui.bridge.checkboxmenuitem.SwingScilabCheckBoxMenuItem;
107 import org.scilab.modules.gui.bridge.console.SwingScilabConsole;
108 import org.scilab.modules.gui.bridge.contextmenu.SwingScilabContextMenu;
109 import org.scilab.modules.gui.bridge.editbox.SwingScilabEditBox;
110 import org.scilab.modules.gui.bridge.editbox.SwingScilabSpinner;
111 import org.scilab.modules.gui.bridge.frame.SwingScilabFrame;
112 import org.scilab.modules.gui.bridge.frame.SwingScilabLayer;
113 import org.scilab.modules.gui.bridge.frame.SwingScilabScrollableFrame;
114 import org.scilab.modules.gui.bridge.label.SwingScilabLabel;
115 import org.scilab.modules.gui.bridge.listbox.SwingScilabListBox;
116 import org.scilab.modules.gui.bridge.menu.SwingScilabMenu;
117 import org.scilab.modules.gui.bridge.menuitem.SwingScilabMenuItem;
118 import org.scilab.modules.gui.bridge.popupmenu.SwingScilabPopupMenu;
119 import org.scilab.modules.gui.bridge.pushbutton.SwingScilabPushButton;
120 import org.scilab.modules.gui.bridge.radiobutton.SwingScilabRadioButton;
121 import org.scilab.modules.gui.bridge.slider.SwingScilabScroll;
122 import org.scilab.modules.gui.bridge.slider.SwingScilabSlider;
123 import org.scilab.modules.gui.bridge.tab.SwingScilabAxes;
124 import org.scilab.modules.gui.bridge.tab.SwingScilabDockablePanel;
125 import org.scilab.modules.gui.bridge.tab.SwingScilabPanel;
126 import org.scilab.modules.gui.bridge.tab.SwingScilabStaticPanel;
127 import org.scilab.modules.gui.bridge.tab.SwingScilabTabGroup;
128 import org.scilab.modules.gui.bridge.uiimage.SwingScilabUiImage;
129 import org.scilab.modules.gui.bridge.uitable.SwingScilabUiTable;
130 import org.scilab.modules.gui.bridge.waitbar.SwingScilabWaitBar;
131 import org.scilab.modules.gui.bridge.window.SwingScilabWindow;
132 import org.scilab.modules.gui.console.ScilabConsole;
133 import org.scilab.modules.gui.ged.Inspector;
134 import org.scilab.modules.gui.menubar.MenuBar;
135 import org.scilab.modules.gui.menubar.ScilabMenuBar;
136 import org.scilab.modules.gui.textbox.ScilabTextBox;
137 import org.scilab.modules.gui.textbox.TextBox;
138 import org.scilab.modules.gui.toolbar.ScilabToolBar;
139 import org.scilab.modules.gui.toolbar.ToolBar;
140 import org.scilab.modules.gui.utils.BorderConvertor;
141 import org.scilab.modules.gui.utils.ClosingOperationsManager;
142 import org.scilab.modules.gui.utils.Size;
143 import org.scilab.modules.gui.utils.WindowsConfigurationManager;
144 import org.scilab.modules.gui.widget.Widget;
145 import org.scilab.modules.renderer.utils.textRendering.FontManager;
148 * @author Bruno JOFRET
149 * @author Vincent COUVERT
151 public final class SwingView implements GraphicView {
153 public static final String NULLUUID = new UUID(0L, 0L).toString();
154 private static SwingView me;
155 private static boolean headless;
156 private Map<Integer, TypedObject> allObjects;
160 System.loadLibrary("gluegen2-rt");
161 } catch (Exception e) {
162 System.err.println(e);
169 private SwingView() {
170 GraphicController.getController().register(this);
171 allObjects = Collections.synchronizedMap(new HashMap<Integer, TypedObject>());
174 GLCanvas tmpCanvas = new GLCanvas(new GLCapabilities(GLProfile.getDefault()));
175 tmpCanvas.getContext().makeCurrent();
176 GL gl = tmpCanvas.getGL();
177 DataLoader.setABGRExt(gl.isExtensionAvailable("GL_EXT_abgr") ? 1 : 0);
178 tmpCanvas.getContext().release();
182 * Forces font loading from the main thread. This is done because if
183 * getSciFontManager (thus, font loading) is concurrently accessed
184 * from 2 different threads (the AWT's and the main one), freezing
187 FontManager.getSciFontManager();
188 } catch (Exception e) {
192 public static void registerSwingView() {
193 DEBUG("SwingView", "calling registerSwingView()");
195 me = new SwingView();
199 public static void setHeadless(boolean headless) {
200 SwingView.headless = headless;
203 public static boolean isHeadless() {
204 return SwingView.headless;
207 public static SwingViewObject getFromId(Integer id) {
208 TypedObject typedObject = me.allObjects.get(id);
210 if (typedObject == null) {
214 return typedObject.getValue();
217 private enum UielementType {
218 Console, CheckBox, Edit, Spinner, Frame, Figure, Axes, Image, ListBox, PopupMenu, Progressbar, PushButton, RadioButton, Slider, Table, Text, Uimenu, UiParentMenu, UiChildMenu, UiCheckedMenu, UiContextMenu, Waitbar, Tab, Layer
221 private class TypedObject {
222 private UielementType _type;
223 private SwingViewObject _value;
224 private Set<Integer> _children;
226 public TypedObject(UielementType _type, SwingViewObject _value) {
228 this._value = _value;
229 this._children = Collections.synchronizedSet(new HashSet<Integer>());
232 public UielementType getType() {
236 public SwingViewObject getValue() {
240 public Set<Integer> getChildren() {
244 public void addChild(Integer childUID) {
245 _children.add(childUID);
248 public void removeChild(Integer childUID) {
249 _children.remove(childUID);
252 public boolean hasChild(Integer childUID) {
253 return _children.contains(childUID);
257 private static final Set<Integer> managedTypes = new HashSet<Integer>(Arrays.asList(
258 GraphicObjectProperties.__GO_FIGURE__,
259 GraphicObjectProperties.__GO_AXES__,
260 GraphicObjectProperties.__GO_UICONTEXTMENU__,
261 GraphicObjectProperties.__GO_UIMENU__,
262 GraphicObjectProperties.__GO_CONSOLE__,
263 GraphicObjectProperties.__GO_PROGRESSIONBAR__,
264 GraphicObjectProperties.__GO_WAITBAR__,
265 GraphicObjectProperties.__GO_UICONTROL__
269 public void createObject(Integer id) {
271 int objectType = (Integer) GraphicController.getController().getProperty(id, __GO_TYPE__);
273 if (managedTypes.contains(objectType) == false) {
276 //System.err.println("[SwingWiew] Object Created : " + id + " with type : " + objectType);
277 boolean isValid = (Boolean) GraphicController.getController().getProperty(id, __GO_VALID__);
282 if (!headless && !GraphicsEnvironment.isHeadless()) {
283 DEBUG("SwingWiew", "Object Created : " + id + "with type : " + objectType);
284 if (objectType != __GO_UICONTROL__) {
285 allObjects.put(id, CreateObjectFromType(objectType, id));
289 if (objectType == __GO_UICONTROL__) {
290 int style = (Integer) GraphicController.getController().getProperty(id, __GO_STYLE__);
291 DEBUG("SwingView", "__GO_STYLE__(" + style + ")");
292 allObjects.put(id, CreateObjectFromType(style, id));
295 if (objectType == __GO_FIGURE__) {
296 Driver.setDefaultVisitor(id);
301 private UielementType StyleToEnum(int style) {
302 DEBUG("SwingView", "StyleToEnum(" + style + ")");
305 return UielementType.Figure;
307 return UielementType.Axes;
309 return UielementType.Console;
310 case __GO_UI_CHECKBOX__:
311 return UielementType.CheckBox;
313 return UielementType.Edit;
314 case __GO_UI_SPINNER__:
315 return UielementType.Spinner;
316 case __GO_UI_FRAME__:
317 return UielementType.Frame;
318 case __GO_UI_IMAGE__:
319 return UielementType.Image;
320 case __GO_UI_LISTBOX__:
321 return UielementType.ListBox;
322 case __GO_UI_POPUPMENU__:
323 return UielementType.PopupMenu;
324 case __GO_UI_PUSHBUTTON__:
325 return UielementType.PushButton;
326 case __GO_UI_RADIOBUTTON__:
327 return UielementType.RadioButton;
328 case __GO_UI_SLIDER__:
329 return UielementType.Slider;
330 case __GO_UI_TABLE__:
331 return UielementType.Table;
333 return UielementType.Text;
335 return UielementType.UiChildMenu;
336 case __GO_UIPARENTMENU__:
337 return UielementType.UiParentMenu;
338 case __GO_UICHILDMENU__:
339 return UielementType.UiChildMenu;
340 case __GO_UICHECKEDMENU__:
341 return UielementType.UiCheckedMenu;
342 case __GO_PROGRESSIONBAR__:
343 return UielementType.Progressbar;
345 return UielementType.Waitbar;
346 case __GO_UICONTEXTMENU__:
347 return UielementType.UiContextMenu;
349 return UielementType.Tab;
350 case __GO_UI_LAYER__:
351 return UielementType.Layer;
356 private TypedObject CreateObjectFromType(final int type, final Integer id) {
357 final UielementType enumType = StyleToEnum(type);
358 final SwingViewObject newSVObject[] = new SwingViewObject[1];
359 if (SwingUtilities.isEventDispatchThread()) {
360 newSVObject[0] = CreateObjectFromType(enumType, id);
363 SwingUtilities.invokeAndWait(new Runnable() {
367 newSVObject[0] = CreateObjectFromType(enumType, id);
370 } catch (InterruptedException e) {
371 // TODO Auto-generated catch block
373 } catch (InvocationTargetException e) {
374 // TODO Auto-generated catch block
378 return new TypedObject(enumType, newSVObject[0]);
381 private SwingViewObject CreateObjectFromType(UielementType type, Integer id) {
384 SwingScilabCheckBox checkBox = new SwingScilabCheckBox();
386 setDefaultProperties(checkBox, id);
389 Console console = (Console) GraphicController.getController().getObjectFromId(id);
390 if (console.getScilabMode() == Console.ScilabMode.STD) {
391 WindowsConfigurationManager.restoreUUID(NULLUUID);
392 SwingScilabConsole sciConsole = ((SwingScilabConsole) ScilabConsole.getConsole().getAsSimpleConsole());
393 SwingScilabDockablePanel consoleTab = (SwingScilabDockablePanel) sciConsole.getParent();
394 consoleTab.setId(id);
399 SwingScilabEditBox edit = new SwingScilabEditBox();
401 setDefaultProperties(edit, id);
405 SwingScilabSpinner spin = new SwingScilabSpinner();
407 setDefaultProperties(spin, id);
411 Figure figure = (Figure) GraphicController.getController().getObjectFromId(id);
412 String figureTitle = figure.getName();
413 Integer figureId = figure.getId();
414 if ((figureTitle != null) && (figureId != null)) {
415 figureTitle = figureTitle.replaceFirst("%d", figureId.toString());
418 SwingScilabWindow window = SwingScilabWindow.createWindow(figure.getDockable());
420 window.setTitle(figureTitle);
421 Integer[] figureSize = figure.getSize();
422 window.setDims(new Size(figureSize[0], figureSize[1]));
424 SwingScilabPanel tab;
425 if (figure.getDockable()) {
426 tab = new SwingScilabDockablePanel(figureTitle, figureId, figure);
428 tab = new SwingScilabStaticPanel(figureTitle, figureId, figure);
433 MenuBar menuBar = ScilabMenuBar.createMenuBar();
434 menuBar.setVisible(figure.getMenubarVisible());
435 tab.setMenuBar(menuBar);
436 window.addMenuBar(menuBar);
439 ToolBar toolbar = ScilabToolBar.createToolBar();
440 toolbar.setVisible(figure.getToolbarVisible());
441 tab.setToolBar(toolbar);
442 window.addToolBar(toolbar);
445 TextBox infoBar = ScilabTextBox.createTextBox();
446 infoBar.setVisible(figure.getInfobarVisible());
447 tab.setInfoBar(infoBar);
448 window.addInfoBar(infoBar);
450 if (figure.getDockable()) {
451 DockingManager.dock((SwingScilabDockablePanel) tab, window.getDockingPort());
452 ActiveDockableTracker.requestDockableActivation((SwingScilabDockablePanel) tab);
457 tab.setWindowIcon("graphic-window");
459 tab.setParentWindowId(window.getId());
461 tab.setEventHandler(figure.getEventHandlerString());
462 tab.setEventHandlerEnabled(figure.getEventHandlerEnable());
463 tab.setVisible(true);
464 tab.setName(figureTitle);
466 String infoMessage = figure.getInfoMessage();
467 if ((infoMessage == null) || (infoMessage.length() == 0)) {
470 infoBar.setText(infoMessage);
473 tab.update(__GO_POSITION__, GraphicController.getController().getProperty(id, __GO_POSITION__));
475 String icon = (String)GraphicController.getController().getProperty(id, __GO_UI_ICON__);
476 if (icon != null && icon.equals("") == false) {
477 tab.update(__GO_UI_ICON__, icon);
480 // TODO set other default properties
482 window.setVisible(figure.getVisible());
487 SwingScilabAxes axes = new SwingScilabAxes();
490 Boolean scrollable = (Boolean) GraphicController.getController().getProperty(id, __GO_UI_SCROLLABLE__);
492 SwingScilabScrollableFrame frame = new SwingScilabScrollableFrame();
494 setDefaultProperties(frame, id);
495 Integer borderId = (Integer) GraphicController.getController().getProperty(id, __GO_UI_FRAME_BORDER__);
497 frame.setBorder(BorderConvertor.getBorder(borderId));
501 SwingScilabFrame frame = new SwingScilabFrame();
503 setDefaultProperties(frame, id);
504 Integer borderId = (Integer) GraphicController.getController().getProperty(id, __GO_UI_FRAME_BORDER__);
506 frame.setBorder(BorderConvertor.getBorder(borderId));
512 SwingScilabUiImage image = new SwingScilabUiImage();
514 setDefaultProperties(image, id);
517 SwingScilabListBox listBox = new SwingScilabListBox();
519 setDefaultProperties(listBox, id);
522 SwingScilabPopupMenu popupMenu = new SwingScilabPopupMenu();
524 setDefaultProperties(popupMenu, id);
527 SwingScilabWaitBar progressbar = new SwingScilabWaitBar();
528 progressbar.setIndeterminateMode(true);
529 progressbar.setId(id);
532 SwingScilabPushButton pushButton = new SwingScilabPushButton();
533 pushButton.setId(id);
534 setDefaultProperties(pushButton, id);
535 String icon = (String)GraphicController.getController().getProperty(id, __GO_UI_ICON__);
536 if (icon != null && icon.equals("") == false) {
537 pushButton.update(__GO_UI_ICON__, icon);
543 SwingScilabRadioButton radioButton = new SwingScilabRadioButton();
544 radioButton.setId(id);
545 setDefaultProperties(radioButton, id);
548 if (Console.getConsole().getUseDeprecatedLF()) {
549 SwingScilabScroll slider = new SwingScilabScroll();
551 setDefaultProperties(slider, id);
554 SwingScilabSlider slider = new SwingScilabSlider();
556 setDefaultProperties(slider, id);
560 SwingScilabUiTable table = new SwingScilabUiTable();
562 setDefaultProperties(table, id);
565 SwingScilabLabel text = new SwingScilabLabel();
567 setDefaultProperties(text, id);
568 String icon = (String)GraphicController.getController().getProperty(id, __GO_UI_ICON__);
569 if (icon != null && icon.equals("") == false) {
570 text.update(__GO_UI_ICON__, icon);
575 throw new UnsupportedOperationException();
576 case UiParentMenu: /* SwingView internal type */
577 SwingScilabMenu parentMenu = new SwingScilabMenu();
578 parentMenu.setId(id);
579 setMenuDefaultProperties(parentMenu, id);
581 case UiChildMenu: /* SwingView internal type */
582 SwingScilabMenuItem childMenu = new SwingScilabMenuItem();
584 setMenuDefaultProperties(childMenu, id);
586 case UiCheckedMenu: /* SwingView internal type */
587 SwingScilabCheckBoxMenuItem checkedMenu = new SwingScilabCheckBoxMenuItem(false);
588 checkedMenu.setId(id);
589 setMenuDefaultProperties(checkedMenu, id);
592 SwingScilabContextMenu contextMenu = new SwingScilabContextMenu();
593 contextMenu.setId(id);
596 SwingScilabWaitBar waitbar = new SwingScilabWaitBar();
597 waitbar.setIndeterminateMode(false);
601 SwingScilabTabGroup TabGroup = new SwingScilabTabGroup();
603 //setDefaultProperties(TabGroup, id);
604 //TabGroup.update(property, value);
607 SwingScilabLayer layer = new SwingScilabLayer();
611 System.err.println("[SwingView] Unmanaged Creation type !!!");
617 * Initialize all poperties according to model
618 * @param uiMenuObject the uimenu
619 * @param id the uimenu id
621 private void setMenuDefaultProperties(Widget uiMenuObject, Integer id) {
622 SwingViewMenu.update(uiMenuObject, __GO_CHILDREN__, GraphicController.getController().getProperty(id, __GO_CHILDREN__));
623 SwingViewMenu.update(uiMenuObject, __GO_CALLBACK__, GraphicController.getController().getProperty(id, __GO_CALLBACK__));
624 SwingViewMenu.update(uiMenuObject, __GO_CALLBACKTYPE__, GraphicController.getController().getProperty(id, __GO_CALLBACKTYPE__));
625 SwingViewMenu.update(uiMenuObject, __GO_UI_CHECKED__, GraphicController.getController().getProperty(id, __GO_UI_CHECKED__));
626 SwingViewMenu.update(uiMenuObject, __GO_UI_ENABLE__, GraphicController.getController().getProperty(id, __GO_UI_ENABLE__));
627 SwingViewMenu.update(uiMenuObject, __GO_UI_FOREGROUNDCOLOR__, GraphicController.getController().getProperty(id, __GO_UI_FOREGROUNDCOLOR__));
628 SwingViewMenu.update(uiMenuObject, __GO_UI_LABEL__, GraphicController.getController().getProperty(id, __GO_UI_LABEL__));
629 SwingViewMenu.update(uiMenuObject, __GO_UI_ICON__, GraphicController.getController().getProperty(id, __GO_UI_ICON__));
633 * Initialize all poperties according to model
634 * @param uiControlObject the uicontrol
635 * @param id the uicontrol id
637 private void setDefaultProperties(SwingViewObject uiControlObject, Integer id) {
640 * Visible property is set first to avoid to see the object rendered
641 * before all its properties to be set (See bug #10346)
643 uiControlObject.update(__GO_VISIBLE__, GraphicController.getController().getProperty(id, __GO_VISIBLE__));
644 uiControlObject.update(__GO_UI_BACKGROUNDCOLOR__, GraphicController.getController().getProperty(id, __GO_UI_BACKGROUNDCOLOR__));
645 uiControlObject.update(__GO_UI_ENABLE__, GraphicController.getController().getProperty(id, __GO_UI_ENABLE__));
646 uiControlObject.update(__GO_UI_FONTANGLE__, GraphicController.getController().getProperty(id, __GO_UI_FONTANGLE__));
647 uiControlObject.update(__GO_UI_FONTNAME__, GraphicController.getController().getProperty(id, __GO_UI_FONTNAME__));
648 uiControlObject.update(__GO_UI_FONTUNITS__, GraphicController.getController().getProperty(id, __GO_UI_FONTUNITS__));
649 uiControlObject.update(__GO_UI_FONTSIZE__, GraphicController.getController().getProperty(id, __GO_UI_FONTSIZE__));
650 uiControlObject.update(__GO_UI_FONTWEIGHT__, GraphicController.getController().getProperty(id, __GO_UI_FONTWEIGHT__));
651 uiControlObject.update(__GO_UI_FOREGROUNDCOLOR__, GraphicController.getController().getProperty(id, __GO_UI_FOREGROUNDCOLOR__));
652 uiControlObject.update(__GO_UI_HORIZONTALALIGNMENT__, GraphicController.getController().getProperty(id, __GO_UI_HORIZONTALALIGNMENT__));
653 uiControlObject.update(__GO_UI_RELIEF__, GraphicController.getController().getProperty(id, __GO_UI_RELIEF__));
654 uiControlObject.update(__GO_UI_STRING__, GraphicController.getController().getProperty(id, __GO_UI_STRING__));
655 uiControlObject.update(__GO_UI_VERTICALALIGNMENT__, GraphicController.getController().getProperty(id, __GO_UI_VERTICALALIGNMENT__));
656 uiControlObject.update(__GO_POSITION__, GraphicController.getController().getProperty(id, __GO_POSITION__));
657 uiControlObject.update(__GO_LAYOUT__, GraphicController.getController().getProperty(id, __GO_LAYOUT__));
658 uiControlObject.update(__GO_UI_MIN__, GraphicController.getController().getProperty(id, __GO_UI_MIN__));
659 uiControlObject.update(__GO_UI_MAX__, GraphicController.getController().getProperty(id, __GO_UI_MAX__));
662 public void deleteObject(Integer id) {
663 final TypedObject requestedObject = allObjects.get(id);
664 if (requestedObject != null) {
665 switch (requestedObject.getType()) {
667 if (SwingUtilities.isEventDispatchThread()) {
668 final SwingScilabPanel tab = (SwingScilabPanel) requestedObject.getValue();
669 if (requestedObject.getValue() instanceof SwingScilabDockablePanel) {
670 final SwingScilabDockablePanel dockableTab = (SwingScilabDockablePanel) tab;
671 dockableTab.disablePaint();
672 DockingManager.close(dockableTab);
673 DockingManager.unregisterDockable((Dockable) dockableTab);
674 ClosingOperationsManager.unregisterClosingOperation(dockableTab);
675 ClosingOperationsManager.removeDependency(dockableTab);
676 ClosingOperationsManager.checkTabForClosing(dockableTab);
683 SwingUtilities.invokeAndWait(new Runnable() {
687 final SwingScilabPanel tab = (SwingScilabPanel) requestedObject.getValue();
688 if (tab instanceof SwingScilabDockablePanel) {
689 final SwingScilabDockablePanel dockableTab = (SwingScilabDockablePanel) tab;
690 dockableTab.disablePaint();
691 DockingManager.close(dockableTab);
692 DockingManager.unregisterDockable((Dockable) dockableTab);
693 ClosingOperationsManager.unregisterClosingOperation(dockableTab);
694 ClosingOperationsManager.removeDependency(dockableTab);
695 ClosingOperationsManager.checkTabForClosing(dockableTab);
703 } catch (InterruptedException e) {
704 // TODO Auto-generated catch block
706 } catch (InvocationTargetException e) {
707 // TODO Auto-generated catch block
712 //try close the Property List (GED)
714 Inspector.getInspector().close();
715 } catch (NullPointerException e) {
720 SwingScilabWaitBar bar = (SwingScilabWaitBar) requestedObject.getValue();
725 // uicontrol case: the object is destroyed when its parent updates its children
728 allObjects.remove(id);
733 public void updateObject(final Integer id, final int property) {
734 final TypedObject registeredObject = allObjects.get(id);
736 if (property == __GO_SIZE__ && (headless || GraphicsEnvironment.isHeadless())) {
737 int objectType = (Integer) GraphicController.getController().getProperty(id, __GO_TYPE__);
738 if (objectType == __GO_FIGURE__) {
739 Integer[] dims = (Integer[]) GraphicController.getController().getProperty(id, __GO_SIZE__);
740 GraphicController.getController().setProperty(id, __GO_AXES_SIZE__, dims);
744 if (registeredObject != null && property == __GO_VALID__ && ((Boolean) GraphicController.getController().getProperty(id, __GO_VALID__))) {
745 if (registeredObject.getValue() instanceof SwingScilabDockablePanel) {
746 final Runnable r = new Runnable() {
749 ((SwingScilabDockablePanel) registeredObject.getValue()).getParentWindow().setVisible(true);
750 ((SwingScilabDockablePanel) registeredObject.getValue()).setVisible(true);
751 Integer[] figureSize = (Integer[]) GraphicController.getController().getProperty(id, __GO_SIZE__);
752 ((SwingScilabDockablePanel) registeredObject.getValue()).getParentWindow().setDims(new Size(figureSize[0], figureSize[1]));
756 if (SwingUtilities.isEventDispatchThread()) {
759 SwingUtilities.invokeLater(r);
764 if (property == __GO_IMMEDIATE_DRAWING__) {
768 if (registeredObject == null && property != __GO_STYLE__) {
772 /* On uicontrol style is set after object creation */
773 if (registeredObject == null && property == __GO_STYLE__) {
774 int style = (Integer) GraphicController.getController().getProperty(id, __GO_STYLE__);
775 allObjects.put(id, CreateObjectFromType(style, id));
779 /* Do not update axes on EDT to avoid dead locks between SwingView & DrawerVisitor */
780 /* Test which freezes without this condition: bug_1257.tst in graphics */
781 int type = (Integer) GraphicController.getController().getProperty(id, __GO_TYPE__);
782 if (type == __GO_AXES__) {
783 if (property == __GO_PARENT__) {
784 Integer parentId = (Integer) GraphicController.getController().getProperty(id, __GO_PARENT__);
785 TypedObject registeredParent = allObjects.get(parentId);
786 if (registeredParent == null) {
787 allObjects.remove(id);
789 ((SwingScilabAxes) allObjects.get(id).getValue()).update(property, parentId);
795 if (SwingUtilities.isEventDispatchThread()) {
796 updateObjectOnEDT(registeredObject, id, property);
799 SwingUtilities.invokeAndWait(new Runnable() {
801 updateObjectOnEDT(registeredObject, id, property);
804 } catch (InterruptedException e) {
806 } catch (InvocationTargetException e) {
812 public void updateObjectOnEDT(TypedObject registeredObject, final Integer id, final int property) {
813 /* Removes the swing object if its parent is not display */
814 if (registeredObject != null && property == __GO_PARENT__) {
815 Integer parentId = (Integer) GraphicController.getController().getProperty(id, __GO_PARENT__);
816 TypedObject registeredParent = allObjects.get(parentId);
817 if (registeredParent == null) {
818 allObjects.remove(id);
822 int type = (Integer) GraphicController.getController().getProperty(id, __GO_TYPE__);
823 /* Children list update */
824 if (registeredObject != null && property == __GO_CHILDREN__) {
825 final Integer[] newChildren = (Integer[]) GraphicController.getController().getProperty(id, __GO_CHILDREN__);
829 * FIGURE CHILDREN UPDATE
832 updateFigureChildren(registeredObject, newChildren);
835 * CONSOLE CHILDREN UPDATE
838 updateConsoleChildren(registeredObject, newChildren);
841 * MENU CHILDREN UPDATE
844 updateMenuChildren(registeredObject, id, newChildren);
847 * CONTEXTMENU CHILDREN UPDATE
849 case __GO_UICONTEXTMENU__:
850 updateContextMenuChildren(registeredObject, newChildren);
853 * UICONTROL "FRAME" CHILDREN UPDATE
855 case __GO_UICONTROL__:
857 int style = (Integer) GraphicController.getController().getProperty(id, __GO_STYLE__);
859 case __GO_UI_LAYER__:
860 updateLayerChildren(registeredObject, newChildren);
862 case __GO_UI_FRAME__:
863 if (registeredObject.getValue() instanceof SwingScilabFrame) {
864 updateFrameChildren(registeredObject, newChildren);
865 } else if (registeredObject.getValue() instanceof SwingScilabScrollableFrame) {
866 updateScrollableFrameChildren(registeredObject, newChildren);
870 updateTabGroupChildren(registeredObject, newChildren);
878 * When the CHECKED property is updated for a UIMENU, the object is
879 * converted to a SwingScilabCheckBoxMenuItem is not already of this
882 if (registeredObject != null && property == __GO_UI_CHECKED__) {
883 if (type == __GO_UIMENU__) {
884 switch (registeredObject.getType()) {
886 SwingScilabMenu meAsAMenu = (SwingScilabMenu) registeredObject.getValue();
887 Container parent = meAsAMenu.getParent();
888 if (parent != null) {
889 parent.remove(meAsAMenu);
892 registeredObject = CreateObjectFromType(__GO_UICHECKEDMENU__, id);
893 allObjects.put(id, registeredObject);
894 SwingScilabCheckBoxMenuItem meAsAMenuItem = (SwingScilabCheckBoxMenuItem) registeredObject.getValue();
895 if (parent != null) {
896 parent.add(meAsAMenuItem);
901 SwingScilabMenuItem childMenu = (SwingScilabMenuItem) allObjects.get(id).getValue();
902 JComponent parentMenu = (JComponent) childMenu.getParent();
904 if (parentMenu != null) {
905 index = parentMenu.getComponentZOrder(childMenu);
906 parentMenu.remove(childMenu);
908 registeredObject = CreateObjectFromType(__GO_UICHECKEDMENU__, id);
909 allObjects.put(id, registeredObject);
910 registeredObject = allObjects.get(id);
911 if (parentMenu != null) {
912 parentMenu.add((SwingScilabCheckBoxMenuItem) registeredObject.getValue(), index);
923 * When the SEPARATOR property is updated for a UIMENU, When the
924 * property is set to TRUE: A separator is added if not already done
925 * When the property is set to FALSE: The previous separator is removed
928 if (registeredObject != null && property == __GO_UI_SEPARATOR__) {
929 if (type == __GO_UIMENU__) {
930 Integer parentId = (Integer) GraphicController.getController().getProperty(id, __GO_PARENT__);
931 int menuPosition = -1;
932 Component currentComponent = (Component) registeredObject.getValue();
933 Component[] allChildren = ((SwingScilabMenu) allObjects.get(parentId).getValue()).getMenuComponents();
934 for (int kChild = 0; kChild < allChildren.length; kChild++) {
935 if (allChildren[kChild] == currentComponent) {
936 menuPosition = kChild;
940 if (menuPosition < 0) {
943 boolean newSeparatorMode = (Boolean) GraphicController.getController().getProperty(id, __GO_UI_SEPARATOR__);
944 if (newSeparatorMode) { // Add a separator above the menu
945 ((SwingScilabMenu) allObjects.get(parentId).getValue()).insertSeparator(menuPosition);
946 } else { // Remove the separator above the menu (if there is one)
947 if (menuPosition == 0) { // There is no object above the menu
950 if (((SwingScilabMenu) allObjects.get(parentId).getValue()).getComponent(menuPosition - 1) instanceof JSeparator) {
951 ((SwingScilabMenu) allObjects.get(parentId).getValue()).remove(menuPosition - 1);
957 if (registeredObject != null) {
958 final SwingViewObject swingObject = registeredObject.getValue();
959 if (swingObject != null) {
960 swingObject.update(property, GraphicController.getController().getProperty(id, property));
966 * Update the figure children (called by generic updateObject method)
967 * @param id the id of the figure
968 * @param newChildren the new children IDs list
970 private void updateFigureChildren(TypedObject updatedObject, Integer[] newChildren) {
971 Container updatedComponent = (Container) updatedObject.getValue();
972 boolean needRevalidate = false;
973 boolean needRevalidateMenubar = false;
976 for (Integer childId : newChildren) {
977 if (!updatedObject.hasChild(childId)) {
980 updatedObject.addChild(childId);
982 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
985 if (childType == __GO_AXES__) {
986 SwingViewObject canvas = allObjects.get(childId).getValue();
987 ((SwingScilabPanel) updatedComponent).addMember(canvas);
990 /* Add an uicontrol */
991 if (childType == __GO_UICONTROL__) {
992 SwingViewObject uiContol = allObjects.get(childId).getValue();
993 ((SwingScilabPanel) updatedComponent).addMember(uiContol);
996 uiContol.update(__GO_POSITION__, GraphicController.getController().getProperty(childId, __GO_POSITION__));
997 needRevalidate = true;
1001 if (childType == __GO_UIMENU__) {
1002 TypedObject childAsTypedObject = allObjects.get(childId);
1003 switch (childAsTypedObject.getType()) {
1006 allObjects.remove(childId);
1007 allObjects.put(childId, CreateObjectFromType(__GO_UIPARENTMENU__, childId));
1008 ((Container) ((SwingScilabPanel) updatedComponent).getMenuBar().getAsSimpleMenuBar()).add((SwingScilabMenu) allObjects.get(childId).getValue());
1010 default: /* UiParentMenu */
1011 ((Container) ((SwingScilabPanel) updatedComponent).getMenuBar().getAsSimpleMenuBar()).add((SwingScilabMenu) allObjects.get(childId).getValue());
1014 needRevalidateMenubar = true;
1019 // Remove children which have been deleted
1020 Set<Integer> newChildrenSet = new HashSet<Integer>(Arrays.asList(newChildren));
1021 // Clone the children set to avoid concurrent accesses
1022 Integer[] oldChildrenSet = updatedObject.getChildren().toArray(new Integer[updatedObject.getChildren().size()]);
1023 for (Integer childId : oldChildrenSet) {
1024 if (!newChildrenSet.contains(childId)) {
1027 updatedObject.removeChild(childId);
1029 final Object childTypeObject = GraphicController.getController().getProperty(childId, __GO_TYPE__);
1030 if (childTypeObject == null) {
1031 // the child has already been removed from the model
1034 int childType = (Integer) childTypeObject;
1036 /* Remove an uicontrol */
1037 if (childType == __GO_UICONTROL__) {
1038 ((SwingScilabPanel) updatedComponent).removeMember(allObjects.get(childId).getValue());
1039 needRevalidate = true;
1042 /* Remove an uimenu */
1043 if (childType == __GO_UIMENU__) {
1044 TypedObject childAsTypedObject = allObjects.get(childId);
1045 switch (childAsTypedObject.getType()) {
1047 ((Container) ((SwingScilabPanel) updatedComponent).getMenuBar().getAsSimpleMenuBar()).remove((SwingScilabCheckBoxMenuItem) allObjects.get(childId).getValue());
1049 default: /* UiParentMenu */
1050 ((Container) ((SwingScilabPanel) updatedComponent).getMenuBar().getAsSimpleMenuBar()).remove((SwingScilabMenu) allObjects.get(childId).getValue());
1053 needRevalidateMenubar = true;
1058 if (needRevalidateMenubar) {
1059 ((JComponent) ((SwingScilabPanel) updatedComponent).getMenuBar().getAsSimpleMenuBar()).revalidate();
1060 ((JComponent) ((SwingScilabPanel) updatedComponent).getMenuBar().getAsSimpleMenuBar()).repaint();
1063 if (needRevalidate && updatedComponent != null) {
1064 ((JComponent) updatedComponent).revalidate();
1069 * Update the frame children (called by generic updateObject method)
1070 * @param id the id of the figure
1071 * @param newChildren the new children IDs list
1073 private void updateFrameChildren(TypedObject updatedObject, Integer[] newChildren) {
1074 SwingScilabFrame updatedComponent = (SwingScilabFrame) updatedObject.getValue();
1075 boolean needRevalidate = false;
1078 for (Integer childId : newChildren) {
1079 if (!updatedObject.hasChild(childId)) {
1082 updatedObject.addChild(childId);
1084 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1086 /* Add an uicontrol */
1087 if (childType == __GO_UICONTROL__ || childType == __GO_AXES__) {
1088 updatedComponent.addMember(allObjects.get(childId).getValue());
1089 needRevalidate = true;
1094 // Remove children which have been deleted
1095 Set<Integer> newChildrenSet = new HashSet<Integer>(Arrays.asList(newChildren));
1096 // Clone the children set to avoid concurrent accesses
1097 Integer[] oldChildrenSet = updatedObject.getChildren().toArray(new Integer[updatedObject.getChildren().size()]);
1098 for (Integer childId : oldChildrenSet) {
1099 if (!newChildrenSet.contains(childId)) {
1102 updatedObject.removeChild(childId);
1104 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1106 /* Remove an uicontrol */
1107 if (childType == __GO_UICONTROL__) {
1108 updatedComponent.remove((Component) allObjects.get(childId).getValue());
1109 needRevalidate = true;
1113 if (needRevalidate && updatedComponent != null) {
1114 updatedComponent.revalidate();
1118 private void updateScrollableFrameChildren(TypedObject updatedObject, Integer[] newChildren) {
1119 SwingScilabScrollableFrame updatedComponent = (SwingScilabScrollableFrame) updatedObject.getValue();
1120 boolean needRevalidate = false;
1123 for (Integer childId : newChildren) {
1124 if (!updatedObject.hasChild(childId)) {
1127 updatedObject.addChild(childId);
1129 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1131 /* Add an uicontrol */
1132 if (childType == __GO_UICONTROL__) {
1133 updatedComponent.addMember(allObjects.get(childId).getValue());
1134 needRevalidate = true;
1139 // Remove children which have been deleted
1140 Set<Integer> newChildrenSet = new HashSet<Integer>(Arrays.asList(newChildren));
1141 // Clone the children set to avoid concurrent accesses
1142 Integer[] oldChildrenSet = updatedObject.getChildren().toArray(new Integer[updatedObject.getChildren().size()]);
1143 for (Integer childId : oldChildrenSet) {
1144 if (!newChildrenSet.contains(childId)) {
1147 updatedObject.removeChild(childId);
1149 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1151 /* Remove an uicontrol */
1152 if (childType == __GO_UICONTROL__) {
1153 updatedComponent.remove((Component) allObjects.get(childId).getValue());
1154 needRevalidate = true;
1158 if (needRevalidate && updatedComponent != null) {
1159 updatedComponent.revalidate();
1164 * Update the frame children (called by generic updateObject method)
1165 * @param id the id of the figure
1166 * @param newChildren the new children IDs list
1168 private void updateLayerChildren(TypedObject updatedObject, Integer[] newChildren) {
1169 SwingScilabLayer updatedComponent = (SwingScilabLayer) updatedObject.getValue();
1172 for (Integer childId : newChildren) {
1173 if (!updatedObject.hasChild(childId)) {
1176 updatedObject.addChild(childId);
1178 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1180 /* Add an uicontrol */
1181 if (childType == __GO_UICONTROL__) {
1182 int childStyle = (Integer) GraphicController.getController().getProperty(childId, __GO_STYLE__);
1183 if (childStyle == __GO_UI_FRAME__) {
1184 SwingViewObject obj = allObjects.get(childId).getValue();
1185 if (obj instanceof SwingScilabScrollableFrame) {
1186 updatedComponent.addMember((SwingScilabScrollableFrame)obj);
1188 updatedComponent.addMember((SwingScilabFrame)obj);
1195 // Remove children which have been deleted
1196 Set<Integer> newChildrenSet = new HashSet<Integer>(Arrays.asList(newChildren));
1197 // Clone the children set to avoid concurrent accesses
1198 Integer[] oldChildrenSet = updatedObject.getChildren().toArray(new Integer[updatedObject.getChildren().size()]);
1199 for (Integer childId : oldChildrenSet) {
1200 if (!newChildrenSet.contains(childId)) {
1203 updatedObject.removeChild(childId);
1205 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1207 /* Remove an uicontrol */
1208 if (childType == __GO_UICONTROL__) {
1209 int childStyle = (Integer) GraphicController.getController().getProperty(childId, __GO_STYLE__);
1210 if (childStyle == __GO_UI_FRAME__) {
1211 SwingViewObject obj = allObjects.get(childId).getValue();
1212 if (obj instanceof SwingScilabScrollableFrame) {
1213 updatedComponent.removeMember((SwingScilabScrollableFrame)obj);
1215 updatedComponent.removeMember((SwingScilabFrame)obj);
1224 * Update the frame children (called by generic updateObject method)
1225 * @param id the id of the figure
1226 * @param newChildren the new children IDs list
1228 private void updateTabGroupChildren(TypedObject updatedObject, Integer[] newChildren) {
1229 SwingScilabTabGroup updatedComponent = (SwingScilabTabGroup) updatedObject.getValue();
1230 boolean needRevalidate = false;
1233 for (Integer childId : newChildren) {
1234 if (!updatedObject.hasChild(childId)) {
1237 updatedObject.addChild(childId);
1239 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1241 /* Add an uicontrol */
1242 if (childType == __GO_UICONTROL__) {
1244 String[] text = (String[]) GraphicController.getController().getProperty(childId, __GO_UI_STRING__);
1245 if (text != null && text[0] != null) {
1249 updatedComponent.insertTab(str, null, (Component) allObjects.get(childId).getValue(), "", 0);
1250 needRevalidate = true;
1255 // Remove children which have been deleted
1256 Set<Integer> newChildrenSet = new HashSet<Integer>(Arrays.asList(newChildren));
1257 // Clone the children set to avoid concurrent accesses
1258 Integer[] oldChildrenSet = updatedObject.getChildren().toArray(new Integer[updatedObject.getChildren().size()]);
1259 for (Integer childId : oldChildrenSet) {
1260 if (!newChildrenSet.contains(childId)) {
1263 updatedObject.removeChild(childId);
1265 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1267 /* Remove an uicontrol */
1268 if (childType == __GO_UICONTROL__) {
1269 updatedComponent.remove((Component) allObjects.get(childId).getValue());
1270 needRevalidate = true;
1274 if (needRevalidate && updatedComponent != null) {
1275 updatedComponent.revalidate();
1280 * Update the Console menus (called by generic updateObject method)
1281 * @param id the id of the console object
1282 * @param newChildren the new children IDs list
1284 private void updateConsoleChildren(TypedObject updatedObject, Integer[] newChildren) {
1285 Container updatedComponent = (SwingScilabDockablePanel) updatedObject.getValue();
1286 boolean needRevalidate = false;
1289 for (Integer childId : newChildren) {
1290 if (!updatedObject.hasChild(childId)) {
1293 updatedObject.addChild(childId);
1295 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1297 if (childType == __GO_UIMENU__) {
1298 TypedObject childAsTypedObject = allObjects.get(childId);
1299 switch (childAsTypedObject.getType()) {
1302 TypedObject newUiParentMenu = CreateObjectFromType(__GO_UIPARENTMENU__, childId);
1303 allObjects.put(childId, newUiParentMenu);
1304 ((Container) ((SwingScilabDockablePanel) updatedObject.getValue()).getMenuBar().getAsSimpleMenuBar()).add((SwingScilabMenu) newUiParentMenu.getValue());
1306 default: /* UiParentMenu */
1307 ((Container) ((SwingScilabDockablePanel) updatedObject.getValue()).getMenuBar().getAsSimpleMenuBar()).add((SwingScilabMenu) childAsTypedObject.getValue());
1310 needRevalidate = true;
1315 // Remove children which have been deleted
1316 Set<Integer> newChildrenSet = new HashSet<Integer>(Arrays.asList(newChildren));
1317 Object[] updatedObjectChildren = updatedObject.getChildren().toArray();
1318 for (int i = 0; i < updatedObjectChildren.length; ++i) {
1319 Integer childId = (Integer) updatedObjectChildren[i];
1320 if (!newChildrenSet.contains(childId)) {
1323 updatedObject.removeChild(childId);
1325 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1327 if (childType == __GO_UIMENU__) {
1328 ((Container) ((SwingScilabDockablePanel) updatedObject.getValue()).getMenuBar().getAsSimpleMenuBar()).remove((SwingScilabMenu) allObjects.get(childId).getValue());
1329 needRevalidate = true;
1333 if (needRevalidate && updatedComponent != null) {
1334 updatedComponent.validate();
1340 * Update the children of a menu menus (called by generic updateObject
1342 * @param id the id of the menu object
1343 * @param newChildren the new children IDs list
1345 private void updateMenuChildren(TypedObject updatedObject, Integer id, Integer[] newChildren) {
1346 Container updatedComponent = null;
1347 boolean needRevalidate = false;
1348 int updatedObjectPosition = 0;
1349 TypedObject newParent = null;
1352 for (Integer childId : newChildren) {
1353 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1354 if (childType == __GO_UIMENU__) {
1355 if (!updatedObject.hasChild(childId)) {
1357 updatedObject.addChild(childId);
1359 TypedObject childAsTypedObject = allObjects.get(childId);
1360 Object addedChild = allObjects.get(childId).getValue();
1361 JComponent parent = null;
1362 switch (updatedObject.getType()) {
1364 updatedComponent = (SwingScilabMenuItem) updatedObject.getValue();
1365 parent = (JComponent) updatedComponent.getParent();
1366 switch (childAsTypedObject.getType()) {
1368 /* Replace the item by a parent menu */
1369 if (parent != null) {
1370 updatedObjectPosition = parent.getComponentZOrder((SwingScilabMenuItem) updatedObject.getValue());
1371 parent.remove((SwingScilabMenuItem) updatedObject.getValue());
1373 newParent = CreateObjectFromType(__GO_UIPARENTMENU__, id);
1374 allObjects.put(id, newParent);
1375 newParent.addChild(childId);
1376 if (parent != null) {
1377 parent.add((SwingScilabMenu) newParent.getValue(), updatedObjectPosition);
1379 /* Update the created menu */
1380 ((SwingScilabMenu) newParent.getValue()).add((SwingScilabMenuItem) addedChild);
1383 /* Replace the item by a parent menu */
1384 if (parent != null) {
1385 updatedObjectPosition = parent.getComponentZOrder((SwingScilabCheckBoxMenuItem) updatedObject.getValue());
1386 parent.remove((SwingScilabCheckBoxMenuItem) updatedObject.getValue());
1388 newParent = CreateObjectFromType(__GO_UIPARENTMENU__, id);
1389 allObjects.put(id, newParent);
1390 newParent.addChild(childId);
1391 if (parent != null) {
1392 parent.add((SwingScilabMenu) newParent.getValue(), updatedObjectPosition);
1394 /* Update the created menu */
1395 ((SwingScilabMenu) newParent.getValue()).add((SwingScilabCheckBoxMenuItem) addedChild);
1397 default: /* UiParentMenu */
1398 ((SwingScilabMenu) updatedObject.getValue()).add((SwingScilabMenu) addedChild);
1403 updatedComponent = (SwingScilabCheckBoxMenuItem) updatedObject.getValue();
1404 parent = (JComponent) updatedComponent.getParent();
1405 switch (childAsTypedObject.getType()) {
1407 /* Replace the item by a parent menu */
1408 if (parent != null) {
1409 updatedObjectPosition = parent.getComponentZOrder((SwingScilabCheckBoxMenuItem) updatedObject.getValue());
1410 parent.remove((SwingScilabCheckBoxMenuItem) allObjects.get(id).getValue());
1412 newParent = CreateObjectFromType(__GO_UIPARENTMENU__, id);
1413 allObjects.put(id, newParent);
1414 newParent.addChild(childId);
1415 if (parent != null) {
1416 parent.add((SwingScilabMenu) newParent.getValue(), updatedObjectPosition);
1418 /* Update the created menu */
1419 ((SwingScilabMenu) newParent.getValue()).add((SwingScilabMenuItem) allObjects.get(childId).getValue());
1422 /* Replace the item by a parent menu */
1423 if (parent != null) {
1424 updatedObjectPosition = parent.getComponentZOrder((SwingScilabCheckBoxMenuItem) updatedObject.getValue());
1425 parent.remove((SwingScilabCheckBoxMenuItem) allObjects.get(id).getValue());
1427 newParent = CreateObjectFromType(__GO_UIPARENTMENU__, id);
1428 allObjects.put(id, newParent);
1429 newParent.addChild(childId);
1430 if (parent != null) {
1431 parent.add((SwingScilabMenu) newParent.getValue(), updatedObjectPosition);
1433 /* Update the created menu */
1434 ((SwingScilabMenu) newParent.getValue()).add((SwingScilabCheckBoxMenuItem) allObjects.get(childId).getValue());
1436 default: /* UiParentMenu */
1437 ((SwingScilabMenu) updatedObject.getValue()).add((SwingScilabMenu) allObjects.get(childId).getValue());
1441 default: /* UiParentMenu */
1442 SwingScilabMenu updatedMenu = (SwingScilabMenu) updatedObject.getValue();
1443 updatedComponent = updatedMenu;
1444 switch (childAsTypedObject.getType()) {
1446 updatedMenu.add((SwingScilabMenuItem) allObjects.get(childId).getValue());
1449 updatedMenu.add((SwingScilabCheckBoxMenuItem) allObjects.get(childId).getValue());
1451 default: /* UiParentMenu */
1452 /* Java can not add a JMenu in a JMenu */
1454 * We need to convert the child into a
1457 TypedObject newMenu = CreateObjectFromType(__GO_UIMENU__, childId);
1458 allObjects.put(childId, newMenu);
1459 updatedMenu.add((SwingScilabMenuItem) newMenu.getValue());
1464 needRevalidate = true;
1468 // Remove children which have been deleted
1469 Set<Integer> newChildrenSet = new HashSet<Integer>(Arrays.asList(newChildren));
1470 Integer[] oldChildren = updatedObject.getChildren().toArray(new Integer[updatedObject.getChildren().size()]);
1471 for (int childIndex = 0; childIndex < oldChildren.length; childIndex++) {
1472 Integer childId = oldChildren[childIndex];
1473 if (!newChildrenSet.contains(childId)) {
1475 updatedObject.removeChild(childId);
1476 updatedComponent = (SwingScilabMenu) updatedObject.getValue();
1478 TypedObject childAsTypedObject = allObjects.get(childId);
1479 Object removedMenu = childAsTypedObject.getValue();
1481 switch (childAsTypedObject.getType()) {
1483 updatedComponent.remove((SwingScilabMenuItem) removedMenu);
1486 updatedComponent.remove((SwingScilabCheckBoxMenuItem) removedMenu);
1489 updatedComponent.remove((SwingScilabMenu) removedMenu);
1492 needRevalidate = true;
1495 if (needRevalidate && updatedComponent != null) {
1496 updatedComponent.validate();
1501 * Update the children of a contextmenu (called by generic updateObject
1503 * @param id the id of the contextmenu object
1504 * @param newChildren the new children IDs list
1506 private void updateContextMenuChildren(TypedObject updatedObject, Integer[] newChildren) {
1507 Container updatedComponent = null;
1508 boolean needRevalidate = false;
1511 for (Integer childId : newChildren) {
1512 int childType = (Integer) GraphicController.getController().getProperty(childId, __GO_TYPE__);
1513 if (childType == __GO_UIMENU__) {
1514 if (!updatedObject.hasChild(childId)) {
1517 updatedObject.addChild(childId);
1519 TypedObject childAsTypedObject = allObjects.get(childId);
1520 SwingScilabContextMenu updatedMenu = (SwingScilabContextMenu) updatedObject.getValue();
1521 updatedComponent = updatedMenu;
1522 switch (childAsTypedObject.getType()) {
1524 updatedMenu.add((SwingScilabMenuItem) allObjects.get(childId).getValue());
1527 updatedMenu.add((SwingScilabCheckBoxMenuItem) allObjects.get(childId).getValue());
1529 default: /* UiParentMenu */
1530 updatedMenu.add((SwingScilabMenu) allObjects.get(childId).getValue());
1533 needRevalidate = true;
1537 // Remove children which have been deleted
1538 Set<Integer> newChildrenSet = new HashSet<Integer>(Arrays.asList(newChildren));
1539 for (Integer childId : updatedObject.getChildren()) {
1540 if (!newChildrenSet.contains(childId)) {
1542 updatedObject.removeChild(childId);
1543 updatedComponent = (SwingScilabMenu) updatedObject.getValue();
1545 TypedObject childAsTypedObject = allObjects.get(childId);
1546 SwingScilabContextMenu updatedMenu = (SwingScilabContextMenu) updatedObject.getValue();
1547 Object removedMenu = allObjects.get(childId).getValue();
1549 switch (childAsTypedObject.getType()) {
1551 updatedMenu.remove((SwingScilabMenuItem) removedMenu);
1554 updatedMenu.remove((SwingScilabCheckBoxMenuItem) removedMenu);
1557 updatedMenu.remove((SwingScilabMenu) removedMenu);
1560 needRevalidate = true;
1563 if (needRevalidate && updatedComponent != null) {
1564 updatedComponent.validate();