@Override
public void mouseDragged(MouseEvent evt)
{
- if (!SwingUtilities.isRightMouseButton(evt)
- && !av.getWrapAlignment())
+ if (!SwingUtilities.isRightMouseButton(evt))
{
- od.updateViewportFromMouse(evt.getX(), evt.getY(), av
+ if (draggingBox)
+ {
+ // set the mouse position as a fixed point in the box
+ // and drag relative to that position
+ od.adjustViewportFromMouse(evt.getX(),
+ evt.getY(), av.getAlignment().getHiddenSequences(),
+ av.getAlignment().getHiddenColumns());
+ }
+ else
+ {
+ od.updateViewportFromMouse(evt.getX(), evt.getY(), av
.getAlignment().getHiddenSequences(), av.getAlignment()
.getHiddenColumns());
+ }
-
+ }
+ }
+
+ @Override
+ public void mouseMoved(MouseEvent evt)
+ {
+ if (od.isPositionInBox(evt.getX(), evt.getY()))
+ {
+ // display drag cursor at mouse position
+ setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
+ }
+ else
+ {
+ // reset cursor
+ setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}
});
showPopupMenu(evt);
}
}
- else if (!av.getWrapAlignment())
+ else
+ // if (!av.getWrapAlignment())
{
- od.updateViewportFromMouse(evt.getX(), evt.getY(), av
- .getAlignment().getHiddenSequences(), av.getAlignment()
- .getHiddenColumns());
+ if (!od.isPositionInBox(evt.getX(), evt.getY()))
+ {
+ // don't do anything if the mouse press is in the overview's box
+ // (wait to see if it's a drag instead)
+ // otherwise update the viewport
+ od.updateViewportFromMouse(evt.getX(), evt.getY(),
+ av.getAlignment().getHiddenSequences(),
+ av.getAlignment().getHiddenColumns());
+ }
+ else
+ {
+ draggingBox = true;
+ od.setDragPoint(evt.getX(), evt.getY(),
+ av.getAlignment().getHiddenSequences(),
+ av.getAlignment().getHiddenColumns());
+ }
+ }
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent evt)
+ {
+ if (draggingBox)
+ {
+ draggingBox = false;
}
}
public void updateViewportFromMouse(int mousex, int mousey,
HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
{
- resetAlignmentDims();
+ int xAsRes = getLeftXFromCentreX(mousex, hiddenCols);
+ int yAsSeq = getTopYFromCentreY(mousey, hiddenSeqs);
+
+ updateViewportFromTopLeft(xAsRes, yAsSeq, hiddenSeqs, hiddenCols);
+
+ }
+
+ @Override
+ public void adjustViewportFromMouse(int mousex, int mousey,
+ HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
+ {
+ // calculate translation in pixel terms:
+ // get mouse location in viewport coords, add translation in viewport
+ // coords, and update viewport as usual
+ int vpx = Math.round((float) mousex * alwidth / width);
+ int vpy = Math.round((float) mousey * alheight / sequencesHeight);
- int x = mousex;
- int y = mousey;
+ updateViewportFromTopLeft(vpx + xdiff, vpy + ydiff, hiddenSeqs,
+ hiddenCols);
- if (x < 0)
+ }
+
+ @Override
+ protected void updateViewportFromTopLeft(int leftx, int topy,
+ HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
+ {
+ int xAsRes = leftx;
+ int yAsSeq = topy;
+ resetAlignmentDims();
+
+ if (xAsRes < 0)
{
- x = 0;
+ xAsRes = 0;
}
- if (y < 0)
+ if (yAsSeq < 0)
{
- y = 0;
+ yAsSeq = 0;
}
- // Determine where scrollCol should be, given visXAsRes
+ if (ranges.isWrappedMode())
+ {
- y = 0; // sorry, no vertical scroll when wrapped
++ yAsSeq = 0; // sorry, no vertical scroll when wrapped
+ }
- //
- // Convert x value to residue position
- //
-
- // need to determine where scrollCol should be, given x
- // to do this also need to know width of viewport, and some hidden column
- // correction
-
- // convert x to residues - this is an absolute position
- int xAsRes = Math.round((float) x * alwidth / width);
-
// get viewport width in residues
int vpwidth = ranges.getViewportWidth();
public void updateViewportFromMouse(int mousex, int mousey,
HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
{
- int x = mousex;
- int y = mousey;
+ // convert mousex and mousey to alignment units as well as
+ // translating to top left corner of viewport - this is an absolute position
+ int xAsRes = getLeftXFromCentreX(mousex, hiddenCols);
+ int yAsSeq = getTopYFromCentreY(mousey, hiddenSeqs);
- resetAlignmentDims();
+ // convert to visible positions
+ int visXAsRes = hiddenCols.findColumnPosition(xAsRes);
+ yAsSeq = hiddenSeqs.adjustForHiddenSeqs(
+ hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq));
++ yAsSeq = Math.max(yAsSeq, 0); // -1 if before first visible sequence
+ int visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq);
++ visYAsSeq = Math.max(visYAsSeq, 0); // -1 if before first visible sequence
- if (x < 0)
- {
- x = 0;
- }
+ // update viewport accordingly
+ updateViewportFromTopLeft(visXAsRes, visYAsSeq, hiddenSeqs, hiddenCols);
+ }
+
+ @Override
+ public void adjustViewportFromMouse(int mousex, int mousey,
+ HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
+ {
+ // calculate translation in pixel terms:
+ // get mouse location in viewport coords, add translation in viewport
+ // coords,
+ // convert back to pixel coords
+ int vpx = Math.round((float) mousex * alwidth / width);
+ int visXAsRes = hiddenCols.findColumnPosition(vpx) + xdiff;
+
+ int vpy = Math.round((float) mousey * alheight / sequencesHeight);
+ int visYAsRes = hiddenSeqs.findIndexWithoutHiddenSeqs(vpy) + ydiff;
+
+ // update viewport accordingly
+ updateViewportFromTopLeft(visXAsRes, visYAsRes,
+ hiddenSeqs,
+ hiddenCols);
+ }
+
+ @Override
+ protected void updateViewportFromTopLeft(int leftx, int topy,
+ HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
+ {
+ int visXAsRes = leftx;
+ int visYAsSeq = topy;
+ resetAlignmentDims();
- if (y < 0)
+ if (visXAsRes < 0)
{
- y = 0;
+ visXAsRes = 0;
}
- if (ranges.isWrappedMode())
+ if (visYAsSeq < 0)
{
- y = 0; // sorry, no vertical scroll when wrapped
+ visYAsSeq = 0;
}
- //
- // Convert x value to residue position
- //
-
- // need to determine where scrollCol should be, given x
- // to do this also need to know width of viewport, and some hidden column
- // correction
-
- // convert x to residues - this is an absolute position
- int xAsRes = Math.round((float) x * alwidth / width);
+ // Determine where scrollCol should be, given visXAsRes
// get viewport width in residues
int vpwidth = ranges.getViewportWidth();