From 4650bd5a0ce2b7ef07bd91baa591fa5d0cadef4c Mon Sep 17 00:00:00 2001 From: kiramt Date: Wed, 15 Nov 2017 08:47:47 +0000 Subject: [PATCH] JAL-2831 ported to applet --- src/jalview/appletgui/AnnotationPanel.java | 4 ++ src/jalview/appletgui/IdCanvas.java | 4 ++ src/jalview/appletgui/ScalePanel.java | 3 +- src/jalview/appletgui/SeqCanvas.java | 16 +++++++- src/jalview/appletgui/SeqPanel.java | 61 +++++++++++++--------------- 5 files changed, 52 insertions(+), 36 deletions(-) diff --git a/src/jalview/appletgui/AnnotationPanel.java b/src/jalview/appletgui/AnnotationPanel.java index 2b2fdea..50a9e33 100755 --- a/src/jalview/appletgui/AnnotationPanel.java +++ b/src/jalview/appletgui/AnnotationPanel.java @@ -783,5 +783,9 @@ public class AnnotationPanel extends Panel fastPaint(((int[]) evt.getNewValue())[0] - ((int[]) evt.getOldValue())[0]); } + else if (evt.getPropertyName().equals(ViewportRanges.MOVE_VIEWPORT)) + { + repaint(); + } } } diff --git a/src/jalview/appletgui/IdCanvas.java b/src/jalview/appletgui/IdCanvas.java index dc906f4..f5ea12e 100755 --- a/src/jalview/appletgui/IdCanvas.java +++ b/src/jalview/appletgui/IdCanvas.java @@ -453,5 +453,9 @@ public class IdCanvas extends Panel implements ViewportListenerI fastPaint(((int[]) evt.getNewValue())[1] - ((int[]) evt.getOldValue())[1]); } + else if (propertyName.equals(ViewportRanges.MOVE_VIEWPORT)) + { + repaint(); + } } } diff --git a/src/jalview/appletgui/ScalePanel.java b/src/jalview/appletgui/ScalePanel.java index 75d4040..04fb22b 100755 --- a/src/jalview/appletgui/ScalePanel.java +++ b/src/jalview/appletgui/ScalePanel.java @@ -469,7 +469,8 @@ public class ScalePanel extends Panel // paint, so scroll events are identified as changes to the horizontal or // vertical start value. if (evt.getPropertyName().equals(ViewportRanges.STARTRES) - || evt.getPropertyName().equals(ViewportRanges.STARTRESANDSEQ)) + || evt.getPropertyName().equals(ViewportRanges.STARTRESANDSEQ) + || evt.getPropertyName().equals(ViewportRanges.MOVE_VIEWPORT)) { // scroll event, repaint panel repaint(); diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index ef47f75..2420cf7 100755 --- a/src/jalview/appletgui/SeqCanvas.java +++ b/src/jalview/appletgui/SeqCanvas.java @@ -889,6 +889,19 @@ public class SeqCanvas extends Panel implements ViewportListenerI { String eventName = evt.getPropertyName(); + if (eventName.equals(SequenceGroup.SEQ_GROUP_CHANGED)) + { + fastPaint = true; + repaint(); + return; + } + else if (eventName.equals(ViewportRanges.MOVE_VIEWPORT)) + { + fastPaint = false; + repaint(); + return; + } + if (!av.getWrapAlignment()) { int scrollX = 0; @@ -935,8 +948,7 @@ public class SeqCanvas extends Panel implements ViewportListenerI } else if (eventName.equals(ViewportRanges.STARTRESANDSEQ)) { - fastPaint(scrollX, ((int[]) evt.getNewValue())[1] - - ((int[]) evt.getOldValue())[1]); + fastPaint(scrollX, 0); } } } diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index 9a61f5f..d74bbb7 100644 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -43,7 +43,6 @@ import jalview.util.Comparison; import jalview.util.MappingUtils; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; -import jalview.viewmodel.ViewportRanges; import java.awt.BorderLayout; import java.awt.Font; @@ -148,13 +147,13 @@ public class SeqPanel extends Panel implements MouseMotionListener, void setCursorRow() { seqCanvas.cursorY = getKeyboardNo1() - 1; - scrollToVisible(); + scrollToVisible(true); } void setCursorColumn() { seqCanvas.cursorX = getKeyboardNo1() - 1; - scrollToVisible(); + scrollToVisible(true); } void setCursorRowAndColumn() @@ -167,7 +166,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, { seqCanvas.cursorX = getKeyboardNo1() - 1; seqCanvas.cursorY = getKeyboardNo2() - 1; - scrollToVisible(); + scrollToVisible(true); } } @@ -176,7 +175,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, SequenceI sequence = av.getAlignment().getSequenceAt(seqCanvas.cursorY); seqCanvas.cursorX = sequence.findIndex(getKeyboardNo1()) - 1; - scrollToVisible(); + scrollToVisible(true); } void moveCursor(int dx, int dy) @@ -202,10 +201,16 @@ public class SeqPanel extends Panel implements MouseMotionListener, seqCanvas.cursorX = original; } } - scrollToVisible(); + scrollToVisible(false); } - void scrollToVisible() + /** + * Scroll to make the cursor visible in the viewport. + * + * @param jump + * just jump to the location rather than scrolling + */ + void scrollToVisible(boolean jump) { if (seqCanvas.cursorX < 0) { @@ -226,44 +231,34 @@ public class SeqPanel extends Panel implements MouseMotionListener, } endEditing(); - if (av.getWrapAlignment()) + + boolean repaintNeeded = true; + if (jump) { - av.getRanges().scrollToWrappedVisible(seqCanvas.cursorX); + // only need to repaint if the viewport did not move, as otherwise it will + // get a repaint + repaintNeeded = !av.getRanges().setViewportLocation(seqCanvas.cursorX, + seqCanvas.cursorY); } else { - ViewportRanges ranges = av.getRanges(); - HiddenColumns hidden = av.getAlignment().getHiddenColumns(); - while (seqCanvas.cursorY < ranges.getStartSeq()) + if (av.getWrapAlignment()) { - ranges.scrollUp(true); + av.getRanges().scrollToWrappedVisible(seqCanvas.cursorX); } - while (seqCanvas.cursorY > ranges.getEndSeq()) - { - ranges.scrollUp(false); - } - while (seqCanvas.cursorX < hidden - .adjustForHiddenColumns(ranges.getStartRes())) - { - - if (!ranges.scrollRight(false)) - { - break; - } - } - while (seqCanvas.cursorX > hidden - .adjustForHiddenColumns(ranges.getEndRes())) + else { - if (!ranges.scrollRight(true)) - { - break; - } + av.getRanges().scrollToVisible(seqCanvas.cursorX, + seqCanvas.cursorY); } } setStatusMessage(av.getAlignment().getSequenceAt(seqCanvas.cursorY), seqCanvas.cursorX, seqCanvas.cursorY); - seqCanvas.repaint(); + if (repaintNeeded) + { + seqCanvas.repaint(); + } } void setSelectionAreaAtCursor(boolean topLeft) -- 1.7.10.2