Bug 13324 fixed: Legends were completely modified when a legend was cliked and modified 71/14471/3
Calixte DENIZET [Mon, 28 Apr 2014 15:40:56 +0000 (17:40 +0200)]
Change-Id: Idc9d8d3f54aff39af56e2b027279816eb919d74d

scilab/CHANGES_5.5.X
scilab/modules/gui/src/java/org/scilab/modules/gui/editor/Editor.java
scilab/modules/gui/src/java/org/scilab/modules/gui/editor/LegendHandler.java

index 2c6e5e3..905f766 100644 (file)
@@ -35,6 +35,8 @@ Scilab Bug Fixes
 
 * Bug #13316 fixed - There were missing tooltips on File Browser buttons.
 
+* Bug #13324 fixed - Legends were completely modified when an item was clicked and modified.
+
 * Bug #13331 fixed - Users are no longer able to write inconsistent options to mopen,
                      mopen(file, "wr") now exits with a proper error.
 
index b9a5318..0b944c3 100644 (file)
@@ -47,17 +47,17 @@ import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement;
 
 
 /**
-* Point and click figure editor.
-*
-* Provides polyline selection by mouse click,
-* copy, cut, paste, delete, hide, unhide polylines
-* by popup menus and keyboard shortcuts.
-*
-* @author Caio Souza <caioc2bolado@gmail.com>
-* @author Pedro Souza <bygrandao@gmail.com>
-*
-* @since 2012-06-01
-*/
+ * Point and click figure editor.
+ *
+ * Provides polyline selection by mouse click,
+ * copy, cut, paste, delete, hide, unhide polylines
+ * by popup menus and keyboard shortcuts.
+ *
+ * @author Caio Souza <caioc2bolado@gmail.com>
+ * @author Pedro Souza <bygrandao@gmail.com>
+ *
+ * @since 2012-06-01
+ */
 
 public class Editor {
 
@@ -90,10 +90,10 @@ public class Editor {
         entityPicker = new EntityPicker();
         dataEditor = new DataEditor();
         dataEditor.setLeaveAction(new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                leaveDataEditor();
-            }
-        });
+                public void actionPerformed(ActionEvent actionEvent) {
+                    leaveDataEditor();
+                }
+            });
     }
 
     /**
@@ -158,35 +158,35 @@ public class Editor {
 
         if (!dataEditEnabled) {
             switch (event.getClickCount()) {
-                case 1:
-                    setSelected(tryPickAnyObject(lastClick));
-                    break;
-                case 2:
-                    /*there is a polyline selected? if yes start dataEditor*/
-                    if (selected != null && selectedType == SelectionType.POLYLINE && dataModifyEnabled) {
-                        enterDataEditor();
-                    }
-                    /*on double click over a legend or label open dialog*/
-                    else if (selectedLegend != null) {
-                        onClickInsert(selectedLegend.polyline);
-                    } else {
-                        /*try pick a label and open the dialog*/
-                        onClickLabel(EntityPicker.pickLabel(figureUid, lastClick));
-                    }
-                    break;
-                default:
-                    break;
+            case 1:
+                setSelected(tryPickAnyObject(lastClick));
+                break;
+            case 2:
+                /*there is a polyline selected? if yes start dataEditor*/
+                if (selected != null && selectedType == SelectionType.POLYLINE && dataModifyEnabled) {
+                    enterDataEditor();
+                }
+                /*on double click over a legend or label open dialog*/
+                else if (selectedLegend != null) {
+                    onClickInsert(selectedLegend.polyline);
+                } else {
+                    /*try pick a label and open the dialog*/
+                    onClickLabel(EntityPicker.pickLabel(figureUid, lastClick));
+                }
+                break;
+            default:
+                break;
             }
         } else { /*data editor is enabled, pass event to it*/
             switch (event.getClickCount()) {
-                case 1:
-                    dataEditor.onLeftMouseDown(event);
-                    break;
-                case 2:
-                    dataEditor.onLeftDoubleClick(event);
-                    break;
-                default:
-                    break;
+            case 1:
+                dataEditor.onLeftMouseDown(event);
+                break;
+            case 2:
+                dataEditor.onLeftDoubleClick(event);
+                break;
+            default:
+                break;
             }
         }
         dragClick[0] = lastClick[0];
@@ -238,46 +238,46 @@ public class Editor {
 
         if (event.isControlDown()) {
             switch (event.getKeyCode()) {
-                case KeyEvent.VK_C:
-                    if (getSelected() != null) {
-                        onClickCopy();
-                    }
-                    break;
-                case KeyEvent.VK_V:
-                    if (ScilabClipboard.getInstance().canPaste()) {
-                        onClickPaste();
-                    }
-                    break;
-                case KeyEvent.VK_X:
-                    onClickCut();
-                    break;
-                case KeyEvent.VK_Z:
-                    if (editorHistory.isUndoEnabled()) {
-                        onClickUndo();
-                    }
-                    break;
-                case KeyEvent.VK_N:
-                    try {
-                        ScilabInterpreterManagement.asynchronousScilabExec(null, "scf();");
-                    } catch (Exception e) {
-                        System.err.println(e);
-                    }
-                    break;
-                default:
-                    break;
+            case KeyEvent.VK_C:
+                if (getSelected() != null) {
+                    onClickCopy();
+                }
+                break;
+            case KeyEvent.VK_V:
+                if (ScilabClipboard.getInstance().canPaste()) {
+                    onClickPaste();
+                }
+                break;
+            case KeyEvent.VK_X:
+                onClickCut();
+                break;
+            case KeyEvent.VK_Z:
+                if (editorHistory.isUndoEnabled()) {
+                    onClickUndo();
+                }
+                break;
+            case KeyEvent.VK_N:
+                try {
+                    ScilabInterpreterManagement.asynchronousScilabExec(null, "scf();");
+                } catch (Exception e) {
+                    System.err.println(e);
+                }
+                break;
+            default:
+                break;
             }
         } else {
             switch (event.getKeyCode()) {
-                case KeyEvent.VK_DELETE:
-                    if (!dataEditEnabled) {
-                        onClickDelete();
-                    }
-                    break;
-                case KeyEvent.VK_ESCAPE:
-                    leaveDataEditor();
-                    break;
-                default:
-                    break;
+            case KeyEvent.VK_DELETE:
+                if (!dataEditEnabled) {
+                    onClickDelete();
+                }
+                break;
+            case KeyEvent.VK_ESCAPE:
+                leaveDataEditor();
+                break;
+            default:
+                break;
             }
         }
     }
@@ -333,118 +333,118 @@ public class Editor {
         pasteStyle.setToolTipText(Messages.gettext("Paste the copied style on these axes"));
 
         copy.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                onClickCopy();
-            }
-        });
+                public void actionPerformed(ActionEvent actionEvent) {
+                    onClickCopy();
+                }
+            });
 
         cut.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                onClickCut();
-            }
-        });
+                public void actionPerformed(ActionEvent actionEvent) {
+                    onClickCut();
+                }
+            });
 
         paste.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                onClickPaste();
-            }
-        });
+                public void actionPerformed(ActionEvent actionEvent) {
+                    onClickPaste();
+                }
+            });
 
         delete.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                onClickDelete();
-            }
-        });
+                public void actionPerformed(ActionEvent actionEvent) {
+                    onClickDelete();
+                }
+            });
 
         clear.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                onClickClear();
-            }
-        });
+                public void actionPerformed(ActionEvent actionEvent) {
+                    onClickClear();
+                }
+            });
 
         hide.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                onClickHide();
-            }
-        });
+                public void actionPerformed(ActionEvent actionEvent) {
+                    onClickHide();
+                }
+            });
 
         unhide.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                onClickUnhide();
-            }
-        });
+                public void actionPerformed(ActionEvent actionEvent) {
+                    onClickUnhide();
+                }
+            });
 
         clipboardCopy.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                onClickCCopy();
-            }
-        });
+                public void actionPerformed(ActionEvent actionEvent) {
+                    onClickCCopy();
+                }
+            });
 
         labelX.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                onClickLabel(AxesHandler.axisTo.__X__);
-            }
-        });
+                public void actionPerformed(ActionEvent actionEvent) {
+                    onClickLabel(AxesHandler.axisTo.__X__);
+                }
+            });
 
         labelY.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                onClickLabel(AxesHandler.axisTo.__Y__);
-            }
-        });
+                public void actionPerformed(ActionEvent actionEvent) {
+                    onClickLabel(AxesHandler.axisTo.__Y__);
+                }
+            });
 
         labelZ.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                onClickLabel(AxesHandler.axisTo.__Z__);
-            }
-        });
+                public void actionPerformed(ActionEvent actionEvent) {
+                    onClickLabel(AxesHandler.axisTo.__Z__);
+                }
+            });
 
         insert.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                onClickInsert(getSelected());
-            }
-        });
+                public void actionPerformed(ActionEvent actionEvent) {
+                    onClickInsert(getSelected());
+                }
+            });
 
         remove.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                onClickRemove();
-            }
-        });
+                public void actionPerformed(ActionEvent actionEvent) {
+                    onClickRemove();
+                }
+            });
 
         ged.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                onClickGED();
-            }
-        });
+                public void actionPerformed(ActionEvent actionEvent) {
+                    onClickGED();
+                }
+            });
 
         editdata.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                setDataModifyEnabled(true);
-            }
-        });
+                public void actionPerformed(ActionEvent actionEvent) {
+                    setDataModifyEnabled(true);
+                }
+            });
 
         undo.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                onClickUndo();
-            }
-        });
+                public void actionPerformed(ActionEvent actionEvent) {
+                    onClickUndo();
+                }
+            });
 
         redo.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                onClickRedo();
-            }
-        });
+                public void actionPerformed(ActionEvent actionEvent) {
+                    onClickRedo();
+                }
+            });
 
         copyStyle.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                onClickCopyStyle();
-            }
-        });
+                public void actionPerformed(ActionEvent actionEvent) {
+                    onClickCopyStyle();
+                }
+            });
 
         pasteStyle.addActionListener(new ActionListener() {
-            public void actionPerformed(ActionEvent actionEvent) {
-                onClickPasteStyle();
-            }
-        });
+                public void actionPerformed(ActionEvent actionEvent) {
+                    onClickPasteStyle();
+                }
+            });
 
 
         labels.add(labelX);
@@ -550,8 +550,8 @@ public class Editor {
     }
 
     /**
-    * Implements copy menu item action(Callback).
-    */
+     * Implements copy menu item action(Callback).
+     */
     public void onClickCopy() {
         if (selectedType != SelectionType.LEGEND) {
             ScilabClipboard.getInstance().copy(getSelected());
@@ -562,7 +562,6 @@ public class Editor {
      * Implements paste menu item action(Callback).
      */
     public void onClickPaste() {
-
         Integer currentObject, newObject, currentParent, newParent;
         boolean isDuplicated = false;
 
@@ -571,8 +570,8 @@ public class Editor {
         Integer oldFigure = CommonHandler.getParentFigure(currentObject);
         if (!CommonHandler.cmpColorMap(figureUid, oldFigure)) {
             String msg =  "The colormap from source figure seems to be different from the destination figure." +
-                          "\nThis may influence the final appearance from the object." +
-                          "\nDo you want copy the color map too?";
+                "\nThis may influence the final appearance from the object." +
+                "\nDo you want copy the color map too?";
             int i = JOptionPane.showConfirmDialog(dialogComponent, Messages.gettext(msg), Messages.gettext("Warning"), JOptionPane.YES_NO_OPTION);
 
             if (i == JOptionPane.YES_OPTION) {
@@ -614,8 +613,8 @@ public class Editor {
     }
 
     /**
-    * Implements clear menu item action(Callback).
-    */
+     * Implements clear menu item action(Callback).
+     */
     public void onClickClear() {
         setSelected(null);
         Integer axesTo = AxesHandler.clickedAxes(figureUid, lastClick);
@@ -625,8 +624,8 @@ public class Editor {
     }
 
     /**
-    * Implements hide menu item action(Callback).
-    */
+     * Implements hide menu item action(Callback).
+     */
     public void onClickHide() {
         if (getSelected() != null) {
             CommonHandler.setVisible(selected, false);
@@ -654,18 +653,17 @@ public class Editor {
      * @param axis axis number.
      */
     public void onClickLabel(AxesHandler.axisTo axis) {
-
         Integer axes = AxesHandler.clickedAxes(figureUid, lastClick);
         if (axes != null && axis != null) {
             String text = LabelHandler.getLabelText(axes, axis);
             String s = (String)JOptionPane.showInputDialog(
-                           dialogComponent,
-                           Messages.gettext("Enter the text"),
-                           Messages.gettext("Set label text"),
-                           JOptionPane.PLAIN_MESSAGE,
-                           null,
-                           null,
-                           text);
+                dialogComponent,
+                Messages.gettext("Enter the text"),
+                Messages.gettext("Set label text"),
+                JOptionPane.PLAIN_MESSAGE,
+                null,
+                null,
+                text);
             if (s != null) {
                 String tmp[] = {s};
                 String[] oldText = {text};
@@ -680,24 +678,23 @@ public class Editor {
      * @param polyline Polyline to be inserted in the legend.
      */
     public void onClickInsert(Integer polyline) {
-
         Integer axes = AxesHandler.clickedAxes(figureUid, lastClick);
         if (axes != null) {
             String text = LegendHandler.getLegendText(axes, polyline);
             String s = (String)JOptionPane.showInputDialog(
-                           dialogComponent,
-                           Messages.gettext("Enter the text"),
-                           Messages.gettext("Set legend text"),
-                           JOptionPane.PLAIN_MESSAGE,
-                           null,
-                           null,
-                           text);
-            if (s != null) {
+                dialogComponent,
+                Messages.gettext("Enter the text"),
+                Messages.gettext("Set legend text"),
+                JOptionPane.PLAIN_MESSAGE,
+                null,
+                null,
+                text);
+            if (s != null && !s.equals(text)) {
                 Integer legend = LegendHandler.searchLegend(axes);
                 Integer[] links = LegendHandler.getLinks(legend);
                 String[] texts = LegendHandler.getText(legend);
                 Double[] position = LegendHandler.getPosition(legend);
-                LegendHandler.setLegend(axes, polyline, s);
+                LegendHandler.setLegend(legend, axes, polyline, s);
                 editorHistory.addAction(new ActionLegend(axes, links, texts, position));
             }
         }
@@ -707,7 +704,6 @@ public class Editor {
      * Implements legend remove action(Callback).
      */
     public void onClickRemove() {
-
         Integer axesTo = AxesHandler.clickedAxes(figureUid, lastClick);
         Integer legend = LegendHandler.searchLegend(axesTo);
         Integer[] links = LegendHandler.getLinks(legend);
@@ -738,8 +734,8 @@ public class Editor {
     }
 
     /**
-    * Starts the GED with the property selected by user.
-    */
+     * Starts the GED with the property selected by user.
+     */
     public void onClickGED() {
         if (DatatipManager.getFromUid(figureUid).pickAndHighlight(lastClick[0], lastClick[1])) {
             Inspector.getInspector(DatatipManager.getFromUid(figureUid).getSelectedTip());
@@ -750,22 +746,22 @@ public class Editor {
     }
 
     /**
-    * Implements Undo action(callBAck)
-    */
+     * Implements Undo action(callBAck)
+     */
     public void onClickUndo() {
         editorHistory.undo();
     }
 
     /**
-    * Implements Redo action(callBack)
-    */
+     * Implements Redo action(callBack)
+     */
     public void onClickRedo() {
         editorHistory.redo();
     }
 
     /**
-    * Implementes copyStyle action(callback)
-    */
+     * Implementes copyStyle action(callback)
+     */
     public void onClickCopyStyle() {
 
         Integer axes = AxesHandler.clickedAxes(figureUid, lastClick);
@@ -773,15 +769,15 @@ public class Editor {
     }
 
     /**
-    * Implementes pasteStyle action(callback)
-    */
+     * Implementes pasteStyle action(callback)
+     */
     public void onClickPasteStyle() {
         boolean flag = true;
         Integer axes = AxesHandler.clickedAxes(figureUid, lastClick);
         if (!AxesHandler.isAxesEmpty(axes)) {
             String msg =  "The axes which the style was copied is not in CubeView" +
-                          "\nIf you don't copy the data bounds the view angles can appear different" +
-                          "\nDo you want copy the data bounds too?(it can shrink/stretch the current view)";
+                "\nIf you don't copy the data bounds the view angles can appear different" +
+                "\nDo you want copy the data bounds too?(it can shrink/stretch the current view)";
             int i = JOptionPane.showConfirmDialog(dialogComponent, Messages.gettext(msg), Messages.gettext("Warning"), JOptionPane.YES_NO_OPTION);
 
             if (i == JOptionPane.NO_OPTION) {
index 215b4d4..d299827 100644 (file)
 
 package org.scilab.modules.gui.editor;
 
-import java.util.Arrays;
-import java.util.List;
 import java.util.ArrayList;
+
 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
 import org.scilab.modules.graphic_objects.graphicObject.GraphicObject;
 import org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties;
 
-import org.scilab.modules.gui.editor.ObjectSearcher;
-import org.scilab.modules.gui.editor.PolylineHandler;
-
 
 /**
-* Implements all legend manipulation functions for the editor.
-*
-* @author Caio Souza <caioc2bolado@gmail.com>
-* @author Pedro Souza <bygrandao@gmail.com>
-*
-* @since 2012-06-01
-*/
+ * Implements all legend manipulation functions for the editor.
+ *
+ * @author Caio Souza <caioc2bolado@gmail.com>
+ * @author Pedro Souza <bygrandao@gmail.com>
+ *
+ * @since 2012-06-01
+ */
 public class LegendHandler {
 
     public static Integer searchLegend(Integer uid) {
@@ -56,19 +52,18 @@ public class LegendHandler {
     }
 
     /**
-    * Set or create a legend for one polyline.
-    *
-    * @param axes The axes that will recieve the legend.
-    * @param polyline The polyline to set/create legend.
-    * @param text The text for the legend.
-    */
+     * Set or create a legend for one polyline.
+     *
+     * @param axes The axes that will recieve the legend.
+     * @param polyline The polyline to set/create legend.
+     * @param text The text for the legend.
+     */
 
-    public static void setLegend(Integer axes, Integer polyline, String text) {
-        if (text == null || text == "" || polyline == null || axes == null) {
+    public static void setLegend(Integer legend, Integer axes, Integer polyline, String text) {
+        if (text == null || text == "" || polyline == null || axes == null || legend == null) {
             return;
         }
 
-        Integer legend = searchLegend(axes);
         Integer[] dimension = { 0, 0 };
         ArrayList<String> texts = new ArrayList<String>();
         ArrayList<Integer> links = new ArrayList<Integer>();
@@ -78,15 +73,17 @@ public class LegendHandler {
             Integer[] linksOld = (Integer[])GraphicController.getController().getProperty(legend, GraphicObjectProperties.__GO_LINKS__);
             int length = linksOld.length;
             for (int i = 0; i < length; i++) {
-                if (polyline != linksOld[i]) {
-                    texts.add(textOld[i]);
-                    links.add(linksOld[i]);
-                } else {
-                    removeLegend(axes, polyline);
-                    setLegend(axes, polyline, text);
+                if (linksOld[i].equals(polyline)) {
+                    textOld[length - i - 1] = text;
+                    GraphicController.getController().setProperty(legend, GraphicObjectProperties.__GO_TEXT_STRINGS__, textOld);
                     return;
                 }
             }
+
+            for (Integer i = 0; i < length; i++) {
+                texts.add(textOld[i]);
+                links.add(linksOld[i]);
+            }
             CommonHandler.delete(legend);
         }
         legend = GraphicController.getController().askObject(GraphicObject.getTypeFromName(GraphicObjectProperties.__GO_LEGEND__));
@@ -109,11 +106,11 @@ public class LegendHandler {
     }
 
     /**
-    * Remove a legend from axes.
-    *
-    * @param axes The axes to remove the legend.
-    * @param polyline The polyline that is linked to the legend.
-    */
+     * Remove a legend from axes.
+     *
+     * @param axes The axes to remove the legend.
+     * @param polyline The polyline that is linked to the legend.
+     */
 
     public static void removeLegend(Integer axes, Integer polyline) {
         if (polyline == null || axes == null) {
@@ -161,12 +158,12 @@ public class LegendHandler {
     }
 
     /**
-    * Get the text of the legend.
-    *
-    * @param axes The axes where is the legend.
-    * @param polyline The polyline that is linked to the legend.
-    * @return The text of the legend.
-    */
+     * Get the text of the legend.
+     *
+     * @param axes The axes where is the legend.
+     * @param polyline The polyline that is linked to the legend.
+     * @return The text of the legend.
+     */
 
     public static String getLegendText(Integer axes, Integer polyline) {
         if (polyline != null && axes != null) {
@@ -187,12 +184,12 @@ public class LegendHandler {
     }
 
     /**
-    * Drag the given legend.
-    *
-    * @param legend  the legend uid.
-    * @param position click position (x,y).
-    * @param nextPosition dragged position (x,y).
-    */
+     * Drag the given legend.
+     *
+     * @param legend  the legend uid.
+     * @param position click position (x,y).
+     * @param nextPosition dragged position (x,y).
+     */
 
     public static void dragLegend(Integer legend, Integer[] position, Integer[] nextPosition) {
         ObjectSearcher searcher = new ObjectSearcher();
@@ -219,11 +216,11 @@ public class LegendHandler {
     }
 
     /**
-    * Get the links of a Legend
-    *
-    * @param legend The legend to get the links
-    * @return Links of the legend
-    */
+     * Get the links of a Legend
+     *
+     * @param legend The legend to get the links
+     * @return Links of the legend
+     */
     public static Integer[] getLinks(Integer legend) {
         if (legend == null) {
             return null;
@@ -233,11 +230,11 @@ public class LegendHandler {
     }
 
     /**
-    * Get the text of a Legend
-    *
-    * @param legend The legend to get the text
-    * @return Text of the legend
-    */
+     * Get the text of a Legend
+     *
+     * @param legend The legend to get the text
+     * @return Text of the legend
+     */
     public static String[] getText(Integer legend) {
         if (legend == null) {
             return null;
@@ -247,11 +244,11 @@ public class LegendHandler {
     }
 
     /**
-    * Get the position of a Legend
-    *
-    * @param legend The legend to get the position
-    * @return The legend position
-    */
+     * Get the position of a Legend
+     *
+     * @param legend The legend to get the position
+     * @return The legend position
+     */
     public static Double[] getPosition(Integer legend) {
         if (legend == null) {
             return null;