From: Jim Procter Date: Sun, 4 Jun 2017 09:43:01 +0000 (+0100) Subject: JAL-2291 ‘Hide Insertions’ now operates on selection or if none available, the sequen... X-Git-Tag: Release_2_10_2~3^2~37 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=c5e7525fa1ce59385fd3e249c2fe4056f4b5371e;p=jalview.git JAL-2291 ‘Hide Insertions’ now operates on selection or if none available, the sequence that was right-clicked on. --- diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 3de7c3c..8f01162 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -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); }