JAL-2505 updates after conflicting merge of JAL-2504
[jalview.git] / src / jalview / appletgui / FeatureRenderer.java
index 38ecf76..81b207f 100644 (file)
@@ -394,11 +394,14 @@ public class FeatureRenderer extends
     /*
      * only update default type and group if we used defaults
      */
-    String enteredType = name.getText().trim();
+    final String enteredType = name.getText().trim();
+    final String enteredGroup = group.getText().trim();
+    final String enteredDesc = description.getText().replace('\n', ' ');
+
     if (dialog.accept && useLastDefaults)
     {
       lastFeatureAdded = enteredType;
-      lastFeatureGroupAdded = group.getText().trim();
+      lastFeatureGroupAdded = enteredGroup;
     }
 
     if (!create)
@@ -406,26 +409,33 @@ public class FeatureRenderer extends
       SequenceFeature sf = features[featureIndex];
       if (dialog.accept)
       {
-        sf.type = enteredType;
-        sf.featureGroup = group.getText().trim();
-        if (sf.featureGroup != null && sf.featureGroup.length() < 1)
-        {
-          sf.featureGroup = null;
-        }
-        sf.description = description.getText().replace('\n', ' ');
         if (!colourPanel.isGcol)
         {
           // update colour - otherwise its already done.
           setColour(sf.type, new FeatureColour(colourPanel.getBackground()));
         }
+        int newBegin = sf.begin;
+        int newEnd = sf.end;
         try
         {
-          sf.begin = Integer.parseInt(start.getText());
-          sf.end = Integer.parseInt(end.getText());
+          newBegin = Integer.parseInt(start.getText());
+          newEnd = Integer.parseInt(end.getText());
         } catch (NumberFormatException ex)
         {
-          //
+          // 
         }
+
+        /*
+         * replace the feature by deleting it and adding a new one
+         * (to ensure integrity of SequenceFeatures data store)
+         */
+        sequences[0].deleteFeature(sf);
+        SequenceFeature newSf = new SequenceFeature(sf, newBegin, newEnd,
+                enteredGroup);
+        newSf.setDescription(enteredDesc);
+        ffile.parseDescriptionHTML(newSf, false);
+        // amend features dialog only updates one sequence at a time
+        sequences[0].addSequenceFeature(newSf);
         boolean typeOrGroupChanged = (!featureType.equals(sf.type) || !featureGroup
                 .equals(sf.featureGroup));
 
@@ -451,12 +461,12 @@ public class FeatureRenderer extends
       {
         for (int i = 0; i < sequences.length; i++)
         {
-          features[i].type = enteredType;
-          features[i].featureGroup = group.getText().trim();
-          features[i].description = description.getText()
-                  .replace('\n', ' ');
-          sequences[i].addSequenceFeature(features[i]);
-          ffile.parseDescriptionHTML(features[i], false);
+          SequenceFeature sf = features[i];
+          SequenceFeature sf2 = new SequenceFeature(enteredType,
+                  enteredDesc, sf.getBegin(), sf.getEnd(), Float.NaN,
+                  enteredGroup);
+          ffile.parseDescriptionHTML(sf2, false);
+          sequences[i].addSequenceFeature(sf2);
         }
 
         Color newColour = colourPanel.getBackground();