Bug 7038 fixed: No toggle button when in datatip mode 91/13091/3
Calixte DENIZET [Wed, 6 Nov 2013 13:27:44 +0000 (14:27 +0100)]
Change-Id: I9af9ee1899b44ccca3839c1776f8f139ca2fbef7

scilab/CHANGES_5.5.X
scilab/modules/gui/etc/graphics_toolbar.xml
scilab/modules/gui/src/java/org/scilab/modules/gui/editor/EditorManager.java
scilab/modules/gui/src/java/org/scilab/modules/gui/utils/ToolBarBuilder.java

index 33a6c66..7ca14c0 100644 (file)
@@ -22,6 +22,8 @@ Scilab Bug Fixes
 
 * Bug #6824 fixed - resize_matrix did not manage hypermatrices.
 
+* Bug #7038 fixed - Toolbar button managing datatip mode did not toggle.
+
 * Bug #7047 fixed - milk_drop is now obsolete. It will be removed in Scilab 5.5.1, but will be kept as a demo.
 
 * Bug #7570 fixed - The switch criterion on x and y is now explicited in beta() help page.
index 625825c..7057be3 100644 (file)
@@ -16,7 +16,7 @@
     </button>
     <separator/>
     <!-- Datatips -->
-    <button icon="datatips" tooltiptext="Toggle datatip mode">
+    <button icon="datatips" tooltiptext="Toggle datatip mode" toggle="true">
         <callback instruction="datatipManagerMode(get_figure_handle([SCILAB_FIGURE_ID]))" type="-2"/>
     </button>
     <!-- Scilab Graphic Editor -->
@@ -25,7 +25,7 @@
         <callback instruction="openged([SCILAB_FIGURE_ID])" type="-2"/>
     </button>
     -->
-    <button icon="data_modify" tooltiptext="Toggle curve data modification">
+    <button icon="data_modify" tooltiptext="Toggle curve data modification" toggle="true">
         <callback instruction="useeditor([SCILAB_FIGURE_ID])" type="-2"/>
     </button>
     <separator/>
index 37bd2e0..19fd266 100644 (file)
@@ -46,7 +46,7 @@ public class EditorManager {
      * Enables the editor which belongs to the given figure uid.
      * @param figureUid Figure wich the editor belongs.
      */
-    public static void enableModify(Integer uid) {
+    public static void enableModify(int uid) {
         Editor editor = allEditors.get(uid);
         if (editor != null) {
             editor.setDataModifyEnabled(true);
@@ -57,7 +57,7 @@ public class EditorManager {
      * Disables the editor which belongs to the given figure uid.
      * @param figureUid Figure wich the editor belongs.
      */
-    public static void disableModify(Integer uid) {
+    public static void disableModify(int uid) {
         Editor editor = allEditors.get(uid);
         if (editor != null) {
             editor.setDataModifyEnabled(false);
@@ -68,7 +68,7 @@ public class EditorManager {
      * Checks if the editor which belongs to the given figure uid is enabled.
      * @return True if the editor is enableb, false otherwise.
      */
-    public static boolean isModifyEnabled(Integer uid) {
+    public static boolean isModifyEnabled(int uid) {
         Editor editor = allEditors.get(uid);
         if (editor != null) {
             return editor.isDataModifyEnabled();
@@ -79,7 +79,7 @@ public class EditorManager {
     /**
      * Remove the editor from the map.
      */
-    public static void deleteEditor(Integer uid) {
+    public static void deleteEditor(int uid) {
         allEditors.remove(uid);
     }
 
@@ -88,7 +88,7 @@ public class EditorManager {
      * @param uid The figure uid.
      * @return The editor instance.
      */
-    public static Editor getFromUid(Integer uid) {
+    public static Editor getFromUid(int uid) {
         return allEditors.get(uid);
     }
 }
index c862de2..81a4254 100644 (file)
@@ -21,10 +21,15 @@ import java.lang.reflect.Proxy;
 import java.util.Collection;
 import java.util.TreeSet;
 
+import javax.swing.AbstractButton;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JToggleButton;
 import javax.xml.parsers.ParserConfigurationException;
 
 import org.scilab.modules.commons.xml.ScilabDocumentBuilderFactory;
 import org.scilab.modules.graphic_objects.graphicObject.CallBack;
+import org.scilab.modules.gui.bridge.toolbar.SwingScilabToolBar;
 import org.scilab.modules.gui.events.callback.CommonCallBack;
 import org.scilab.modules.gui.pushbutton.PushButton;
 import org.scilab.modules.gui.pushbutton.ScilabPushButton;
@@ -127,6 +132,7 @@ public final class ToolBarBuilder {
         protected static final String INSTRUCTION = "instruction";
         protected static final String TRUE = "true";
         protected static final String TOOLTIPTEXT = "tooltiptext";
+        protected static final String TOGGLE = "toggle";
 
         private final Document dom;
         private final Collection<String> internalMethodNames;
@@ -189,61 +195,80 @@ public final class ToolBarBuilder {
             Node button = menubar.getFirstChild();
 
             NamedNodeMap buttonAttributes = null;
-            PushButton pushButton = null;
-
-            // Get all children
-            while (button != null) {
-
-                if (button.getNodeName().equals(BUTTON)) {
-                    // The child is a button
-                    pushButton = ScilabPushButton.createPushButton();
-                    // Read all its attributes
-                    buttonAttributes = button.getAttributes();
-
-                    for (int i = 0; i < buttonAttributes.getLength(); i++) {
-
-                        if (buttonAttributes.item(i).getNodeName().equals(ICON)) {
-                            // Icon file
-                            pushButton.setIcon(ScilabSwingUtilities.findIcon(buttonAttributes.item(i).getNodeValue()));
-                        } else if (buttonAttributes.item(i).getNodeName().equals(ENABLED)) {
-                            // Enable are disable the button
-                            pushButton.setEnabled(buttonAttributes.item(i).getNodeValue().equals(TRUE));
-                        } else if (buttonAttributes.item(i).getNodeName().equals(TOOLTIPTEXT)) {
-                            // Add a ToolTip on the button
-                            pushButton.setToolTipText(Messages.gettext(buttonAttributes.item(i).getNodeValue()));
+            AbstractButton pushButton = null;
+
+            try {
+                // Get all children
+                while (button != null) {
+                    if (button.getNodeName().equals(BUTTON)) {
+                        // Read all its attributes
+                        buttonAttributes = button.getAttributes();
+
+                        boolean toggle = false;
+                        for (int i = 0; i < buttonAttributes.getLength(); i++) {
+                            if (buttonAttributes.item(i).getNodeName().equals(TOGGLE)) {
+                                toggle = buttonAttributes.item(i).getNodeValue().equals(TRUE);
+                                break;
+                            }
                         }
-                    }
-                    // Add the button to the toolbar
-                    tb.add(pushButton);
-
-                    // Then we get its callback (if exists)
-                    Node callback = button.getFirstChild();
-                    while (callback != null) {
-                        if (callback.getNodeName() == CALLBACK) {
-                            NamedNodeMap cbAttributes = callback.getAttributes();
-                            String command = null;
-                            int commandType = CallBack.UNTYPED;
-                            for (int j = 0; j < cbAttributes.getLength(); j++) {
-                                if (cbAttributes.item(j).getNodeName() == INSTRUCTION) {
-                                    command = cbAttributes.item(j).getNodeValue();
-                                } else if (cbAttributes.item(j).getNodeName() == TYPE) {
-                                    commandType = Integer.parseInt(cbAttributes.item(j).getNodeValue());
-                                }
+
+                        if (toggle) {
+                            pushButton = new JToggleButton();
+                        } else {
+                            pushButton = new JButton();
+                        }
+
+                        pushButton.setFocusable(false);
+                        pushButton.setContentAreaFilled(true);
+                        pushButton.setOpaque(false);
+
+                        for (int i = 0; i < buttonAttributes.getLength(); i++) {
+                            if (buttonAttributes.item(i).getNodeName().equals(ICON)) {
+                                // Icon file
+                                pushButton.setIcon(new ImageIcon(ScilabSwingUtilities.findIcon(buttonAttributes.item(i).getNodeValue())));
+                            } else if (buttonAttributes.item(i).getNodeName().equals(ENABLED)) {
+                                // Enable are disable the button
+                                pushButton.setEnabled(buttonAttributes.item(i).getNodeValue().equals(TRUE));
+                            } else if (buttonAttributes.item(i).getNodeName().equals(TOOLTIPTEXT)) {
+                                // Add a ToolTip on the button
+                                pushButton.setToolTipText(Messages.gettext(buttonAttributes.item(i).getNodeValue()));
                             }
-                            if (command != null && commandType != CallBack.UNTYPED) {
-                                pushButton.setCallback(CommonCallBack.createCallback(replaceFigureID(command), commandType));
+                        }
+                        // Add the button to the toolbar
+                        ((SwingScilabToolBar) tb.getAsSimpleToolBar()).add(pushButton);
+
+                        // Then we get its callback (if exists)
+                        Node callback = button.getFirstChild();
+                        while (callback != null) {
+                            if (callback.getNodeName() == CALLBACK) {
+                                NamedNodeMap cbAttributes = callback.getAttributes();
+                                String command = null;
+                                int commandType = CallBack.UNTYPED;
+                                for (int j = 0; j < cbAttributes.getLength(); j++) {
+                                    if (cbAttributes.item(j).getNodeName() == INSTRUCTION) {
+                                        command = cbAttributes.item(j).getNodeValue();
+                                    } else if (cbAttributes.item(j).getNodeName() == TYPE) {
+                                        commandType = Integer.parseInt(cbAttributes.item(j).getNodeValue());
+                                    }
+                                }
+                                if (command != null && commandType != CallBack.UNTYPED) {
+                                    pushButton.addActionListener(CommonCallBack.createCallback(replaceFigureID(command), commandType));
+                                }
                             }
+                            // Read next child
+                            callback = callback.getNextSibling();
                         }
-                        // Read next child
-                        callback = callback.getNextSibling();
-                    }
 
-                } else if (button.getNodeName().equals(SEPARATOR)) {
-                    // The child is a separator
-                    tb.addSeparator();
+                    } else if (button.getNodeName().equals(SEPARATOR)) {
+                        // The child is a separator
+                        tb.addSeparator();
+                    }
+                    // Get next child
+                    button = button.getNextSibling();
                 }
-                // Get next child
-                button = button.getNextSibling();
+            } catch (Exception e) {
+                System.err.println(e);
+                e.printStackTrace();
             }
         }