X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fgui%2FSeqPanelTest.java;h=fa0e35282dd4a99fe8ee16cc22eed37b947c7e8a;hb=fdf90308b1b24f4063648449c5f316ced24c938b;hp=7f3aef1cdb111a9400ac487aeeb05388b9addcf1;hpb=b87e96a7592f21c11e2e3a218b24de524c3a39fc;p=jalview.git diff --git a/test/jalview/gui/SeqPanelTest.java b/test/jalview/gui/SeqPanelTest.java index 7f3aef1..fa0e352 100644 --- a/test/jalview/gui/SeqPanelTest.java +++ b/test/jalview/gui/SeqPanelTest.java @@ -22,19 +22,37 @@ package jalview.gui; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; +import jalview.api.AlignViewportI; +import jalview.bin.Cache; +import jalview.bin.Jalview; 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; +import jalview.gui.SeqPanel.MousePos; +import jalview.io.DataSourceType; +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; + +import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import junit.extensions.PA; + public class SeqPanelTest { AlignFrame af; @@ -59,22 +77,24 @@ public class SeqPanelTest assertEquals( alignFrame.alignPanel.getSeqPanel().setStatusMessage( visAl.getSequenceAt(1), 1, 1), 2); - assertEquals(alignFrame.statusBar.getText(), + assertEquals(((JLabel) PA.getValue(alignFrame, "statusBar")).getText(), "Sequence 2 ID: Seq2 Residue: ALA (2)"); assertEquals( alignFrame.alignPanel.getSeqPanel().setStatusMessage( visAl.getSequenceAt(1), 4, 1), 3); - assertEquals(alignFrame.statusBar.getText(), + assertEquals(((JLabel) PA.getValue(alignFrame, "statusBar")).getText(), "Sequence 2 ID: Seq2 Residue: GLU (3)"); // no status message at a gap, returns next residue position to the right assertEquals( alignFrame.alignPanel.getSeqPanel().setStatusMessage( visAl.getSequenceAt(1), 2, 1), 3); - assertEquals(alignFrame.statusBar.getText(), "Sequence 2 ID: Seq2"); + assertEquals(((JLabel) PA.getValue(alignFrame, "statusBar")).getText(), + "Sequence 2 ID: Seq2"); assertEquals( alignFrame.alignPanel.getSeqPanel().setStatusMessage( visAl.getSequenceAt(1), 3, 1), 3); - assertEquals(alignFrame.statusBar.getText(), "Sequence 2 ID: Seq2"); + assertEquals(((JLabel) PA.getValue(alignFrame, "statusBar")).getText(), + "Sequence 2 ID: Seq2"); } @Test(groups = "Functional") @@ -90,7 +110,7 @@ public class SeqPanelTest assertEquals( alignFrame.alignPanel.getSeqPanel().setStatusMessage( visAl.getSequenceAt(1), 1, 1), 2); - assertEquals(alignFrame.statusBar.getText(), + assertEquals(((JLabel) PA.getValue(alignFrame, "statusBar")).getText(), "Sequence 2 ID: Seq2 Residue: B (2)"); } @@ -198,4 +218,686 @@ public class SeqPanelTest expected = MessageManager.formatMessage("label.delete_gaps", "3"); assertEquals(SeqPanel.getEditStatusMessage(edit), expected); } + + public void testFindMousePosition_unwrapped() + { + String seqData = ">Seq1\nAACDE\n>Seq2\nAA--E\n"; + AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(seqData, + DataSourceType.PASTE); + AlignViewportI av = alignFrame.getViewport(); + av.setShowAnnotation(true); + av.setWrapAlignment(false); + final int charHeight = av.getCharHeight(); + final int charWidth = av.getCharWidth(); + // 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 unwrapped panel + */ + 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, 0); + assertEquals(pos.annotationIndex, -1); + } + + @AfterMethod(alwaysRun = true) + public void tearDown() + { + Desktop.instance.closeAll_actionPerformed(null); + } + + @Test(groups = "Functional") + public void testFindMousePosition_wrapped_annotations() + { + Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", "true"); + 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); + waitForSwing(); // for Swing thread + + 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, "291"); + assertEquals(pos.column, 0); + assertEquals(pos.seqIndex, -1); // above sequences + assertEquals(pos.annotationIndex, -1); + + /* + * cursor at bottom of gap above + */ + 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 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 first sequence + */ + y = 2 * 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, 0); + assertEquals(pos.annotationIndex, -1); + + /* + * cursor at top of second sequence + */ + y = 2 * charHeight; + 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 bottom of second sequence + */ + y = 3 * 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 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, 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, + false, 0); + pos = testee.findMousePosition(evt); + assertEquals(pos.seqIndex, alignmentHeight - 1); + assertEquals(pos.annotationIndex, -1); + + /* + * 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, + false, 0); + pos = testee.findMousePosition(evt); + assertEquals(pos.seqIndex, alignmentHeight - 1); + assertEquals(pos.annotationIndex, -1); + + 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 + */ + 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 at bottom of gap between wrapped 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 top of first sequence, second wrapped 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); + } + + @Test(groups = "Functional") + public void testFindMousePosition_wrapped_scaleAbove() + { + Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", "true"); + Cache.applicationProperties.setProperty("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(); + + 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, "466"); + assertEquals(pos.column, 0); + assertEquals(pos.seqIndex, -1); // above sequences + assertEquals(pos.annotationIndex, -1); + + /* + * cursor at bottom of gap above + * two charHeights including scale panel + */ + y = 2 * 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 over top of first sequence + */ + 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); + + /* + * cursor at bottom of first sequence + */ + 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, 0); + assertEquals(pos.annotationIndex, -1); + + /* + * cursor at top of second sequence + */ + 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 at bottom of second sequence + */ + 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 bottom of last sequence + * (scale + gap + sequences) + */ + y = charHeight * (2 + 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, in 3-pixel gap above annotations + */ + 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 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, + false, 0); + pos = testee.findMousePosition(evt); + assertEquals(pos.seqIndex, alignmentHeight - 1); + assertEquals(pos.annotationIndex, -1); + + 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 + */ + 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 at bottom of gap between wrapped 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 top of scale, second wrapped 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, -1); + assertEquals(pos.annotationIndex, -1); + + /* + * 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, + false, 0); + pos = testee.findMousePosition(evt); + assertEquals(pos.seqIndex, -1); + assertEquals(pos.annotationIndex, -1); + + /* + * 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, + false, 0); + pos = testee.findMousePosition(evt); + 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); + waitForSwing(); + + 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, "662"); + 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); + } + + @Test(groups = "Functional") + public void testFindColumn_unwrapped() + { + Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "false"); + AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded( + "examples/uniref50.fa", DataSourceType.FILE); + SeqPanel testee = alignFrame.alignPanel.getSeqPanel(); + int x = 0; + final int charWidth = alignFrame.getViewport().getCharWidth(); + assertTrue(charWidth > 0); // sanity check + assertEquals(alignFrame.getViewport().getRanges().getStartRes(), 0); + + /* + * mouse at top left of unwrapped panel + */ + MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, + 0, 0, 0, false, 0); + assertEquals(testee.findColumn(evt), 0); + + /* + * not quite one charWidth across + */ + x = charWidth-1; + evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, + 0, 0, 0, false, 0); + assertEquals(testee.findColumn(evt), 0); + + /* + * one charWidth across + */ + x = charWidth; + evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0, + false, 0); + assertEquals(testee.findColumn(evt), 1); + + /* + * two charWidths across + */ + x = 2 * charWidth; + evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0, + false, 0); + assertEquals(testee.findColumn(evt), 2); + + /* + * limited to last column of seqcanvas + */ + x = 20000; + evt = new MouseEvent(testee, Event.MOUSE_MOVE, 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; + assertEquals(testee.findColumn(evt), expected); + + /* + * hide columns 5-10 (base 1) + */ + 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, + false, 0); + assertEquals(testee.findColumn(evt), 11); + } + + @Test(groups = "Functional") + public void testFindColumn_wrapped() + { + Cache.applicationProperties.setProperty("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(); + SeqPanel testee = alignFrame.alignPanel.getSeqPanel(); + int x = 0; + final int charWidth = av.getCharWidth(); + assertTrue(charWidth > 0); // sanity check + assertEquals(av.getRanges().getStartRes(), 0); + + /* + * mouse at top left of wrapped panel, no West (left) scale + */ + MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, + 0, 0, 0, false, 0); + assertEquals(testee.findColumn(evt, "808"), 0); + + /* + * not quite one charWidth across + */ + x = charWidth-1; + evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, + 0, 0, 0, false, 0); + assertEquals(testee.findColumn(evt), 0); + + /* + * one charWidth across + */ + x = charWidth; + evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0, + false, 0); + assertEquals(testee.findColumn(evt), 1); + + /* + * x over scale left (before drawn columns) results in -1 + */ + av.setScaleLeftWrapped(true); + alignFrame.alignPanel.paintAlignment(false, false); + waitForSwing(); + 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, + false, 0); + assertEquals(testee.findColumn(evt), -1); + + x = labelWidth; + evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0, + false, 0); + assertEquals(testee.findColumn(evt), 0); + + /* + * x over right edge of last residue (including scale left) + */ + 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, + false, 0); + assertEquals(testee.findColumn(evt), residuesWide - 1); + + /* + * x over scale right (beyond drawn columns) results in -1 + */ + av.setScaleRightWrapped(true); + alignFrame.alignPanel.paintAlignment(false, false); + waitForSwing(); + 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, + false, 0); + assertEquals(testee.findColumn(evt), -1); + + // todo add startRes offset, hidden columns + + } + @BeforeClass(alwaysRun = true) + public static void setUpBeforeClass() throws Exception + { + /* + * use read-only test properties file + */ + Cache.loadProperties("test/jalview/io/testProps.jvprops"); + Jalview.main(new String[] { "-nonews" }); + } + + /** + * waits for Swing event dispatch queue to empty + */ + synchronized void waitForSwing() + { + try + { + EventQueue.invokeAndWait(new Runnable() + { + @Override + public void run() + { + } + }); + } catch (InterruptedException | InvocationTargetException e) + { + e.printStackTrace(); + } + } }