}
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:
// 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
int res = 0;
int x = evt.getX();
+ int startRes = av.getRanges().getStartRes();
if (av.getWrapAlignment())
{
}
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())
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;
}
}
// 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
@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());
-
}
}
});
showPopupMenu(evt);
}
}
- else if (!av.getWrapAlignment())
+ else
+ // if (!av.getWrapAlignment())
{
od.updateViewportFromMouse(evt.getX(), evt.getY(), av
.getAlignment().getHiddenSequences(), av.getAlignment()
{
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))
int res = 0;
int x = evt.getX();
+ int startRes = av.getRanges().getStartRes();
if (av.getWrapAlignment())
{
}
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
{
// 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
public void setWrapAlignment(boolean state)
{
viewStyle.setWrapAlignment(state);
+ ranges.setWrappedMode(state);
}
/**
public static final String ENDSEQ = "endseq";
+ private boolean wrappedMode = false;
+
// start residue of viewport
private int startRes;
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);
}
{
endRes = 0;
}
- else if (end > getVisibleAlignmentWidth() - 1)
+ else if (!wrappedMode && (end > getVisibleAlignmentWidth() - 1))
{
endRes = Math.max(getVisibleAlignmentWidth() - 1, 0);
}
{
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);
}
{
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);
}
*/
public void pageUp()
{
- setViewportStartAndHeight(2 * startSeq - endSeq, getViewportHeight());
+ if (wrappedMode)
+ {
+ setStartRes(getStartRes() - getViewportWidth());
+ }
+ else
+ {
+ setViewportStartAndHeight(startSeq - (endSeq - startSeq),
+ getViewportHeight());
+ }
}
/**
*/
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;
}
}