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.AlignmentI;
31 import jalview.datamodel.Sequence;
32 import jalview.datamodel.SequenceI;
33 import jalview.gui.SeqPanel.MousePos;
34 import jalview.io.DataSourceType;
35 import jalview.io.FileLoader;
37 import java.awt.Event;
38 import java.awt.event.MouseEvent;
40 import javax.swing.JLabel;
42 import org.testng.annotations.AfterMethod;
43 import org.testng.annotations.BeforeClass;
44 import org.testng.annotations.Test;
46 import junit.extensions.PA;
48 public class SeqPanelTest
52 @BeforeClass(alwaysRun = true)
53 public void setUpJvOptionPane()
55 JvOptionPane.setInteractiveMode(false);
56 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
58 @Test(groups = "Functional")
59 public void testSetStatusReturnsNearestResiduePosition()
61 SequenceI seq1 = new Sequence("Seq1", "AACDE");
62 SequenceI seq2 = new Sequence("Seq2", "AA--E");
63 AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
64 AlignFrame alignFrame = new AlignFrame(al, al.getWidth(),
66 AlignmentI visAl = alignFrame.getViewport().getAlignment();
68 // Test either side of gap
70 alignFrame.alignPanel.getSeqPanel().setStatusMessage(
71 visAl.getSequenceAt(1), 1, 1), 2);
72 assertEquals(((JLabel) PA.getValue(alignFrame, "statusBar")).getText(),
73 "Sequence 2 ID: Seq2 Residue: ALA (2)");
75 alignFrame.alignPanel.getSeqPanel().setStatusMessage(
76 visAl.getSequenceAt(1), 4, 1), 3);
77 assertEquals(((JLabel) PA.getValue(alignFrame, "statusBar")).getText(),
78 "Sequence 2 ID: Seq2 Residue: GLU (3)");
79 // no status message at a gap, returns next residue position to the right
81 alignFrame.alignPanel.getSeqPanel().setStatusMessage(
82 visAl.getSequenceAt(1), 2, 1), 3);
83 assertEquals(((JLabel) PA.getValue(alignFrame, "statusBar")).getText(),
84 "Sequence 2 ID: Seq2");
86 alignFrame.alignPanel.getSeqPanel().setStatusMessage(
87 visAl.getSequenceAt(1), 3, 1), 3);
88 assertEquals(((JLabel) PA.getValue(alignFrame, "statusBar")).getText(),
89 "Sequence 2 ID: Seq2");
92 @Test(groups = "Functional")
93 public void testAmbiguousAminoAcidGetsStatusMessage()
95 SequenceI seq1 = new Sequence("Seq1", "ABCDE");
96 SequenceI seq2 = new Sequence("Seq2", "AB--E");
97 AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
98 AlignFrame alignFrame = new AlignFrame(al, al.getWidth(),
100 AlignmentI visAl = alignFrame.getViewport().getAlignment();
103 alignFrame.alignPanel.getSeqPanel().setStatusMessage(
104 visAl.getSequenceAt(1), 1, 1), 2);
105 assertEquals(((JLabel) PA.getValue(alignFrame, "statusBar")).getText(),
106 "Sequence 2 ID: Seq2 Residue: B (2)");
109 @Test(groups = "Functional")
110 public void testFindMousePosition_unwrapped()
112 String seqData = ">Seq1\nAACDE\n>Seq2\nAA--E\n";
113 AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(seqData,
114 DataSourceType.PASTE);
115 AlignViewportI av = alignFrame.getViewport();
116 av.setShowAnnotation(true);
117 av.setWrapAlignment(false);
118 final int charHeight = av.getCharHeight();
119 final int charWidth = av.getCharWidth();
121 assertTrue(charHeight > 0);
122 assertTrue(charWidth > 0);
123 assertTrue(alignFrame.alignPanel.getSeqPanel().getWidth() > 0);
125 SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
130 * mouse at top left of unwrapped panel
132 MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y,
134 MousePos pos = testee.findMousePosition(evt);
135 assertEquals(pos.column, 0);
136 assertEquals(pos.seqIndex, 0);
137 assertEquals(pos.annotationIndex, -1);
140 @AfterMethod(alwaysRun = true)
141 public void tearDown()
143 Desktop.instance.closeAll_actionPerformed(null);
146 @Test(groups = "Functional")
147 public void testFindMousePosition_wrapped_annotations()
149 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", "true");
150 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true");
151 AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
152 "examples/uniref50.fa", DataSourceType.FILE);
153 AlignViewportI av = alignFrame.getViewport();
154 av.setScaleAboveWrapped(false);
155 av.setScaleLeftWrapped(false);
156 av.setScaleRightWrapped(false);
157 alignFrame.alignPanel.paintAlignment(false, false);
158 waitForSwing(); // for Swing thread
160 final int charHeight = av.getCharHeight();
161 final int charWidth = av.getCharWidth();
162 final int alignmentHeight = av.getAlignment().getHeight();
165 assertTrue(charHeight > 0);
166 assertTrue(charWidth > 0);
167 assertTrue(alignFrame.alignPanel.getSeqPanel().getWidth() > 0);
169 SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
174 * mouse at top left of wrapped panel; there is a gap of charHeight
175 * above the alignment
177 MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y,
179 MousePos pos = testee.findMousePosition(evt);
180 assertEquals(pos.column, 0);
181 assertEquals(pos.seqIndex, -1); // above sequences
182 assertEquals(pos.annotationIndex, -1);
185 * cursor at bottom of gap above
188 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
190 pos = testee.findMousePosition(evt);
191 assertEquals(pos.seqIndex, -1);
192 assertEquals(pos.annotationIndex, -1);
195 * cursor over top of first sequence
198 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
200 pos = testee.findMousePosition(evt);
201 assertEquals(pos.seqIndex, 0);
202 assertEquals(pos.annotationIndex, -1);
205 * cursor at bottom of first sequence
207 y = 2 * charHeight - 1;
208 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
210 pos = testee.findMousePosition(evt);
211 assertEquals(pos.seqIndex, 0);
212 assertEquals(pos.annotationIndex, -1);
215 * cursor at top of second sequence
218 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
220 pos = testee.findMousePosition(evt);
221 assertEquals(pos.seqIndex, 1);
222 assertEquals(pos.annotationIndex, -1);
225 * cursor at bottom of second sequence
227 y = 3 * charHeight - 1;
228 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
230 pos = testee.findMousePosition(evt);
231 assertEquals(pos.seqIndex, 1);
232 assertEquals(pos.annotationIndex, -1);
235 * cursor at bottom of last sequence
237 y = charHeight * (1 + alignmentHeight) - 1;
238 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
240 pos = testee.findMousePosition(evt);
241 assertEquals(pos.seqIndex, alignmentHeight - 1);
242 assertEquals(pos.annotationIndex, -1);
245 * cursor below sequences, in 3-pixel gap above annotations
246 * method reports index of nearest sequence above
249 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
251 pos = testee.findMousePosition(evt);
252 assertEquals(pos.seqIndex, alignmentHeight - 1);
253 assertEquals(pos.annotationIndex, -1);
256 * cursor still in the gap above annotations, now at the bottom of it
258 y += SeqCanvas.SEQS_ANNOTATION_GAP - 1; // 3-1 = 2
259 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
261 pos = testee.findMousePosition(evt);
262 assertEquals(pos.seqIndex, alignmentHeight - 1);
263 assertEquals(pos.annotationIndex, -1);
266 * cursor at the top of the first annotation
269 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
271 pos = testee.findMousePosition(evt);
272 assertEquals(pos.seqIndex, alignmentHeight - 1);
273 assertEquals(pos.annotationIndex, 0); // over first annotation
276 * cursor at the bottom of the first annotation
278 y += av.getAlignment().getAlignmentAnnotation()[0].height - 1;
279 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
281 pos = testee.findMousePosition(evt);
282 assertEquals(pos.seqIndex, alignmentHeight - 1);
283 assertEquals(pos.annotationIndex, 0);
286 * cursor at the top of the second annotation
289 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
291 pos = testee.findMousePosition(evt);
292 assertEquals(pos.seqIndex, alignmentHeight - 1);
293 assertEquals(pos.annotationIndex, 1);
296 * cursor at the bottom of the second annotation
298 y += av.getAlignment().getAlignmentAnnotation()[1].height - 1;
299 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
301 pos = testee.findMousePosition(evt);
302 assertEquals(pos.seqIndex, alignmentHeight - 1);
303 assertEquals(pos.annotationIndex, 1);
306 * cursor at the top of the third annotation
309 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
311 pos = testee.findMousePosition(evt);
312 assertEquals(pos.seqIndex, alignmentHeight - 1);
313 assertEquals(pos.annotationIndex, 2);
316 * cursor at the bottom of the third annotation
318 y += av.getAlignment().getAlignmentAnnotation()[2].height - 1;
319 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
321 pos = testee.findMousePosition(evt);
322 assertEquals(pos.seqIndex, alignmentHeight - 1);
323 assertEquals(pos.annotationIndex, 2);
326 * cursor in gap between wrapped widths
329 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
331 pos = testee.findMousePosition(evt);
332 assertEquals(pos.seqIndex, -1);
333 assertEquals(pos.annotationIndex, -1);
336 * cursor at bottom of gap between wrapped widths
339 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
341 pos = testee.findMousePosition(evt);
342 assertEquals(pos.seqIndex, -1);
343 assertEquals(pos.annotationIndex, -1);
346 * cursor at top of first sequence, second wrapped width
349 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
351 pos = testee.findMousePosition(evt);
352 assertEquals(pos.seqIndex, 0);
353 assertEquals(pos.annotationIndex, -1);
356 @Test(groups = "Functional")
357 public void testFindMousePosition_wrapped_scaleAbove()
359 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", "true");
360 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true");
361 AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
362 "examples/uniref50.fa", DataSourceType.FILE);
363 AlignViewportI av = alignFrame.getViewport();
364 av.setScaleAboveWrapped(true);
365 av.setScaleLeftWrapped(false);
366 av.setScaleRightWrapped(false);
367 alignFrame.alignPanel.paintAlignment(false, false);
370 final int charHeight = av.getCharHeight();
371 final int charWidth = av.getCharWidth();
372 final int alignmentHeight = av.getAlignment().getHeight();
375 assertTrue(charHeight > 0);
376 assertTrue(charWidth > 0);
377 assertTrue(alignFrame.alignPanel.getSeqPanel().getWidth() > 0);
379 SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
384 * mouse at top left of wrapped panel; there is a gap of charHeight
385 * above the alignment
387 MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y,
389 MousePos pos = testee.findMousePosition(evt);
390 assertEquals(pos.column, 0);
391 assertEquals(pos.seqIndex, -1); // above sequences
392 assertEquals(pos.annotationIndex, -1);
395 * cursor at bottom of gap above
396 * two charHeights including scale panel
398 y = 2 * charHeight - 1;
399 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
401 pos = testee.findMousePosition(evt);
402 assertEquals(pos.seqIndex, -1);
403 assertEquals(pos.annotationIndex, -1);
406 * cursor over top of first sequence
409 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
411 pos = testee.findMousePosition(evt);
412 assertEquals(pos.seqIndex, 0);
413 assertEquals(pos.annotationIndex, -1);
416 * cursor at bottom of first sequence
419 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
421 pos = testee.findMousePosition(evt);
422 assertEquals(pos.seqIndex, 0);
423 assertEquals(pos.annotationIndex, -1);
426 * cursor at top of second sequence
429 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
431 pos = testee.findMousePosition(evt);
432 assertEquals(pos.seqIndex, 1);
433 assertEquals(pos.annotationIndex, -1);
436 * cursor at bottom of second sequence
439 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
441 pos = testee.findMousePosition(evt);
442 assertEquals(pos.seqIndex, 1);
443 assertEquals(pos.annotationIndex, -1);
446 * cursor at bottom of last sequence
447 * (scale + gap + sequences)
449 y = charHeight * (2 + alignmentHeight) - 1;
450 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
452 pos = testee.findMousePosition(evt);
453 assertEquals(pos.seqIndex, alignmentHeight - 1);
454 assertEquals(pos.annotationIndex, -1);
457 * cursor below sequences, in 3-pixel gap above annotations
460 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
462 pos = testee.findMousePosition(evt);
463 assertEquals(pos.seqIndex, alignmentHeight - 1);
464 assertEquals(pos.annotationIndex, -1);
467 * cursor still in the gap above annotations, now at the bottom of it
468 * method reports index of nearest sequence above
470 y += SeqCanvas.SEQS_ANNOTATION_GAP - 1; // 3-1 = 2
471 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
473 pos = testee.findMousePosition(evt);
474 assertEquals(pos.seqIndex, alignmentHeight - 1);
475 assertEquals(pos.annotationIndex, -1);
478 * cursor at the top of the first annotation
481 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
483 pos = testee.findMousePosition(evt);
484 assertEquals(pos.seqIndex, alignmentHeight - 1);
485 assertEquals(pos.annotationIndex, 0); // over first annotation
488 * cursor at the bottom of the first annotation
490 y += av.getAlignment().getAlignmentAnnotation()[0].height - 1;
491 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
493 pos = testee.findMousePosition(evt);
494 assertEquals(pos.seqIndex, alignmentHeight - 1);
495 assertEquals(pos.annotationIndex, 0);
498 * cursor at the top of the second annotation
501 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
503 pos = testee.findMousePosition(evt);
504 assertEquals(pos.seqIndex, alignmentHeight - 1);
505 assertEquals(pos.annotationIndex, 1);
508 * cursor at the bottom of the second annotation
510 y += av.getAlignment().getAlignmentAnnotation()[1].height - 1;
511 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
513 pos = testee.findMousePosition(evt);
514 assertEquals(pos.seqIndex, alignmentHeight - 1);
515 assertEquals(pos.annotationIndex, 1);
518 * cursor at the top of the third annotation
521 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
523 pos = testee.findMousePosition(evt);
524 assertEquals(pos.seqIndex, alignmentHeight - 1);
525 assertEquals(pos.annotationIndex, 2);
528 * cursor at the bottom of the third annotation
530 y += av.getAlignment().getAlignmentAnnotation()[2].height - 1;
531 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
533 pos = testee.findMousePosition(evt);
534 assertEquals(pos.seqIndex, alignmentHeight - 1);
535 assertEquals(pos.annotationIndex, 2);
538 * cursor in gap between wrapped widths
541 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
543 pos = testee.findMousePosition(evt);
544 assertEquals(pos.seqIndex, -1);
545 assertEquals(pos.annotationIndex, -1);
548 * cursor at bottom of gap between wrapped widths
551 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
553 pos = testee.findMousePosition(evt);
554 assertEquals(pos.seqIndex, -1);
555 assertEquals(pos.annotationIndex, -1);
558 * cursor at top of scale, second wrapped width
561 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
563 pos = testee.findMousePosition(evt);
564 assertEquals(pos.seqIndex, -1);
565 assertEquals(pos.annotationIndex, -1);
568 * cursor at bottom of scale, second wrapped width
571 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
573 pos = testee.findMousePosition(evt);
574 assertEquals(pos.seqIndex, -1);
575 assertEquals(pos.annotationIndex, -1);
578 * cursor at top of first sequence, second wrapped width
581 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
583 pos = testee.findMousePosition(evt);
584 assertEquals(pos.seqIndex, 0);
585 assertEquals(pos.annotationIndex, -1);
588 @Test(groups = "Functional")
589 public void testFindMousePosition_wrapped_noAnnotations()
591 Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", "false");
592 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true");
593 AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
594 "examples/uniref50.fa", DataSourceType.FILE);
595 AlignViewportI av = alignFrame.getViewport();
596 av.setScaleAboveWrapped(false);
597 av.setScaleLeftWrapped(false);
598 av.setScaleRightWrapped(false);
599 alignFrame.alignPanel.paintAlignment(false, false);
602 final int charHeight = av.getCharHeight();
603 final int charWidth = av.getCharWidth();
604 final int alignmentHeight = av.getAlignment().getHeight();
607 assertTrue(charHeight > 0);
608 assertTrue(charWidth > 0);
609 assertTrue(alignFrame.alignPanel.getSeqPanel().getWidth() > 0);
611 SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
616 * mouse at top left of wrapped panel; there is a gap of charHeight
617 * above the alignment
619 MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y,
621 MousePos pos = testee.findMousePosition(evt);
622 assertEquals(pos.column, 0);
623 assertEquals(pos.seqIndex, -1); // above sequences
624 assertEquals(pos.annotationIndex, -1);
627 * cursor over top of first sequence
630 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
632 pos = testee.findMousePosition(evt);
633 assertEquals(pos.seqIndex, 0);
634 assertEquals(pos.annotationIndex, -1);
637 * cursor at bottom of last sequence
639 y = charHeight * (1 + alignmentHeight) - 1;
640 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
642 pos = testee.findMousePosition(evt);
643 assertEquals(pos.seqIndex, alignmentHeight - 1);
644 assertEquals(pos.annotationIndex, -1);
647 * cursor below sequences, at top of charHeight gap between widths
650 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
652 pos = testee.findMousePosition(evt);
653 assertEquals(pos.seqIndex, -1);
654 assertEquals(pos.annotationIndex, -1);
657 * cursor below sequences, at top of charHeight gap between widths
660 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
662 pos = testee.findMousePosition(evt);
663 assertEquals(pos.seqIndex, -1);
664 assertEquals(pos.annotationIndex, -1);
667 * cursor at the top of the first sequence, second width
670 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, y, 0, 0, 0,
672 pos = testee.findMousePosition(evt);
673 assertEquals(pos.seqIndex, 0);
674 assertEquals(pos.annotationIndex, -1);
677 @Test(groups = "Functional")
678 public void testFindColumn_unwrapped()
680 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "false");
681 AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
682 "examples/uniref50.fa", DataSourceType.FILE);
683 SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
685 final int charWidth = alignFrame.getViewport().getCharWidth();
686 assertTrue(charWidth > 0); // sanity check
687 assertEquals(alignFrame.getViewport().getRanges().getStartRes(), 0);
690 * mouse at top left of unwrapped panel
692 MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0,
694 assertEquals(testee.findColumn(evt), 0);
697 * not quite one charWidth across
700 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0,
702 assertEquals(testee.findColumn(evt), 0);
705 * one charWidth across
708 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
710 assertEquals(testee.findColumn(evt), 1);
713 * two charWidths across
716 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
718 assertEquals(testee.findColumn(evt), 2);
721 * limited to last column of seqcanvas
724 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
726 SeqCanvas seqCanvas = alignFrame.alignPanel.getSeqPanel().seqCanvas;
727 int w = seqCanvas.getWidth();
728 // limited to number of whole columns, base 0
729 int expected = w / charWidth - 1;
730 assertEquals(testee.findColumn(evt), expected);
733 * hide columns 5-10 (base 1)
735 alignFrame.getViewport().hideColumns(4, 9);
736 x = 5 * charWidth + 2;
737 // x is in 6th visible column, absolute column 12, or 11 base 0
738 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
740 assertEquals(testee.findColumn(evt), 11);
743 @Test(groups = "Functional")
744 public void testFindColumn_wrapped()
746 Cache.applicationProperties.setProperty("WRAP_ALIGNMENT", "true");
747 AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(
748 "examples/uniref50.fa", DataSourceType.FILE);
749 AlignViewport av = alignFrame.getViewport();
750 av.setScaleAboveWrapped(false);
751 av.setScaleLeftWrapped(false);
752 av.setScaleRightWrapped(false);
753 alignFrame.alignPanel.paintAlignment(false, false);
754 // need to wait for repaint to finish!
756 SeqPanel testee = alignFrame.alignPanel.getSeqPanel();
758 final int charWidth = av.getCharWidth();
759 assertTrue(charWidth > 0); // sanity check
760 assertEquals(av.getRanges().getStartRes(), 0);
763 * mouse at top left of wrapped panel, no West (left) scale
765 MouseEvent evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0,
767 assertEquals(testee.findColumn(evt), 0);
770 * not quite one charWidth across
773 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0,
775 assertEquals(testee.findColumn(evt), 0);
778 * one charWidth across
781 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
783 assertEquals(testee.findColumn(evt), 1);
786 * x over scale left (before drawn columns) results in -1
788 av.setScaleLeftWrapped(true);
789 alignFrame.alignPanel.paintAlignment(false, false);
791 SeqCanvas seqCanvas = testee.seqCanvas;
792 int labelWidth = (int) PA.getValue(seqCanvas, "labelWidthWest");
793 assertTrue(labelWidth > 0);
795 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
797 assertEquals(testee.findColumn(evt), -1);
800 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
802 assertEquals(testee.findColumn(evt), 0);
805 * x over right edge of last residue (including scale left)
807 int residuesWide = av.getRanges().getViewportWidth();
808 assertTrue(residuesWide > 0);
809 x = labelWidth + charWidth * residuesWide - 1;
810 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
812 assertEquals(testee.findColumn(evt), residuesWide - 1);
815 * x over scale right (beyond drawn columns) results in -1
817 av.setScaleRightWrapped(true);
818 alignFrame.alignPanel.paintAlignment(false, false);
820 labelWidth = (int) PA.getValue(seqCanvas, "labelWidthEast");
821 assertTrue(labelWidth > 0);
822 int residuesWide2 = av.getRanges().getViewportWidth();
823 assertTrue(residuesWide2 > 0);
824 assertTrue(residuesWide2 < residuesWide); // available width reduced
825 x += 1; // just over left edge of scale right
826 evt = new MouseEvent(testee, Event.MOUSE_MOVE, 0L, 0, x, 0, 0, 0, 0,
828 assertEquals(testee.findColumn(evt), -1);
830 // todo add startRes offset, hidden columns
833 @BeforeClass(alwaysRun = true)
834 public static void setUpBeforeClass() throws Exception
837 * use read-only test properties file
839 Cache.loadProperties("test/jalview/io/testProps.jvprops");
840 Jalview.main(new String[] { "-nonews" });
844 * waits a few ms for Swing to do something
846 synchronized void waitForSwing()
851 } catch (InterruptedException e)