From 1af07fa4f32bcb8c9f35be3f92565774ca35215c Mon Sep 17 00:00:00 2001 From: kiramt Date: Mon, 8 May 2017 08:12:15 +0100 Subject: [PATCH] JAL-2491 Started moving other scrolling fns into viewportranges --- src/jalview/gui/AlignFrame.java | 11 +- src/jalview/gui/AlignmentPanel.java | 137 ++++++--------------- src/jalview/gui/AnnotationPanel.java | 4 +- src/jalview/gui/IdPanel.java | 12 +- src/jalview/gui/OverviewPanel.java | 6 +- src/jalview/gui/SeqPanel.java | 48 ++++---- src/jalview/viewmodel/ViewportRanges.java | 190 +++++++++++++++++++---------- 7 files changed, 209 insertions(+), 199 deletions(-) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index d4c87d8..bee5e5b 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -681,23 +681,22 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, case KeyEvent.VK_PAGE_UP: if (viewport.getWrapAlignment()) { - alignPanel.scrollUp(true); + vpRanges.scrollUp(true); } else { - alignPanel.setScrollValues(vpRanges.getStartRes(), - 2 * vpRanges.getStartSeq() - vpRanges.getEndSeq()); + vpRanges.setStartSeq(2 * vpRanges.getStartSeq() + - vpRanges.getEndSeq()); } break; case KeyEvent.VK_PAGE_DOWN: if (viewport.getWrapAlignment()) { - alignPanel.scrollUp(false); + vpRanges.scrollUp(false); } else { - alignPanel.setScrollValues(vpRanges.getStartRes(), - vpRanges.getEndSeq()); + vpRanges.setStartSeq(vpRanges.getEndSeq()); } break; } diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 795146d..4cfa7d5 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -152,16 +152,25 @@ public class AlignmentPanel extends GAlignmentPanel implements // reset the viewport ranges when the alignment panel is resized // in particular, this initialises the end residue value when Jalview // is initialised - int widthInRes = (getSeqPanel().seqCanvas.getWidth() / av - .getCharWidth()) - 1; - int currentStartRes = vpRanges.getStartRes(); + + if (av.getWrapAlignment()) { - widthInRes = getSeqPanel().seqCanvas + int widthInRes = getSeqPanel().seqCanvas .getWrappedCanvasWidth(getSeqPanel().seqCanvas.getWidth()); + vpRanges.setStartEndRes(vpRanges.getStartRes(), widthInRes); + } + else + { + int widthInRes = (getSeqPanel().seqCanvas.getWidth() / av + .getCharWidth()) - 1; + int heightInSeq = (getSeqPanel().seqCanvas.getHeight() / av.getCharHeight()) - 1; + + vpRanges.setStartEndRes(vpRanges.getStartRes(), widthInRes); + vpRanges.setStartEndSeq(vpRanges.getStartSeq(), heightInSeq); } - vpRanges.setStartEndRes(currentStartRes, widthInRes); + } }); @@ -227,10 +236,6 @@ public class AlignmentPanel extends GAlignmentPanel implements getIdPanel().getIdCanvas().setPreferredSize(d); hscrollFillerPanel.setPreferredSize(d); - if (overviewPanel != null) - { - overviewPanel.setBoxPosition(); - } if (this.alignFrame.getSplitViewContainer() != null) { ((SplitFrame) this.alignFrame.getSplitViewContainer()).adjustLayout(); @@ -482,29 +487,15 @@ public class AlignmentPanel extends GAlignmentPanel implements } else { - scrollToWrappedVisible(start); + vpRanges.scrollToWrappedVisible(start); + // scrollToWrappedVisible(start); } } - if (redrawOverview && overviewPanel != null) - { - overviewPanel.setBoxPosition(); - } + paintAlignment(redrawOverview); return true; } - void scrollToWrappedVisible(int res) - { - int cwidth = getSeqPanel().seqCanvas - .getWrappedCanvasWidth(getSeqPanel().seqCanvas.getWidth()); - if (res < vpRanges.getStartRes() - || res >= (vpRanges.getStartRes() + cwidth)) - { - vscroll.setValue((res / cwidth)); - } - - } - /** * DOCUMENT ME! * @@ -640,75 +631,28 @@ public class AlignmentPanel extends GAlignmentPanel implements annotationSpaceFillerHolder.setVisible(true); } - idSpaceFillerPanel1.setVisible(!wrap); - - repaint(); - } - - // return value is true if the scroll is valid - public boolean scrollUp(boolean up) - { - if (up) + if (wrap) { - if (vscroll.getValue() < 1) - { - return false; - } - - fastPaint = false; - vscroll.setValue(vscroll.getValue() - 1); + int widthInRes = getSeqPanel().seqCanvas + .getWrappedCanvasWidth(getSeqPanel().seqCanvas.getWidth()); + vpRanges.setStartEndRes(vpRanges.getStartRes(), widthInRes); } else { - if ((vextent + vscroll.getValue()) >= av.getAlignment().getHeight()) - { - return false; - } + int widthInRes = (getSeqPanel().seqCanvas.getWidth() / av + .getCharWidth()) - 1; + int heightInSeq = (getSeqPanel().seqCanvas.getHeight() / av + .getCharHeight()) - 1; - fastPaint = false; - vscroll.setValue(vscroll.getValue() + 1); + vpRanges.setStartEndRes(vpRanges.getStartRes(), widthInRes); + vpRanges.setStartEndSeq(vpRanges.getStartSeq(), heightInSeq); } - fastPaint = true; + idSpaceFillerPanel1.setVisible(!wrap); - return true; + repaint(); } - /** - * DOCUMENT ME! - * - * @param right - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ - public boolean scrollRight(boolean right) - { - if (!right) - { - if (hscroll.getValue() < 1) - { - return false; - } - - fastPaint = false; - hscroll.setValue(hscroll.getValue() - 1); - } - else - { - if ((hextent + hscroll.getValue()) >= av.getAlignment().getWidth()) - { - return false; - } - - fastPaint = false; - hscroll.setValue(hscroll.getValue() + 1); - } - - fastPaint = true; - - return true; - } /** * Adjust row/column scrollers to show a visible position in the alignment. @@ -791,7 +735,9 @@ public class AlignmentPanel extends GAlignmentPanel implements public void adjustmentValueChanged(AdjustmentEvent evt) { int oldX = vpRanges.getStartRes(); + int oldwidth = vpRanges.getViewportWidth(); int oldY = vpRanges.getStartSeq(); + int oldheight = vpRanges.getViewportHeight(); if (av.getWrapAlignment()) { @@ -808,7 +754,7 @@ public class AlignmentPanel extends GAlignmentPanel implements // 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) + if ((offy * rowSize == oldX) && (oldwidth == rowSize)) { return; } @@ -840,34 +786,31 @@ public class AlignmentPanel extends GAlignmentPanel implements if (evt.getSource() == hscroll) { int x = hscroll.getValue(); + int width = (getSeqPanel().seqCanvas.getWidth() / av.getCharWidth()) - 1; // 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) + if ((x == oldX) && (width == oldwidth)) { return; } - vpRanges.setStartEndRes(x, - (x + (getSeqPanel().seqCanvas.getWidth() / av - .getCharWidth())) - 1); + vpRanges.setStartEndRes(x, x + width); } else if (evt.getSource() == vscroll) { - int offy = vscroll.getValue(); + int y = vscroll.getValue(); + int height = (getSeqPanel().seqCanvas.getHeight() / av + .getCharHeight()) - 1; // 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) + if ((y == oldY) && (height == oldheight)) { return; } - vpRanges.setStartEndSeq( - offy, - offy - + (getSeqPanel().seqCanvas.getHeight() / av - .getCharHeight()) - 1); + vpRanges.setStartEndSeq(y, y + height); } if (!fastPaint) { diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 8dc168a..6997517 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -175,11 +175,11 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, e.consume(); if (e.getWheelRotation() > 0) { - ap.scrollRight(true); + av.getRanges().scrollRight(true); } else { - ap.scrollRight(false); + av.getRanges().scrollRight(false); } } else diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index 2074900..6097089 100755 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@ -152,22 +152,22 @@ public class IdPanel extends JPanel implements MouseListener, { if (e.isShiftDown()) { - alignPanel.scrollRight(true); + av.getRanges().scrollRight(true); } else { - alignPanel.scrollUp(false); + av.getRanges().scrollUp(false); } } else { if (e.isShiftDown()) { - alignPanel.scrollRight(false); + av.getRanges().scrollRight(false); } else { - alignPanel.scrollUp(true); + av.getRanges().scrollUp(true); } } } @@ -446,7 +446,7 @@ public class IdPanel extends JPanel implements MouseListener, if ((av.getRanges().getStartSeq() > index) || (av.getRanges().getEndSeq() < index)) { - alignPanel.setScrollValues(av.getRanges().getStartRes(), index); + av.getRanges().setStartSeq(index); } } @@ -485,7 +485,7 @@ public class IdPanel extends JPanel implements MouseListener, while (running) { - if (alignPanel.scrollUp(up)) + if (av.getRanges().scrollUp(up)) { // scroll was ok, so add new sequence to selection int seq = av.getRanges().getStartSeq(); diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index 3bd7388..da2cdbb 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -122,6 +122,8 @@ public class OverviewPanel extends JPanel implements Runnable, od.updateViewportFromMouse(evt.getX(), evt.getY(), av .getAlignment().getHiddenSequences(), av .getColumnSelection(), av.getRanges()); + // TODO set via ViewportRanges in overview dimensions once JAL-2388 is + // merged ap.setScrollValues(od.getScrollCol(), od.getScrollRow()); } } @@ -137,6 +139,8 @@ public class OverviewPanel extends JPanel implements Runnable, od.updateViewportFromMouse(evt.getX(), evt.getY(), av .getAlignment().getHiddenSequences(), av .getColumnSelection(), av.getRanges()); + // TODO set via ViewportRanges in overview dimensions once JAL-2388 is + // merged ap.setScrollValues(od.getScrollCol(), od.getScrollRow()); } } @@ -324,7 +328,7 @@ public class OverviewPanel extends JPanel implements Runnable, * changed * */ - public void setBoxPosition() + private void setBoxPosition() { od.setBoxPosition(av.getAlignment() .getHiddenSequences(), av.getColumnSelection(), av.getRanges()); diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index ce434f5..82d98c0 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -383,37 +383,37 @@ public class SeqPanel extends JPanel implements MouseListener, endEditing(); if (av.getWrapAlignment()) { - ap.scrollToWrappedVisible(seqCanvas.cursorX); + av.getRanges().scrollToWrappedVisible(seqCanvas.cursorX); + // ap.scrollToWrappedVisible(seqCanvas.cursorX); } else { while (seqCanvas.cursorY < av.getRanges().getStartSeq()) { - ap.scrollUp(true); + av.getRanges().scrollUp(true); } while (seqCanvas.cursorY + 1 > av.getRanges().getEndSeq()) { - ap.scrollUp(false); + av.getRanges().scrollUp(false); } - if (!av.getWrapAlignment()) + + while (seqCanvas.cursorX < av.getColumnSelection() + .adjustForHiddenColumns(av.getRanges().getStartRes())) { - while (seqCanvas.cursorX < av.getColumnSelection() - .adjustForHiddenColumns(av.getRanges().getStartRes())) + if (!av.getRanges().scrollRight(false)) { - if (!ap.scrollRight(false)) - { - break; - } + break; } - while (seqCanvas.cursorX > av.getColumnSelection() - .adjustForHiddenColumns(av.getRanges().getEndRes())) + } + while (seqCanvas.cursorX > av.getColumnSelection() + .adjustForHiddenColumns(av.getRanges().getEndRes())) + { + if (!av.getRanges().scrollRight(true)) { - if (!ap.scrollRight(true)) - { - break; - } + break; } } + } setStatusMessage(av.getAlignment().getSequenceAt(seqCanvas.cursorY), seqCanvas.cursorX, seqCanvas.cursorY); @@ -1522,23 +1522,23 @@ public class SeqPanel extends JPanel implements MouseListener, { if (e.isShiftDown()) { - ap.scrollRight(true); + av.getRanges().scrollRight(true); } else { - ap.scrollUp(false); + av.getRanges().scrollUp(false); } } else { if (e.isShiftDown()) { - ap.scrollRight(false); + av.getRanges().scrollRight(false); } else { - ap.scrollUp(true); + av.getRanges().scrollUp(true); } } // TODO Update tooltip for new position. @@ -1906,23 +1906,23 @@ public class SeqPanel extends JPanel implements MouseListener, if (mouseDragging && (evt.getY() < 0) && (av.getRanges().getStartSeq() > 0)) { - running = ap.scrollUp(true); + running = av.getRanges().scrollUp(true); } if (mouseDragging && (evt.getY() >= getHeight()) && (av.getAlignment().getHeight() > av.getRanges() .getEndSeq())) { - running = ap.scrollUp(false); + running = av.getRanges().scrollUp(false); } if (mouseDragging && (evt.getX() < 0)) { - running = ap.scrollRight(false); + running = av.getRanges().scrollRight(false); } else if (mouseDragging && (evt.getX() >= getWidth())) { - running = ap.scrollRight(true); + running = av.getRanges().scrollRight(true); } } diff --git a/src/jalview/viewmodel/ViewportRanges.java b/src/jalview/viewmodel/ViewportRanges.java index a14fc26..72155aa 100644 --- a/src/jalview/viewmodel/ViewportRanges.java +++ b/src/jalview/viewmodel/ViewportRanges.java @@ -86,29 +86,33 @@ public class ViewportRanges extends ViewportProperties */ public void setStartRes(int res) { - int oldres = this.startRes; - setStartResInternal(res); - changeSupport.firePropertyChange("startres", oldres, res); + int width = getViewportWidth(); + setStartEndRes(res, res + width - 1); } - private void setStartResInternal(int res) + public void setStartEndRes(int startres, int endres) { - if (res > al.getWidth() - 1) + int oldres = this.startRes; + if (startres > al.getWidth() - 1) { - res = al.getWidth() - 1; + startres = al.getWidth() - 1; } - else if (res < 0) + else if (startres < 0) { - res = 0; + startres = 0; } - this.startRes = res; - } + this.startRes = startres; + + if (endres >= al.getWidth()) + { + endres = al.getWidth() - 1; + } + else if (endres < 0) + { + endres = 0; + } + this.endRes = endres; - public void setStartEndRes(int startres, int endres) - { - int oldres = this.startRes; - setStartResInternal(startres); - setEndResInternal(endres); changeSupport.firePropertyChange("startres", oldres, startres); } @@ -120,23 +124,8 @@ public class ViewportRanges extends ViewportProperties */ public void setEndRes(int res) { - int oldres = this.endRes; - setEndResInternal(res); - - changeSupport.firePropertyChange("endres", oldres, res); - } - - private void setEndResInternal(int res) - { - if (res >= al.getWidth()) - { - res = al.getWidth() - 1; - } - else if (res < 0) - { - res = 0; - } - this.endRes = res; + int width = getViewportWidth(); + setStartEndRes(res - width + 1, res); } /** @@ -147,29 +136,32 @@ public class ViewportRanges extends ViewportProperties */ public void setStartSeq(int seq) { - int oldseq = this.startSeq; - setStartSeqInternal(seq); - changeSupport.firePropertyChange("startseq", oldseq, seq); + int height = getViewportHeight(); + setStartEndSeq(seq, seq + height - 1); } - private void setStartSeqInternal(int seq) + public void setStartEndSeq(int startseq, int endseq) { - if (seq > al.getHeight() - 1) + int oldseq = this.startSeq; + if (startseq > al.getHeight() - 1) { - seq = al.getHeight() - 1; + startseq = al.getHeight() - 1; } - else if (seq < 0) + else if (startseq < 0) { - seq = 0; + startseq = 0; } - this.startSeq = seq; - } + this.startSeq = startseq; - public void setStartEndSeq(int startseq, int endseq) - { - int oldseq = this.startSeq; - setStartSeqInternal(startseq); - setEndSeqInternal(endseq); + if (endseq >= al.getHeight()) + { + endseq = al.getHeight() - 1; + } + else if (endseq < 0) + { + endseq = 0; + } + this.endSeq = endseq; changeSupport.firePropertyChange("startseq", oldseq, startseq); } @@ -181,22 +173,8 @@ public class ViewportRanges extends ViewportProperties */ public void setEndSeq(int seq) { - int oldseq = this.endSeq; - setEndSeqInternal(seq); - changeSupport.firePropertyChange("endseq", oldseq, seq); - } - - private void setEndSeqInternal(int seq) - { - if (seq >= al.getHeight()) - { - seq = al.getHeight() - 1; - } - else if (seq < 0) - { - seq = 0; - } - this.endSeq = seq; + int height = getViewportHeight(); + setStartEndSeq(seq - height + 1, seq); } /** @@ -230,4 +208,90 @@ public class ViewportRanges extends ViewportProperties { return endSeq; } + + /** + * Get width of viewport in residues + * + * @return width of viewport + */ + public int getViewportWidth() + { + return (endRes - startRes + 1); // TODO get for wrapped alignments too + } + + /** + * Get height of viewport in residues + * + * @return height of viewport + */ + public int getViewportHeight() + { + return (endSeq - startSeq + 1); + } + + // return value is true if the scroll is valid + public boolean scrollUp(boolean up) + { + if (up) + { + if (startSeq < 1) + { + return false; + } + + setStartSeq(startSeq - 1); + } + else + { + if (endSeq >= al.getHeight() - 1) + { + return false; + } + + setStartSeq(startSeq + 1); + } + return true; + } + + /** + * DOCUMENT ME! + * + * @param right + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public boolean scrollRight(boolean right) + { + if (!right) + { + if (startRes < 1) + { + return false; + } + + setStartRes(startRes - 1); + } + else + { + if (endRes > al.getWidth() - 1) + { + return false; + } + + setStartRes(startRes + 1); + } + + return true; + } + + public void scrollToWrappedVisible(int res) + { + if (res < startRes || res > endRes) + { + setEndSeq(res / getViewportWidth()); + } + + } + } -- 1.7.10.2