2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.assertTrue;
26 import jalview.api.AlignViewportI;
27 import jalview.bin.Cache;
28 import jalview.bin.Jalview;
29 import jalview.datamodel.Alignment;
30 import jalview.datamodel.AlignmentAnnotation;
31 import jalview.datamodel.AlignmentI;
32 import jalview.datamodel.Sequence;
33 import jalview.datamodel.SequenceI;
34 import jalview.gui.SeqPanel.MousePos;
35 import jalview.io.DataSourceType;
36 import jalview.io.FileLoader;
38 import java.awt.Event;
39 import java.awt.EventQueue;
40 import java.awt.event.MouseEvent;
41 import java.lang.reflect.InvocationTargetException;
43 import javax.swing.JLabel;
45 import org.testng.annotations.AfterMethod;
46 import org.testng.annotations.BeforeClass;
47 import org.testng.annotations.Test;
49 import junit.extensions.PA;
51 public class SeqPanelTest
55 @BeforeClass(alwaysRun = true)
56 public void setUpJvOptionPane()
58 JvOptionPane.setInteractiveMode(false);
59 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
61 @Test(groups = "Functional")
62 public void testSetStatusReturnsNearestResiduePosition()
64 SequenceI seq1 = new Sequence("Seq1", "AACDE");
65 SequenceI seq2 = new Sequence("Seq2", "AA--E");
66 AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
67 AlignFrame alignFrame = new AlignFrame(al, al.getWidth(),
69 AlignmentI visAl = alignFrame.getViewport().getAlignment();
71 // Test either side of gap
73 alignFrame.alignPanel.getSeqPanel().setStatusMessage(
74 visAl.getSequenceAt(1), 1, 1), 2);
75 assertEquals(((JLabel) PA.getValue(alignFrame, "statusBar")).getText(),
76 "Sequence 2 ID: Seq2 Residue: ALA (2)");
78 alignFrame.alignPanel.getSeqPanel().setStatusMessage(
79 visAl.getSequenceAt(1), 4, 1), 3);
80 assertEquals(((JLabel) PA.getValue(alignFrame, "statusBar")).getText(),
81 "Sequence 2 ID: Seq2 Residue: GLU (3)");
82 // no status message at a gap, returns next residue position to the right
84 alignFrame.alignPanel.getSeqPanel().setStatusMessage(
85 visAl.getSequenceAt(1), 2, 1), 3);
86 assertEquals(((JLabel) PA.getValue(alignFrame, "statusBar")).getText(),
87 "Sequence 2 ID: Seq2");
89 alignFrame.alignPanel.getSeqPanel().setStatusMessage(
90 visAl.getSequenceAt(1), 3, 1), 3);
91 assertEquals(((JLabel) PA.getValue(alignFrame, "statusBar")).getText(),
92 "Sequence 2 ID: Seq2");
95 @Test(groups = "Functional")
96 public void testAmbiguousAminoAcidGetsStatusMessage()
98 SequenceI seq1 = new Sequence("Seq1", "ABCDE");
99 SequenceI seq2 = new Sequence("Seq2", "AB--E");
100 AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
101 AlignFrame alignFrame = new AlignFrame(al, al.getWidth(),
103 AlignmentI visAl = alignFrame.getViewport().getAlignment();
106 alignFrame.alignPanel.getSeqPanel().setStatusMessage(
107 visAl.getSequenceAt(1), 1, 1), 2);
108 assertEquals(((JLabel) PA.getValue(alignFrame, "statusBar")).getText(),
109 "Sequence 2 ID: Seq2 Residue: B (2)");
112 @Test(groups = "Functional")
113 public void testFindMousePosition_unwrapped()
115 String seqData = ">Seq1\nAACDE\n>Seq2\nAA--E\n";
116 AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(seqData,
117 DataSourceType.PASTE);
118 AlignViewportI av = alignFrame.getViewport();
119 av.setShowAnnotation(true);
120 av.setWrapAlignment(false);
121 final int charHeight = av.getCharHeight();
122 final int charWidth = av.getCharWidth();
124 assertTrue(charHeight > 0);
125 assertTrue(charWidth > 0);
126 assertTrue(alignFrame.alignPanel.getSeqPanel().getWidth() > 0);
128 SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
133 * mouse at top left of unwrapped panel
135 MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y,
137 MousePos pos = testee.findMousePosition(evt);
138 assertEquals(pos.column, 0);
139 assertEquals(pos.seqIndex, 0);
140 assertEquals(pos.annotationIndex, -1);
143 @AfterMethod(alwaysRun = true)
144 public void tearDown()
146 Desktop.instance.closeAll_actionPerformed(null);
149 @Test(groups = "Functional")
150 public void testFindMousePosition_wrapped_annotations()
152 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", "true");
153 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true");
154 AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
155 "examples/uniref50.fa", DataSourceType.FILE);
156 AlignViewportI av = alignFrame.getViewport();
157 av.setScaleAboveWrapped(false);
158 av.setScaleLeftWrapped(false);
159 av.setScaleRightWrapped(false);
160 alignFrame.alignPanel.paintAlignment(false, false);
161 waitForSwing(); // for Swing thread
163 final int charHeight = av.getCharHeight();
164 final int charWidth = av.getCharWidth();
165 final int alignmentHeight = av.getAlignment().getHeight();
168 assertTrue(charHeight > 0);
169 assertTrue(charWidth > 0);
170 assertTrue(alignFrame.alignPanel.getSeqPanel().getWidth() > 0);
172 SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
177 * mouse at top left of wrapped panel; there is a gap of charHeight
178 * above the alignment
180 MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y,
182 MousePos pos = testee.findMousePosition(evt);
183 assertEquals(pos.column, 0);
184 assertEquals(pos.seqIndex, -1); // above sequences
185 assertEquals(pos.annotationIndex, -1);
188 * cursor at bottom of gap above
191 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
193 pos = testee.findMousePosition(evt);
194 assertEquals(pos.seqIndex, -1);
195 assertEquals(pos.annotationIndex, -1);
198 * cursor over top of first sequence
201 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
203 pos = testee.findMousePosition(evt);
204 assertEquals(pos.seqIndex, 0);
205 assertEquals(pos.annotationIndex, -1);
208 * cursor at bottom of first sequence
210 y = 2 * charHeight - 1;
211 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
213 pos = testee.findMousePosition(evt);
214 assertEquals(pos.seqIndex, 0);
215 assertEquals(pos.annotationIndex, -1);
218 * cursor at top of second sequence
221 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
223 pos = testee.findMousePosition(evt);
224 assertEquals(pos.seqIndex, 1);
225 assertEquals(pos.annotationIndex, -1);
228 * cursor at bottom of second sequence
230 y = 3 * charHeight - 1;
231 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
233 pos = testee.findMousePosition(evt);
234 assertEquals(pos.seqIndex, 1);
235 assertEquals(pos.annotationIndex, -1);
238 * cursor at bottom of last sequence
240 y = charHeight * (1 + alignmentHeight) - 1;
241 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
243 pos = testee.findMousePosition(evt);
244 assertEquals(pos.seqIndex, alignmentHeight - 1);
245 assertEquals(pos.annotationIndex, -1);
248 * cursor below sequences, in 3-pixel gap above annotations
249 * method reports index of nearest sequence above
252 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
254 pos = testee.findMousePosition(evt);
255 assertEquals(pos.seqIndex, alignmentHeight - 1);
256 assertEquals(pos.annotationIndex, -1);
259 * cursor still in the gap above annotations, now at the bottom of it
261 y += SeqCanvas.SEQS_ANNOTATION_GAP - 1; // 3-1 = 2
262 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
264 pos = testee.findMousePosition(evt);
265 assertEquals(pos.seqIndex, alignmentHeight - 1);
266 assertEquals(pos.annotationIndex, -1);
268 AlignmentAnnotation[] annotationRows = av.getAlignment()
269 .getAlignmentAnnotation();
270 for (int n = 0; n < annotationRows.length; n++)
273 * cursor at the top of the n'th annotation
276 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
278 pos = testee.findMousePosition(evt);
279 assertEquals(pos.seqIndex, alignmentHeight - 1);
280 assertEquals(pos.annotationIndex, n); // over n'th annotation
283 * cursor at the bottom of the n'th annotation
285 y += annotationRows[n].height - 1;
286 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
288 pos = testee.findMousePosition(evt);
289 assertEquals(pos.seqIndex, alignmentHeight - 1);
290 assertEquals(pos.annotationIndex, n);
294 * cursor in gap between wrapped widths
297 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
299 pos = testee.findMousePosition(evt);
300 assertEquals(pos.seqIndex, -1);
301 assertEquals(pos.annotationIndex, -1);
304 * cursor at bottom of gap between wrapped widths
307 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
309 pos = testee.findMousePosition(evt);
310 assertEquals(pos.seqIndex, -1);
311 assertEquals(pos.annotationIndex, -1);
314 * cursor at top of first sequence, second wrapped width
317 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
319 pos = testee.findMousePosition(evt);
320 assertEquals(pos.seqIndex, 0);
321 assertEquals(pos.annotationIndex, -1);
324 @Test(groups = "Functional")
325 public void testFindMousePosition_wrapped_scaleAbove()
327 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", "true");
328 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true");
329 AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
330 "examples/uniref50.fa", DataSourceType.FILE);
331 AlignViewportI av = alignFrame.getViewport();
332 av.setScaleAboveWrapped(true);
333 av.setScaleLeftWrapped(false);
334 av.setScaleRightWrapped(false);
335 alignFrame.alignPanel.paintAlignment(false, false);
338 final int charHeight = av.getCharHeight();
339 final int charWidth = av.getCharWidth();
340 final int alignmentHeight = av.getAlignment().getHeight();
343 assertTrue(charHeight > 0);
344 assertTrue(charWidth > 0);
345 assertTrue(alignFrame.alignPanel.getSeqPanel().getWidth() > 0);
347 SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
352 * mouse at top left of wrapped panel; there is a gap of charHeight
353 * above the alignment
355 MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y,
357 MousePos pos = testee.findMousePosition(evt);
358 assertEquals(pos.column, 0);
359 assertEquals(pos.seqIndex, -1); // above sequences
360 assertEquals(pos.annotationIndex, -1);
363 * cursor at bottom of gap above
364 * two charHeights including scale panel
366 y = 2 * charHeight - 1;
367 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
369 pos = testee.findMousePosition(evt);
370 assertEquals(pos.seqIndex, -1);
371 assertEquals(pos.annotationIndex, -1);
374 * cursor over top of first sequence
377 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
379 pos = testee.findMousePosition(evt);
380 assertEquals(pos.seqIndex, 0);
381 assertEquals(pos.annotationIndex, -1);
384 * cursor at bottom of first sequence
387 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
389 pos = testee.findMousePosition(evt);
390 assertEquals(pos.seqIndex, 0);
391 assertEquals(pos.annotationIndex, -1);
394 * cursor at top of second sequence
397 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
399 pos = testee.findMousePosition(evt);
400 assertEquals(pos.seqIndex, 1);
401 assertEquals(pos.annotationIndex, -1);
404 * cursor at bottom of second sequence
407 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
409 pos = testee.findMousePosition(evt);
410 assertEquals(pos.seqIndex, 1);
411 assertEquals(pos.annotationIndex, -1);
414 * cursor at bottom of last sequence
415 * (scale + gap + sequences)
417 y = charHeight * (2 + alignmentHeight) - 1;
418 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
420 pos = testee.findMousePosition(evt);
421 assertEquals(pos.seqIndex, alignmentHeight - 1);
422 assertEquals(pos.annotationIndex, -1);
425 * cursor below sequences, in 3-pixel gap above annotations
428 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
430 pos = testee.findMousePosition(evt);
431 assertEquals(pos.seqIndex, alignmentHeight - 1);
432 assertEquals(pos.annotationIndex, -1);
435 * cursor still in the gap above annotations, now at the bottom of it
436 * method reports index of nearest sequence above
438 y += SeqCanvas.SEQS_ANNOTATION_GAP - 1; // 3-1 = 2
439 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
441 pos = testee.findMousePosition(evt);
442 assertEquals(pos.seqIndex, alignmentHeight - 1);
443 assertEquals(pos.annotationIndex, -1);
445 AlignmentAnnotation[] annotationRows = av.getAlignment().getAlignmentAnnotation();
446 for (int n = 0; n < annotationRows.length; n++)
449 * cursor at the top of the n'th annotation
452 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
454 pos = testee.findMousePosition(evt);
455 assertEquals(pos.seqIndex, alignmentHeight - 1);
456 assertEquals(pos.annotationIndex, n); // over n'th annotation
459 * cursor at the bottom of the n'th annotation
461 y += annotationRows[n].height - 1;
462 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
464 pos = testee.findMousePosition(evt);
465 assertEquals(pos.seqIndex, alignmentHeight - 1);
466 assertEquals(pos.annotationIndex, n);
470 * cursor in gap between wrapped widths
473 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
475 pos = testee.findMousePosition(evt);
476 assertEquals(pos.seqIndex, -1);
477 assertEquals(pos.annotationIndex, -1);
480 * cursor at bottom of gap between wrapped widths
483 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
485 pos = testee.findMousePosition(evt);
486 assertEquals(pos.seqIndex, -1);
487 assertEquals(pos.annotationIndex, -1);
490 * cursor at top of scale, second wrapped width
493 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
495 pos = testee.findMousePosition(evt);
496 assertEquals(pos.seqIndex, -1);
497 assertEquals(pos.annotationIndex, -1);
500 * cursor at bottom of scale, second wrapped width
503 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
505 pos = testee.findMousePosition(evt);
506 assertEquals(pos.seqIndex, -1);
507 assertEquals(pos.annotationIndex, -1);
510 * cursor at top of first sequence, second wrapped width
513 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
515 pos = testee.findMousePosition(evt);
516 assertEquals(pos.seqIndex, 0);
517 assertEquals(pos.annotationIndex, -1);
520 @Test(groups = "Functional")
521 public void testFindMousePosition_wrapped_noAnnotations()
523 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", "false");
524 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true");
525 AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
526 "examples/uniref50.fa", DataSourceType.FILE);
527 AlignViewportI av = alignFrame.getViewport();
528 av.setScaleAboveWrapped(false);
529 av.setScaleLeftWrapped(false);
530 av.setScaleRightWrapped(false);
531 alignFrame.alignPanel.paintAlignment(false, false);
534 final int charHeight = av.getCharHeight();
535 final int charWidth = av.getCharWidth();
536 final int alignmentHeight = av.getAlignment().getHeight();
539 assertTrue(charHeight > 0);
540 assertTrue(charWidth > 0);
541 assertTrue(alignFrame.alignPanel.getSeqPanel().getWidth() > 0);
543 SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
548 * mouse at top left of wrapped panel; there is a gap of charHeight
549 * above the alignment
551 MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y,
553 MousePos pos = testee.findMousePosition(evt);
554 assertEquals(pos.column, 0);
555 assertEquals(pos.seqIndex, -1); // above sequences
556 assertEquals(pos.annotationIndex, -1);
559 * cursor over top of first sequence
562 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
564 pos = testee.findMousePosition(evt);
565 assertEquals(pos.seqIndex, 0);
566 assertEquals(pos.annotationIndex, -1);
569 * cursor at bottom of last sequence
571 y = charHeight * (1 + alignmentHeight) - 1;
572 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
574 pos = testee.findMousePosition(evt);
575 assertEquals(pos.seqIndex, alignmentHeight - 1);
576 assertEquals(pos.annotationIndex, -1);
579 * cursor below sequences, at top of charHeight gap between widths
582 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
584 pos = testee.findMousePosition(evt);
585 assertEquals(pos.seqIndex, -1);
586 assertEquals(pos.annotationIndex, -1);
589 * cursor below sequences, at top of charHeight gap between widths
592 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
594 pos = testee.findMousePosition(evt);
595 assertEquals(pos.seqIndex, -1);
596 assertEquals(pos.annotationIndex, -1);
599 * cursor at the top of the first sequence, second width
602 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
604 pos = testee.findMousePosition(evt);
605 assertEquals(pos.seqIndex, 0);
606 assertEquals(pos.annotationIndex, -1);
609 @Test(groups = "Functional")
610 public void testFindColumn_unwrapped()
612 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "false");
613 AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
614 "examples/uniref50.fa", DataSourceType.FILE);
615 SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
617 final int charWidth = alignFrame.getViewport().getCharWidth();
618 assertTrue(charWidth > 0); // sanity check
619 assertEquals(alignFrame.getViewport().getRanges().getStartRes(), 0);
622 * mouse at top left of unwrapped panel
624 MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0,
626 assertEquals(testee.findColumn(evt), 0);
629 * not quite one charWidth across
632 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0,
634 assertEquals(testee.findColumn(evt), 0);
637 * one charWidth across
640 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
642 assertEquals(testee.findColumn(evt), 1);
645 * two charWidths across
648 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
650 assertEquals(testee.findColumn(evt), 2);
653 * limited to last column of seqcanvas
656 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
658 SeqCanvas seqCanvas = alignFrame.alignPanel.getSeqPanel().seqCanvas;
659 int w = seqCanvas.getWidth();
660 // limited to number of whole columns, base 0
661 int expected = w / charWidth - 1;
662 assertEquals(testee.findColumn(evt), expected);
665 * hide columns 5-10 (base 1)
667 alignFrame.getViewport().hideColumns(4, 9);
668 x = 5 * charWidth + 2;
669 // x is in 6th visible column, absolute column 12, or 11 base 0
670 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
672 assertEquals(testee.findColumn(evt), 11);
675 @Test(groups = "Functional")
676 public void testFindColumn_wrapped()
678 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true");
679 AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
680 "examples/uniref50.fa", DataSourceType.FILE);
681 AlignViewport av = alignFrame.getViewport();
682 av.setScaleAboveWrapped(false);
683 av.setScaleLeftWrapped(false);
684 av.setScaleRightWrapped(false);
685 alignFrame.alignPanel.paintAlignment(false, false);
686 // need to wait for repaint to finish!
688 SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
690 final int charWidth = av.getCharWidth();
691 assertTrue(charWidth > 0); // sanity check
692 assertEquals(av.getRanges().getStartRes(), 0);
695 * mouse at top left of wrapped panel, no West (left) scale
697 MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0,
699 assertEquals(testee.findColumn(evt), 0);
702 * not quite one charWidth across
705 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0,
707 assertEquals(testee.findColumn(evt), 0);
710 * one charWidth across
713 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
715 assertEquals(testee.findColumn(evt), 1);
718 * x over scale left (before drawn columns) results in -1
720 av.setScaleLeftWrapped(true);
721 alignFrame.alignPanel.paintAlignment(false, false);
723 SeqCanvas seqCanvas = testee.seqCanvas;
724 int labelWidth = (int) PA.getValue(seqCanvas, "labelWidthWest");
725 assertTrue(labelWidth > 0);
727 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
729 assertEquals(testee.findColumn(evt), -1);
732 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
734 assertEquals(testee.findColumn(evt), 0);
737 * x over right edge of last residue (including scale left)
739 int residuesWide = av.getRanges().getViewportWidth();
740 assertTrue(residuesWide > 0);
741 x = labelWidth + charWidth * residuesWide - 1;
742 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
744 assertEquals(testee.findColumn(evt), residuesWide - 1);
747 * x over scale right (beyond drawn columns) results in -1
749 av.setScaleRightWrapped(true);
750 alignFrame.alignPanel.paintAlignment(false, false);
752 labelWidth = (int) PA.getValue(seqCanvas, "labelWidthEast");
753 assertTrue(labelWidth > 0);
754 int residuesWide2 = av.getRanges().getViewportWidth();
755 assertTrue(residuesWide2 > 0);
756 assertTrue(residuesWide2 < residuesWide); // available width reduced
757 x += 1; // just over left edge of scale right
758 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
760 assertEquals(testee.findColumn(evt), -1);
762 // todo add startRes offset, hidden columns
765 @BeforeClass(alwaysRun = true)
766 public static void setUpBeforeClass() throws Exception
769 * use read-only test properties file
771 Cache.loadProperties("test/jalview/io/testProps.jvprops");
772 Jalview.main(new String[] { "-nonews" });
776 * waits for Swing event dispatch queue to empty
778 synchronized void waitForSwing()
782 EventQueue.invokeAndWait(new Runnable()
789 } catch (InterruptedException | InvocationTargetException e)