JAL-3093 tweaks to code and test for 3px gap above annotations in
[jalview.git] / test / jalview / gui / SeqPanelTest.java
index 4177acc..d5c012e 100644 (file)
@@ -138,7 +138,7 @@ public class SeqPanelTest
   }
 
   @Test(groups = "Functional")
-  public void testFindMousePosition_wrapped()
+  public void testFindMousePosition_wrapped_annotations()
   {
     Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", "true");
     Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true");
@@ -236,6 +236,7 @@ public class SeqPanelTest
 
     /*
      * cursor below sequences, in 3-pixel gap above annotations
+     * method reports index of nearest sequence above
      */
     y += 1;
     evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
@@ -246,7 +247,6 @@ public class SeqPanelTest
 
     /*
      * cursor still in the gap above annotations, now at the bottom of it
-     * method reports index of nearest sequence above  
      */
     y += SeqCanvas.SEQS_ANNOTATION_GAP - 1; // 3-1 = 2
     evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
@@ -576,6 +576,93 @@ public class SeqPanelTest
     assertEquals(pos.seqIndex, 0);
     assertEquals(pos.annotationIndex, -1);
   }
+  @Test(groups = "Functional")
+  public void testFindMousePosition_wrapped_noAnnotations()
+  {
+    Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", "false");
+    Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true");
+    AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
+            "examples/uniref50.fa", DataSourceType.FILE);
+    AlignViewportI av = alignFrame.getViewport();
+    av.setScaleAboveWrapped(false);
+    av.setScaleLeftWrapped(false);
+    av.setScaleRightWrapped(false);
+    alignFrame.alignPanel.paintAlignment(false, false);
+  
+    final int charHeight = av.getCharHeight();
+    final int charWidth = av.getCharWidth();
+    final int alignmentHeight = av.getAlignment().getHeight();
+    
+    // sanity checks:
+    assertTrue(charHeight > 0);
+    assertTrue(charWidth > 0);
+    assertTrue(alignFrame.alignPanel.getSeqPanel().getWidth() > 0);
+  
+    SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
+    int x = 0;
+    int y = 0;
+  
+    /*
+     * mouse at top left of wrapped panel; there is a gap of charHeight
+     * above the alignment
+     */
+    MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y,
+            0, 0, 0, false, 0);
+    MousePos pos = testee.findMousePosition(evt);
+    assertEquals(pos.column, 0);
+    assertEquals(pos.seqIndex, -1); // above sequences
+    assertEquals(pos.annotationIndex, -1);
+  
+    /*
+     * cursor over top of first sequence
+     */
+    y = charHeight;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, 0);
+    assertEquals(pos.annotationIndex, -1);
+
+    /*
+     * cursor at bottom of last sequence
+     */
+    y = charHeight * (1 + alignmentHeight) - 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, alignmentHeight - 1);
+    assertEquals(pos.annotationIndex, -1);
+  
+    /*
+     * cursor below sequences, at top of charHeight gap between widths
+     */
+    y += 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, -1);
+    assertEquals(pos.annotationIndex, -1);
+  
+    /*
+     * cursor below sequences, at top of charHeight gap between widths
+     */
+    y += charHeight - 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, -1);
+    assertEquals(pos.annotationIndex, -1);
+  
+    /*
+     * cursor at the top of the first sequence, second width  
+     */
+    y += 1;
+    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+            false, 0);
+    pos = testee.findMousePosition(evt);
+    assertEquals(pos.seqIndex, 0);
+    assertEquals(pos.annotationIndex, -1);
+  }
   @BeforeClass(alwaysRun = true)
   public static void setUpBeforeClass() throws Exception
   {