private boolean showHidden = true;
+ private boolean draggingBox = false;
+
/**
* Creates a new OverviewPanel object.
*
if (!SwingUtilities.isRightMouseButton(evt)
&& !av.getWrapAlignment())
{
- od.updateViewportFromMouse(evt.getX(), evt.getY(), av
+ if (draggingBox)
+ {
+ 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());
+ }
}
}
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;
}
}
protected int alheight;
+ protected int transX;
+
+ protected int transY;
+
/**
* Create an OverviewDimensions object
*
public abstract void updateViewportFromMouse(int mousex, int mousey,
HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
+ public abstract void adjustViewportFromMouse(int mousex, int mousey,
+ HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
+
+ public abstract void setDragPoint(int x, int y,
+ HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
+
+ protected abstract void updateViewportFromTopLeft(int mousex, int mousey,
+ HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
+
/**
* Set the overview panel's box position to match the viewport
*
// boxHeight is the height in sequences translated to pixels
boxHeight = Math.round((float) vpheight * sequencesHeight / alheight);
+
+ System.out.println("Update box: x: " + boxX);
}
/**
*/
public boolean isPositionInBox(int x, int y)
{
- return (x > boxX && y > boxY && boxX + x < boxWidth
- && boxY + y < boxHeight);
- }
-
- public void setMousePosition(int x, int y)
- {
-
+ return (x > boxX && y > boxY && x < boxX + boxWidth
+ && y < boxY + boxHeight);
}
protected abstract int getLeftXFromCentreX(int mousex, HiddenColumns hidden);
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);
+
+ updateViewportFromTopLeft(vpx + transX, vpy + transY, hiddenSeqs,
+ hiddenCols);
+
+ }
+
+ @Override
+ protected void updateViewportFromTopLeft(int xAsRes, int yAsSeq,
+ HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
+ {
+
+ resetAlignmentDims();
+
if (xAsRes < 0)
{
xAsRes = 0;
int vpy = Math.round((float) mousey * alheight / sequencesHeight);
return vpy - ranges.getViewportHeight() / 2;
}
+
+ @Override
+ public void setDragPoint(int x, int y, HiddenSequences hiddenSeqs,
+ HiddenColumns hiddenCols)
+ {
+ // get alignment position of x and box (can get directly from vpranges) and
+ // calc difference
+ int vpx = Math.round((float) x * alwidth / width);
+
+ int vpy = Math.round((float) y * alheight / sequencesHeight);
+
+ transX = ranges.getStartRes() - vpx;
+ transY = ranges.getStartSeq() - vpy;
+
+ }
+
}
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,
+ // convert back to pixel coords
+ int vpx = Math.round((float) mousex * alwidth / width);
+ int visXAsRes = hiddenCols.findColumnPosition(vpx);
+
+ int vpy = Math.round((float) mousey * alheight / sequencesHeight);
+ int visYAsRes = hiddenSeqs.findIndexWithoutHiddenSeqs(vpy);
+
+ updateViewportFromTopLeft(visXAsRes + transX, visYAsRes + transY,
+ hiddenSeqs,
+ hiddenCols);
+ }
+
+ @Override
+ protected void updateViewportFromTopLeft(int xAsRes, int yAsSeq,
+ HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
+ {
+
resetAlignmentDims();
if (xAsRes < 0)
public void setBoxPosition(HiddenSequences hiddenSeqs,
HiddenColumns hiddenCols)
{
+
// work with absolute values of startRes and endRes
int startRes = hiddenCols.adjustForHiddenColumns(ranges.getStartRes());
int endRes = hiddenCols.adjustForHiddenColumns(ranges.getEndRes());
int vpy = Math.round((float) mousey * alheight / sequencesHeight);
return hidden.subtractVisibleRows(ranges.getViewportHeight() / 2, vpy);
}
+
+ @Override
+ public void setDragPoint(int x, int y, HiddenSequences hiddenSeqs,
+ HiddenColumns hiddenCols)
+ {
+ {
+ // get alignment position of x and box (can get directly from vpranges) and calc difference
+ int vpx = Math.round((float) x * alwidth / width);
+ int visXAsRes = hiddenCols.findColumnPosition(vpx);
+
+ int vpy = Math.round((float) y * alheight / sequencesHeight);
+ int visYAsRes = hiddenSeqs.findIndexWithoutHiddenSeqs(vpy);
+
+ transX = ranges.getStartRes() - visXAsRes;
+ transY = ranges.getStartSeq() - visYAsRes;
+ }
+ }
+
}