JAL-2291 ‘Hide Insertions’ now operates on selection or if none available, the sequen...
authorJim Procter <jprocter@issues.jalview.org>
Sun, 4 Jun 2017 09:43:01 +0000 (10:43 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Sun, 4 Jun 2017 09:43:01 +0000 (10:43 +0100)
src/jalview/gui/PopupMenu.java

index 3de7c3c..8f01162 100644 (file)
@@ -57,6 +57,7 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.BitSet;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Hashtable;
@@ -1444,21 +1445,39 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener
 
   protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
   {
-    if (sequence != null)
+    HiddenColumns hidden = ap.av.getAlignment().getHiddenColumns();
+    if (hidden == null)
     {
-      /* ColumnSelection cs = ap.av.getColumnSelection();
-       if (cs == null)
-       {
-         cs = new ColumnSelection();
-       }
-       cs.hideInsertionsFor(sequence);
-       ap.av.setColumnSelection(cs);*/
-
-      HiddenColumns hidden = ap.av.getAlignment().getHiddenColumns();
-      if (hidden == null)
+      hidden = new HiddenColumns();
+    }
+    if (ap.av.getSelectionGroup() != null)
+    {
+      BitSet inserts = new BitSet();
+      inserts.set(0, ap.av.getAlignment().getWidth());
+      ;
+      for (SequenceI sq : ap.av.getSelectionGroup().getSequences())
       {
-        hidden = new HiddenColumns();
+        inserts.and(sq.getInsertionsAsBits());
       }
+      int firstSet = 0, lastSet = 0;
+      do
+      {
+        if (inserts.get(firstSet))
+        {
+          lastSet = inserts.nextClearBit(firstSet) - 1;
+          hidden.hideColumns(firstSet, lastSet);
+          firstSet = lastSet + 1;
+        }
+        else
+        {
+          firstSet = inserts.nextSetBit(firstSet);
+        }
+      } while (firstSet > -1);
+
+    }
+    else
+    if (sequence != null)
+    {
       hidden.hideInsertionsFor(sequence);
       ap.av.getAlignment().setHiddenColumns(hidden);
     }