From c5e7525fa1ce59385fd3e249c2fe4056f4b5371e Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Sun, 4 Jun 2017 10:43:01 +0100 Subject: [PATCH] =?utf8?q?JAL-2291=20=E2=80=98Hide=20Insertions=E2=80=99=20n?= =?utf8?q?ow=20operates=20on=20selection=20or=20if=20none=20available,=20the?= =?utf8?q?=20sequence=20that=20was=20right-clicked=20on.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/jalview/gui/PopupMenu.java | 43 +++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 12 deletions(-) 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); } -- 1.7.10.2