JAL-2658 ensure features dropdown entries are unique
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 10 Aug 2017 09:10:51 +0000 (10:10 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 10 Aug 2017 09:10:51 +0000 (10:10 +0100)
src/jalview/gui/FeatureRenderer.java

index 6f6bc02..4d82d7e 100644 (file)
@@ -41,6 +41,7 @@ import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Comparator;
 import java.util.List;
@@ -234,8 +235,9 @@ public class FeatureRenderer extends
     if (!create && features.size() > 1)
     {
       /*
-       * more than one feature at selected position - add a drop-down
-       * to choose the feature to amend
+       * more than one feature at selected position - 
+       * add a drop-down to choose the feature to amend
+       * space pad text if necessary to make entries distinct
        */
       gridPanel = new JPanel(new GridLayout(4, 1));
       JPanel choosePanel = new JPanel();
@@ -243,11 +245,17 @@ public class FeatureRenderer extends
               .getString("label.select_feature")
               + ":"));
       final JComboBox<String> overlaps = new JComboBox<String>();
+      List<String> added = new ArrayList<>();
       for (SequenceFeature sf : features)
       {
-        String text = sf.getType() + "/" + sf.getBegin() + "-"
-                + sf.getEnd() + " (" + sf.getFeatureGroup() + ")";
+        String text = String.format("%s/%d-%d (%s)", sf.getType(),
+                sf.getBegin(), sf.getEnd(), sf.getFeatureGroup());
+        while (added.contains(text))
+        {
+          text += " ";
+        }
         overlaps.addItem(text);
+        added.add(text);
       }
       choosePanel.add(overlaps);