Merge branch 'feature/JAL-2613' into feature/JAL-2611
[jalview.git] / test / jalview / viewmodel / OverviewDimensionsHideHiddenTest.java
index 28b7029..ebafba6 100644 (file)
@@ -212,7 +212,7 @@ public class OverviewDimensionsHideHiddenTest
     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);
 
@@ -221,14 +221,13 @@ public class OverviewDimensionsHideHiddenTest
     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(),
@@ -240,7 +239,7 @@ public class OverviewDimensionsHideHiddenTest
 
     // 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);
@@ -268,18 +267,19 @@ public class OverviewDimensionsHideHiddenTest
                     / 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
@@ -313,20 +313,20 @@ public class OverviewDimensionsHideHiddenTest
     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);
@@ -344,7 +344,7 @@ public class OverviewDimensionsHideHiddenTest
   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);
@@ -357,7 +357,7 @@ public class OverviewDimensionsHideHiddenTest
     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);
@@ -366,45 +366,51 @@ public class OverviewDimensionsHideHiddenTest
 
     // 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);
@@ -442,19 +448,22 @@ public class OverviewDimensionsHideHiddenTest
 
     // 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
@@ -779,9 +788,9 @@ public class OverviewDimensionsHideHiddenTest
     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);
   }
@@ -827,22 +836,22 @@ public class OverviewDimensionsHideHiddenTest
     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);
   }
@@ -886,18 +895,18 @@ public class OverviewDimensionsHideHiddenTest
     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);
@@ -993,8 +1002,8 @@ public class OverviewDimensionsHideHiddenTest
   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);