JAL-2291 only hide/show columns intersecting with currently selected region.
authorJim Procter <jprocter@issues.jalview.org>
Sun, 4 Jun 2017 12:18:38 +0000 (13:18 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Sun, 4 Jun 2017 12:18:45 +0000 (13:18 +0100)
src/jalview/gui/PopupMenu.java

index c7e3fd9..9a6c760 100644 (file)
@@ -1445,14 +1445,28 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener
 
   protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
   {
+
     HiddenColumns hidden = new HiddenColumns();
-    BitSet inserts = new BitSet();
-    inserts.set(0, ap.av.getAlignment().getWidth());
+    BitSet inserts = new BitSet(), mask = new BitSet();
+
+    // set mask to preserve existing hidden columns outside selected group
+    if (ap.av.hasHiddenColumns())
+    {
+      ap.av.getAlignment().getHiddenColumns().markHiddenRegions(mask);
+    }
 
     boolean markedPopup = false;
     // mark inserts in current selection
     if (ap.av.getSelectionGroup() != null)
     {
+      // mark just the columns in the selection group to be hidden
+      inserts.set(ap.av.getSelectionGroup().getStartRes(), ap.av
+              .getSelectionGroup().getEndRes() + 1);
+
+      // and clear that part of the mask
+      mask.andNot(inserts);
+
+      // now clear columns without gaps
       for (SequenceI sq : ap.av.getSelectionGroup().getSequences())
       {
         if (sq == sequence)
@@ -1462,6 +1476,14 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener
         inserts.and(sq.getInsertionsAsBits());
       }
     }
+    else
+    {
+      // initially, mark all columns to be hidden
+      inserts.set(0, ap.av.getAlignment().getWidth());
+
+      // and clear out old hidden regions completely
+      mask.clear();
+    }
 
     // now mark for sequence under popup if we haven't already done it
     if (!markedPopup && sequence != null)
@@ -1469,8 +1491,12 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener
       inserts.and(sequence.getInsertionsAsBits());
     }
 
-    // finally, hide and set hidden columns
+    // finally, preserve hidden regions outside selection
+    inserts.or(mask);
+
+    // and set hidden columns accordingly
     hidden.hideMarkedBits(inserts);
+
     ap.av.getAlignment().setHiddenColumns(hidden);
     refresh();
   }