Merge branch 'develop' into features/JAL-2446NCList
[jalview.git] / src / jalview / gui / FeatureRenderer.java
index 2f12eef..0779760 100644 (file)
@@ -43,6 +43,7 @@ import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.util.Arrays;
 import java.util.Comparator;
+import java.util.HashMap;
 import java.util.List;
 
 import javax.swing.JColorChooser;
@@ -422,24 +423,50 @@ public class FeatureRenderer extends
          * YES_OPTION corresponds to the Amend button
          * need to refresh Feature Settings if type, group or colour changed
          */
-        sf.type = name.getText().trim();
-        sf.featureGroup = group.getText().trim();
-        sf.description = description.getText().replaceAll("\n", " ");
+        String newType = name.getText().trim();
+        String newFeatureGroup = group.getText().trim();
+        String newDescription = description.getText().replaceAll("\n", " ");
         boolean refreshSettings = (!featureType.equals(sf.type) || !featureGroup
                 .equals(sf.featureGroup));
         refreshSettings |= (fcol != oldcol);
-
-        setColour(sf.type, fcol);
-
+        setColour(newType, fcol);
+/*?*/        getFeaturesDisplayed().setVisible(newType);
+        int newBegin = sf.begin;
+        int newEnd = sf.end;
         try
         {
-          sf.begin = ((Integer) start.getValue()).intValue();
-          sf.end = ((Integer) end.getValue()).intValue();
+          newBegin = ((Integer) start.getValue()).intValue();
+          newEnd = ((Integer) end.getValue()).intValue();
         } catch (NumberFormatException ex)
         {
+          // JSpinner doesn't accept invalid format data :-)
+        }
+
+        /*
+         * replace the feature by deleting it and adding a new one
+         * (to ensure integrity of SequenceFeatures data store)
+         */
+        sequences.get(0).deleteFeature(sf);
+        SequenceFeature newSf = new SequenceFeature(newType,
+                newDescription, newBegin, newEnd, sf.getScore(),
+                newFeatureGroup);
+        // ensure any additional properties are copied
+        if (sf.otherDetails != null)
+        {
+          newSf.otherDetails = new HashMap<String, Object>(sf.otherDetails);
+        }
+        ffile.parseDescriptionHTML(newSf, false);
+        // add any additional links not parsed from description
+        if (sf.links != null)
+        {
+          for (String link : sf.links)
+          {
+            newSf.addLink(link);
+          }
         }
+        // amend features only gets one sequence to act on
+        sequences.get(0).addSequenceFeature(newSf);
 
-        ffile.parseDescriptionHTML(sf, false);
         if (refreshSettings)
         {
           featuresAdded();