From 0089e3442ccafc1073eff6055ef458745aabce18 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 27 Apr 2015 11:03:48 +0100 Subject: [PATCH] JAL-1691 more stable linked scrolling across split frame (+javadoc) --- src/jalview/gui/AlignmentPanel.java | 6 ++++-- src/jalview/gui/SeqPanel.java | 16 ++++++++++++++-- src/jalview/viewmodel/AlignmentViewport.java | 5 +++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index c7ef3ce..80f568d 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -397,14 +397,16 @@ public class AlignmentPanel extends GAlignmentPanel implements /* * Scroll left to make start of search results visible */ - setScrollValues(start - 1, seqIndex); + // setScrollValues(start - 1, seqIndex); // plus one residue + setScrollValues(start, seqIndex); } else if ((endv = av.getEndRes()) <= end) { /* * Scroll right to make end of search results visible */ - setScrollValues(startv + 1 + end - endv, seqIndex); + // setScrollValues(startv + 1 + end - endv, seqIndex); // plus one + setScrollValues(startv + end - endv, seqIndex); } else if ((starts = av.getStartSeq()) > seqIndex) { diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 791a371..e34a864 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -167,6 +167,13 @@ public class SeqPanel extends JPanel implements MouseListener, int wrappedBlock = -1; + /** + * Returns the aligned sequence position (base 0) at the mouse position, or + * the closest visible one + * + * @param evt + * @return + */ int findRes(MouseEvent evt) { int res = 0; @@ -203,13 +210,18 @@ public class SeqPanel extends JPanel implements MouseListener, } else { - if (x > seqCanvas.getWidth() + seqCanvas.getWidth()) + if (x > seqCanvas.getX() + seqCanvas.getWidth()) { // make sure we calculate relative to visible alignment, rather than // right-hand gutter x = seqCanvas.getX() + seqCanvas.getWidth(); } res = (x / av.getCharWidth()) + av.getStartRes(); + if (res > av.getEndRes()) + { + // moused off right + res = av.getEndRes(); + } } if (av.hasHiddenColumns()) @@ -650,7 +662,7 @@ public class SeqPanel extends JPanel implements MouseListener, if (av.isFollowHighlight()) { /* - * if scrollToPosition requires scroll adjustment, this flag prevents + * if scrollToPosition requires a scroll adjustment, this flag prevents * another scroll event being propagated back to the originator * * @see AlignmentPanel#adjustmentValueChanged diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index d6aa400..d8ade26 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -2549,6 +2549,11 @@ public abstract class AlignmentViewport implements AlignViewportI, */ int seqOffset = 0; SequenceI sequence = null; + + /* + * locate 'middle' column (true middle if an odd number visible, left of + * middle if an even number visible) + */ int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2; final HiddenSequences hiddenSequences = getAlignment() .getHiddenSequences(); -- 1.7.10.2