Merge branch 'develop' into features/JAL-2446NCList
[jalview.git] / src / jalview / gui / FeatureRenderer.java
index 0779760..ac56590 100644 (file)
@@ -43,7 +43,6 @@ 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;
@@ -200,7 +199,7 @@ public class FeatureRenderer extends
           if (col != null)
           {
             fcol = new FeatureColour(col);
-            updateColourButton(mainPanel, colour, new FeatureColour(col));
+            updateColourButton(mainPanel, colour, fcol);
           }
         }
         else
@@ -358,7 +357,7 @@ public class FeatureRenderer extends
     end.setValue(new Integer(firstFeature.getEnd()));
     description.setText(firstFeature.getDescription());
     updateColourButton(mainPanel, colour,
-            (oldcol = fcol = getFeatureStyle(name.getText())));
+            (oldcol = fcol = getFeatureStyle(featureType)));
     Object[] options;
     if (!create)
     {
@@ -387,15 +386,19 @@ public class FeatureRenderer extends
 
     FeaturesFile ffile = new FeaturesFile();
 
-    if (reply == JvOptionPane.OK_OPTION && name.getText().length() > 0)
+    final String enteredType = name.getText().trim();
+    final String enteredGroup = group.getText().trim();
+    final String enteredDescription = description.getText().replaceAll("\n", " ");
+
+    if (reply == JvOptionPane.OK_OPTION && enteredType.length() > 0)
     {
       /*
        * update default values only if creating using default values
        */
       if (useLastDefaults)
       {
-        lastFeatureAdded = name.getText().trim();
-        lastFeatureGroupAdded = group.getText().trim();
+        lastFeatureAdded = enteredType;
+        lastFeatureGroupAdded = enteredGroup;
         // TODO: determine if the null feature group is valid
         if (lastFeatureGroupAdded.length() < 1)
         {
@@ -421,16 +424,14 @@ public class FeatureRenderer extends
       {
         /*
          * YES_OPTION corresponds to the Amend button
-         * need to refresh Feature Settings if type, group or colour changed
+         * need to refresh Feature Settings if type, group or colour changed;
+         * note we don't force the feature to be visible - the user has been
+         * warned if a hidden feature type or group was entered
          */
-        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));
+        boolean refreshSettings = (!featureType.equals(enteredType) || !featureGroup
+                .equals(enteredGroup));
         refreshSettings |= (fcol != oldcol);
-        setColour(newType, fcol);
-/*?*/        getFeaturesDisplayed().setVisible(newType);
+        setColour(enteredType, fcol);
         int newBegin = sf.begin;
         int newEnd = sf.end;
         try
@@ -447,24 +448,11 @@ public class FeatureRenderer extends
          * (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);
-        }
+        SequenceFeature newSf = new SequenceFeature(sf, newBegin, newEnd,
+                enteredGroup, sf.getScore());
+        sf.setDescription(enteredDescription);
         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
+        // amend features dialog only updates one sequence at a time
         sequences.get(0).addSequenceFeature(newSf);
 
         if (refreshSettings)
@@ -476,20 +464,19 @@ public class FeatureRenderer extends
     else
     // NEW FEATURES ADDED
     {
-      if (reply == JvOptionPane.OK_OPTION && lastFeatureAdded.length() > 0)
+      if (reply == JvOptionPane.OK_OPTION && enteredType.length() > 0)
       {
         for (int i = 0; i < sequences.size(); i++)
         {
           SequenceFeature sf = features.get(i);
-          sf.type = name.getText().trim();
-          // fix for JAL-1538 - always set feature group here
-          sf.featureGroup = group.getText().trim();
-          sf.description = description.getText().replaceAll("\n", " ");
-          sequences.get(i).addSequenceFeature(sf);
-          ffile.parseDescriptionHTML(sf, false);
+          SequenceFeature sf2 = new SequenceFeature(enteredType,
+                  enteredDescription, sf.getBegin(), sf.getEnd(),
+                  enteredGroup);
+          ffile.parseDescriptionHTML(sf2, false);
+          sequences.get(i).addSequenceFeature(sf2);
         }
 
-        setColour(lastFeatureAdded, fcol);
+        setColour(enteredType, fcol);
 
         featuresAdded();