From: gmungoc Date: Wed, 9 Jan 2019 16:31:20 +0000 (+0000) Subject: JAL-3184 restore group visibility on Cancel in Feature Settings X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8ac25f08dacd4759548f62332004288b0e86fdee;p=jalview.git JAL-3184 restore group visibility on Cancel in Feature Settings --- diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 1358c8f..c310c47 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -62,6 +62,7 @@ import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; +import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; @@ -135,6 +136,10 @@ public class FeatureSettings extends JPanel private Map originalFilters; + private List originalVisibleGroups; + + private List originalHiddenGroups; + final JInternalFrame frame; JScrollPane scrollPane = new JScrollPane(); @@ -187,6 +192,10 @@ public class FeatureSettings extends JPanel originalFilters = new HashMap<>(fr.getFeatureFilters()); // shallow copy + originalVisibleGroups = new ArrayList<>(fr.getGroups(true)); + + originalHiddenGroups = new ArrayList<>(fr.getGroups(false)); + try { jbInit(); @@ -1236,10 +1245,7 @@ public class FeatureSettings extends JPanel @Override public void actionPerformed(ActionEvent e) { - fr.setTransparency(originalTransparency); - fr.setFeatureFilters(originalFilters); - updateFeatureRenderer(originalData); - close(); + cancel(); } }); @@ -1321,6 +1327,22 @@ public class FeatureSettings extends JPanel this.add(settingsPane); } + /** + * Restores feature type and group visibility, and any filters and + * transparency setting, to the values when this dialog was opened. Note this + * won't affect any feature types or groups which were added while the dialog + * was open. + */ + void cancel() + { + fr.setTransparency(originalTransparency); + fr.setFeatureFilters(originalFilters); + fr.setGroupVisibility(originalVisibleGroups, true); + fr.setGroupVisibility(originalHiddenGroups, false); + updateFeatureRenderer(originalData); + close(); + } + // /////////////////////////////////////////////////////////////////////// // http://java.sun.com/docs/books/tutorial/uiswing/components/table.html // /////////////////////////////////////////////////////////////////////// diff --git a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java index 553f813..186b57b 100644 --- a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java +++ b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java @@ -43,6 +43,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -859,30 +860,27 @@ public abstract class FeatureRendererModel } /** - * get visible or invisible groups + * Answers a (possibly empty) list of visible or invisible feature groups * * @param visible - * true to return visible groups, false to return hidden ones. - * @return list of groups + * true to return visible groups, false to return hidden ones + * @return */ @Override public List getGroups(boolean visible) { + List groups = new ArrayList<>(); if (featureGroups != null) { - List gp = new ArrayList<>(); - - for (String grp : featureGroups.keySet()) + for (Entry grp : featureGroups.entrySet()) { - Boolean state = featureGroups.get(grp); - if (state.booleanValue() == visible) + if (grp.getValue() == visible) { - gp.add(grp); + groups.add(grp.getKey()); } } - return gp; } - return null; + return groups; } @Override