X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fgui%2FSeqPanelTest.java;h=fd611fca9fe2fdd90f2184ce652379879eaae8df;hb=fcb944cdd9de849c89f0a8744ae6e56e22de9c1e;hp=f16329940204e46facbecd90e00dc0a58b11faa9;hpb=f36251d568f123f14631d4839362355a058dc673;p=jalview.git diff --git a/test/jalview/gui/SeqPanelTest.java b/test/jalview/gui/SeqPanelTest.java index f163299..fd611fc 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; @@ -249,22 +252,22 @@ public class SeqPanelTest @AfterMethod(alwaysRun = true) public void tearDown() { - Desktop.instance.closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); } @Test(groups = "Functional") public void testFindMousePosition_wrapped_annotations() { - Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", "true"); - Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true"); + Cache.setPropertyNoSave("SHOW_ANNOTATIONS", "true"); + Cache.setPropertyNoSave("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); - waitForSwing(); // for Swing thread + + alignFrame.alignPanel.updateLayout(); final int charHeight = av.getCharHeight(); final int charWidth = av.getCharWidth(); @@ -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 @@ -465,16 +433,15 @@ public class SeqPanelTest @Test(groups = "Functional") public void testFindMousePosition_wrapped_scaleAbove() { - Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", "true"); - Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true"); + Cache.setPropertyNoSave("SHOW_ANNOTATIONS", "true"); + Cache.setPropertyNoSave("WRAP_ALIGNMENT", "true"); AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded( "examples/uniref50.fa", DataSourceType.FILE); AlignViewportI av = alignFrame.getViewport(); 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(); @@ -583,65 +550,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 @@ -697,16 +628,15 @@ public class SeqPanelTest @Test(groups = "Functional") public void testFindMousePosition_wrapped_noAnnotations() { - Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", "false"); - Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true"); + Cache.setPropertyNoSave("SHOW_ANNOTATIONS", "false"); + Cache.setPropertyNoSave("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); - waitForSwing(); + alignFrame.alignPanel.updateLayout(); final int charHeight = av.getCharHeight(); final int charWidth = av.getCharWidth(); @@ -786,7 +716,7 @@ public class SeqPanelTest @Test(groups = "Functional") public void testFindColumn_unwrapped() { - Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "false"); + Cache.setPropertyNoSave("WRAP_ALIGNMENT", "false"); AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded( "examples/uniref50.fa", DataSourceType.FILE); SeqPanel testee = alignFrame.alignPanel.getSeqPanel(); @@ -794,7 +724,6 @@ public class SeqPanelTest final int charWidth = alignFrame.getViewport().getCharWidth(); assertTrue(charWidth > 0); // sanity check assertEquals(alignFrame.getViewport().getRanges().getStartRes(), 0); - /* * mouse at top left of unwrapped panel */ @@ -835,8 +764,13 @@ public class SeqPanelTest SeqCanvas seqCanvas = alignFrame.alignPanel.getSeqPanel().seqCanvas; int w = seqCanvas.getWidth(); // limited to number of whole columns, base 0 - int expected = w / charWidth - 1; - assertEquals(testee.findColumn(evt), expected); + + int expected = w / charWidth; + expected = Math.min( + alignFrame.getViewport().getRanges().getEndRes(), + expected); + int col = testee.findColumn(evt); + assertEquals(col, expected); /* * hide columns 5-10 (base 1) @@ -846,22 +780,21 @@ public class SeqPanelTest // 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, false, 0); - assertEquals(testee.findColumn(evt), 11); + col = testee.findColumn(evt); + assertEquals(col, 11); } @Test(groups = "Functional") public void testFindColumn_wrapped() { - Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true"); + Cache.setPropertyNoSave("WRAP_ALIGNMENT", "true"); AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded( "examples/uniref50.fa", DataSourceType.FILE); AlignViewport av = alignFrame.getViewport(); 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(); @@ -895,8 +828,7 @@ 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); @@ -924,8 +856,7 @@ 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(); @@ -950,14 +881,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(); }