JAL-4020 class formatting
[jalview.git] / test / jalview / viewmodel / OverviewDimensionsHideHiddenTest.java
index 120c715..4640674 100644 (file)
@@ -21,6 +21,8 @@
 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;
@@ -48,10 +50,15 @@ public class OverviewDimensionsHideHiddenTest
 
   // cached widths and heights
   int boxWidth;
+
   int boxHeight;
+
   int viewHeight;
+
   int viewWidth;
+
   int alheight;
+
   int alwidth;
 
   ViewportRanges vpranges;
@@ -77,7 +84,7 @@ public class OverviewDimensionsHideHiddenTest
     }
     ColumnSelection colsel = new ColumnSelection();
     hiddenCols.revealAllHiddenColumns(colsel);
-    
+
     vpranges = new ViewportRanges(al);
     vpranges.setViewportStartAndHeight(0, 18);
     vpranges.setViewportStartAndWidth(0, 63);
@@ -98,12 +105,12 @@ public class OverviewDimensionsHideHiddenTest
     alheight = vpranges.getVisibleAlignmentHeight();
     alwidth = vpranges.getVisibleAlignmentWidth();
 
-    boxWidth = Math.round((float) (vpranges.getEndRes()
-            - vpranges.getStartRes() + 1)
-            * od.getWidth() / alwidth);
-    boxHeight = Math.round((float) (vpranges.getEndSeq()
-            - vpranges.getStartSeq() + 1)
-            * od.getSequencesHeight() / alheight);
+    boxWidth = Math.round(
+            (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
+                    * od.getWidth() / alwidth);
+    boxHeight = Math.round(
+            (float) (vpranges.getEndSeq() - vpranges.getStartSeq() + 1)
+                    * od.getSequencesHeight() / alheight);
   }
 
   @AfterClass(alwaysRun = true)
@@ -230,10 +237,8 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(od.getBoxHeight(), boxHeight);
     assertEquals(vpranges.getStartRes(),
             Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
-    assertEquals(
-            vpranges.getStartSeq(),
-            Math.round((float) od.getBoxY() * alheight
-                    / od.getSequencesHeight()));
+    assertEquals(vpranges.getStartSeq(), Math.round(
+            (float) od.getBoxY() * alheight / od.getSequencesHeight()));
 
     // overly large boxY value reset to sequenceHeight - boxHeight
     mouseClick(od, 10, 520);
@@ -247,10 +252,8 @@ public class OverviewDimensionsHideHiddenTest
     // here (float) od.getBoxY() * alheight / od.getSequencesHeight() = 507.5
     // and round rounds to 508; however we get 507 working with row values
     // hence the subtraction of 1
-    assertEquals(
-            vpranges.getStartSeq(),
-            Math.round((float) od.getBoxY() * alheight
-                    / od.getSequencesHeight()) - 1);
+    assertEquals(vpranges.getStartSeq(), Math.round(
+            (float) od.getBoxY() * alheight / od.getSequencesHeight()) - 1);
 
     // click past end of alignment, as above
     mouseClick(od, 3000, 5);
@@ -259,10 +262,8 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(od.getBoxHeight(), boxHeight);
     assertEquals(vpranges.getStartRes(),
             Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
-    assertEquals(
-            vpranges.getStartSeq(),
-            Math.round((float) od.getBoxY() * alheight
-                    / od.getSequencesHeight()));
+    assertEquals(vpranges.getStartSeq(), Math.round(
+            (float) od.getBoxY() * alheight / od.getSequencesHeight()));
 
     // move viewport so startRes non-zero and then mouseclick
     moveViewportH(20);
@@ -278,10 +279,8 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(vpranges.getStartRes(),
             Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
     assertEquals(od.getBoxY(), oldboxy + 3);
-    assertEquals(
-            vpranges.getStartSeq(),
-            Math.round((float) od.getBoxY() * alheight
-                    / od.getSequencesHeight()));
+    assertEquals(vpranges.getStartSeq(), Math.round(
+            (float) od.getBoxY() * alheight / od.getSequencesHeight()));
 
     // click at top corner
     mouseClick(od, 0, 0);
@@ -348,7 +347,7 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(vpranges.getStartRes(), 0);
     assertEquals(vpranges.getStartSeq(), 0);
-    
+
     // hide columns 63-73, no change to box position or dimensions
     int firstHidden = 63;
     int lastHidden = 73;
@@ -365,7 +364,7 @@ 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 = 54 - boxWidth / 2; // 54 is position in overview approx halfway
-                              // between cols 60 and 70
+    // between cols 60 and 70
     mouseClick(od, xpos, boxHeight / 2);
     testBoxIsAtClickPoint(xpos, boxHeight / 2);
     assertEquals(vpranges.getStartRes(), 1 + // rounding
@@ -377,9 +376,8 @@ public class OverviewDimensionsHideHiddenTest
     xpos = 33;
     mouseClick(od, xpos, boxHeight / 2);
     testBoxIsAtClickPoint(xpos, boxHeight / 2);
-    assertEquals(vpranges.getStartRes(),
-            Math.round((float) (xpos - boxWidth / 2) * alwidth
-                    / od.getWidth()));
+    assertEquals(vpranges.getStartRes(), 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
@@ -404,7 +402,7 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(od.getBoxHeight(), boxHeight);
     assertEquals(vpranges.getStartSeq(), 0);
     assertEquals(vpranges.getStartRes(), 75);
-    
+
     // move box so it goes beyond full width of alignment
     // boxX, scrollCol adjusted back, box width normal
     xpos = 3000;
@@ -459,9 +457,8 @@ public class OverviewDimensionsHideHiddenTest
     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 - boxWidth / 2) * alwidth
-                    / od.getWidth()));
+    assertEquals(vpranges.getStartRes(), Math.round(
+            (float) (xpos - boxWidth / 2) * alwidth / od.getWidth()));
     assertEquals(vpranges.getStartSeq(), 0);
 
     // click off end of alignment
@@ -539,9 +536,8 @@ public class OverviewDimensionsHideHiddenTest
     // move viewport to end of alignment - need to make startRes by removing
     // hidden cols because of how viewport/overview are implemented
     moveViewport(98 - lastHidden - 1, 0);
-    assertEquals(od.getBoxX(),
-            Math.round((float) (98 - lastHidden - 1) * od.getWidth()
-                    / alwidth));
+    assertEquals(od.getBoxX(), Math.round(
+            (float) (98 - lastHidden - 1) * od.getWidth() / alwidth));
     assertEquals(od.getBoxY(), 0);
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
@@ -617,9 +613,8 @@ public class OverviewDimensionsHideHiddenTest
     // viewport can't actually extend into hidden cols,
     // so move to the far right edge of the viewport
     moveViewport(firstHidden - viewWidth, 0);
-    assertEquals(od.getBoxX(),
-            Math.round((float) (firstHidden - viewWidth)
-                    * od.getWidth() / alwidth));
+    assertEquals(od.getBoxX(), Math.round(
+            (float) (firstHidden - viewWidth) * od.getWidth() / alwidth));
     assertEquals(od.getBoxY(), 0);
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
@@ -640,12 +635,12 @@ public class OverviewDimensionsHideHiddenTest
     alheight = vpranges.getVisibleAlignmentHeight();
     alwidth = vpranges.getVisibleAlignmentWidth();
 
-    boxWidth = Math.round((float) (vpranges.getEndRes()
-            - vpranges.getStartRes() + 1)
-            * od.getWidth() / alwidth);
-    boxHeight = Math.round((float) (vpranges.getEndSeq()
-            - vpranges.getStartSeq() + 1)
-            * od.getSequencesHeight() / alheight);
+    boxWidth = Math.round(
+            (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
+                    * od.getWidth() / alwidth);
+    boxHeight = Math.round(
+            (float) (vpranges.getEndSeq() - vpranges.getStartSeq() + 1)
+                    * od.getSequencesHeight() / alheight);
 
     // move viewport to start of alignment:
     // box moves to below hidden rows, height remains same
@@ -658,11 +653,9 @@ public class OverviewDimensionsHideHiddenTest
     // move viewport to end of alignment
     moveViewport(0, 525 - viewHeight - lastHidden - 1);
     assertEquals(od.getBoxX(), 0);
-    assertEquals(
-            od.getBoxY(),
+    assertEquals(od.getBoxY(),
             Math.round((float) (525 - viewHeight - lastHidden - 1)
-                    * od.getSequencesHeight()
-                    / alheight));
+                    * od.getSequencesHeight() / alheight));
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
   }
@@ -682,12 +675,12 @@ public class OverviewDimensionsHideHiddenTest
     alheight = vpranges.getVisibleAlignmentHeight();
     alwidth = vpranges.getVisibleAlignmentWidth();
 
-    boxWidth = Math.round((float) (vpranges.getEndRes()
-            - vpranges.getStartRes() + 1)
-            * od.getWidth() / alwidth);
-    boxHeight = Math.round((float) (vpranges.getEndSeq()
-            - vpranges.getStartSeq() + 1)
-            * od.getSequencesHeight() / alheight);
+    boxWidth = Math.round(
+            (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
+                    * od.getWidth() / alwidth);
+    boxHeight = Math.round(
+            (float) (vpranges.getEndSeq() - vpranges.getStartSeq() + 1)
+                    * od.getSequencesHeight() / alheight);
 
     // move viewport to start of alignment:
     // box, height etc as in non-hidden case
@@ -700,8 +693,8 @@ public class OverviewDimensionsHideHiddenTest
     // move viewport to straddle hidden rows
     moveViewport(0, 198);
     assertEquals(od.getBoxX(), 0);
-    assertEquals(od.getBoxY(), Math.round ((float)198 * od.getSequencesHeight()
-            / alheight));
+    assertEquals(od.getBoxY(),
+            Math.round((float) 198 * od.getSequencesHeight() / alheight));
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
   }
@@ -721,12 +714,12 @@ public class OverviewDimensionsHideHiddenTest
     alheight = vpranges.getVisibleAlignmentHeight();
     alwidth = vpranges.getVisibleAlignmentWidth();
 
-    boxWidth = Math.round((float) (vpranges.getEndRes()
-            - vpranges.getStartRes() + 1)
-            * od.getWidth() / alwidth);
-    boxHeight = Math.round((float) (vpranges.getEndSeq()
-            - vpranges.getStartSeq() + 1)
-            * od.getSequencesHeight() / alheight);
+    boxWidth = Math.round(
+            (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
+                    * od.getWidth() / alwidth);
+    boxHeight = Math.round(
+            (float) (vpranges.getEndSeq() - vpranges.getStartSeq() + 1)
+                    * od.getSequencesHeight() / alheight);
 
     // move viewport to start of alignment:
     // box, height etc as in non-hidden case
@@ -740,8 +733,7 @@ public class OverviewDimensionsHideHiddenTest
     // viewport sits above hidden rows and does not include them
     moveViewport(0, firstHidden - viewHeight - 1);
     assertEquals(od.getBoxX(), 0);
-    assertEquals(
-            od.getBoxY(),
+    assertEquals(od.getBoxY(),
             Math.round((float) (firstHidden - viewHeight - 1)
                     * od.getSequencesHeight() / alheight));
     assertEquals(od.getBoxWidth(), boxWidth);
@@ -772,12 +764,12 @@ public class OverviewDimensionsHideHiddenTest
     alheight = vpranges.getVisibleAlignmentHeight();
     alwidth = vpranges.getVisibleAlignmentWidth();
 
-    boxWidth = Math.round((float) (vpranges.getEndRes()
-            - vpranges.getStartRes() + 1)
-            * od.getWidth() / alwidth);
-    boxHeight = Math.round((float) (vpranges.getEndSeq()
-            - vpranges.getStartSeq() + 1)
-            * od.getSequencesHeight() / alheight);
+    boxWidth = Math.round(
+            (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
+                    * od.getWidth() / alwidth);
+    boxHeight = Math.round(
+            (float) (vpranges.getEndSeq() - vpranges.getStartSeq() + 1)
+                    * od.getSequencesHeight() / alheight);
 
     od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
     assertEquals(od.getBoxX(), 0);
@@ -819,12 +811,12 @@ public class OverviewDimensionsHideHiddenTest
     alheight = vpranges.getVisibleAlignmentHeight();
     alwidth = vpranges.getVisibleAlignmentWidth();
 
-    boxWidth = Math.round((float) (vpranges.getEndRes()
-            - vpranges.getStartRes() + 1)
-            * od.getWidth() / alwidth);
-    boxHeight = Math.round((float) (vpranges.getEndSeq()
-            - vpranges.getStartSeq() + 1)
-            * od.getSequencesHeight() / alheight);
+    boxWidth = Math.round(
+            (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
+                    * od.getWidth() / alwidth);
+    boxHeight = Math.round(
+            (float) (vpranges.getEndSeq() - vpranges.getStartSeq() + 1)
+                    * od.getSequencesHeight() / alheight);
 
     od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
 
@@ -879,12 +871,12 @@ public class OverviewDimensionsHideHiddenTest
     alheight = vpranges.getVisibleAlignmentHeight();
     alwidth = vpranges.getVisibleAlignmentWidth();
 
-    boxWidth = Math.round((float) (vpranges.getEndRes()
-            - vpranges.getStartRes() + 1)
-            * od.getWidth() / alwidth);
-    boxHeight = Math.round((float) (vpranges.getEndSeq()
-            - vpranges.getStartSeq() + 1)
-            * od.getSequencesHeight() / alheight);
+    boxWidth = Math.round(
+            (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
+                    * od.getWidth() / alwidth);
+    boxHeight = Math.round(
+            (float) (vpranges.getEndSeq() - vpranges.getStartSeq() + 1)
+                    * od.getSequencesHeight() / alheight);
 
     od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
     assertEquals(od.getBoxX(), 0);
@@ -908,15 +900,91 @@ public class OverviewDimensionsHideHiddenTest
     mouseClick(od, 0,
             Math.round((float) ypos * od.getSequencesHeight() / alheight));
     assertEquals(od.getBoxX(), 0);
-    assertEquals(
-            od.getBoxY(),
-            Math.round((float) firstHidden * od.getSequencesHeight()
-                    / alheight)
-                    - boxHeight);
+    assertEquals(od.getBoxY(), Math
+            .round((float) firstHidden * od.getSequencesHeight() / alheight)
+            - boxHeight);
     assertEquals(od.getBoxWidth(), boxWidth);
     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.
    */
@@ -957,7 +1025,7 @@ public class OverviewDimensionsHideHiddenTest
     // normally
     od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
   }
-  
+
   /*
    * Test that the box is positioned with the top left corner at xpos, ypos
    * and with the original width and height
@@ -979,7 +1047,7 @@ public class OverviewDimensionsHideHiddenTest
   {
     SequenceI[] allseqs = al.getSequencesArray();
     SequenceGroup theseSeqs = new SequenceGroup();
-    
+
     for (int i = start; i <= end; i++)
     {
       theseSeqs.addSequence(allseqs[i], false);