protected int alheight;
- protected int fixedX;
-
- protected int fixedY;
-
/**
* Create an OverviewDimensions object
*
public abstract void updateViewportFromMouse(int mousex, int mousey,
HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
+ /**
+ * Update the viewport location from a mouse drag within the overview's box
+ *
+ * @param mousex
+ * x location of mouse
+ * @param mousey
+ * y location of mouse
+ * @param hiddenSeqs
+ * the alignment's hidden sequences
+ * @param hiddenCols
+ * the alignment's hidden columns
+ */
public abstract void adjustViewportFromMouse(int mousex, int mousey,
HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
+ /**
+ * Initialise dragging from the mouse - must be called on initial mouse click
+ * before using adjustViewportFromMouse in drag operations
+ *
+ * @param mousex
+ * x location of mouse
+ * @param mousey
+ * y location of mouse
+ * @param hiddenSeqs
+ * the alignment's hidden sequences
+ * @param hiddenCols
+ * the alignment's hidden columns
+ */
public abstract void setDragPoint(int x, int y,
HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
- protected abstract void updateViewportFromTopLeft(int mousex, int mousey,
+ /*
+ * Move the viewport so that the top left corner of the overview's box
+ * is at the mouse position (leftx, topy)
+ */
+ protected abstract void updateViewportFromTopLeft(int leftx, int topy,
HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
/**
*/
protected abstract void resetAlignmentDims();
+ /*
+ * Given the box coordinates in residues and sequences, set the box dimensions in the overview window
+ */
protected void setBoxPosition(int startRes, int startSeq, int vpwidth,
int vpheight)
{
// boxHeight is the height in sequences translated to pixels
boxHeight = Math.round((float) vpheight * sequencesHeight / alheight);
-
- System.out.println("Update box: x: " + boxX);
}
/**
&& y < boxY + boxHeight);
}
+ /*
+ * Given the centre x position, calculate the box's left x position
+ */
protected abstract int getLeftXFromCentreX(int mousex, HiddenColumns hidden);
+ /*
+ * Given the centre y position, calculate the box's top y position
+ */
protected abstract int getTopYFromCentreY(int mousey,
HiddenSequences hidden);
{
private ViewportRanges ranges;
+ private int xdiff; // when dragging, difference in alignment units between
+ // start residue and original mouse click position
+
+ private int ydiff; // when dragging, difference in alignment units between
+ // start sequence and original mouse click position
+
public OverviewDimensionsHideHidden(ViewportRanges vpranges,
boolean showAnnotationPanel)
{
int vpx = Math.round((float) mousex * alwidth / width);
int vpy = Math.round((float) mousey * alheight / sequencesHeight);
- updateViewportFromTopLeft(vpx + fixedX, vpy + fixedY, hiddenSeqs,
+ updateViewportFromTopLeft(vpx + xdiff, vpy + ydiff, hiddenSeqs,
hiddenCols);
}
@Override
- protected void updateViewportFromTopLeft(int xAsRes, int yAsSeq,
+ protected void updateViewportFromTopLeft(int leftx, int topy,
HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
{
-
+ int xAsRes = leftx;
+ int yAsSeq = topy;
resetAlignmentDims();
if (xAsRes < 0)
yAsSeq = 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();
}
}
-
- //
- // Convert y value to sequence position
- //
+ // Determine where scrollRow should be, given visYAsSeq
// get viewport height in sequences
// add 1 because height includes both endSeq and startSeq
// update viewport
ranges.setStartRes(xAsRes);
ranges.setStartSeq(yAsSeq);
-
}
@Override
HiddenColumns hiddenCols)
{
// get alignment position of x and box (can get directly from vpranges) and
- // calc difference
+ // calculate difference between the positions
int vpx = Math.round((float) x * alwidth / width);
-
int vpy = Math.round((float) y * alheight / sequencesHeight);
- fixedX = ranges.getStartRes() - vpx;
- fixedY = ranges.getStartSeq() - vpy;
-
+ xdiff = ranges.getStartRes() - vpx;
+ ydiff = ranges.getStartSeq() - vpy;
}
}
{
private ViewportRanges ranges;
+ private int xdiff; // when dragging, difference in alignment units between
+ // start residue and original mouse click position
+
+ private int ydiff; // when dragging, difference in alignment units between
+ // start sequence and original mouse click position
+
/**
* Create an OverviewDimensions object
*
public void updateViewportFromMouse(int mousex, int mousey,
HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
{
+ // 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);
+ // convert to visible positions
int visXAsRes = hiddenCols.findColumnPosition(xAsRes);
yAsSeq = hiddenSeqs.adjustForHiddenSeqs(
hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq));
int visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq);
+ // update viewport accordingly
updateViewportFromTopLeft(visXAsRes, visYAsSeq, hiddenSeqs, hiddenCols);
}
// coords,
// convert back to pixel coords
int vpx = Math.round((float) mousex * alwidth / width);
- int visXAsRes = hiddenCols.findColumnPosition(vpx) + fixedX;
+ int visXAsRes = hiddenCols.findColumnPosition(vpx) + xdiff;
int vpy = Math.round((float) mousey * alheight / sequencesHeight);
- int visYAsRes = hiddenSeqs.findIndexWithoutHiddenSeqs(vpy) + fixedY;
+ int visYAsRes = hiddenSeqs.findIndexWithoutHiddenSeqs(vpy) + ydiff;
+ // update viewport accordingly
updateViewportFromTopLeft(visXAsRes, visYAsRes,
hiddenSeqs,
hiddenCols);
}
@Override
- protected void updateViewportFromTopLeft(int visXAsRes, int visYAsSeq,
+ protected void updateViewportFromTopLeft(int leftx, int topy,
HiddenSequences hiddenSeqs, HiddenColumns hiddenCols)
{
-
+ int visXAsRes = leftx;
+ int visYAsSeq = topy;
resetAlignmentDims();
if (visXAsRes < 0)
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();
- // get where x should be when accounting for hidden cols
- // if x is in a hidden col region, shift to left - but we still need
- // absolute position
- // so convert back after getting visible region position
-
-
// check in case we went off the edge of the alignment
int visAlignWidth = hiddenCols.findColumnPosition(alwidth - 1);
if (visXAsRes + vpwidth - 1 > visAlignWidth)
}
}
- //
- // Convert y value to sequence position
- //
-
- // convert y to residues
- // int yAsSeq = Math.round((float) y * alheight / sequencesHeight);
+ // Determine where scrollRow should be, given visYAsSeq
// get viewport height in sequences
int vpheight = ranges.getViewportHeight();
- // get where y should be when accounting for hidden rows
- // if y is in a hidden row region, shift up - but we still need absolute
- // position,
- // so convert back after getting visible region position
-
-
// check in case we went off the edge of the alignment
int visAlignHeight = hiddenSeqs.findIndexWithoutHiddenSeqs(alheight);
// update viewport
ranges.setStartRes(visXAsRes);
ranges.setStartSeq(visYAsSeq);
-
}
/**
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 startSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getStartSeq());
int endSeq = hiddenSeqs.adjustForHiddenSeqs(ranges.getEndSeq());
- System.out.println("Update box: startres: " + startRes);
-
setBoxPosition(startRes, startSeq, endRes - startRes + 1, endSeq
- startSeq + 1);
}
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);
- fixedX = ranges.getStartRes() - hiddenCols.findColumnPosition(vpx);
-
- int vpy = Math.round((float) y * alheight / sequencesHeight);
- fixedY = ranges.getStartSeq()
- - hiddenSeqs.findIndexWithoutHiddenSeqs(vpy);
- }
+ // get alignment position of x and box (can get directly from vpranges) and
+ // calculate difference between the positions
+ int vpx = Math.round((float) x * alwidth / width);
+ int vpy = Math.round((float) y * alheight / sequencesHeight);
+
+ xdiff = ranges.getStartRes() - hiddenCols.findColumnPosition(vpx);
+ ydiff = ranges.getStartSeq()
+ - hiddenSeqs.findIndexWithoutHiddenSeqs(vpy);
}
}
assertFalse(od.isPositionInBox(75, 20));
}
+ /**
+ * Test the dragging functionality
+ */
+ @Test(groups = { "Functional" })
+ public void testDragging()
+ {
+ od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
+ od.setDragPoint(4, 16, al.getHiddenSequences(),
+ hiddenCols);
+ od.adjustViewportFromMouse(20, 22,
+ al.getHiddenSequences(), hiddenCols);
+
+ // updates require an OverviewPanel to exist which it doesn't here
+ // so call setBoxPosition() as it would be called by the AlignmentPanel
+ // normally
+ od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
+
+ // corner moves 16 (20-4) right and 6 (22-16) up
+ assertEquals(od.getBoxX(), 16);
+ assertEquals(od.getBoxY(), 6);
+ }
+
/*
* Move viewport horizontally: startRes + previous width gives new horizontal extent. Vertical extent stays the same.
*/
assertTrue(od.isPositionInBox(47, 10));
}
+ /**
+ * Test the dragging functionality
+ */
+ @Test(groups = { "Functional" })
+ public void testDragging()
+ {
+ od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
+ od.setDragPoint(4, 16, al.getHiddenSequences(), hiddenCols);
+ od.adjustViewportFromMouse(20, 22, al.getHiddenSequences(), hiddenCols);
+
+ // updates require an OverviewPanel to exist which it doesn't here
+ // so call setBoxPosition() as it would be called by the AlignmentPanel
+ // normally
+ od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
+
+ // corner moves 16 (20-4) right and 6 (22-16) up
+ assertEquals(od.getBoxX(), 16);
+ assertEquals(od.getBoxY(), 6);
+ }
+
/*
* Move viewport horizontally: startRes + previous width gives new horizontal extent. Vertical extent stays the same.
*/