From: gmungoc Date: Tue, 30 Jun 2015 11:14:45 +0000 (+0100) Subject: JAL-1691 trackpad scrolling goes to full width even with short sequences X-Git-Tag: Release_2_10_0~585^2~11 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=3b1a35f953ef3bcfd8c0dd8a00919212b69ba25d;p=jalview.git JAL-1691 trackpad scrolling goes to full width even with short sequences --- diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index fc889ad..cf82bfe 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -1027,13 +1027,13 @@ public class AlignViewport extends AlignmentViewport implements * is found, the result will be empty. */ SearchResults sr = new SearchResults(); - int seqOffset = findComplementScrollTarget(sr); + int verticalOffset = findComplementScrollTarget(sr); if (!sr.isEmpty()) { // TODO would like next line without cast but needs more refactoring... final AlignmentPanel complementPanel = ((AlignViewport) getCodingComplement()).getAlignPanel(); complementPanel.setFollowingComplementScroll(true); - complementPanel.scrollToCentre(sr, seqOffset); + complementPanel.scrollToCentre(sr, verticalOffset); } } diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 588411e..7228e1b 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -305,7 +305,7 @@ public class AlignmentPanel extends GAlignmentPanel implements */ public boolean scrollToPosition(SearchResults results) { - return scrollToPosition(results, true, false); + return scrollToPosition(results, 0, true, false); } /** @@ -318,7 +318,7 @@ public class AlignmentPanel extends GAlignmentPanel implements */ public boolean scrollToPosition(SearchResults searchResults, boolean redrawOverview) { - return scrollToPosition(searchResults, redrawOverview, false); + return scrollToPosition(searchResults, 0, redrawOverview, false); } /** @@ -326,6 +326,9 @@ public class AlignmentPanel extends GAlignmentPanel implements * (if any) * * @param results + * @param verticalOffset + * if greater than zero, allows scrolling to a position below the + * first displayed sequence * @param redrawOverview * - when set, the overview will be recalculated (takes longer) * @param centre @@ -333,6 +336,7 @@ public class AlignmentPanel extends GAlignmentPanel implements * @return false if results were not found */ public boolean scrollToPosition(SearchResults results, + int verticalOffset, boolean redrawOverview, boolean centre) { int startv, endv, starts, ends; @@ -391,6 +395,12 @@ public class AlignmentPanel extends GAlignmentPanel implements } } } + + /* + * allow for offset of target sequence (actually scroll to one above it) + */ + seqIndex = Math.max(0, seqIndex - verticalOffset); + if (!av.getWrapAlignment()) { if ((startv = av.getStartRes()) >= start) @@ -1727,10 +1737,10 @@ public class AlignmentPanel extends GAlignmentPanel implements * @param sr * holds mapped region(s) of this alignment that we are scrolling * 'to'; may be modified for sequence offset by this method - * @param seqOffset + * @param verticalOffset * the number of visible sequences to show above the mapped region */ - public void scrollToCentre(SearchResults sr, int seqOffset) + public void scrollToCentre(SearchResults sr, int verticalOffset) { /* * To avoid jumpy vertical scrolling (if some sequences are gapped or not @@ -1744,7 +1754,6 @@ public class AlignmentPanel extends GAlignmentPanel implements * This is like AlignmentI.findIndex(seq) but here we are matching the * dataset sequence not the aligned sequence */ - int sequenceIndex = 0; boolean matched = false; for (SequenceI seq : seqs) { @@ -1753,20 +1762,16 @@ public class AlignmentPanel extends GAlignmentPanel implements matched = true; break; } - sequenceIndex++; } if (!matched) { return; // failsafe, shouldn't happen } - sequenceIndex = Math.max(0, sequenceIndex - seqOffset); - sr.getResults().get(0) - .setSequence(av.getAlignment().getSequenceAt(sequenceIndex)); /* * Scroll to position but centring the target residue. */ - scrollToPosition(sr, true, true); + scrollToPosition(sr, verticalOffset, true, true); } /** diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 5617bcf..899e8a7 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -2501,14 +2501,14 @@ public abstract class AlignmentViewport implements AlignViewportI, */ protected int findComplementScrollTarget(SearchResults sr) { - final AlignViewportI codingComplement = getCodingComplement(); - if (codingComplement == null || !codingComplement.isFollowHighlight()) + final AlignViewportI complement = getCodingComplement(); + if (complement == null || !complement.isFollowHighlight()) { return 0; } boolean iAmProtein = !getAlignment().isNucleotide(); AlignmentI proteinAlignment = iAmProtein ? getAlignment() - : codingComplement.getAlignment(); + : complement.getAlignment(); if (proteinAlignment == null) { return 0; @@ -2546,7 +2546,7 @@ public abstract class AlignmentViewport implements AlignViewportI, .findMappingsForSequence(sequence, mappings); if (!seqMappings.isEmpty()) { - break; + break; } }