From 6716ff86e500acc2800936b3f3c7132927a9246b Mon Sep 17 00:00:00 2001 From: kiramt Date: Tue, 14 Nov 2017 10:15:46 +0000 Subject: [PATCH] JAL-2831 Added move viewport event and set up cursor code to use it --- src/jalview/gui/AnnotationPanel.java | 4 +++ src/jalview/gui/IdCanvas.java | 4 +++ src/jalview/gui/ScalePanel.java | 3 +- src/jalview/gui/SeqCanvas.java | 6 ++++ src/jalview/gui/SeqPanel.java | 43 ++++++++++++++++++++++------- src/jalview/viewmodel/ViewportRanges.java | 38 ++++++++++++++++++++++++- 6 files changed, 86 insertions(+), 12 deletions(-) diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index ef41047..438e81b 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -1190,5 +1190,9 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, fastPaint(((int[]) evt.getNewValue())[0] - ((int[]) evt.getOldValue())[0]); } + else if (evt.getPropertyName().equals(ViewportRanges.MOVE_VIEWPORT)) + { + repaint(); + } } } diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index 235dea0..085b259 100755 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@ -569,5 +569,9 @@ public class IdCanvas extends JPanel implements ViewportListenerI fastPaint(((int[]) evt.getNewValue())[1] - ((int[]) evt.getOldValue())[1]); } + else if (propertyName.equals(ViewportRanges.MOVE_VIEWPORT)) + { + repaint(); + } } } diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index 2dc198e..798c833 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -550,7 +550,8 @@ public class ScalePanel extends JPanel // 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/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 6919f8a..66739e0 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -1661,6 +1661,12 @@ public class SeqCanvas extends JComponent implements ViewportListenerI repaint(); return; } + else if (eventName.equals(ViewportRanges.MOVE_VIEWPORT)) + { + fastPaint = false; + repaint(); + return; + } int scrollX = 0; if (eventName.equals(ViewportRanges.STARTRES) diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 2223ee5..9a5f6c6 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -320,13 +320,13 @@ public class SeqPanel extends JPanel void setCursorRow() { seqCanvas.cursorY = getKeyboardNo1() - 1; - scrollToVisible(); + scrollToVisible(true); } void setCursorColumn() { seqCanvas.cursorX = getKeyboardNo1() - 1; - scrollToVisible(); + scrollToVisible(true); } void setCursorRowAndColumn() @@ -339,7 +339,7 @@ public class SeqPanel extends JPanel { seqCanvas.cursorX = getKeyboardNo1() - 1; seqCanvas.cursorY = getKeyboardNo2() - 1; - scrollToVisible(); + scrollToVisible(true); } } @@ -348,7 +348,7 @@ public class SeqPanel extends JPanel SequenceI sequence = av.getAlignment().getSequenceAt(seqCanvas.cursorY); seqCanvas.cursorX = sequence.findIndex(getKeyboardNo1()) - 1; - scrollToVisible(); + scrollToVisible(true); } void moveCursor(int dx, int dy) @@ -376,10 +376,16 @@ public class SeqPanel extends JPanel } } - 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) { @@ -400,20 +406,37 @@ public class SeqPanel extends JPanel } 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 { - av.getRanges().scrollToVisible(seqCanvas.cursorX, seqCanvas.cursorY); + if (av.getWrapAlignment()) + { + av.getRanges().scrollToWrappedVisible(seqCanvas.cursorX); + } + else + { + 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) { SequenceI sequence = av.getAlignment().getSequenceAt(seqCanvas.cursorY); diff --git a/src/jalview/viewmodel/ViewportRanges.java b/src/jalview/viewmodel/ViewportRanges.java index 4bdaa81..9a1e13c 100644 --- a/src/jalview/viewmodel/ViewportRanges.java +++ b/src/jalview/viewmodel/ViewportRanges.java @@ -41,6 +41,8 @@ public class ViewportRanges extends ViewportProperties public static final String STARTRESANDSEQ = "startresandseq"; + public static final String MOVE_VIEWPORT = "move_viewport"; + private boolean wrappedMode = false; // start residue of viewport @@ -593,7 +595,7 @@ public class ViewportRanges extends ViewportProperties { scrollUp(false); } - + HiddenColumns hidden = al.getHiddenColumns(); while (x < hidden.adjustForHiddenColumns(startRes)) { @@ -612,6 +614,40 @@ public class ViewportRanges extends ViewportProperties } /** + * Set the viewport location so that a position is visible + * + * @param x + * column to be visible + * @param y + * row to be visible + */ + public boolean setViewportLocation(int x, int y) + { + // if (x,y) is already visible don't do anything + boolean changedLocation = false; + if (startRes > x || x > endRes || startSeq > y && y > endSeq) + { + int width = getViewportWidth(); + int[] oldresvalues = updateStartEndRes(x, x + width - 1); + + int startseq = y; + int height = getViewportHeight(); + if (startseq + height - 1 > getVisibleAlignmentHeight() - 1) + { + startseq = getVisibleAlignmentHeight() - height; + } + int[] oldseqvalues = updateStartEndSeq(startseq, + startseq + height - 1); + + int[] old = new int[] { oldresvalues[0], oldseqvalues[0] }; + int[] newresseq = new int[] { startRes, startSeq }; + changedLocation = true; + changeSupport.firePropertyChange(MOVE_VIEWPORT, old, newresseq); + } + return changedLocation; + } + + /** * Adjust sequence position for page up. Fires a property change event. */ public void pageUp() -- 1.7.10.2