From c8ce35475df2851ea907283d3ec6b841b7fd05fa Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Fri, 14 Sep 2018 12:31:24 +0100 Subject: [PATCH] =?utf8?q?JAL-345=20view=20controller=20method=20to=20select?= =?utf8?q?=20highlighted=20sequences=20(note=20-=20doesn=E2=80=99t=20select=20?= =?utf8?q?sequences=20which=20contain=20search=20results,=20just=20ID=20high?= =?utf8?q?lights)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/jalview/controller/AlignViewController.java | 83 +++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/src/jalview/controller/AlignViewController.java b/src/jalview/controller/AlignViewController.java index d992e4e..13b84ef 100644 --- a/src/jalview/controller/AlignViewController.java +++ b/src/jalview/controller/AlignViewController.java @@ -38,6 +38,7 @@ import jalview.io.FeaturesFile; import jalview.util.MessageManager; import java.awt.Color; +import java.util.ArrayList; import java.util.BitSet; import java.util.List; @@ -383,6 +384,88 @@ public class AlignViewController implements AlignViewControllerI } + /** + * + * Add highlighted sequences to selected rows. Exclude highlighted sequences + * from selected rows. toggle inclusion or exclusion of highlighted sequences. + * or add/exclude/toggle for sequences not highlighted. + * + * @param invert + * - when true, sequences that are not highlighted are used to modify + * selection + * @param extendCurrent + * - normally true , the current selected group is modified. + * @param toggle + * - if a select + * @return + */ + public boolean selectHighlightedSequences(boolean invert, + boolean extendCurrent, boolean toggle) + { + List results = alignPanel.getAlignViewport() + .getHighlightedSeqs(); + + SequenceGroup sq = (extendCurrent + && viewport.getSelectionGroup() != null) + ? viewport.getSelectionGroup() + : new SequenceGroup(); + + if (invert) + { + List nothighlighted = new ArrayList(); + for (SequenceI seq : alignPanel.getAlignViewport().getAlignment() + .getSequences()) + { + if (!results.contains(seq)) + { + nothighlighted.add(seq); + } + } + results = nothighlighted; + } + + if (results == null || results.size() == 0) + { + // do nothing if no selection exists + // unless toggle ?? + return false; + } + + boolean changed = false; + + for (SequenceI seq : results) + { + int size = sq.getSize(); + if (toggle) + { + sq.addOrRemove(seq, false); + } + else + { + sq.addSequence(seq, false); + } + changed |= size != sq.getSize(); + } + + if (sq.getSize() == 0) + { + viewport.setSelectionGroup(null); + } + else + { + if (sq != viewport.getSelectionGroup()) + { + sq.setStartRes(0); + sq.setEndRes(viewport.getRanges().getAbsoluteAlignmentWidth()); + } + viewport.setSelectionGroup(sq); + } + + alignPanel.paintAlignment(false, false); + + return changed; + } + @Override public boolean markHighlightedColumns(boolean invert, boolean extendCurrent, boolean toggle) -- 1.7.10.2