From: kiramt Date: Wed, 3 May 2017 13:55:08 +0000 (+0100) Subject: JAL-2491 Wrapped panel scrolling X-Git-Tag: Release_2_10_2~3^2~64^2~26 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=43c2cb35733f4c3427ad8cc41ea55a52912980a2;p=jalview.git JAL-2491 Wrapped panel scrolling --- diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 4e5158d..a2773e8 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -702,62 +702,66 @@ public class AlignmentPanel extends GAlignmentPanel implements { return; } - int width = av.getAlignment().getWidth(); - int height = av.getAlignment().getHeight(); - if (av.hasHiddenColumns()) + if (av.getWrapAlignment()) { - // reset the width to exclude hidden columns - width = av.getColumnSelection().findColumnPosition(width); + setScrollingForWrappedPanel(x, y); } + else + { - hextent = getSeqPanel().seqCanvas.getWidth() / av.getCharWidth(); - vextent = getSeqPanel().seqCanvas.getHeight() / av.getCharHeight(); + int width = av.getAlignment().getWidth(); + int height = av.getAlignment().getHeight(); - if (hextent > width) - { - hextent = width; - } + if (av.hasHiddenColumns()) + { + // reset the width to exclude hidden columns + width = av.getColumnSelection().findColumnPosition(width); + } - if (vextent > height) - { - vextent = height; - } + hextent = getSeqPanel().seqCanvas.getWidth() / av.getCharWidth(); + vextent = getSeqPanel().seqCanvas.getHeight() / av.getCharHeight(); - if ((hextent + x) > width) - { - x = width - hextent; - } + if (hextent > width) + { + hextent = width; + } - if ((vextent + y) > height) - { - y = height - vextent; - } + if (vextent > height) + { + vextent = height; + } - if (y < 0) - { - y = 0; - } + if ((hextent + x) > width) + { + x = width - hextent; + } - if (x < 0) - { - x = 0; - } + if ((vextent + y) > height) + { + y = height - vextent; + } - // update endRes after x has (possibly) been adjusted - // vpRanges.setEndRes((x + (getSeqPanel().seqCanvas.getWidth() / av - // .getCharWidth())) - 1); + if (y < 0) + { + y = 0; + } - /* - * each scroll adjustment triggers adjustmentValueChanged, which resets the - * 'do not scroll complement' flag; ensure it is the same for both - * operations - */ - // boolean flag = isDontScrollComplement(); - hscroll.setValues(x, hextent, 0, width); - // setDontScrollComplement(flag); - vscroll.setValues(y, vextent, 0, height); + if (x < 0) + { + x = 0; + } + /* + * each scroll adjustment triggers adjustmentValueChanged, which resets the + * 'do not scroll complement' flag; ensure it is the same for both + * operations + */ + // boolean flag = isDontScrollComplement(); + hscroll.setValues(x, hextent, 0, width); + // setDontScrollComplement(flag); + vscroll.setValues(y, vextent, 0, height); + } } /** @@ -772,43 +776,24 @@ public class AlignmentPanel extends GAlignmentPanel implements int oldX = vpRanges.getStartRes(); int oldY = vpRanges.getStartSeq(); - // check for horizontal scroll with wrapped alignment - // as this can happen via triggered events (and we don't want to hscroll - // when wrapped) - if (evt.getSource() == hscroll && !av.getWrapAlignment()) + if (av.getWrapAlignment()) { - int x = hscroll.getValue(); - if (x == oldX) + if (evt.getSource() == hscroll) { - return; + return; // no horizontal scroll when wrapped } - // vpRanges.setStartRes(x); - // vpRanges.setEndRes((x + (getSeqPanel().seqCanvas.getWidth() / av - // .getCharWidth())) - 1); - vpRanges.setStartEndRes( - x, - (x + (getSeqPanel().seqCanvas.getWidth() / av - .getCharWidth())) - 1); - } - - if (evt.getSource() == vscroll) - { - int offy = vscroll.getValue(); - - if (av.getWrapAlignment()) + else if (evt.getSource() == vscroll) { - if (offy == oldX) + int offy = vscroll.getValue(); + int rowSize = getSeqPanel().seqCanvas + .getWrappedCanvasWidth(getSeqPanel().seqCanvas.getWidth()); + if (offy * rowSize == oldX) { return; } - if (offy > -1) + else if (offy > -1) { - int rowSize = getSeqPanel().seqCanvas - .getWrappedCanvasWidth(getSeqPanel().seqCanvas.getWidth()); vpRanges.setStartEndRes(offy * rowSize, (offy + 1) * rowSize); - // vpRanges.setStartRes(offy * rowSize); - // vpRanges.setEndRes((offy + 1) * rowSize); - } else { @@ -826,73 +811,40 @@ public class AlignmentPanel extends GAlignmentPanel implements }); } } - else + repaint(); + } + else + { + // horizontal scroll + if (evt.getSource() == hscroll) + { + int x = hscroll.getValue(); + if (x == oldX) + { + return; + } + vpRanges.setStartEndRes(x, + (x + (getSeqPanel().seqCanvas.getWidth() / av + .getCharWidth())) - 1); + } + else if (evt.getSource() == vscroll) { + int offy = vscroll.getValue(); if (offy == oldY) { return; } - // vpRanges.setStartSeq(offy); - // vpRanges.setEndSeq(offy - // + (getSeqPanel().seqCanvas.getHeight() / av.getCharHeight()) - // - 1); vpRanges.setStartEndSeq( offy, offy + (getSeqPanel().seqCanvas.getHeight() / av .getCharHeight()) - 1); } + if (!fastPaint) + { + repaint(); + } } - - /*if (overviewPanel != null) - { - overviewPanel.setBoxPosition(); - }*/ - - // int scrollX = vpRanges.getStartRes() - oldX; - // int scrollY = vpRanges.getStartSeq() - oldY; - - if (av.getWrapAlignment() || !fastPaint) - { - 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(); - } - - if (scrollX != 0 || scrollY != 0) - { - getIdPanel().getIdCanvas().fastPaint(scrollY); - getSeqPanel().seqCanvas.fastPaint(scrollX, scrollY); - getScalePanel().repaint(); - - if (av.isShowAnnotation() && scrollX != 0) - { - getAnnotationPanel().fastPaint(scrollX); - } - } - } - /* - * If there is one, scroll the (Protein/cDNA) complementary alignment to - * match, unless we are ourselves doing that. - */ - /* if (isDontScrollComplement()) - { - setDontScrollComplement(false); - } - else - { - av.scrollComplementaryAlignment(); - }*/ } /** @@ -940,33 +892,33 @@ public class AlignmentPanel extends GAlignmentPanel implements * set scroll bar positions; first suppress this being 'followed' in any * complementary split pane */ - setDontScrollComplement(true); - if (av.getWrapAlignment()) - { - int maxwidth = av.getAlignment().getWidth(); + // setDontScrollComplement(true); + setScrollValues(vpRanges.getStartRes(), vpRanges.getStartSeq()); + } - if (av.hasHiddenColumns()) - { - maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; - } + /* + * Set vertical scroll bar parameters for wrapped panel + */ + private void setScrollingForWrappedPanel(int x, int y) + { + int maxwidth = av.getAlignment().getWidth(); - int canvasWidth = getSeqPanel().seqCanvas - .getWrappedCanvasWidth(getSeqPanel().seqCanvas.getWidth()); - if (canvasWidth > 0) - { - int max = maxwidth - / getSeqPanel().seqCanvas - .getWrappedCanvasWidth(getSeqPanel().seqCanvas - .getWidth()) + 1; - vscroll.setMaximum(max); - vscroll.setUnitIncrement(1); - vscroll.setVisibleAmount(1); - } - } - else + if (av.hasHiddenColumns()) { - setScrollValues(vpRanges.getStartRes(), vpRanges.getStartSeq()); + maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; + } + + int canvasWidth = getSeqPanel().seqCanvas + .getWrappedCanvasWidth(getSeqPanel().seqCanvas.getWidth()); + if (canvasWidth > 0) + { + int current = x / canvasWidth; + int max = maxwidth / canvasWidth + 1; + vscroll.setMaximum(max); + vscroll.setUnitIncrement(1); + vscroll.setVisibleAmount(1); + vscroll.setValues(current, 1, 0, max); } } diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 7b8dd92..df953a2 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -983,29 +983,34 @@ public class SeqCanvas extends JComponent implements ViewportListenerI @Override public void propertyChange(PropertyChangeEvent evt) { + if (av.getWrapAlignment()) + { - if (evt.getPropertyName().equals("startres") - || evt.getPropertyName().equals("endres")) + } + else { - // Make sure we're not trying to draw a panel - // larger than the visible window - ViewportRanges vpRanges = av.getRanges(); - int scrollX = (int) evt.getNewValue() - (int) evt.getOldValue(); - if (scrollX > vpRanges.getEndRes() - vpRanges.getStartRes()) + if (evt.getPropertyName().equals("startres") + || evt.getPropertyName().equals("endres")) { - scrollX = vpRanges.getEndRes() - vpRanges.getStartRes(); + // Make sure we're not trying to draw a panel + // larger than the visible window + ViewportRanges vpRanges = av.getRanges(); + int scrollX = (int) evt.getNewValue() - (int) evt.getOldValue(); + if (scrollX > vpRanges.getEndRes() - vpRanges.getStartRes()) + { + scrollX = vpRanges.getEndRes() - vpRanges.getStartRes(); + } + else if (scrollX < vpRanges.getStartRes() - vpRanges.getEndRes()) + { + scrollX = vpRanges.getStartRes() - vpRanges.getEndRes(); + } + fastPaint(scrollX, 0); } - else if (scrollX < vpRanges.getStartRes() - vpRanges.getEndRes()) + else if (evt.getPropertyName() == "startseq" + || evt.getPropertyName() == "endseq") { - scrollX = vpRanges.getStartRes() - vpRanges.getEndRes(); + fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue()); } - fastPaint(scrollX, 0); } - else if (evt.getPropertyName() == "startseq" - || evt.getPropertyName() == "endseq") - { - fastPaint(0, (int) evt.getNewValue() - (int) evt.getOldValue()); - } - } }