From d3792892a182540d35193a6aa93072197955e2a5 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 15 May 2017 16:55:54 +0100 Subject: [PATCH] JAL-2532 new feature types and colour changes from Amend Features retained after Cancel in Feature Settings --- src/jalview/gui/FeatureRenderer.java | 5 +-- src/jalview/gui/FeatureSettings.java | 66 ++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/src/jalview/gui/FeatureRenderer.java b/src/jalview/gui/FeatureRenderer.java index 7be3e51..0921a48 100644 --- a/src/jalview/gui/FeatureRenderer.java +++ b/src/jalview/gui/FeatureRenderer.java @@ -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(); } diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 67bfb79..34f0b4a 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -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 + * + * + * @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. -- 1.7.10.2