X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fgui%2FSeqPanelTest.java;fp=test%2Fjalview%2Fgui%2FSeqPanelTest.java;h=0d4993630723cca5ac96768791174cdf53aa62cc;hb=d34f80c67881e79d7304eb143e9c907bc16d052b;hp=f16329940204e46facbecd90e00dc0a58b11faa9;hpb=f36251d568f123f14631d4839362355a058dc673;p=jalview.git diff --git a/test/jalview/gui/SeqPanelTest.java b/test/jalview/gui/SeqPanelTest.java index f163299..0d49936 100644 --- a/test/jalview/gui/SeqPanelTest.java +++ b/test/jalview/gui/SeqPanelTest.java @@ -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; @@ -40,7 +41,9 @@ import jalview.io.FileLoader; import jalview.util.MessageManager; import java.awt.Event; +import java.awt.EventQueue; import java.awt.event.MouseEvent; +import java.lang.reflect.InvocationTargetException; import javax.swing.JLabel; @@ -371,65 +374,30 @@ public class SeqPanelTest 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 @@ -583,65 +551,29 @@ public class SeqPanelTest 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 @@ -950,14 +882,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(); }