import java.awt.BorderLayout;
import java.awt.CheckboxMenuItem;
+import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Panel;
import java.awt.PopupMenu;
private boolean updateRunning = false;
+ private boolean draggingBox = false;
+
public OverviewPanel(AlignmentPanel alPanel)
{
this.av = alPanel.av;
@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));
+ }
}
@Override
public void mousePressed(MouseEvent evt)
{
- mouseAction(evt);
+ if ((evt.getModifiers()
+ & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
+ {
+ if (!Platform.isAMac())
+ {
+ showPopupMenu(evt);
+ }
+ }
+ else
+ {
+ 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)
{
- mouseAction(evt);
+ if (draggingBox)
+ {
+ draggingBox = false;
+ }
}
@Override
public void mouseDragged(MouseEvent evt)
{
- mouseAction(evt);
- }
-
- private void mouseAction(MouseEvent evt)
- {
if ((evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
{
if (!Platform.isAMac())
}
else
{
- od.updateViewportFromMouse(evt.getX(), evt.getY(), av.getAlignment()
- .getHiddenSequences(), av.getAlignment().getHiddenColumns());
+ 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());
+ }
ap.paintAlignment(false);
}
}
return startRow - visibleDistance;
}
- int index = startRow;
+ int index = Math.min(startRow, hiddenSequences.length - 1);
int count = 0;
while ((index > -1) && (count < visibleDistance))
{
import jalview.viewmodel.ViewportListenerI;
import java.awt.BorderLayout;
+import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
private boolean showHidden = true;
+ private boolean draggingBox = false;
+
/**
* Creates a new OverviewPanel object.
*
{
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));
}
}
});
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;
}
}
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);
+
+ /*
+ * 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);
+
+ /**
* Set the overview panel's box position to match the viewport
*
* @param hiddenSeqs
*/
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);
}
+
+ /**
+ * Answers if a mouse position is in the overview's red box
+ *
+ * @param x
+ * mouse x position
+ * @param y
+ * mouse y position
+ * @return true if (x,y) is inside the box
+ */
+ public boolean isPositionInBox(int x, int y)
+ {
+ return (x > boxX && y > boxY && x < boxX + boxWidth
+ && 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);
+
}
\ No newline at end of file
{
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)
{
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;
}
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();
}
}
-
- //
- // 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
// add 1 because height includes both endSeq and startSeq
// update viewport
ranges.setStartRes(xAsRes);
ranges.setStartSeq(yAsSeq);
-
}
@Override
alwidth = ranges.getVisibleAlignmentWidth();
alheight = ranges.getVisibleAlignmentHeight();
}
+
+ @Override
+ protected int getLeftXFromCentreX(int mousex, HiddenColumns hidden)
+ {
+ int vpx = Math.round((float) mousex * alwidth / width);
+ return vpx - ranges.getViewportWidth() / 2;
+ }
+
+ @Override
+ protected int getTopYFromCentreY(int mousey, HiddenSequences hidden)
+ {
+ 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
+ // calculate difference between the positions
+ int vpx = Math.round((float) x * alwidth / width);
+ int vpy = Math.round((float) y * alheight / sequencesHeight);
+
+ 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)
{
- 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();
- // 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
- int visXAsRes = hiddenCols.findColumnPosition(xAsRes);
-
// 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
- yAsSeq = hiddenSeqs.adjustForHiddenSeqs(hiddenSeqs
- .findIndexWithoutHiddenSeqs(yAsSeq));
- yAsSeq = Math.max(yAsSeq, 0); // -1 if before first visible sequence
-
// check in case we went off the edge of the alignment
int visAlignHeight = hiddenSeqs.findIndexWithoutHiddenSeqs(alheight);
- int visYAsSeq = hiddenSeqs.findIndexWithoutHiddenSeqs(yAsSeq);
- visYAsSeq = Math.max(visYAsSeq, 0); // -1 if before first visible sequence
+
if (visYAsSeq + vpheight - 1 > visAlignHeight)
{
// went past the end of the alignment, adjust backwards
alwidth = ranges.getAbsoluteAlignmentWidth();
alheight = ranges.getAbsoluteAlignmentHeight();
}
+
+ @Override
+ protected int getLeftXFromCentreX(int mousex, HiddenColumns hidden)
+ {
+ int vpx = Math.round((float) mousex * alwidth / width);
+ return hidden.subtractVisibleColumns(ranges.getViewportWidth() / 2,
+ vpx);
+ }
+
+ @Override
+ protected int getTopYFromCentreY(int mousey, HiddenSequences hidden)
+ {
+ 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
+ // 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);
+ }
+
}
package jalview.viewmodel;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
import jalview.analysis.AlignmentGenerator;
import jalview.datamodel.Alignment;
ViewportRanges vpranges;
- Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
+ Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences = new Hashtable<>();
HiddenColumns hiddenCols = new HiddenColumns();
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
- assertEquals(vpranges.getStartSeq(),
+ assertEquals(vpranges.getStartSeq() + vpranges.getViewportHeight() / 2,
Math.round((float) 10 * alheight / od.getSequencesHeight()));
assertEquals(vpranges.getStartRes(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
- assertEquals(vpranges.getStartRes(),
- Math.round((float) 6 * alwidth / od.getWidth()));
+ assertEquals(vpranges.getStartRes(), 0);
assertEquals(vpranges.getStartSeq(), 0);
// overly large boxX value reset to width-boxWidth
- mouseClick(od, 100, 6);
+ mouseClick(od, 101, 6);
assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
- assertEquals(od.getBoxY(), 6);
+ assertEquals(od.getBoxY(), 1);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
assertEquals(vpranges.getStartRes(),
// overly large boxY value reset to sequenceHeight - boxHeight
mouseClick(od, 10, 520);
- assertEquals(od.getBoxX(), 10);
+ assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), od.getSequencesHeight() - od.getBoxHeight());
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
/ od.getSequencesHeight()));
// move viewport so startRes non-zero and then mouseclick
- moveViewportH(50);
+ moveViewportH(20);
// click at viewport position
int oldboxx = od.getBoxX();
int oldboxy = od.getBoxY();
- mouseClick(od, od.getBoxX() + 5, od.getBoxY() + 2);
- assertEquals(od.getBoxX(), oldboxx + 5);
+ mouseClick(od, od.getBoxX() + od.getBoxWidth() / 2 + 6,
+ od.getBoxY() + od.getBoxHeight() / 2 + 3);
+ assertEquals(od.getBoxX(), oldboxx + 6);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
assertEquals(vpranges.getStartRes(),
Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
- assertEquals(od.getBoxY(), oldboxy + 2);
+ assertEquals(od.getBoxY(), oldboxy + 3);
assertEquals(
vpranges.getStartSeq(),
Math.round((float) od.getBoxY() * alheight
int lastHiddenCol = 30;
hiddenCols.hideColumns(0, lastHiddenCol);
- testBoxIsAtClickPoint(0, 0);
+ testBoxIsAtClickPoint(boxWidth / 2, boxHeight / 2);
// click to right of hidden columns, box moves to click point
- testBoxIsAtClickPoint(40, 0);
+ testBoxIsAtClickPoint(41 + boxWidth / 2, boxHeight / 2);
assertEquals(vpranges.getStartSeq(), 0);
assertEquals(vpranges.getStartRes(),
- Math.round((float) 40 * alwidth / od.getWidth()));
+ Math.round((float) 41 * alwidth / od.getWidth()));
// click to right of hidden columns such that box runs over right hand side
// of alignment
// box position is adjusted away from the edge
// overly large boxX value reset to width-boxWidth
- int xpos = 100;
- mouseClick(od, xpos, 0);
+ int xpos = 100 + boxWidth / 2;
+ mouseClick(od, xpos, boxHeight / 2);
assertEquals(od.getBoxX(), Math.round(od.getWidth()) - boxWidth);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
public void testFromMouseWithHiddenColsInMiddle()
{
od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
- testBoxIsAtClickPoint(0, 0);
+ testBoxIsAtClickPoint(boxWidth / 2, boxHeight / 2);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
hiddenCols.hideColumns(firstHidden, lastHidden);
od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
- testBoxIsAtClickPoint(0, 0);
+ testBoxIsAtClickPoint(boxWidth / 2, boxHeight / 2);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
// move box so that it overlaps with hidden cols on one side
// box width, boxX and scrollCol as for unhidden case
- int xpos = 55 - boxWidth; // 55 is position in overview approx halfway
+ int xpos = 54 - boxWidth / 2; // 54 is position in overview approx halfway
// between cols 60 and 70
- mouseClick(od, xpos, 0);
- testBoxIsAtClickPoint(xpos, 0);
- assertEquals(vpranges.getStartRes(),
- Math.round(xpos * alwidth / od.getWidth()));
+ mouseClick(od, xpos, boxHeight / 2);
+ testBoxIsAtClickPoint(xpos, boxHeight / 2);
+ assertEquals(vpranges.getStartRes(), 1 + // rounding
+ Math.round((xpos - boxWidth / 2) * alwidth / od.getWidth()));
assertEquals(vpranges.getStartSeq(), 0);
// move box so that it completely covers hidden cols
// box width, boxX and scrollCol as for unhidden case
xpos = 33;
- mouseClick(od, xpos, 0);
- testBoxIsAtClickPoint(xpos, 0);
+ mouseClick(od, xpos, boxHeight / 2);
+ testBoxIsAtClickPoint(xpos, boxHeight / 2);
assertEquals(vpranges.getStartRes(),
- Math.round((float) xpos * alwidth / od.getWidth()));
+ Math.round((float) (xpos - boxWidth / 2) * alwidth
+ / od.getWidth()));
assertEquals(vpranges.getStartSeq(), 0);
// move box so boxX is in hidden cols, box overhangs at right
// boxX and scrollCol at left of hidden area, box width unchanged
- xpos = 50;
- mouseClick(od, xpos, 0);
- testBoxIsAtClickPoint(xpos, 0);
- assertEquals(vpranges.getStartRes(),
- Math.round((float) xpos * alwidth / od.getWidth()));
+ xpos = Math.round((float) 50 * od.getWidth() / alwidth) + boxWidth / 2;
+ mouseClick(od, xpos, boxHeight / 2);
+ assertEquals(od.getBoxX() + od.getBoxWidth() / 2, xpos);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
+ assertEquals(vpranges.getStartRes(), 50);
assertEquals(vpranges.getStartSeq(), 0);
// move box so boxX is to right of hidden cols, but does not go beyond full
// width of alignment
// box width, boxX and scrollCol all as for non-hidden case
- xpos = 75;
- testBoxIsAtClickPoint(xpos, 0);
+ xpos = Math.round((float) 75 * od.getWidth() / alwidth) + boxWidth / 2;
+ mouseClick(od, xpos, boxHeight / 2);
+ assertEquals(od.getBoxX() + od.getBoxWidth() / 2, xpos);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
assertEquals(vpranges.getStartSeq(), 0);
- assertEquals(vpranges.getStartRes(),
- Math.round(xpos * alwidth / od.getWidth()));
+ assertEquals(vpranges.getStartRes(), 75);
// move box so it goes beyond full width of alignment
// boxX, scrollCol adjusted back, box width normal
xpos = 3000;
- mouseClick(od, xpos, 0);
+ mouseClick(od, xpos, boxHeight / 2);
assertEquals(od.getBoxX(), Math.round(od.getWidth()) - boxWidth);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
// click to left of hidden cols, without overlapping
// boxX, scrollCol and width as normal
- int xpos = 5;
- testBoxIsAtClickPoint(xpos, 0);
- assertEquals(vpranges.getStartSeq(), 0);
- assertEquals(vpranges.getStartRes(),
- Math.round((float) xpos * alwidth / od.getWidth()));
+ int xpos = 30;
+ int ypos = 6;
+ testBoxIsAtClickPoint(xpos, ypos);
+ assertEquals(vpranges.getStartSeq(), Math.round(
+ (float) (ypos - boxHeight / 2) * alheight / od.getHeight()));
+ assertEquals(vpranges.getStartRes(), Math.round(
+ (float) (xpos - boxWidth / 2) * alwidth / od.getWidth()));
// click to left of hidden cols, with overlap
// boxX and scrollCol adjusted for hidden cols, width normal
- xpos = Math.round((float) 145 * od.getWidth() / alwidth) - boxWidth;
- mouseClick(od, xpos, 0);
- testBoxIsAtClickPoint(xpos, 0);
+ xpos = Math.round((float) 144 * od.getWidth() / alwidth) - boxWidth;
+ mouseClick(od, xpos, boxHeight / 2);
+ testBoxIsAtClickPoint(xpos, boxHeight / 2);
assertEquals(vpranges.getStartRes(),
- Math.round((float) xpos * alwidth / od.getWidth()));
+ Math.round((float) (xpos - boxWidth / 2) * alwidth
+ / od.getWidth()));
assertEquals(vpranges.getStartSeq(), 0);
// click off end of alignment
assertEquals(od.getBoxHeight(), boxHeight);
// click below hidden rows
- mouseClick(od, 0, 150);
+ mouseClick(od, 0, 151 + boxHeight / 2);
assertEquals(od.getBoxX(), 0);
- assertEquals(od.getBoxY(), 150);
+ assertEquals(od.getBoxY(), 151);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
}
assertEquals(od.getBoxHeight(), boxHeight);
// click above hidden rows, so that box overlaps
- int ypos = 35; // column value in residues
+ int ypos = 35 + viewHeight / 2; // row value in residues
mouseClick(od, 0,
Math.round((float) ypos * od.getSequencesHeight() / alheight));
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(),
- Math.round((float) ypos * od.getSequencesHeight() / alheight));
+ Math.round((float) 35 * od.getSequencesHeight() / alheight));
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
// click so that box straddles hidden rows
- ypos = 44; // column value in residues
+ ypos = 45 + viewHeight / 2; // row value in residues
mouseClick(od, 0,
Math.round((float) ypos * od.getSequencesHeight() / alheight));
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(),
- Math.round((float) ypos * od.getSequencesHeight() / alheight));
+ Math.round((float) 45 * od.getSequencesHeight() / alheight));
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
}
assertEquals(od.getBoxHeight(), boxHeight);
// click above hidden rows
- int ypos = 40; // row 40
+ int ypos = 41 + viewHeight / 2; // row 41
mouseClick(od, 0,
Math.round((float) ypos * od.getSequencesHeight() / alheight));
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(),
- Math.round((float) ypos * od.getSequencesHeight() / alheight));
+ Math.round((float) 41 * od.getSequencesHeight() / alheight));
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
// click above hidden rows so box overlaps
// boxY, boxHeight remains same
- ypos = 497; // row 497
+ ypos = 497 + viewHeight / 2; // row 497
mouseClick(od, 0,
Math.round((float) ypos * od.getSequencesHeight() / alheight));
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxHeight(), boxHeight);
}
+ /**
+ * Test the function to determine if a point is in the overview's box or not
+ */
+ @Test(groups = { "Functional" })
+ public void testPositionInBox()
+ {
+ od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
+
+ assertFalse(od.isPositionInBox(0, 0));
+ assertTrue(od.isPositionInBox(10, 9));
+ assertFalse(od.isPositionInBox(0, 9));
+ assertFalse(od.isPositionInBox(9, 0));
+ assertFalse(od.isPositionInBox(75, 20));
+
+ // hide columns in the box area
+ // makes absolutely no difference
+ hiddenCols.hideColumns(1, 4);
+ od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
+ assertFalse(od.isPositionInBox(0, 0));
+ assertTrue(od.isPositionInBox(10, 9));
+ assertFalse(od.isPositionInBox(0, 9));
+ assertFalse(od.isPositionInBox(9, 0));
+ assertFalse(od.isPositionInBox(75, 20));
+
+ // hide sequences in box area
+ // makes absolutely no difference
+ hideSequences(1, 3);
+ od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
+ assertFalse(od.isPositionInBox(0, 0));
+ assertTrue(od.isPositionInBox(10, 9));
+ assertFalse(od.isPositionInBox(0, 9));
+ assertFalse(od.isPositionInBox(9, 0));
+ 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);
+
+ // hide columns - makes no difference
+ hiddenCols.hideColumns(1, 4);
+ od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
+ od.setDragPoint(4, 16, al.getHiddenSequences(), hiddenCols);
+ od.adjustViewportFromMouse(20, 22, al.getHiddenSequences(), hiddenCols);
+ od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
+
+ // corner moves 16 (20-4) right and 6 (22-16) up
+ assertEquals(od.getBoxX(), 16);
+ assertEquals(od.getBoxY(), 6);
+
+ // hide sequences in box area
+ // makes absolutely no difference
+ hideSequences(1, 3);
+ od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
+ od.setDragPoint(4, 16, al.getHiddenSequences(), hiddenCols);
+ od.adjustViewportFromMouse(20, 22, al.getHiddenSequences(), hiddenCols);
+ 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.
*/
private void testBoxIsAtClickPoint(int xpos, int ypos)
{
mouseClick(od, xpos, ypos);
- assertEquals(od.getBoxX(), xpos);
- assertEquals(od.getBoxY(), ypos);
+ assertEquals(od.getBoxX() + od.getBoxWidth() / 2, xpos);
+ assertEquals(od.getBoxY() + od.getBoxHeight() / 2, ypos);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
package jalview.viewmodel;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
import jalview.analysis.AlignmentGenerator;
import jalview.datamodel.Alignment;
ViewportRanges vpranges;
- Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
+ Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences = new Hashtable<>();
HiddenColumns hiddenCols = new HiddenColumns();
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
- assertEquals(vpranges.getStartSeq(),
+ assertEquals(vpranges.getStartSeq() + vpranges.getViewportHeight() / 2,
Math.round((float) 10 * alheight / od.getSequencesHeight()));
assertEquals(vpranges.getStartRes(), 0);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
- assertEquals(vpranges.getStartRes(),
- Math.round((float) 6 * alwidth / od.getWidth()));
+ assertEquals(vpranges.getStartRes(), 0);
assertEquals(vpranges.getStartSeq(), 0);
// overly large boxX value reset to width-boxWidth
- mouseClick(od, 100, 6);
+ mouseClick(od, 101, 6);
assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
- assertEquals(od.getBoxY(), 6);
+ assertEquals(od.getBoxY(), 1);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
assertEquals(vpranges.getStartRes(),
// overly large boxY value reset to sequenceHeight - boxHeight
mouseClick(od, 10, 520);
- assertEquals(od.getBoxX(), 10);
+ assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), od.getSequencesHeight() - od.getBoxHeight());
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
- assertEquals(vpranges.getStartRes(),
+ assertEquals(0,
Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
// here (float) od.getBoxY() * alheight / od.getSequencesHeight() = 507.5
/ od.getSequencesHeight()));
// move viewport so startRes non-zero and then mouseclick
- moveViewportH(50);
+ moveViewportH(20);
// click at viewport position
int oldboxx = od.getBoxX();
int oldboxy = od.getBoxY();
- mouseClick(od, od.getBoxX() + 5, od.getBoxY() + 2);
- assertEquals(od.getBoxX(), oldboxx + 5);
+ mouseClick(od, od.getBoxX() + od.getBoxWidth() / 2 + 6,
+ od.getBoxY() + od.getBoxHeight() / 2 + 3);
+ assertEquals(od.getBoxX(), oldboxx + 6);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
assertEquals(vpranges.getStartRes(),
Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
- assertEquals(od.getBoxY(), oldboxy + 2);
+ assertEquals(od.getBoxY(), oldboxy + 3);
assertEquals(
vpranges.getStartSeq(),
Math.round((float) od.getBoxY() * alheight
assertEquals(vpranges.getStartRes(), 0);
// click to right of hidden columns, box moves to click point
- testBoxIsAtClickPoint(40, 0);
+ mouseClick(od, 60 + boxWidth / 2, boxHeight / 2);
+ assertEquals(od.getBoxX(), 60);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
assertEquals(vpranges.getStartSeq(), 0);
assertEquals(vpranges.getStartRes(),
- Math.round((float) 40 * alwidth / od.getWidth())
+ Math.round(
+ (float) 60 * alwidth / od.getWidth())
- (lastHiddenCol + 1));
// click to right of hidden columns such that box runs over right hand side
// box position is adjusted away from the edge
// overly large boxX value reset to width-boxWidth
xpos = 100;
- mouseClick(od, xpos, 5);
+ mouseClick(od, xpos + boxWidth / 2, 5 + boxHeight / 2);
assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
assertEquals(od.getBoxY(), 5);
assertEquals(od.getBoxWidth(), boxWidth);
// move box so that it overlaps with hidden cols on one side
// box width changes, boxX and scrollCol as for unhidden case
- int xpos = 55 - boxWidth; // 55 is position in overview approx halfway
+ int xpos = 54 - boxWidth / 2; // 54 is position in overview approx halfway
// between cols 60 and 70
- mouseClick(od, xpos, 0);
- assertEquals(od.getBoxX(), xpos);
+ mouseClick(od, xpos, boxHeight / 2);
+ assertEquals(od.getBoxX(), xpos - boxWidth / 2);
assertEquals(od.getBoxY(), 0);
assertEquals(
od.getBoxWidth(),
* od.getWidth() / alwidth));
assertEquals(od.getBoxHeight(), boxHeight);
assertEquals(vpranges.getStartRes(),
- Math.round(xpos * alwidth / od.getWidth()));
+ Math.round((xpos - boxWidth / 2) * alwidth / od.getWidth())
+ + 1); // +1 for rounding
assertEquals(vpranges.getStartSeq(), 0);
// move box so that it completely covers hidden cols
// box width changes, boxX and scrollCol as for hidden case
- xpos = 33;
+ xpos = 24 + boxWidth / 2;
mouseClick(od, xpos, 0);
- assertEquals(od.getBoxX(), xpos);
+ assertEquals(od.getBoxX(), 24);
assertEquals(od.getBoxY(), 0);
assertEquals(
od.getBoxWidth(),
* od.getWidth() / alwidth));
assertEquals(od.getBoxHeight(), boxHeight);
assertEquals(vpranges.getStartRes(),
- Math.round((float) xpos * alwidth / od.getWidth()));
- assertEquals(vpranges.getStartSeq(), 0);
-
- // move box so boxX is in hidden cols, box overhangs at right
- // boxX and scrollCol at left of hidden area, box width extends across
- // hidden region
- xpos = 50;
- mouseClick(od, xpos, 0);
- assertEquals(od.getBoxX(),
- Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth));
- assertEquals(od.getBoxY(), 0);
- assertEquals(
- od.getBoxWidth(),
- boxWidth
- + Math.round((float) (lastHidden - firstHidden + 1)
- * od.getWidth() / alwidth));
- assertEquals(od.getBoxHeight(), boxHeight);
- assertEquals(vpranges.getStartRes(), firstHidden - 1);
+ Math.round((float) 24 * alwidth / od.getWidth()));
assertEquals(vpranges.getStartSeq(), 0);
// move box so boxX is to right of hidden cols, but does not go beyond full
// width of alignment
// box width, boxX and scrollCol all as for non-hidden case
- xpos = 75;
- testBoxIsAtClickPoint(xpos, 0);
+ xpos = Math.round((float) 75 * od.getWidth() / alwidth) + boxWidth / 2;
+ mouseClick(od, xpos, boxHeight / 2);
+ assertEquals(od.getBoxX(), xpos - boxWidth / 2);
+ assertEquals(od.getBoxY(), 0);
+ assertEquals(od.getBoxWidth(), boxWidth);
+ assertEquals(od.getBoxHeight(), boxHeight);
assertEquals(vpranges.getStartSeq(), 0);
assertEquals(vpranges.getStartRes(),
- Math.round(xpos * alwidth / od.getWidth())
- - (lastHidden - firstHidden + 1));
+ 75 - (lastHidden - firstHidden + 1));
// move box so it goes beyond full width of alignment
// boxX, scrollCol adjusted back, box width normal
xpos = 3000;
mouseClick(od, xpos, 5);
assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
- assertEquals(od.getBoxY(), 5);
+ assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
assertEquals(
// click to left of hidden cols, without overlapping
// boxX, scrollCol and width as normal
- int xpos = 5;
- testBoxIsAtClickPoint(xpos, 0);
- assertEquals(vpranges.getStartSeq(), 0);
- assertEquals(vpranges.getStartRes(),
- Math.round((float) xpos * alwidth / od.getWidth()));
+ int xpos = 30;
+ int ypos = 6;
+ testBoxIsAtClickPoint(xpos, ypos);
+ assertEquals(vpranges.getStartSeq(), Math
+ .round((float) (ypos - boxHeight / 2) * alheight
+ / od.getHeight()));
+ assertEquals(vpranges.getStartRes(), Math.round(
+ (float) (xpos - boxWidth / 2) * alwidth / od.getWidth()));
// click to left of hidden cols, with overlap
// boxX and scrollCol adjusted for hidden cols, width normal
xpos = Math.round((float) 145 * od.getWidth() / alwidth) - boxWidth;
- mouseClick(od, xpos, 0);
+ mouseClick(od, xpos + boxWidth / 2, boxHeight / 2);
assertEquals(od.getBoxX(),
- Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth)
+ Math.round((float) (firstHidden - 1)
+ * od.getWidth() / alwidth)
- boxWidth + 1);
assertEquals(od.getBoxY(), 0);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
assertEquals(vpranges.getStartRes(),
- Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
+ Math.round((float) (od.getBoxX()) * alwidth
+ / od.getWidth()));
assertEquals(vpranges.getStartSeq(), 0);
// click in hidden cols
assertEquals(od.getBoxHeight(), boxHeight);
// click below hidden rows
- mouseClick(od, 0, 150);
+ mouseClick(od, 0, 150 + boxHeight/2);
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(), 150);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
// click above hidden rows, so that box overlaps
- int ypos = 35; // column value in residues
- mouseClick(od, 0,
- Math.round((float) ypos * od.getSequencesHeight() / alheight));
- assertEquals(od.getBoxX(), 0);
- assertEquals(od.getBoxY(),
- Math.round((float) ypos * od.getSequencesHeight() / alheight));
- assertEquals(od.getBoxWidth(), boxWidth);
- assertEquals(
- od.getBoxHeight(),
- boxHeight
- + Math.round((float) (lastHiddenRow - firstHiddenRow + 1)
- * od.getSequencesHeight() / alheight));
-
- // click so that box straddles hidden rows
- ypos = 44; // column value in residues
+ int rowpos = 35; // row value in residues
+ int centrepos = 43; // centre row
mouseClick(od, 0,
- Math.round((float) ypos * od.getSequencesHeight() / alheight));
+ Math.round((float) centrepos * od.getSequencesHeight()
+ / alheight));
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(),
- Math.round((float) ypos * od.getSequencesHeight() / alheight));
+ Math.round(
+ (float) rowpos * od.getSequencesHeight() / alheight));
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(
od.getBoxHeight(),
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
- // click above hidden rows
- int ypos = 40; // row 40
+ // click above hidden rows, no overlap
+ int ypos = 40 + viewHeight / 2; // top is row 40
mouseClick(od, 0,
Math.round((float) ypos * od.getSequencesHeight() / alheight));
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxY(),
- Math.round((float) ypos * od.getSequencesHeight() / alheight));
+ Math.round((float) 40 * od.getSequencesHeight() / alheight));
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);
// click above hidden rows so box overlaps
// boxY moved upwards, boxHeight remains same
- ypos = 497; // row 497
+ ypos = 497 + viewHeight / 2; // row 497
mouseClick(od, 0,
Math.round((float) ypos * od.getSequencesHeight() / alheight));
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxHeight(), boxHeight);
// click within hidden rows
- ypos = 505;
+ ypos = 505 + boxHeight / 2;
mouseClick(od, 0,
Math.round((float) ypos * od.getSequencesHeight() / alheight));
assertEquals(od.getBoxX(), 0);
assertEquals(od.getBoxHeight(), boxHeight);
}
+ /**
+ * Test the function to determine if a point is in the overview's box or not
+ */
+ @Test(groups = { "Functional" })
+ public void testPositionInBox()
+ {
+ od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
+
+ assertFalse(od.isPositionInBox(0, 0));
+ assertTrue(od.isPositionInBox(10, 9));
+ assertFalse(od.isPositionInBox(0, 9));
+ assertFalse(od.isPositionInBox(9, 0));
+ assertFalse(od.isPositionInBox(75, 20));
+
+ assertTrue(od.isPositionInBox(47, 6));
+ assertFalse(od.isPositionInBox(48, 6));
+ assertTrue(od.isPositionInBox(47, 9));
+ assertFalse(od.isPositionInBox(47, 10));
+
+ // hide columns in the box area
+ // extends area where a point is considered to be in the box
+ hiddenCols.hideColumns(1, 4);
+ od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
+ assertFalse(od.isPositionInBox(0, 0));
+ assertTrue(od.isPositionInBox(10, 9));
+ assertFalse(od.isPositionInBox(0, 9));
+ assertFalse(od.isPositionInBox(9, 0));
+ assertFalse(od.isPositionInBox(75, 20));
+
+ assertTrue(od.isPositionInBox(47, 6));
+ assertTrue(od.isPositionInBox(48, 6));
+ assertTrue(od.isPositionInBox(47, 9));
+ assertFalse(od.isPositionInBox(47, 10));
+
+ // hide sequences in box area
+ // extends area where a point is considered to be in the box
+ hideSequences(1, 3);
+ ColumnSelection cs = new ColumnSelection();
+ hiddenCols.revealAllHiddenColumns(cs);
+ od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
+ assertFalse(od.isPositionInBox(0, 0));
+ assertTrue(od.isPositionInBox(10, 9));
+ assertFalse(od.isPositionInBox(0, 9));
+ assertFalse(od.isPositionInBox(9, 0));
+ assertFalse(od.isPositionInBox(75, 20));
+
+ assertTrue(od.isPositionInBox(47, 6));
+ assertFalse(od.isPositionInBox(48, 6));
+ assertTrue(od.isPositionInBox(47, 9));
+ 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);
+
+ // hide columns - box moves drag distance + hidden cols, vertically makes no
+ // difference
+ hiddenCols.hideColumns(1, 4);
+ od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
+ od.setDragPoint(4, 16, al.getHiddenSequences(), hiddenCols);
+ od.adjustViewportFromMouse(20, 22, al.getHiddenSequences(), hiddenCols);
+ od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
+
+ // corner moves 16 (20-4) + hiddenCols right and 6 (22-16) down
+ assertEquals(od.getBoxX(),
+ 16 + Math.round((float) 4 * od.getWidth() / alwidth));
+ assertEquals(od.getBoxY(), 6);
+
+ // hide sequences in box area
+ // makes absolutely no difference
+ hideSequences(1, 3);
+ od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
+ od.setDragPoint(4, 16, al.getHiddenSequences(), hiddenCols);
+ od.adjustViewportFromMouse(20, 22, al.getHiddenSequences(), hiddenCols);
+ od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
+
+ // corner moves 16 (20-4) + hiddenCols right and 6 (22-16) + hiddenRows down
+ assertEquals(od.getBoxX(),
+ 16 + Math.round((float) 4 * od.getWidth() / alwidth));
+ assertEquals(od.getBoxY(),
+ 6 + Math.round((float) 3 * od.getHeight() / alheight));
+ }
+
/*
* Move viewport horizontally: startRes + previous width gives new horizontal extent. Vertical extent stays the same.
*/
}
/*
- * Test that the box is positioned with the top left corner at xpos, ypos
+ * Test that the box is positioned with the centre at xpos, ypos
* and with the original width and height
*/
private void testBoxIsAtClickPoint(int xpos, int ypos)
{
mouseClick(od, xpos, ypos);
- assertEquals(od.getBoxX(), xpos);
- assertEquals(od.getBoxY(), ypos);
+ assertEquals(od.getBoxX() + od.getBoxWidth() / 2, xpos);
+ assertEquals(od.getBoxY() + od.getBoxHeight() / 2, ypos);
assertEquals(od.getBoxWidth(), boxWidth);
assertEquals(od.getBoxHeight(), boxHeight);