From 4aba828c0082348bc73c82a5ba0d901f7a181413 Mon Sep 17 00:00:00 2001 From: kiramt Date: Fri, 12 May 2017 09:39:19 +0100 Subject: [PATCH] JAL-2491 Added adjustment methods to be called directly --- src/jalview/appletgui/AlignmentPanel.java | 150 ++++++++++++----------------- 1 file changed, 62 insertions(+), 88 deletions(-) diff --git a/src/jalview/appletgui/AlignmentPanel.java b/src/jalview/appletgui/AlignmentPanel.java index 842841b..4ecf05f 100644 --- a/src/jalview/appletgui/AlignmentPanel.java +++ b/src/jalview/appletgui/AlignmentPanel.java @@ -733,6 +733,11 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, hscroll.setValues(x, hextent, 0, width); vscroll.setValues(y, vextent, 0, height); + // AWT scrollbar does not fire adjustmentValueChanged for setValues + // so also call adjustment code! + adjustHorizontal(x); + adjustVertical(y); + sendViewPosition(); } } @@ -740,120 +745,89 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, @Override public void adjustmentValueChanged(AdjustmentEvent evt) { - int oldX = vpRanges.getStartRes(); - int oldwidth = vpRanges.getViewportWidth(); - int oldY = vpRanges.getStartSeq(); - int oldheight = vpRanges.getViewportHeight(); - if (evt == null || evt.getSource() == apvscroll) { annotationPanel.setScrollOffset(apvscroll.getValue(), false); alabels.setScrollOffset(apvscroll.getValue(), false); - // annotationPanel.image=null; - // alabels.image=null; - // alabels.repaint(); - // annotationPanel.repaint(); } if (evt == null || evt.getSource() == hscroll) { int x = hscroll.getValue(); - int width = seqPanel.seqCanvas.getWidth() / av.getCharWidth(); + adjustHorizontal(x); + } + + if (evt == null || evt.getSource() == vscroll) + { + int offy = vscroll.getValue(); + adjustVertical(offy); + } + + } + + private void adjustHorizontal(int x) + { + int oldX = vpRanges.getStartRes(); + int oldwidth = vpRanges.getViewportWidth(); + int width = seqPanel.seqCanvas.getWidth() / av.getCharWidth(); + + // if we're scrolling to the position we're already at, stop + // this prevents infinite recursion of events when the scroll/viewport + // ranges values are the same + if ((x == oldX) && (width == oldwidth)) + { + return; + } + vpRanges.setViewportStartAndWidth(x, width); + + if (av.getWrapAlignment() || !fastPaint || av.MAC) + { + repaint(); + } + sendViewPosition(); + } + + private void adjustVertical(int offy) + { + int oldX = vpRanges.getStartRes(); + int oldwidth = vpRanges.getViewportWidth(); + int oldY = vpRanges.getStartSeq(); + int oldheight = vpRanges.getViewportHeight(); + + if (av.getWrapAlignment()) + { + int rowSize = seqPanel.seqCanvas + .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()); // if we're scrolling to the position we're already at, stop // this prevents infinite recursion of events when the scroll/viewport // ranges values are the same - if ((x == oldX) && (width == oldwidth)) + if ((offy * rowSize == oldX) && (oldwidth == rowSize)) { return; } - vpRanges.setViewportStartAndWidth(x, width); + else if (offy > -1) + { + vpRanges.setViewportStartAndWidth(offy * rowSize, rowSize); + } } - - if (evt == null || evt.getSource() == vscroll) + else { - int offy = vscroll.getValue(); - if (av.getWrapAlignment()) - { - int rowSize = seqPanel.seqCanvas - .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()); + int height = seqPanel.seqCanvas.getHeight() / av.getCharHeight(); - // if we're scrolling to the position we're already at, stop - // this prevents infinite recursion of events when the scroll/viewport - // ranges values are the same - if ((offy * rowSize == oldX) && (oldwidth == rowSize)) - { - return; - } - else if (offy > -1) - { - vpRanges.setViewportStartAndWidth(offy * rowSize, rowSize); - } - } - else + // if we're scrolling to the position we're already at, stop + // this prevents infinite recursion of events when the scroll/viewport + // ranges values are the same + if ((offy == oldY) && (height == oldheight)) { - int height = seqPanel.seqCanvas.getHeight() / av.getCharHeight(); - - // if we're scrolling to the position we're already at, stop - // this prevents infinite recursion of events when the scroll/viewport - // ranges values are the same - if ((offy == oldY) && (height == oldheight)) - { - return; - } - vpRanges.setViewportStartAndHeight(offy, height); + return; } + vpRanges.setViewportStartAndHeight(offy, height); } - - /* if (overviewPanel != null) - { - overviewPanel.setBoxPosition(); - } - - int scrollX = vpRanges.getStartRes() - oldX; - int scrollY = vpRanges.getStartSeq() - oldY; - */ if (av.getWrapAlignment() || !fastPaint || av.MAC) { repaint(); } - /* else - { - // Make sure we're not trying to draw a panel - // larger than the visible window - if (scrollX > vpRanges.getEndRes() - vpRanges.getStartRes()) - { - scrollX = vpRanges.getEndRes() - vpRanges.getStartRes(); - } - else if (scrollX < vpRanges.getStartRes() - vpRanges.getEndRes()) - { - scrollX = vpRanges.getStartRes() - vpRanges.getEndRes(); - } - - idPanel.idCanvas.fastPaint(scrollY); - seqPanel.seqCanvas.fastPaint(scrollX, scrollY); - - scalePanel.repaint(); - if (av.isShowAnnotation()) - { - annotationPanel.fastPaint(vpRanges.getStartRes() - oldX); - } - }*/ sendViewPosition(); - - /* - * If there is one, scroll the (Protein/cDNA) complementary alignment to - * match, unless we are ourselves doing that. - */ - /* if (isFollowingComplementScroll()) - { - setFollowingComplementScroll(false); - } - else - { - AlignmentPanel ap = getComplementPanel(); - av.scrollComplementaryAlignment(ap); - }*/ - } /** -- 1.7.10.2