JAL-3493 failing test - creates a highlight and column selection and then called...
[jalview.git] / test / jalview / gui / SeqPanelTest.java
index f163299..a03819d 100644 (file)
@@ -31,6 +31,7 @@ import jalview.commands.EditCommand;
 import jalview.commands.EditCommand.Action;
 import jalview.commands.EditCommand.Edit;
 import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
@@ -38,9 +39,11 @@ import jalview.gui.SeqPanel.MousePos;
 import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
 import jalview.util.MessageManager;
+import jalview.viewmodel.ViewportRanges;
 
-import java.awt.Event;
+import java.awt.EventQueue;
 import java.awt.event.MouseEvent;
+import java.lang.reflect.InvocationTargetException;
 
 import javax.swing.JLabel;
 
@@ -238,7 +241,7 @@ public class SeqPanelTest
     /*
      * mouse at top left of unwrapped panel
      */
-    MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y,
+    MouseEvent evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y,
             0, 0, 0, false, 0);
     MousePos pos = testee.findMousePosition(evt);
     assertEquals(pos.column, 0);
@@ -263,8 +266,8 @@ public class SeqPanelTest
     av.setScaleAboveWrapped(false);
     av.setScaleLeftWrapped(false);
     av.setScaleRightWrapped(false);
-    alignFrame.alignPanel.paintAlignment(false, false);
-    waitForSwing(); // for Swing thread
+
+    alignFrame.alignPanel.updateLayout();
 
     final int charHeight = av.getCharHeight();
     final int charWidth = av.getCharWidth();
@@ -283,7 +286,7 @@ public class SeqPanelTest
      * 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,
+    MouseEvent evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y,
             0, 0, 0, false, 0);
     MousePos pos = testee.findMousePosition(evt);
     assertEquals(pos.column, 0);
@@ -294,7 +297,7 @@ public class SeqPanelTest
      * cursor at bottom of gap above
      */
     y = charHeight - 1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, -1);
@@ -304,7 +307,7 @@ public class SeqPanelTest
      * cursor over top of first sequence
      */
     y = charHeight;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, 0);
@@ -314,7 +317,7 @@ public class SeqPanelTest
      * cursor at bottom of first sequence
      */
     y = 2 * charHeight - 1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, 0);
@@ -324,7 +327,7 @@ public class SeqPanelTest
      * cursor at top of second sequence
      */
     y = 2 * charHeight;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, 1);
@@ -334,7 +337,7 @@ public class SeqPanelTest
      * cursor at bottom of second sequence
      */
     y = 3 * charHeight - 1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, 1);
@@ -344,7 +347,7 @@ public class SeqPanelTest
      * 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,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, alignmentHeight - 1);
@@ -355,7 +358,7 @@ public class SeqPanelTest
      * method reports index of nearest sequence above
      */
     y += 1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, alignmentHeight - 1);
@@ -365,77 +368,42 @@ public class SeqPanelTest
      * cursor still in the gap above annotations, now at the bottom of it
      */
     y += SeqCanvas.SEQS_ANNOTATION_GAP - 1; // 3-1 = 2
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, alignmentHeight - 1);
     assertEquals(pos.annotationIndex, -1);
 
-    /*
-     * cursor at the top of the first annotation  
-     */
-    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, alignmentHeight - 1);
-    assertEquals(pos.annotationIndex, 0); // over first annotation
-
-    /*
-     * cursor at the bottom of the first annotation  
-     */
-    y += av.getAlignment().getAlignmentAnnotation()[0].height - 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, 0);
-
-    /*
-     * cursor at the top of the second annotation  
-     */
-    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, alignmentHeight - 1);
-    assertEquals(pos.annotationIndex, 1);
-
-    /*
-     * cursor at the bottom of the second annotation  
-     */
-    y += av.getAlignment().getAlignmentAnnotation()[1].height - 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 at the top of the third annotation  
-     */
-    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, alignmentHeight - 1);
-    assertEquals(pos.annotationIndex, 2);
-
-    /*
-     * cursor at the bottom of the third annotation  
-     */
-    y += av.getAlignment().getAlignmentAnnotation()[2].height - 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, 2);
+    AlignmentAnnotation[] annotationRows = av.getAlignment()
+            .getAlignmentAnnotation();
+    for (int n = 0; n < annotationRows.length; n++)
+    {
+      /*
+       * cursor at the top of the n'th annotation  
+       */
+      y += 1;
+      evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
+              false, 0);
+      pos = testee.findMousePosition(evt);
+      assertEquals(pos.seqIndex, alignmentHeight - 1);
+      assertEquals(pos.annotationIndex, n); // over n'th annotation
+
+      /*
+       * cursor at the bottom of the n'th annotation  
+       */
+      y += annotationRows[n].height - 1;
+      evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
+              false, 0);
+      pos = testee.findMousePosition(evt);
+      assertEquals(pos.seqIndex, alignmentHeight - 1);
+      assertEquals(pos.annotationIndex, n);
+    }
 
     /*
      * cursor in gap between wrapped widths  
      */
     y += 1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, -1);
@@ -445,7 +413,7 @@ public class SeqPanelTest
      * cursor at bottom of gap between wrapped widths  
      */
     y += charHeight - 1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, -1);
@@ -455,7 +423,7 @@ public class SeqPanelTest
      * cursor at top of first sequence, second wrapped width  
      */
     y += 1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, 0);
@@ -473,8 +441,7 @@ public class SeqPanelTest
     av.setScaleAboveWrapped(true);
     av.setScaleLeftWrapped(false);
     av.setScaleRightWrapped(false);
-    alignFrame.alignPanel.paintAlignment(false, false);
-    waitForSwing();
+    alignFrame.alignPanel.updateLayout();
 
     final int charHeight = av.getCharHeight();
     final int charWidth = av.getCharWidth();
@@ -493,7 +460,7 @@ public class SeqPanelTest
      * 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,
+    MouseEvent evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y,
             0, 0, 0, false, 0);
     MousePos pos = testee.findMousePosition(evt);
     assertEquals(pos.column, 0);
@@ -505,7 +472,7 @@ public class SeqPanelTest
      * two charHeights including scale panel
      */
     y = 2 * charHeight - 1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, -1);
@@ -515,7 +482,7 @@ public class SeqPanelTest
      * cursor over top of first sequence
      */
     y += 1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, 0);
@@ -525,7 +492,7 @@ public class SeqPanelTest
      * cursor at bottom of first sequence
      */
     y += charHeight - 1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, 0);
@@ -535,7 +502,7 @@ public class SeqPanelTest
      * cursor at top of second sequence
      */
     y += 1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, 1);
@@ -545,7 +512,7 @@ public class SeqPanelTest
      * cursor at bottom of second sequence
      */
     y += charHeight - 1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, 1);
@@ -556,7 +523,7 @@ public class SeqPanelTest
      * (scale + gap + sequences)
      */
     y = charHeight * (2 + alignmentHeight) - 1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, alignmentHeight - 1);
@@ -566,7 +533,7 @@ public class SeqPanelTest
      * cursor below sequences, in 3-pixel gap above annotations
      */
     y += 1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, alignmentHeight - 1);
@@ -577,77 +544,46 @@ public class SeqPanelTest
      * 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,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, alignmentHeight - 1);
     assertEquals(pos.annotationIndex, -1);
   
-    /*
-     * cursor at the top of the first annotation  
-     */
-    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, alignmentHeight - 1);
-    assertEquals(pos.annotationIndex, 0); // over first annotation
-  
-    /*
-     * cursor at the bottom of the first annotation  
-     */
-    y += av.getAlignment().getAlignmentAnnotation()[0].height - 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, 0);
-  
-    /*
-     * cursor at the top of the second annotation  
-     */
-    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, alignmentHeight - 1);
-    assertEquals(pos.annotationIndex, 1);
-  
-    /*
-     * cursor at the bottom of the second annotation  
-     */
-    y += av.getAlignment().getAlignmentAnnotation()[1].height - 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 at the top of the third annotation  
-     */
-    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, alignmentHeight - 1);
-    assertEquals(pos.annotationIndex, 2);
-  
-    /*
-     * cursor at the bottom of the third annotation  
-     */
-    y += av.getAlignment().getAlignmentAnnotation()[2].height - 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, 2);
+    AlignmentAnnotation[] annotationRows = av.getAlignment().getAlignmentAnnotation();
+    for (int n = 0; n < annotationRows.length; n++)
+    {
+      /*
+       * cursor at the top of the n'th annotation  
+       */
+      y += 1;
+      evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
+              false, 0);
+      pos = testee.findMousePosition(evt);
+      assertEquals(pos.seqIndex, alignmentHeight - 1);
+      assertEquals(pos.annotationIndex, n); // over n'th annotation
+
+      /*
+       * cursor at the bottom of the n'th annotation  
+       */
+      y += annotationRows[n].height - 1;
+      evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
+              false, 0);
+      pos = testee.findMousePosition(evt);
+      SeqCanvas sc = testee.seqCanvas;
+      assertEquals(pos.seqIndex, alignmentHeight - 1,
+              String.format("%s n=%d y=%d %d, %d, %d, %d",
+                      annotationRows[n].label, n, y, sc.getWidth(),
+                      sc.getHeight(), sc.wrappedRepeatHeightPx,
+                      sc.wrappedSpaceAboveAlignment));
+      assertEquals(pos.annotationIndex, n);
+    }
   
     /*
      * cursor in gap between wrapped widths  
      */
     y += 1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, -1);
@@ -657,7 +593,7 @@ public class SeqPanelTest
      * cursor at bottom of gap between wrapped widths  
      */
     y += charHeight - 1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, -1);
@@ -667,7 +603,7 @@ public class SeqPanelTest
      * cursor at top of scale, second wrapped width  
      */
     y += 1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, -1);
@@ -677,7 +613,7 @@ public class SeqPanelTest
      * cursor at bottom of scale, second wrapped width  
      */
     y += charHeight - 1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, -1);
@@ -687,7 +623,7 @@ public class SeqPanelTest
      * cursor at top of first sequence, second wrapped width  
      */
     y += 1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, 0);
@@ -705,8 +641,7 @@ public class SeqPanelTest
     av.setScaleAboveWrapped(false);
     av.setScaleLeftWrapped(false);
     av.setScaleRightWrapped(false);
-    alignFrame.alignPanel.paintAlignment(false, false);
-    waitForSwing();
+    alignFrame.alignPanel.updateLayout();
 
     final int charHeight = av.getCharHeight();
     final int charWidth = av.getCharWidth();
@@ -725,7 +660,7 @@ public class SeqPanelTest
      * 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,
+    MouseEvent evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y,
             0, 0, 0, false, 0);
     MousePos pos = testee.findMousePosition(evt);
     assertEquals(pos.column, 0);
@@ -736,7 +671,7 @@ public class SeqPanelTest
      * cursor over top of first sequence
      */
     y = charHeight;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, 0);
@@ -746,7 +681,7 @@ public class SeqPanelTest
      * 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,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, alignmentHeight - 1);
@@ -756,7 +691,7 @@ public class SeqPanelTest
      * 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,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, -1);
@@ -766,7 +701,7 @@ public class SeqPanelTest
      * 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,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, -1);
@@ -776,7 +711,7 @@ public class SeqPanelTest
      * 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,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, y, 0, 0, 0,
             false, 0);
     pos = testee.findMousePosition(evt);
     assertEquals(pos.seqIndex, 0);
@@ -793,12 +728,13 @@ public class SeqPanelTest
     int x = 0;
     final int charWidth = alignFrame.getViewport().getCharWidth();
     assertTrue(charWidth > 0); // sanity check
-    assertEquals(alignFrame.getViewport().getRanges().getStartRes(), 0);
+    ViewportRanges ranges = alignFrame.getViewport().getRanges();
+    assertEquals(ranges.getStartRes(), 0);
 
     /*
      * mouse at top left of unwrapped panel
      */
-    MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0,
+    MouseEvent evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, 0,
             0, 0, 0, false, 0);
     assertEquals(testee.findColumn(evt), 0);
     
@@ -806,7 +742,7 @@ public class SeqPanelTest
      * not quite one charWidth across
      */
     x = charWidth-1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, 0,
             0, 0, 0, false, 0);
     assertEquals(testee.findColumn(evt), 0);
 
@@ -814,7 +750,7 @@ public class SeqPanelTest
      * one charWidth across
      */
     x = charWidth;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, 0, 0, 0, 0,
             false, 0);
     assertEquals(testee.findColumn(evt), 1);
 
@@ -822,7 +758,7 @@ public class SeqPanelTest
      * two charWidths across
      */
     x = 2 * charWidth;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, 0, 0, 0, 0,
             false, 0);
     assertEquals(testee.findColumn(evt), 2);
 
@@ -830,12 +766,14 @@ public class SeqPanelTest
      * limited to last column of seqcanvas
      */
     x = 20000;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, 0, 0, 0, 0,
             false, 0);
     SeqCanvas seqCanvas = alignFrame.alignPanel.getSeqPanel().seqCanvas;
     int w = seqCanvas.getWidth();
-    // limited to number of whole columns, base 0
-    int expected = w / charWidth - 1;
+    // limited to number of whole columns, base 0,
+    // and to end of visible range
+    int expected = w / charWidth;
+    expected = Math.min(expected, ranges.getEndRes());
     assertEquals(testee.findColumn(evt), expected);
 
     /*
@@ -844,7 +782,7 @@ public class SeqPanelTest
     alignFrame.getViewport().hideColumns(4, 9);
     x = 5 * charWidth + 2;
     // x is in 6th visible column, absolute column 12, or 11 base 0
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, 0, 0, 0, 0,
             false, 0);
     assertEquals(testee.findColumn(evt), 11);
   }
@@ -859,9 +797,7 @@ public class SeqPanelTest
     av.setScaleAboveWrapped(false);
     av.setScaleLeftWrapped(false);
     av.setScaleRightWrapped(false);
-    alignFrame.alignPanel.paintAlignment(false, false);
-    // need to wait for repaint to finish!
-    waitForSwing();
+    alignFrame.alignPanel.updateLayout();
     SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
     int x = 0;
     final int charWidth = av.getCharWidth();
@@ -871,7 +807,7 @@ public class SeqPanelTest
     /*
      * mouse at top left of wrapped panel, no West (left) scale
      */
-    MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0,
+    MouseEvent evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, 0,
             0, 0, 0, false, 0);
     assertEquals(testee.findColumn(evt), 0);
     
@@ -879,7 +815,7 @@ public class SeqPanelTest
      * not quite one charWidth across
      */
     x = charWidth-1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, 0,
             0, 0, 0, false, 0);
     assertEquals(testee.findColumn(evt), 0);
   
@@ -887,7 +823,7 @@ public class SeqPanelTest
      * one charWidth across
      */
     x = charWidth;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, 0, 0, 0, 0,
             false, 0);
     assertEquals(testee.findColumn(evt), 1);
 
@@ -895,18 +831,17 @@ public class SeqPanelTest
      * x over scale left (before drawn columns) results in -1
      */
     av.setScaleLeftWrapped(true);
-    alignFrame.alignPanel.paintAlignment(false, false);
-    waitForSwing();
+    alignFrame.alignPanel.updateLayout();
     SeqCanvas seqCanvas = testee.seqCanvas;
     int labelWidth = (int) PA.getValue(seqCanvas, "labelWidthWest");
     assertTrue(labelWidth > 0);
     x = labelWidth - 1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, 0, 0, 0, 0,
             false, 0);
     assertEquals(testee.findColumn(evt), -1);
 
     x = labelWidth;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, 0, 0, 0, 0,
             false, 0);
     assertEquals(testee.findColumn(evt), 0);
 
@@ -916,7 +851,7 @@ public class SeqPanelTest
     int residuesWide = av.getRanges().getViewportWidth();
     assertTrue(residuesWide > 0);
     x = labelWidth + charWidth * residuesWide - 1;
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, 0, 0, 0, 0,
             false, 0);
     assertEquals(testee.findColumn(evt), residuesWide - 1);
 
@@ -924,15 +859,14 @@ public class SeqPanelTest
      * x over scale right (beyond drawn columns) results in -1
      */
     av.setScaleRightWrapped(true);
-    alignFrame.alignPanel.paintAlignment(false, false);
-    waitForSwing();
+    alignFrame.alignPanel.updateLayout();
     labelWidth = (int) PA.getValue(seqCanvas, "labelWidthEast");
     assertTrue(labelWidth > 0);
     int residuesWide2 = av.getRanges().getViewportWidth();
     assertTrue(residuesWide2 > 0);
     assertTrue(residuesWide2 < residuesWide); // available width reduced
     x += 1; // just over left edge of scale right
-    evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
+    evt = new MouseEvent(testee, MouseEvent.MOUSE_MOVED, 0L, 0, x, 0, 0, 0, 0,
             false, 0);
     assertEquals(testee.findColumn(evt), -1);
     
@@ -950,14 +884,20 @@ public class SeqPanelTest
   }
 
   /**
-   * waits a few ms for Swing to do something
+   * waits for Swing event dispatch queue to empty
    */
   synchronized void waitForSwing()
   {
     try
     {
-      super.wait(10);
-    } catch (InterruptedException e)
+      EventQueue.invokeAndWait(new Runnable()
+      {
+        @Override
+        public void run()
+        {
+        }
+      });
+    } catch (InterruptedException | InvocationTargetException e)
     {
       e.printStackTrace();
     }