JAL-2532 new feature types and colour changes from Amend Features
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 15 May 2017 15:55:54 +0000 (16:55 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 15 May 2017 15:55:54 +0000 (16:55 +0100)
retained after Cancel in Feature Settings

src/jalview/gui/FeatureRenderer.java
src/jalview/gui/FeatureSettings.java

index 7be3e51..0921a48 100644 (file)
@@ -450,8 +450,9 @@ public class FeatureRenderer extends
         /*
          * YES_OPTION corresponds to the Amend button
          */
-        boolean typeOrGroupChanged = (!lastFeatureAdded.equals(sf.type) || !lastFeatureGroupAdded
+        boolean refreshSettings = (!lastFeatureAdded.equals(sf.type) || !lastFeatureGroupAdded
                 .equals(sf.featureGroup));
+        refreshSettings |= (fcol != oldcol);
         sf.type = lastFeatureAdded;
         sf.featureGroup = lastFeatureGroupAdded;
         sf.description = lastDescriptionAdded;
@@ -467,7 +468,7 @@ public class FeatureRenderer extends
         }
 
         ffile.parseDescriptionHTML(sf, false);
-        if (typeOrGroupChanged)
+        if (refreshSettings)
         {
           featuresAdded();
         }
index 67bfb79..34f0b4a 100644 (file)
@@ -704,6 +704,10 @@ public class FeatureSettings extends JPanel implements
         System.arraycopy(data[i], 0, originalData[i], 0, 3);
       }
     }
+    else
+    {
+      updateOriginalData(data);
+    }
 
     table.setModel(new FeatureTableModel(data));
     table.getColumnModel().getColumn(0).setPreferredWidth(200);
@@ -718,6 +722,68 @@ public class FeatureSettings extends JPanel implements
   }
 
   /**
+   * Updates 'originalData' (used for restore on Cancel) if we detect that
+   * changes have been made outwith this dialog
+   * <ul>
+   * <li>a new feature type added (and made visible)</li>
+   * <li>a feature colour changed (in the Amend Features dialog)</li>
+   * </ul>
+   * 
+   * @param foundData
+   */
+  protected void updateOriginalData(Object[][] foundData)
+  {
+    // todo LinkedHashMap instead of Object[][] would be nice
+
+    Object[][] currentData = ((FeatureTableModel) table.getModel())
+            .getData();
+    for (Object[] row : foundData)
+    {
+      String type = (String) row[0];
+      boolean found = false;
+      for (Object[] current : currentData)
+      {
+        if (type.equals(current[0]))
+        {
+          found = true;
+          /*
+           * currently dependent on object equality here;
+           * really need an equals method on FeatureColour
+           */
+          if (!row[1].equals(current[1]))
+          {
+            /*
+             * feature colour has changed externally - update originalData
+             */
+            for (Object[] original : originalData)
+            {
+              if (type.equals(original[0]))
+              {
+                original[1] = row[1];
+                break;
+              }
+            }
+          }
+          break;
+        }
+      }
+      if (!found)
+      {
+        /*
+         * new feature detected - add to original data (on top)
+         */
+        Object[][] newData = new Object[originalData.length + 1][3];
+        for (int i = 0; i < originalData.length; i++)
+        {
+          System.arraycopy(originalData[i], 0, newData[i + 1], 0, 3);
+        }
+        newData[0] = row;
+        originalData = newData;
+      }
+    }
+  }
+
+  /**
    * Remove from the groups panel any checkboxes for groups that are not in the
    * foundGroups set. This enables removing a group from the display when the
    * last feature in that group is deleted.