import jalview.bin.Cache;
import jalview.bin.Jalview;
import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceI;
import jalview.io.FileLoader;
import java.awt.Event;
+import java.awt.EventQueue;
import java.awt.event.MouseEvent;
+import java.lang.reflect.InvocationTargetException;
import javax.swing.JLabel;
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, Event.MOUSE_MOVE, 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, Event.MOUSE_MOVE, 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
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, Event.MOUSE_MOVE, 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, Event.MOUSE_MOVE, 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
}
/**
- * 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();
}