manage menu in xml 71/13871/2
Antoine ELIAS [Fri, 28 Feb 2014 16:35:39 +0000 (17:35 +0100)]
Change-Id: Ie11275ed14eba75d209e6e7f0e66114a4248d7b6

scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/uicontrol/Uicontrol.java
scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/uimenu/Uimenu.java
scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/xmlloader/GOBuilder.java
scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/xmlloader/XmlLoader.java
scilab/modules/gui/src/java/org/scilab/modules/gui/SwingView.java
scilab/modules/gui/src/java/org/scilab/modules/gui/SwingViewMenu.java
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/menuitem/SwingScilabMenuItem.java

index 9050979..4168ce9 100644 (file)
@@ -287,7 +287,7 @@ public class Uicontrol extends GraphicObject {
 
     private UicontrolStyle style;
     private Double[] backgroundColor = { -1.0, -1.0, -1.0};
-    private boolean enable = true;
+    private Boolean enable = true;
     private String fontAngle = "";
     private String fontName = "";
     private double fontSize = 0;
@@ -867,15 +867,15 @@ public class Uicontrol extends GraphicObject {
     }
 
     /* Enable */
-    public boolean getEnable() {
-        return this.enable;
+    public Boolean getEnable() {
+        return enable;
     }
 
-    public UpdateStatus setEnable(boolean status) {
-        if (this.enable == status) {
+    public UpdateStatus setEnable(Boolean status) {
+        if (enable.equals(status)) {
             return UpdateStatus.NoChange;
         }
-        this.enable = status;
+        enable = status;
         return UpdateStatus.Success;
     }
 
index eb601ee..679ccaf 100644 (file)
@@ -24,7 +24,6 @@ import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProp
 
 import org.scilab.modules.graphic_objects.graphicObject.GraphicObject;
 import org.scilab.modules.graphic_objects.graphicObject.Visitor;
-import org.scilab.modules.graphic_objects.graphicObject.GraphicObject.UpdateStatus;
 
 /**
  * @author Vincent COUVERT
index b0413dd..40d1bc4 100644 (file)
@@ -1,9 +1,12 @@
 package org.scilab.modules.graphic_objects.xmlloader;
 
-import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CLOSEREQUESTFCN__;
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_FIGURE__;
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_CHECKED__;
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_LABEL__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_BORDER_OPT_PADDING__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CALLBACKTYPE__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CALLBACK__;
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CLOSEREQUESTFCN__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_DOCKABLE__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_GRID_OPT_GRID__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_GRID_OPT_PADDING__;
@@ -21,6 +24,7 @@ import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProp
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TITLE__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TOOLBAR_VISIBLE__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TYPE__;
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UIMENU__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_BACKGROUNDCOLOR__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_BORDER_POSITION__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_BORDER_PREFERREDSIZE__;
@@ -69,6 +73,7 @@ import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProp
 
 import java.awt.Color;
 import java.lang.reflect.Field;
+import java.util.HashMap;
 import java.util.Map;
 
 import org.scilab.modules.graphic_objects.builder.Builder;
@@ -161,7 +166,6 @@ public class GOBuilder {
             controller.setProperty(fig, __GO_UI_ICON__, item);
         }
 
-        //callback
         item = attributes.getValue("onclose");
         if (item != null) {
             controller.setProperty(fig, __GO_CLOSEREQUESTFCN__, item);
@@ -170,6 +174,7 @@ public class GOBuilder {
         // visible
         XmlTools.setPropAsBoolean(fig, __GO_VISIBLE__, attributes.getValue("visible"));
 
+
         return fig;
     }
 
@@ -200,19 +205,27 @@ public class GOBuilder {
         String item = null;
 
         try {
+            Map<String, String> xmlAttributes = new HashMap<String, String>();
             Map<String, String> map = null;
             // Common attributes
 
+            if (fromModel != null) {
+                for (Map.Entry<String, String> prop : fromModel.entrySet()) {
+                    xmlAttributes.put(prop.getKey(), prop.getValue());
+                }
+            }
+
+            for (int i = 0; i < attributes.getLength(); i++) {
+                String name = attributes.getLocalName(i);
+                String value = attributes.getValue(i);
+                xmlAttributes.put(name, value);
+            }
+
             // id
-            XmlTools.setPropAsString(uic, __GO_TAG__, attributes.getValue("id"));
+            XmlTools.setPropAsString(uic, __GO_TAG__, xmlAttributes.get("id"));
 
             // layout and layout_options
-            item = attributes.getValue("layout");
-            if (item == null) {
-                if (fromModel != null) {
-                    item = fromModel.get("layout");
-                }
-            }
+            item = xmlAttributes.get("layout");
 
             if (item == null) {
                 item = "name:none";
@@ -220,7 +233,7 @@ public class GOBuilder {
             setLayoutProperty(controller, uic, item);
 
             //visible
-            item = attributes.getValue("visible");
+            item = xmlAttributes.get("visible");
             if (item == null || item.equals("true") || item.equals("on")) {
                 controller.setProperty(uic, __GO_VISIBLE__, true);
             } else {
@@ -243,7 +256,7 @@ public class GOBuilder {
             controller.setProperty(uic, __GO_UI_ENABLE__, enable);
 
             //backgroundcolor
-            item = attributes.getValue("background");
+            item = xmlAttributes.get("background");
             if (item != null) {
                 controller.setProperty(uic, __GO_UI_BACKGROUNDCOLOR__, getColor(item));
             }
@@ -258,24 +271,19 @@ public class GOBuilder {
 
 
             //font properties
-            item = attributes.getValue("font-name");
+            item = xmlAttributes.get("font-name");
             if (item != null) {
                 controller.setProperty(uic, __GO_UI_FONTNAME__, item);
             }
 
-            item = attributes.getValue("font-size");
+            item = xmlAttributes.get("font-size");
             if (item != null) {
                 controller.setProperty(uic, __GO_UI_FONTSIZE__, Double.parseDouble(item));
             }
 
 
             if (layout != LayoutType.NONE) {
-                item = attributes.getValue("constraint");
-                if (item == null && fromModel != null) {
-                    // use value from model if property is not in "declaration"
-                    item = XmlTools.getFromMap(fromModel, "constraint");
-                }
-
+                item = xmlAttributes.get("constraint");
                 if (item != null) {
                     map = CSSParser.parseLine(item);
                 }
@@ -285,7 +293,7 @@ public class GOBuilder {
                         item = XmlTools.getFromMap(map, "position", "center");
                         controller.setProperty(uic, __GO_UI_BORDER_POSITION__, Uicontrol.BorderLayoutType.stringToEnum(item).ordinal());
                         Integer[] preferredsize = new Integer[] { -1, -1};
-                        item = attributes.getValue("preferred-size");
+                        item = xmlAttributes.get("preferred-size");
                         if (item != null) {
                             String[] pref = item.split(",");
                             for (int i = 0; i < pref.length && i < 4; i++) {
@@ -315,7 +323,7 @@ public class GOBuilder {
                         padding[1] = Integer.parseInt(XmlTools.getFromMap(map, "ipady", "0"));
 
                         Integer[] preferredsize = new Integer[] { -1, -1};
-                        item = attributes.getValue("preferred-size");
+                        item = xmlAttributes.get("preferred-size");
                         if (item != null) {
                             String[] pref = item.split(",");
                             for (int i = 0; i < pref.length && i < 4; i++) {
@@ -350,13 +358,7 @@ public class GOBuilder {
             switch (type) {
                 case __GO_UI_FRAME__: {
                     // border
-                    item = attributes.getValue("border");
-                    if (item == null && fromModel != null) {
-                        // use value from model if property is not in
-                        // "declaration"
-                        item = XmlTools.getFromMap(fromModel, "border");
-                    }
-
+                    item = xmlAttributes.get("border");
                     if (item != null) {
                         map = CSSParser.parseLine(item);
                     }
@@ -366,12 +368,12 @@ public class GOBuilder {
                     controller.setProperty(uic, __GO_UI_FRAME_BORDER__, border);
 
                     String[] text = new String[1];
-                    text[0] = attributes.getValue("tab-title");
+                    text[0] = xmlAttributes.get("tab-title");
                     if (text[0] != null) {
                         controller.setProperty(uic, __GO_UI_STRING__, text);
                     }
 
-                    item = attributes.getValue("scrollable");
+                    item = xmlAttributes.get("scrollable");
                     if (item == null || item.equals("false")) {
                         controller.setProperty(uic, __GO_UI_SCROLLABLE__, false);
                     } else {
@@ -382,7 +384,7 @@ public class GOBuilder {
                 }
 
                 case __GO_UI_TAB__: {
-                    item = attributes.getValue("ui-style");
+                    item = xmlAttributes.get("ui-style");
                     if (item != null) {
                         map = CSSParser.parseLine(item);
                         item = XmlTools.getFromMap(map, "bold", "false");
@@ -399,19 +401,19 @@ public class GOBuilder {
                 }
                 case __GO_UI_CHECKBOX__: {
                     String[] text = new String[1];
-                    text[0] = attributes.getValue("text");
+                    text[0] = xmlAttributes.get("text");
                     if (text[0] != null) {
                         controller.setProperty(uic, __GO_UI_STRING__, text);
                     }
 
                     //groupname
-                    item = attributes.getValue("button-group");
+                    item = xmlAttributes.get("button-group");
                     if (item != null && item.equals("") == false) {
                         controller.setProperty(uic, __GO_UI_GROUP_NAME__, item);
                     }
 
                     //callback
-                    item = attributes.getValue("onclick");
+                    item = xmlAttributes.get("onclick");
                     if (item != null && item.equals("") == false) {
                         controller.setProperty(uic, __GO_CALLBACK__, item);
                         controller.setProperty(uic, __GO_CALLBACKTYPE__, 0);
@@ -421,19 +423,19 @@ public class GOBuilder {
                 }
                 case __GO_UI_RADIOBUTTON__: {
                     String[] text = new String[1];
-                    text[0] = attributes.getValue("text");
+                    text[0] = xmlAttributes.get("text");
                     if (text[0] != null) {
                         controller.setProperty(uic, __GO_UI_STRING__, text);
                     }
 
                     //groupname
-                    item = attributes.getValue("button-group");
+                    item = xmlAttributes.get("button-group");
                     if (item != null && item.equals("") == false) {
                         controller.setProperty(uic, __GO_UI_GROUP_NAME__, item);
                     }
 
                     //callback
-                    item = attributes.getValue("onclick");
+                    item = xmlAttributes.get("onclick");
                     if (item != null && item.equals("") == false) {
                         controller.setProperty(uic, __GO_CALLBACK__, item);
                         controller.setProperty(uic, __GO_CALLBACKTYPE__, 0);
@@ -445,20 +447,20 @@ public class GOBuilder {
 
                     //string
                     String[] text = new String[1];
-                    text[0] = attributes.getValue("text");
+                    text[0] = xmlAttributes.get("text");
                     if (text[0] != null) {
                         controller.setProperty(uic, __GO_UI_STRING__, text);
                     }
 
 
                     //icon
-                    item = attributes.getValue("icon");
+                    item = xmlAttributes.get("icon");
                     if (item != null) {
                         controller.setProperty(uic, __GO_UI_ICON__, item);
                     }
 
                     //callback
-                    item = attributes.getValue("onclick");
+                    item = xmlAttributes.get("onclick");
                     if (item != null && item.equals("") == false) {
                         controller.setProperty(uic, __GO_CALLBACK__, item);
                         controller.setProperty(uic, __GO_CALLBACKTYPE__, 0);
@@ -469,7 +471,7 @@ public class GOBuilder {
                 case __GO_UI_TEXT__: { //label
                     controller.setProperty(uic, __GO_UI_HORIZONTALALIGNMENT__, "left");
                     String[] text = new String[1];
-                    text[0] = attributes.getValue("text");
+                    text[0] = xmlAttributes.get("text");
                     if (text[0] != null) {
                         String[] old = (String[])controller.getProperty(uic, __GO_UI_STRING__);
                         if (old != null && old[0] != null && old[0].equals("$$")) {
@@ -479,7 +481,7 @@ public class GOBuilder {
                     }
 
                     //icon
-                    item = attributes.getValue("icon");
+                    item = xmlAttributes.get("icon");
                     if (item != null) {
                         controller.setProperty(uic, __GO_UI_ICON__, item);
                     }
@@ -487,19 +489,19 @@ public class GOBuilder {
                     break;
                 }
                 case __GO_UI_EDIT__ : {
-                    item = attributes.getValue("columns");
+                    item = xmlAttributes.get("columns");
                     if (item != null) {
                         controller.setProperty(uic, __GO_UI_MAX__, Double.parseDouble(item));
                     }
 
                     //callback
-                    item = attributes.getValue("onenter");
+                    item = xmlAttributes.get("onenter");
                     if (item != null && item.equals("") == false) {
                         controller.setProperty(uic, __GO_CALLBACK__, item);
                         controller.setProperty(uic, __GO_CALLBACKTYPE__, 0);
                     }
 
-                    item = attributes.getValue("onfocusloss");
+                    item = xmlAttributes.get("onfocusloss");
                     if (item != null && item.equals("") == false) {
                         controller.setProperty(uic, __GO_CALLBACK__, item);
                         controller.setProperty(uic, __GO_CALLBACKTYPE__, 0);
@@ -508,18 +510,18 @@ public class GOBuilder {
                     break;
                 }
                 case __GO_UI_POPUPMENU__ : {
-                    item = attributes.getValue("items");
+                    item = xmlAttributes.get("items");
                     if (item != null && item.equals("") == false) {
                         controller.setProperty(uic, __GO_UI_STRING__, new String[] {item});
                     }
 
-                    item = attributes.getValue("prototype-display-value");
+                    item = xmlAttributes.get("prototype-display-value");
                     if (item != null && item.equals("") == false) {
                         controller.setProperty(uic, __GO_UI_MAX__, new Double(item.length()));
                     }
 
                     //callback
-                    item = attributes.getValue("onchange");
+                    item = xmlAttributes.get("onchange");
                     if (item != null && item.equals("") == false) {
                         controller.setProperty(uic, __GO_CALLBACK__, item);
                         controller.setProperty(uic, __GO_CALLBACKTYPE__, 0);
@@ -528,19 +530,19 @@ public class GOBuilder {
                     break;
                 }
                 case __GO_UI_LISTBOX__ : {
-                    item = attributes.getValue("items");
+                    item = xmlAttributes.get("items");
                     if (item != null && item.equals("") == false) {
                         controller.setProperty(uic, __GO_UI_STRING__, new String[] {item});
                     }
 
-                    item = attributes.getValue("multiple");
+                    item = xmlAttributes.get("multiple");
                     if (item != null && item.equals("true")) {
                         controller.setProperty(uic, __GO_UI_MIN__, 0.0);
                         controller.setProperty(uic, __GO_UI_MAX__, 2.0);
                     }
 
                     //callback
-                    item = attributes.getValue("onclick");
+                    item = xmlAttributes.get("onclick");
                     if (item != null && item.equals("") == false) {
                         controller.setProperty(uic, __GO_CALLBACK__, item);
                         controller.setProperty(uic, __GO_CALLBACKTYPE__, 0);
@@ -600,6 +602,45 @@ public class GOBuilder {
 
     }
 
+    public static Integer uimenuBuilder(GraphicController controller, Attributes attributes, int parent) {
+        Integer parentType = (Integer)controller.getProperty(parent, __GO_TYPE__);
+        if (parentType == __GO_FIGURE__) {
+            controller.setProperty(parent, __GO_MENUBAR_VISIBLE__, true);
+        }
+
+        Integer uim = controller.askObject(GraphicObject.getTypeFromName(__GO_UIMENU__));
+
+        String item = null;
+
+        item = attributes.getValue("id");
+        if (item != null) {
+            controller.setProperty(uim, __GO_TAG__, item);
+        }
+
+        item = attributes.getValue("text");
+        if (item != null) {
+            controller.setProperty(uim, __GO_UI_LABEL__, item);
+        }
+
+        item = attributes.getValue("onclick");
+        if (item != null) {
+            controller.setProperty(uim, __GO_CALLBACK__, item);
+            controller.setProperty(uim, __GO_CALLBACKTYPE__, 0);
+        }
+
+        item = attributes.getValue("checked");
+        if (item != null && (item.equals("true") || item.equals("on"))) {
+            controller.setProperty(uim, __GO_UI_CHECKED__, true);
+        }
+
+        item = attributes.getValue("icon");
+        if (item != null) {
+            controller.setProperty(uim, __GO_UI_ICON__, item);
+        }
+
+        return uim;
+    }
+
     private static Integer createBorder(GraphicController controller, Integer uic, FrameBorderType borderType, Map<String, String> map) {
         Integer border = controller.askObject(GraphicObject.getTypeFromName(__GO_UI_FRAME_BORDER__));
         controller.setProperty(border, __GO_UI_FRAME_BORDER_STYLE__, borderType.ordinal());
index d27c6da..4ec19f4 100644 (file)
@@ -12,6 +12,8 @@
 
 package org.scilab.modules.graphic_objects.xmlloader;
 
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_TAG__;
+import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_UI_ENABLE__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_CHILDREN__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_AXES__;
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_FIGURE__;
@@ -99,7 +101,6 @@ public class XmlLoader extends DefaultHandler {
 
         nameToGO.put("UIMenu", __GO_UIMENU__);
         nameToGO.put("UIMenuItem", __GO_UIMENU__);
-        nameToGO.put("UIMenuBar", -2);
 
     }
 
@@ -212,6 +213,8 @@ public class XmlLoader extends DefaultHandler {
         if (stackGO.size() != 0) {
             Integer go = stackGO.pop();
             if (go == null) {
+                System.out.println("go == null !!!!!");
+                //nothing to do
             } else if (stackGO.size() > 0) {
                 Integer parent = stackGO.peek();
 
@@ -248,22 +251,21 @@ public class XmlLoader extends DefaultHandler {
             Integer uitype = getTypeFromName(localName);
             Integer go = 0;
             if (uitype != null) {
-                if (uitype == -2) { //menubar, nothing to do
-                    return;
-                } else if (uitype == __GO_FIGURE__) {
+                if (uitype == __GO_FIGURE__) {
                     // never create a new figure, clone figure model !
                     go = GOBuilder.figureBuilder(controller, attributes);
                 } else if (uitype == __GO_AXES__) {
                     go = GraphicController.getController().askObject(Type.AXES);
                 } else if (uitype == __GO_UIMENU__) {
-                    int parent = 0;
+                    Integer parent = 0;
                     if (stackGO.isEmpty() == false) {
                         parent = stackGO.peek();
                     }
 
-                    go = GOBuilder.uimenuUpdater(controller, attributes, parent);
+                    System.out.println("parent : " + parent);
+                    go = GOBuilder.uimenuBuilder(controller, attributes, parent);
                 } else {
-                    int parent = 0;
+                    Integer parent = 0;
                     if (stackGO.isEmpty() == false) {
                         parent = stackGO.peek();
                     }
@@ -319,7 +321,13 @@ public class XmlLoader extends DefaultHandler {
     }
 
     Integer cloneObject(Integer root) {
+        Boolean avant = (Boolean)controller.getProperty(root, __GO_UI_ENABLE__);
         Integer newGo = controller.cloneObject(root);
+        Boolean apres = (Boolean)controller.getProperty(root, __GO_UI_ENABLE__);
+        if (apres.equals(avant) == false) {
+            System.out.println("bad clone for " + (String)controller.getProperty(root, __GO_TAG__));
+        }
+
         Integer[] children = (Integer[]) controller.getProperty(root, __GO_CHILDREN__);
         for (int i = children.length - 1; i >= 0 ; i--) {
             if ((Integer)controller.getProperty(children[i], __GO_TYPE__) == __GO_AXES__) {
index 964560c..166efcb 100644 (file)
@@ -873,26 +873,37 @@ public final class SwingView implements GraphicView {
         if (registeredObject != null && property == __GO_UI_CHECKED__) {
             if (type == __GO_UIMENU__) {
                 switch (registeredObject.getType()) {
-                    case UiParentMenu:
+                    case UiParentMenu: {
                         SwingScilabMenu meAsAMenu = (SwingScilabMenu) registeredObject.getValue();
                         Container parent = meAsAMenu.getParent();
-                        parent.remove(meAsAMenu);
+                        if (parent != null) {
+                            parent.remove(meAsAMenu);
+                        }
+
                         registeredObject = CreateObjectFromType(__GO_UICHECKEDMENU__, id);
                         allObjects.put(id, registeredObject);
                         SwingScilabCheckBoxMenuItem meAsAMenuItem = (SwingScilabCheckBoxMenuItem) registeredObject.getValue();
-                        parent.add(meAsAMenuItem);
+                        if (parent != null) {
+                            parent.add(meAsAMenuItem);
+                        }
                         break;
-                    case UiChildMenu:
+                    }
+                    case UiChildMenu: {
                         SwingScilabMenuItem childMenu = (SwingScilabMenuItem) allObjects.get(id).getValue();
                         JComponent parentMenu = (JComponent) childMenu.getParent();
-
-                        int index = parentMenu.getComponentZOrder(childMenu);
-                        parentMenu.remove(childMenu);
+                        int index = 0;
+                        if (parentMenu != null) {
+                            index = parentMenu.getComponentZOrder(childMenu);
+                            parentMenu.remove(childMenu);
+                        }
                         registeredObject = CreateObjectFromType(__GO_UICHECKEDMENU__, id);
                         allObjects.put(id, registeredObject);
                         registeredObject = allObjects.get(id);
-                        parentMenu.add((SwingScilabCheckBoxMenuItem) registeredObject.getValue(), index);
+                        if (parentMenu != null) {
+                            parentMenu.add((SwingScilabCheckBoxMenuItem) registeredObject.getValue(), index);
+                        }
                         return;
+                    }
                     default:
                         break;
                 }
@@ -1339,23 +1350,31 @@ public final class SwingView implements GraphicView {
                             switch (childAsTypedObject.getType()) {
                                 case UiChildMenu:
                                     /* Replace the item by a parent menu */
-                                    updatedObjectPosition = parent.getComponentZOrder((SwingScilabMenuItem) updatedObject.getValue());
-                                    parent.remove((SwingScilabMenuItem) updatedObject.getValue());
+                                    if (parent != null) {
+                                        updatedObjectPosition = parent.getComponentZOrder((SwingScilabMenuItem) updatedObject.getValue());
+                                        parent.remove((SwingScilabMenuItem) updatedObject.getValue());
+                                    }
                                     newParent = CreateObjectFromType(__GO_UIPARENTMENU__, id);
                                     allObjects.put(id, newParent);
                                     newParent.addChild(childId);
-                                    parent.add((SwingScilabMenu) newParent.getValue(), updatedObjectPosition);
+                                    if (parent != null) {
+                                        parent.add((SwingScilabMenu) newParent.getValue(), updatedObjectPosition);
+                                    }
                                     /* Update the created menu */
                                     ((SwingScilabMenu) newParent.getValue()).add((SwingScilabMenuItem) addedChild);
                                     break;
                                 case UiCheckedMenu:
                                     /* Replace the item by a parent menu */
-                                    updatedObjectPosition = parent.getComponentZOrder((SwingScilabCheckBoxMenuItem) updatedObject.getValue());
-                                    parent.remove((SwingScilabCheckBoxMenuItem) updatedObject.getValue());
+                                    if (parent != null) {
+                                        updatedObjectPosition = parent.getComponentZOrder((SwingScilabCheckBoxMenuItem) updatedObject.getValue());
+                                        parent.remove((SwingScilabCheckBoxMenuItem) updatedObject.getValue());
+                                    }
                                     newParent = CreateObjectFromType(__GO_UIPARENTMENU__, id);
                                     allObjects.put(id, newParent);
                                     newParent.addChild(childId);
-                                    parent.add((SwingScilabMenu) newParent.getValue(), updatedObjectPosition);
+                                    if (parent != null) {
+                                        parent.add((SwingScilabMenu) newParent.getValue(), updatedObjectPosition);
+                                    }
                                     /* Update the created menu */
                                     ((SwingScilabMenu) newParent.getValue()).add((SwingScilabCheckBoxMenuItem) addedChild);
                                     break;
@@ -1370,23 +1389,31 @@ public final class SwingView implements GraphicView {
                             switch (childAsTypedObject.getType()) {
                                 case UiChildMenu:
                                     /* Replace the item by a parent menu */
-                                    updatedObjectPosition = parent.getComponentZOrder((SwingScilabCheckBoxMenuItem) updatedObject.getValue());
-                                    parent.remove((SwingScilabCheckBoxMenuItem) allObjects.get(id).getValue());
+                                    if (parent != null) {
+                                        updatedObjectPosition = parent.getComponentZOrder((SwingScilabCheckBoxMenuItem) updatedObject.getValue());
+                                        parent.remove((SwingScilabCheckBoxMenuItem) allObjects.get(id).getValue());
+                                    }
                                     newParent = CreateObjectFromType(__GO_UIPARENTMENU__, id);
                                     allObjects.put(id, newParent);
                                     newParent.addChild(childId);
-                                    parent.add((SwingScilabMenu) newParent.getValue(), updatedObjectPosition);
+                                    if (parent != null) {
+                                        parent.add((SwingScilabMenu) newParent.getValue(), updatedObjectPosition);
+                                    }
                                     /* Update the created menu */
                                     ((SwingScilabMenu) newParent.getValue()).add((SwingScilabMenuItem) allObjects.get(childId).getValue());
                                     break;
                                 case UiCheckedMenu:
                                     /* Replace the item by a parent menu */
-                                    updatedObjectPosition = parent.getComponentZOrder((SwingScilabCheckBoxMenuItem) updatedObject.getValue());
-                                    parent.remove((SwingScilabCheckBoxMenuItem) allObjects.get(id).getValue());
+                                    if (parent != null) {
+                                        updatedObjectPosition = parent.getComponentZOrder((SwingScilabCheckBoxMenuItem) updatedObject.getValue());
+                                        parent.remove((SwingScilabCheckBoxMenuItem) allObjects.get(id).getValue());
+                                    }
                                     newParent = CreateObjectFromType(__GO_UIPARENTMENU__, id);
                                     allObjects.put(id, newParent);
                                     newParent.addChild(childId);
-                                    parent.add((SwingScilabMenu) newParent.getValue(), updatedObjectPosition);
+                                    if (parent != null) {
+                                        parent.add((SwingScilabMenu) newParent.getValue(), updatedObjectPosition);
+                                    }
                                     /* Update the created menu */
                                     ((SwingScilabMenu) newParent.getValue()).add((SwingScilabCheckBoxMenuItem) allObjects.get(childId).getValue());
                                     break;
index 9675fe4..a91d443 100644 (file)
@@ -24,7 +24,11 @@ import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProp
 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_VISIBLE__;
 
 import java.awt.Color;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
 
+import javax.imageio.ImageIO;
 import javax.swing.ImageIcon;
 
 import org.scilab.modules.commons.gui.FindIconHelper;
@@ -86,7 +90,31 @@ public final class SwingViewMenu {
                 break;
             case __GO_UI_ICON__ :
                 if (!((String) value).equals("")) {
-                    ((SwingScilabMenuItem) uimenu).setIcon(new ImageIcon(FindIconHelper.findIcon((String) value, "16x16")));
+                    File file = new File((String)value);
+                    if (file.exists() == false) {
+                        String filename = FindIconHelper.findImage((String)value);
+                        file = new File(filename);
+                    }
+
+                    try {
+                        BufferedImage icon = ImageIO.read(file);
+                        if (uimenu instanceof SwingScilabMenuItem) {
+                            ((SwingScilabMenuItem) uimenu).setIcon(new ImageIcon(icon));
+                        } else if (uimenu instanceof SwingScilabMenu) {
+                            ((SwingScilabMenu) uimenu).setIcon(new ImageIcon(icon));
+                        } else if (uimenu instanceof SwingScilabMenu) {
+                            ((SwingScilabCheckBoxMenuItem) uimenu).setIcon(new ImageIcon(icon));
+                        }
+                    } catch (IOException e) {
+                    }
+                } else {
+                    if (uimenu instanceof SwingScilabMenuItem) {
+                        ((SwingScilabMenuItem) uimenu).setIcon(null);
+                    } else if (uimenu instanceof SwingScilabMenu) {
+                        ((SwingScilabMenu) uimenu).setIcon(null);
+                    } else if (uimenu instanceof SwingScilabCheckBoxMenuItem) {
+                        ((SwingScilabCheckBoxMenuItem) uimenu).setIcon(null);
+                    }
                 }
                 break;
             case __GO_UI_LABEL__ :
index 37d27d7..f49a609 100644 (file)
@@ -256,14 +256,18 @@ public class SwingScilabMenuItem extends JMenuItem implements SwingViewObject, S
             meAsAMenu.add(childMenuItem);
             if (meAsACheckBoxMenuItem == null) {
                 Container parent = getParent();
-                int index = parent.getComponentZOrder(this);
-                parent.remove(this.getComponent());
-                parent.add((SwingScilabMenu) meAsAMenu.getAsSimpleMenu(), index);
+                if (parent != null) {
+                    int index = parent.getComponentZOrder(this);
+                    parent.remove(this.getComponent());
+                    parent.add((SwingScilabMenu) meAsAMenu.getAsSimpleMenu(), index);
+                }
             } else {
                 Container parent = ((SwingScilabCheckBoxMenuItem) meAsACheckBoxMenuItem.getAsSimpleCheckBoxMenuItem()).getParent();
-                int index = parent.getComponentZOrder(((SwingScilabCheckBoxMenuItem) meAsACheckBoxMenuItem.getAsSimpleCheckBoxMenuItem()));
-                parent.remove(((SwingScilabCheckBoxMenuItem) meAsACheckBoxMenuItem.getAsSimpleCheckBoxMenuItem()).getComponent());
-                parent.add((SwingScilabMenu) meAsAMenu.getAsSimpleMenu(), index);
+                if (parent != null) {
+                    int index = parent.getComponentZOrder(((SwingScilabCheckBoxMenuItem) meAsACheckBoxMenuItem.getAsSimpleCheckBoxMenuItem()));
+                    parent.remove(((SwingScilabCheckBoxMenuItem) meAsACheckBoxMenuItem.getAsSimpleCheckBoxMenuItem()).getComponent());
+                    parent.add((SwingScilabMenu) meAsAMenu.getAsSimpleMenu(), index);
+                }
             }
         } else {
             meAsAMenu.add(childMenuItem);
@@ -282,14 +286,18 @@ public class SwingScilabMenuItem extends JMenuItem implements SwingViewObject, S
             ((SwingScilabMenu) meAsAMenu.getAsSimpleMenu()).add(childMenuItem);
             if (meAsACheckBoxMenuItem == null) {
                 Container parent = getParent();
-                int index = parent.getComponentZOrder(this);
-                parent.remove(this.getComponent());
-                parent.add((SwingScilabMenu) meAsAMenu.getAsSimpleMenu(), index);
+                if (parent != null) {
+                    int index = parent.getComponentZOrder(this);
+                    parent.remove(this.getComponent());
+                    parent.add((SwingScilabMenu) meAsAMenu.getAsSimpleMenu(), index);
+                }
             } else {
                 Container parent = ((SwingScilabCheckBoxMenuItem) meAsACheckBoxMenuItem.getAsSimpleCheckBoxMenuItem()).getParent();
-                int index = parent.getComponentZOrder(((SwingScilabCheckBoxMenuItem) meAsACheckBoxMenuItem.getAsSimpleCheckBoxMenuItem()));
-                parent.remove(((SwingScilabCheckBoxMenuItem) meAsACheckBoxMenuItem.getAsSimpleCheckBoxMenuItem()).getComponent());
-                parent.add((SwingScilabMenu) meAsAMenu.getAsSimpleMenu(), index);
+                if (parent != null) {
+                    int index = parent.getComponentZOrder(((SwingScilabCheckBoxMenuItem) meAsACheckBoxMenuItem.getAsSimpleCheckBoxMenuItem()));
+                    parent.remove(((SwingScilabCheckBoxMenuItem) meAsACheckBoxMenuItem.getAsSimpleCheckBoxMenuItem()).getComponent());
+                    parent.add((SwingScilabMenu) meAsAMenu.getAsSimpleMenu(), index);
+                }
             }
         } else {
             ((SwingScilabMenu) meAsAMenu.getAsSimpleMenu()).add(childMenuItem);
@@ -336,9 +344,11 @@ public class SwingScilabMenuItem extends JMenuItem implements SwingViewObject, S
             meAsAMenu.setText(getText());
             meAsAMenu.add(childMenu);
             Container parent = getParent();
-            int index = parent.getComponentZOrder(this);
-            parent.remove(this.getComponent());
-            parent.add((SwingScilabMenu) meAsAMenu.getAsSimpleMenu(), index);
+            if (parent != null) {
+                int index = parent.getComponentZOrder(this);
+                parent.remove(this.getComponent());
+                parent.add((SwingScilabMenu) meAsAMenu.getAsSimpleMenu(), index);
+            }
         } else {
             meAsAMenu.add(childMenu);
         }
@@ -382,9 +392,11 @@ public class SwingScilabMenuItem extends JMenuItem implements SwingViewObject, S
             meAsACheckBoxMenuItem.setChecked(status);
             meAsACheckBoxMenuItem.setCallback(getCallback());
             Container parent = getParent();
-            int index = parent.getComponentZOrder(this);
-            parent.remove(this.getComponent());
-            parent.add((SwingScilabCheckBoxMenuItem) meAsACheckBoxMenuItem.getAsSimpleCheckBoxMenuItem(), index);
+            if (parent != null) {
+                int index = parent.getComponentZOrder(this);
+                parent.remove(this.getComponent());
+                parent.add((SwingScilabCheckBoxMenuItem) meAsACheckBoxMenuItem.getAsSimpleCheckBoxMenuItem(), index);
+            }
         } else {
             meAsACheckBoxMenuItem.setChecked(status);
         }
@@ -409,9 +421,11 @@ public class SwingScilabMenuItem extends JMenuItem implements SwingViewObject, S
             meAsAMenu.setText(getText());
             meAsAMenu.add(newCheckBoxMenuItem);
             Container parent = getParent();
-            int index = parent.getComponentZOrder(this);
-            parent.remove(this.getComponent());
-            parent.add((SwingScilabMenu) meAsAMenu.getAsSimpleMenu(), index);
+            if (parent != null) {
+                int index = parent.getComponentZOrder(this);
+                parent.remove(this.getComponent());
+                parent.add((SwingScilabMenu) meAsAMenu.getAsSimpleMenu(), index);
+            }
         } else {
             meAsAMenu.add(newCheckBoxMenuItem);
         }