JAL-2291 use HiddenColumns.hideMarkedBits and take union of selection and sequence...
authorJim Procter <jprocter@issues.jalview.org>
Sun, 4 Jun 2017 11:17:31 +0000 (12:17 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Sun, 4 Jun 2017 11:17:31 +0000 (12:17 +0100)
src/jalview/gui/PopupMenu.java

index 8f01162..c7e3fd9 100644 (file)
@@ -1445,42 +1445,33 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener
 
   protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
   {
-    HiddenColumns hidden = ap.av.getAlignment().getHiddenColumns();
-    if (hidden == null)
-    {
-      hidden = new HiddenColumns();
-    }
+    HiddenColumns hidden = new HiddenColumns();
+    BitSet inserts = new BitSet();
+    inserts.set(0, ap.av.getAlignment().getWidth());
+
+    boolean markedPopup = false;
+    // mark inserts in current selection
     if (ap.av.getSelectionGroup() != null)
     {
-      BitSet inserts = new BitSet();
-      inserts.set(0, ap.av.getAlignment().getWidth());
-      ;
       for (SequenceI sq : ap.av.getSelectionGroup().getSequences())
       {
-        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
+        if (sq == sequence)
         {
-          firstSet = inserts.nextSetBit(firstSet);
+          markedPopup = true;
         }
-      } while (firstSet > -1);
-
+        inserts.and(sq.getInsertionsAsBits());
+      }
     }
-    else
-    if (sequence != null)
+
+    // now mark for sequence under popup if we haven't already done it
+    if (!markedPopup && sequence != null)
     {
-      hidden.hideInsertionsFor(sequence);
-      ap.av.getAlignment().setHiddenColumns(hidden);
+      inserts.and(sequence.getInsertionsAsBits());
     }
+
+    // finally, hide and set hidden columns
+    hidden.hideMarkedBits(inserts);
+    ap.av.getAlignment().setHiddenColumns(hidden);
     refresh();
   }