From 204ab8e31a8230cb1fdf328a86f675e55c6aa990 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 29 Jun 2017 19:59:08 +0100 Subject: [PATCH] JAL-147 improved wrapped scrolling (including Overview) with ViewportRanges --- src/jalview/appletgui/AlignFrame.java | 18 +------ src/jalview/appletgui/AlignmentPanel.java | 8 ++- src/jalview/appletgui/SeqPanel.java | 10 ++-- src/jalview/gui/AlignFrame.java | 18 +------ src/jalview/gui/AlignmentPanel.java | 8 ++- src/jalview/gui/OverviewPanel.java | 7 ++- src/jalview/gui/SeqCanvas.java | 9 +++- src/jalview/gui/SeqPanel.java | 10 ++-- src/jalview/viewmodel/AlignmentViewport.java | 1 + src/jalview/viewmodel/ViewportRanges.java | 75 ++++++++++++++++++++++---- 10 files changed, 104 insertions(+), 60 deletions(-) diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index 8f28658..4ffdfc1 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -599,25 +599,11 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, } case KeyEvent.VK_PAGE_UP: - if (viewport.getWrapAlignment()) - { - ranges.scrollUp(true); - } - else - { - ranges.pageUp(); - } + ranges.pageUp(); break; case KeyEvent.VK_PAGE_DOWN: - if (viewport.getWrapAlignment()) - { - ranges.scrollUp(false); - } - else - { - ranges.pageDown(); - } + ranges.pageDown(); break; case KeyEvent.VK_Z: diff --git a/src/jalview/appletgui/AlignmentPanel.java b/src/jalview/appletgui/AlignmentPanel.java index e402b9b..6826c4c 100644 --- a/src/jalview/appletgui/AlignmentPanel.java +++ b/src/jalview/appletgui/AlignmentPanel.java @@ -817,13 +817,17 @@ public class AlignmentPanel extends Panel implements AdjustmentListener, // 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)) + int newX = offy * rowSize; + newX += oldX % rowSize; // horizontal scroll offset if any + if ((newX == oldX) && (oldwidth == rowSize)) { return; } else if (offy > -1) { - vpRanges.setViewportStartAndWidth(offy * rowSize, rowSize); + // limit page up/down to one width's worth of positions + newX = newX > oldX ? oldX + rowSize : oldX - rowSize; + vpRanges.setViewportStartAndWidth(newX, rowSize); } } else diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index 5bebe28..e4e3640 100644 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -616,6 +616,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, int res = 0; int x = evt.getX(); + int startRes = av.getRanges().getStartRes(); if (av.getWrapAlignment()) { @@ -639,14 +640,15 @@ public class SeqPanel extends Panel implements MouseMotionListener, } wrappedBlock = y / cHeight; - wrappedBlock += av.getRanges().getStartRes() / cwidth; - + wrappedBlock += startRes / cwidth; + int startOffset = startRes % cwidth; // in case start is scrolled right + // from 0 res = wrappedBlock * cwidth - + Math.min(cwidth - 1, x / av.getCharWidth()); + + Math.min(cwidth - 1, startOffset + x / av.getCharWidth()); } else { - res = (x / av.getCharWidth()) + av.getRanges().getStartRes(); + res = (x / av.getCharWidth()) + startRes; } if (av.hasHiddenColumns()) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index fe84012..1a58e21 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -689,24 +689,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, break; } case KeyEvent.VK_PAGE_UP: - if (viewport.getWrapAlignment()) - { - vpRanges.scrollUp(true); - } - else - { - vpRanges.pageUp(); - } + vpRanges.pageUp(); break; case KeyEvent.VK_PAGE_DOWN: - if (viewport.getWrapAlignment()) - { - vpRanges.scrollUp(false); - } - else - { - vpRanges.pageDown(); - } + vpRanges.pageDown(); break; } } diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 395f6b3..437e678 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -755,13 +755,17 @@ 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) && (oldwidth == rowSize)) + int newX = offy * rowSize; + newX += oldX % rowSize; // horizontal scroll offset if any + if ((newX == oldX) && (oldwidth == rowSize)) { return; } else if (offy > -1) { - vpRanges.setViewportStartAndWidth(offy * rowSize, rowSize); + // limit page up/down to one width's worth of positions + newX = newX > oldX ? oldX + rowSize : oldX - rowSize; + vpRanges.setViewportStartAndWidth(newX, rowSize); } } else diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index 3fa674e..62e7a68 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -107,13 +107,11 @@ public class OverviewPanel extends JPanel implements Runnable, @Override public void mouseDragged(MouseEvent evt) { - if (!SwingUtilities.isRightMouseButton(evt) - && !av.getWrapAlignment()) + if (!SwingUtilities.isRightMouseButton(evt)) { od.updateViewportFromMouse(evt.getX(), evt.getY(), av .getAlignment().getHiddenSequences(), av.getAlignment() .getHiddenColumns()); - } } }); @@ -130,7 +128,8 @@ public class OverviewPanel extends JPanel implements Runnable, showPopupMenu(evt); } } - else if (!av.getWrapAlignment()) + else + // if (!av.getWrapAlignment()) { od.updateViewportFromMouse(evt.getX(), evt.getY(), av .getAlignment().getHiddenSequences(), av.getAlignment() diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index f392810..5cfa8c0 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -990,7 +990,14 @@ public class SeqCanvas extends JComponent implements ViewportListenerI { String eventName = evt.getPropertyName(); - if (!av.getWrapAlignment()) + if (av.getWrapAlignment()) + { + if (eventName.equals(ViewportRanges.STARTRES)) + { + repaint(); + } + } + else { int scrollX = 0; if (eventName.equals(ViewportRanges.STARTRES)) diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 917925b..6fbed49 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -189,6 +189,7 @@ public class SeqPanel extends JPanel implements MouseListener, int res = 0; int x = evt.getX(); + int startRes = av.getRanges().getStartRes(); if (av.getWrapAlignment()) { @@ -212,10 +213,11 @@ public class SeqPanel extends JPanel implements MouseListener, } wrappedBlock = y / cHeight; - wrappedBlock += av.getRanges().getStartRes() / cwidth; - + wrappedBlock += startRes / cwidth; + // allow for wrapped view scrolled right (possible from Overview) + int startOffset = startRes % cwidth; res = wrappedBlock * cwidth - + Math.min(cwidth - 1, x / av.getCharWidth()); + + Math.min(cwidth - 1, startOffset + x / av.getCharWidth()); } else { @@ -225,7 +227,7 @@ public class SeqPanel extends JPanel implements MouseListener, // right-hand gutter x = seqCanvas.getX() + seqCanvas.getWidth(); } - res = (x / av.getCharWidth()) + av.getRanges().getStartRes(); + res = (x / av.getCharWidth()) + startRes; if (res > av.getRanges().getEndRes()) { // moused off right diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 107cdd4..0cdba1e 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -405,6 +405,7 @@ public abstract class AlignmentViewport implements AlignViewportI, public void setWrapAlignment(boolean state) { viewStyle.setWrapAlignment(state); + ranges.setWrappedMode(state); } /** diff --git a/src/jalview/viewmodel/ViewportRanges.java b/src/jalview/viewmodel/ViewportRanges.java index c2bcf3f..162e712 100644 --- a/src/jalview/viewmodel/ViewportRanges.java +++ b/src/jalview/viewmodel/ViewportRanges.java @@ -40,6 +40,8 @@ public class ViewportRanges extends ViewportProperties public static final String ENDSEQ = "endseq"; + private boolean wrappedMode = false; + // start residue of viewport private int startRes; @@ -129,7 +131,11 @@ public class ViewportRanges extends ViewportProperties public void setStartEndRes(int start, int end) { int oldstartres = this.startRes; - if (start > getVisibleAlignmentWidth() - 1) + + /* + * if not wrapped, don't leave white space at the right margin + */ + if (!wrappedMode && (start > getVisibleAlignmentWidth() - 1)) { startRes = Math.max(getVisibleAlignmentWidth() - 1, 0); } @@ -147,7 +153,7 @@ public class ViewportRanges extends ViewportProperties { endRes = 0; } - else if (end > getVisibleAlignmentWidth() - 1) + else if (!wrappedMode && (end > getVisibleAlignmentWidth() - 1)) { endRes = Math.max(getVisibleAlignmentWidth() - 1, 0); } @@ -175,9 +181,16 @@ public class ViewportRanges extends ViewportProperties { int startres = res; int width = getViewportWidth(); - if (startres + width - 1 > getVisibleAlignmentWidth() - 1) + + /* + * if not wrapped, don't leave white space at the right margin + */ + if (!wrappedMode) { - startres = getVisibleAlignmentWidth() - width; + if (startres + width - 1 > getVisibleAlignmentWidth() - 1) + { + startres = getVisibleAlignmentWidth() - width; + } } setStartEndRes(startres - width + 1, startres); } @@ -338,12 +351,18 @@ public class ViewportRanges extends ViewportProperties { vpstart = 0; } - else if ((w <= getVisibleAlignmentWidth()) - && (vpstart + w - 1 > getVisibleAlignmentWidth() - 1)) - // viewport width is less than the full alignment and we are running off the - // RHS edge + + /* + * if not wrapped, don't leave white space at the right margin + */ + if (!wrappedMode) { - vpstart = getVisibleAlignmentWidth() - w; + if ((w <= getVisibleAlignmentWidth()) + && (vpstart + w - 1 > getVisibleAlignmentWidth() - 1)) + { + vpstart = getVisibleAlignmentWidth() - w; + } + } setStartEndRes(vpstart, vpstart + w - 1); } @@ -514,7 +533,15 @@ public class ViewportRanges extends ViewportProperties */ public void pageUp() { - setViewportStartAndHeight(2 * startSeq - endSeq, getViewportHeight()); + if (wrappedMode) + { + setStartRes(getStartRes() - getViewportWidth()); + } + else + { + setViewportStartAndHeight(startSeq - (endSeq - startSeq), + getViewportHeight()); + } } /** @@ -522,6 +549,32 @@ public class ViewportRanges extends ViewportProperties */ public void pageDown() { - setViewportStartAndHeight(endSeq, getViewportHeight()); + if (wrappedMode) + { + /* + * if height is more than width (i.e. not all sequences fit on screen), + * increase page down to height + */ + int newStart = getStartRes() + + Math.max(getViewportHeight(), getViewportWidth()); + + /* + * don't page down beyond end of alignment, or if not all + * sequences fit in the visible height + */ + if (newStart < getVisibleAlignmentWidth()) + { + setStartRes(newStart); + } + } + else + { + setViewportStartAndHeight(endSeq, getViewportHeight()); + } + } + + public void setWrappedMode(boolean wrapped) + { + wrappedMode = wrapped; } } -- 1.7.10.2