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.
21 package jalview.viewmodel;
23 import static org.testng.Assert.assertEquals;
25 import jalview.analysis.AlignmentGenerator;
26 import jalview.bin.Cache;
27 import jalview.bin.Jalview;
28 import jalview.datamodel.Alignment;
29 import jalview.datamodel.AlignmentI;
30 import jalview.datamodel.Sequence;
31 import jalview.datamodel.SequenceGroup;
32 import jalview.datamodel.SequenceI;
33 import jalview.gui.AlignFrame;
34 import jalview.gui.AlignViewport;
35 import jalview.gui.Desktop;
36 import jalview.gui.JvOptionPane;
37 import jalview.io.DataSourceType;
38 import jalview.io.FileLoader;
40 import java.util.List;
42 import org.testng.annotations.AfterClass;
43 import org.testng.annotations.AfterMethod;
44 import org.testng.annotations.BeforeClass;
45 import org.testng.annotations.BeforeMethod;
46 import org.testng.annotations.Test;
48 @Test(singleThreaded = true)
49 public class OverviewDimensionsTest {
51 SequenceI seq1 = new Sequence(
53 "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
55 SequenceI seq2 = new Sequence(
57 "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
59 SequenceI seq3 = new Sequence(
61 "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
63 SequenceI seq4 = new Sequence(
65 "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
67 SequenceI seq5 = new Sequence(
69 "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
75 OverviewDimensions od;
84 @BeforeClass(alwaysRun = true)
85 public void setUpJvOptionPane()
87 JvOptionPane.setInteractiveMode(false);
88 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
90 // create random alignment
91 AlignmentGenerator gen = new AlignmentGenerator(false);
92 al = gen.generate(157, 525, 123, 5, 5);
95 @BeforeMethod(alwaysRun = true)
98 Jalview.main(new String[] { "-nonews", "-props",
99 "test/jalview/testProps.jvprops" });
101 Cache.applicationProperties.setProperty("SHOW_IDENTITY",
102 Boolean.TRUE.toString());
103 af = new FileLoader().LoadFileWaitTillLoaded(al.toString(),
104 DataSourceType.PASTE);
107 * wait for Consensus thread to complete
111 while (af.getViewport().getConsensusSeq() == null)
116 } catch (InterruptedException e)
122 av = af.getViewport();
124 od = new OverviewDimensions(av.getPosProps(), true);
126 while (av.isCalcInProgress())
131 } catch (InterruptedException e)
137 // Initial box sizing - default path through code
138 od.setBoxPosition(av.getAlignment()
139 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
146 av.showAllHiddenColumns();
147 av.showAllHiddenSeqs();
148 av.setSelectionGroup(null);
149 // o/w hidden seqs retain selection group, causes problems later when hiding
152 // wait for conservation calc to complete again
153 while (av.isCalcInProgress())
158 } catch (InterruptedException e)
164 mouseClick(od, 0, 0);
167 viewHeight = av.getEndSeq() - av.getStartSeq();
168 viewWidth = av.getEndRes() - av.getStartRes();
170 // wait for gui to get set up
171 // this does actually appear to be necessary
172 while (viewHeight != 17 || viewWidth != 62)
177 viewHeight = av.getEndSeq() - av.getStartSeq();
178 viewWidth = av.getEndRes() - av.getStartRes();
179 } catch (InterruptedException e)
185 // calculate before hidden columns so we get absolute values
186 alheight = av.getAlignment().getHeight();
187 alwidth = av.getAlignment().getWidth();
189 boxWidth = Math.round((float) (av.getEndRes() - av.getStartRes() + 1)
190 / alwidth * od.getWidth());
191 boxHeight = Math.round((float) (av.getEndSeq() - av.getStartSeq())
192 / alheight * od.getHeight());
193 System.out.println(boxHeight);
197 @AfterMethod(alwaysRun = true)
198 public void tearDown()
202 Desktop.instance.closeAll_actionPerformed(null);
205 @AfterClass(alwaysRun = true)
206 public void cleanUp()
212 * Test that the OverviewDimensions constructor sets width and height
215 @Test(groups = { "Functional" })
216 public void testConstructor()
218 SequenceI seqa = new Sequence("Seq1", "ABC");
219 SequenceI seqb = new Sequence("Seq2", "ABC");
220 SequenceI seqc = new Sequence("Seq3", "ABC");
221 SequenceI seqd = new Sequence("Seq4", "ABC");
222 SequenceI seqe = new Sequence("Seq5",
223 "ABCABCABCABCABCABCABCABCBACBACBACBAC");
225 int defaultGraphHeight = 20;
228 int maxSeqHeight = 300;
229 int minSeqHeight = 40;
231 // test for alignment with width > height
232 SequenceI[] seqs1 = new SequenceI[] { seqa, seqb };
233 Alignment al1 = new Alignment(seqs1);
234 al1.setDataset(null);
235 AlignViewport av1 = new AlignViewport(al1);
237 OverviewDimensions od = new OverviewDimensions(av1.getPosProps(), true);
238 int scaledHeight = 266;
239 assertEquals(od.getGraphHeight(), defaultGraphHeight);
240 assertEquals(od.getSequencesHeight(), scaledHeight);
241 assertEquals(od.getWidth(), maxWidth);
242 assertEquals(od.getHeight(), scaledHeight + defaultGraphHeight);
244 // test for alignment with width < height
245 SequenceI[] seqs2 = new SequenceI[] { seqa, seqb, seqc, seqd };
246 Alignment al2 = new Alignment(seqs2);
247 al2.setDataset(null);
248 AlignViewport av2 = new AlignViewport(al2);
250 od = new OverviewDimensions(av2.getPosProps(), true);
251 int scaledWidth = 300;
252 assertEquals(od.getGraphHeight(), defaultGraphHeight);
253 assertEquals(od.getSequencesHeight(), maxSeqHeight);
254 assertEquals(od.getWidth(), scaledWidth);
255 assertEquals(od.getHeight(), scaledWidth + defaultGraphHeight);
257 // test for alignment with width > height and sequence height scaled below
259 SequenceI[] seqs3 = new SequenceI[] { seqe };
260 Alignment al3 = new Alignment(seqs3);
261 al3.setDataset(null);
262 AlignViewport av3 = new AlignViewport(al3);
264 od = new OverviewDimensions(av3.getPosProps(), true);
265 assertEquals(od.getGraphHeight(), defaultGraphHeight);
266 assertEquals(od.getSequencesHeight(), minSeqHeight);
267 assertEquals(od.getWidth(), maxWidth);
268 assertEquals(od.getHeight(), minSeqHeight + defaultGraphHeight);
270 // test for alignment with width < height and width scaled below min value
271 SequenceI[] seqs4 = new SequenceI[] { seqa, seqb, seqc, seqd, seqa,
272 seqb, seqc, seqd, seqa, seqb, seqc, seqd, seqa, seqb, seqc, seqd };
273 Alignment al4 = new Alignment(seqs4);
274 al4.setDataset(null);
275 AlignViewport av4 = new AlignViewport(al4);
277 od = new OverviewDimensions(av4.getPosProps(), true);
278 assertEquals(od.getGraphHeight(), defaultGraphHeight);
279 assertEquals(od.getSequencesHeight(), maxSeqHeight);
280 assertEquals(od.getWidth(), minWidth);
281 assertEquals(od.getHeight(), maxSeqHeight + defaultGraphHeight);
283 Alignment al5 = new Alignment(seqs4);
284 al5.setDataset(null);
285 AlignViewport av5 = new AlignViewport(al5);
287 od = new OverviewDimensions(av5.getPosProps(), false);
288 assertEquals(od.getGraphHeight(), 0);
289 assertEquals(od.getSequencesHeight(), maxSeqHeight);
290 assertEquals(od.getWidth(), minWidth);
291 assertEquals(od.getHeight(), maxSeqHeight);
295 * Test that validation after mouse adjustments to boxX and boxY sets box
296 * dimensions and scroll values correctly, when there are no hidden rows or
299 * The current implementation uses multiple transformations between coordinate
300 * systems which often involve casting to int, which causes values to be
301 * truncated. As a result we can lose accuracy. The tests below use
302 * approximate test values where appropriate.
304 @Test(groups = { "Functional" })
305 public void testSetBoxFromMouseClick()
307 od.updateViewportFromMouse(0, 0,
308 av.getAlignment().getHiddenSequences(),
309 av.getColumnSelection(), av.getPosProps());
310 assertEquals(od.getBoxX(), 0);
311 assertEquals(od.getBoxY(), 0);
312 assertEquals(od.getBoxWidth(), boxWidth);
313 assertEquals(od.getScrollCol(), 0);
314 assertEquals(od.getScrollRow(), 0);
316 // negative boxX value reset to 0
317 mouseClick(od, -5, 10);
318 assertEquals(od.getBoxX(), 0);
319 assertEquals(od.getBoxWidth(), boxWidth);
320 assertEquals(od.getBoxHeight(), boxHeight);
321 assertEquals(od.getScrollRow(),
322 Math.round((float) 10 * alheight / od.getSequencesHeight()));
323 assertEquals(od.getScrollCol(), 0);
325 // negative boxY value reset to 0
326 mouseClick(od, 6, -2);
327 assertEquals(od.getBoxY(), 0);
328 assertEquals(od.getBoxWidth(), boxWidth);
329 assertEquals(od.getBoxHeight(), boxHeight);
330 assertEquals(od.getScrollCol(),
331 Math.round((float) 6 * alwidth / od.getWidth()));
332 assertEquals(od.getScrollRow(), 0);
334 // overly large boxX value reset to width-boxWidth
335 mouseClick(od, 100, 6);
336 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
337 assertEquals(od.getBoxY(), 6);
338 assertEquals(od.getBoxWidth(), boxWidth);
339 assertEquals(od.getBoxHeight(), boxHeight);
340 assertEquals(od.getScrollCol(),
341 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
342 assertEquals(od.getScrollRow(),
343 Math.round((float) od.getBoxY() * alheight
344 / od.getSequencesHeight()));
346 // overly large boxY value reset to sequenceHeight - boxHeight
347 mouseClick(od, 10, 520);
348 assertEquals(od.getBoxX(), 10);
349 assertEquals(od.getBoxY(), od.getSequencesHeight() - od.getBoxHeight());
350 assertEquals(od.getBoxWidth(), boxWidth);
351 assertEquals(od.getBoxHeight(), boxHeight);
352 assertEquals(od.getScrollCol(),
353 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
354 assertEquals(od.getScrollRow(),
355 Math.round((float) od.getBoxY() * alheight
356 / od.getSequencesHeight()));
358 // click past end of alignment, as above
359 mouseClick(od, 3000, 5);
360 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
361 assertEquals(od.getBoxWidth(), boxWidth);
362 assertEquals(od.getBoxHeight(), boxHeight);
363 assertEquals(od.getScrollCol(),
364 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
365 assertEquals(od.getScrollRow(),
366 Math.round((float) od.getBoxY() * alheight
367 / od.getSequencesHeight()));
369 // move viewport so startRes non-zero and then mouseclick
372 // click at viewport position
373 int oldboxx = od.getBoxX();
374 int oldboxy = od.getBoxY();
375 mouseClick(od, od.getBoxX() + 5, od.getBoxY() + 2);
376 assertEquals(od.getBoxX(), oldboxx + 5);
377 assertEquals(od.getBoxWidth(), boxWidth);
378 assertEquals(od.getBoxHeight(), boxHeight);
379 assertEquals(od.getScrollCol(),
380 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
381 assertEquals(od.getBoxY(), oldboxy + 2);
382 assertEquals(od.getScrollRow(),
383 Math.round((float) od.getBoxY() * alheight
384 / od.getSequencesHeight()));
386 // click at top corner
387 mouseClick(od, 0, 0);
388 assertEquals(od.getBoxX(), 0);
389 assertEquals(od.getScrollCol(), 0);
390 assertEquals(od.getBoxY(), 0);
391 assertEquals(od.getScrollRow(), 0);
392 assertEquals(od.getBoxWidth(), boxWidth);
393 assertEquals(od.getBoxHeight(), boxHeight);
397 * Test setting of the box position, when there are hidden cols at the start
400 @Test(groups = { "Functional" })
401 public void testFromMouseWithHiddenColsAtStart()
403 od.updateViewportFromMouse(0, 0,
404 av.getAlignment().getHiddenSequences(),
405 av.getColumnSelection(), av.getPosProps());
406 assertEquals(od.getBoxX(), 0);
407 assertEquals(od.getBoxY(), 0);
408 assertEquals(od.getBoxWidth(), boxWidth);
409 assertEquals(od.getScrollCol(), 0);
410 assertEquals(od.getScrollRow(), 0);
412 // hide cols at start and check updated box position is correct
413 // changes boxX but not boxwidth
414 int lastHiddenCol = 30;
415 hideColumns(0, lastHiddenCol);
417 od.setBoxPosition(av.getAlignment()
418 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
419 assertEquals(od.getBoxX(),
420 Math.round((float) (lastHiddenCol + 1) * od.getWidth()
422 assertEquals(od.getBoxWidth(), boxWidth);
423 assertEquals(od.getBoxHeight(), boxHeight);
425 // try to click in hidden cols, check box does not move
426 // this test currently fails as the overview box does not behave like this!
428 mouseClick(od, xpos, 0);
429 assertEquals(od.getBoxX(),
430 Math.round ((lastHiddenCol + 1) * od.getWidth() / alwidth));
431 assertEquals(od.getBoxY(), 0);
432 assertEquals(od.getBoxWidth(), boxWidth);
433 assertEquals(od.getBoxHeight(), boxHeight);
434 assertEquals(od.getScrollRow(), 0);
435 assertEquals(od.getScrollCol(),
436 Math.round (xpos * alwidth / od.getWidth()));
438 // click to right of hidden columns, box moves to click point
439 testBoxIsAtClickPoint(40, 0);
440 assertEquals(od.getScrollRow(), 0);
441 assertEquals(od.getScrollCol(),
442 Math.round((float) 40 * alwidth / od.getWidth())
443 - (lastHiddenCol + 1));
445 // click to right of hidden columns such that box runs over right hand side
447 // box position is adjusted away from the edge
448 // overly large boxX value reset to width-boxWidth
450 mouseClick(od, xpos, 5);
451 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
452 assertEquals(od.getBoxY(), 5);
453 assertEquals(od.getBoxWidth(), boxWidth);
454 assertEquals(od.getBoxHeight(), boxHeight);
455 assertEquals(od.getScrollCol(),
456 Math.round((float) od.getBoxX() * alwidth / od.getWidth())
457 - (lastHiddenCol + 1));
458 assertEquals(od.getScrollRow(),
459 Math.round((float) od.getBoxY() * alheight
460 / od.getSequencesHeight()));
464 * Test setting of the box position, when there are hidden cols in the middle
467 @Test(groups = { "Functional" })
468 public void testFromMouseWithHiddenColsInMiddle()
470 od.updateViewportFromMouse(0, 0,
471 av.getAlignment().getHiddenSequences(),
472 av.getColumnSelection(), av.getPosProps());
473 assertEquals(od.getBoxX(), 0);
474 assertEquals(od.getBoxY(), 0);
475 assertEquals(od.getBoxWidth(), boxWidth);
476 assertEquals(od.getScrollCol(), 0);
477 assertEquals(od.getScrollRow(), 0);
479 // hide columns 60-68, no change to box position or dimensions
480 int firstHidden = 63;
482 hideColumns(firstHidden, lastHidden);
484 od.setBoxPosition(av.getAlignment()
485 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
486 assertEquals(od.getBoxX(), 0);
487 assertEquals(od.getBoxY(), 0);
488 assertEquals(od.getBoxWidth(), boxWidth);
489 assertEquals(od.getScrollCol(), 0);
490 assertEquals(od.getScrollRow(), 0);
492 // move box so that it overlaps with hidden cols on one side
493 // box width changes, boxX and scrollCol as for unhidden case
494 int xpos = 55 - boxWidth; // 55 is position in overview approx halfway
495 // between cols 60 and 70
496 mouseClick(od, xpos, 0);
497 assertEquals(od.getBoxX(), xpos);
498 assertEquals(od.getBoxY(), 0);
501 Math.round(boxWidth + (float) (lastHidden - firstHidden + 1)
502 * od.getWidth() / alwidth));
503 assertEquals(od.getBoxHeight(), boxHeight);
504 assertEquals(od.getScrollCol(),
505 Math.round(xpos * alwidth / od.getWidth()));
506 assertEquals(od.getScrollRow(), 0);
508 // move box so that it completely covers hidden cols
509 // box width changes, boxX and scrollCol as for hidden case
511 mouseClick(od, xpos, 0);
512 assertEquals(od.getBoxX(), xpos);
513 assertEquals(od.getBoxY(), 0);
516 Math.round(boxWidth + (float) (lastHidden - firstHidden + 1)
517 * od.getWidth() / alwidth));
518 assertEquals(od.getBoxHeight(), boxHeight);
519 assertEquals(od.getScrollCol(),
520 Math.round((float) xpos * alwidth / od.getWidth()));
521 assertEquals(od.getScrollRow(), 0);
523 // move box so boxX is in hidden cols, box overhangs at right
524 // box width back to normal, boxX and scrollCol move to right of hidden area
525 // TODO currently this test fails in the Jalview GUI, there is a gap between
526 // the rhs of the hidden area and the box
528 mouseClick(od, xpos, 0);
529 assertEquals(od.getBoxX(),
530 (lastHidden + 1) * scalew * av.getCharWidth());
531 assertEquals(od.getBoxY(), 0);
532 assertEquals(od.getBoxWidth(), boxWidth);
533 assertEquals(od.getBoxHeight(), boxHeight);
534 assertEquals(od.getScrollCol(),
535 Math.round(xpos * alwidth / od.getWidth()));
536 assertEquals(od.getScrollRow(), 0);*/
538 // move box so boxX is to right of hidden cols, but does not go beyond full
539 // width of alignment
540 // box width, boxX and scrollCol all as for non-hidden case
541 // TODO currently this test fails in the Jalview GUI because boxX is
543 // based on the current boxWidth, which includes hidden columns, thereby
545 // the box off the end of the alignment. So boxX is adjusted backwards
548 testBoxIsAtClickPoint(xpos, 0);
549 assertEquals(od.getScrollRow(), 0);
550 assertEquals(od.getScrollCol(),
551 Math.round(xpos * alwidth / od.getWidth())
554 // move box so it goes beyond full width of alignment
555 // boxX, scrollCol adjusted back, box width normal
557 mouseClick(od, xpos, 5);
558 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
559 assertEquals(od.getBoxY(), 5);
560 assertEquals(od.getBoxWidth(), boxWidth);
561 assertEquals(od.getBoxHeight(), boxHeight);
562 assertEquals(od.getScrollCol(),
563 Math.round(((float) od.getBoxX() * alwidth / od.getWidth())
564 - (lastHidden - firstHidden + 1)));
565 assertEquals(od.getScrollRow(),
566 Math.round((float) od.getBoxY() * alheight
567 / od.getSequencesHeight()));
572 * Test setting of the box position, when there are hidden cols at the end of
575 @Test(groups = { "Functional" })
576 public void testFromMouseWithHiddenColsAtEnd()
578 od.updateViewportFromMouse(0, 0,
579 av.getAlignment().getHiddenSequences(),
580 av.getColumnSelection(), av.getPosProps());
581 assertEquals(od.getBoxX(), 0);
582 assertEquals(od.getBoxY(), 0);
583 assertEquals(od.getBoxWidth(), boxWidth);
584 assertEquals(od.getScrollCol(), 0);
585 assertEquals(od.getScrollRow(), 0);
587 // hide columns 140-157, no change to box position or dimensions
588 int firstHidden = 140;
589 int lastHidden = 157;
590 hideColumns(firstHidden, lastHidden);
591 od.setBoxPosition(av.getAlignment()
592 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
593 assertEquals(od.getBoxX(), 0);
594 assertEquals(od.getBoxY(), 0);
595 assertEquals(od.getBoxWidth(), boxWidth);
596 assertEquals(od.getScrollCol(), 0);
597 assertEquals(od.getScrollRow(), 0);
599 // click to left of hidden cols, without overlapping
600 // boxX, scrollCol and width as normal
602 testBoxIsAtClickPoint(xpos, 0);
603 assertEquals(od.getScrollRow(), 0);
604 assertEquals(od.getScrollCol(),
605 Math.round((float) xpos * alwidth / od.getWidth()));
607 // click to left of hidden cols, with overlap
608 // boxX and scrollCol adjusted for hidden cols, width normal
609 // TODO this fails because setBoxPosition screws up the hidden cols calc
610 // only works in GUI because of AlignmentPanel::setScrollValues
611 /*xpos = 115 - boxWidth;
612 mouseClick(od, xpos, 0);
615 Math.round((firstHidden - 1) * scalew * av.getCharWidth())
617 assertEquals(od.getBoxY(), 0);
618 assertEquals(od.getBoxWidth(), boxWidth);
619 assertEquals(od.getBoxHeight(), boxHeight);
620 assertEquals(od.getScrollCol(),
621 Math.round(od.getBoxX() * alwidth / od.getWidth()));
622 assertEquals(od.getScrollRow(), 0);*/
624 // click in hidden cols
625 // boxX and scrollCol adjusted for hidden cols, width normal
626 // TODO breaks as above test
630 Math.round((firstHidden - 1) * scalew * av.getCharWidth())
632 assertEquals(od.getBoxY(), 0);
633 assertEquals(od.getBoxWidth(), boxWidth);
634 assertEquals(od.getBoxHeight(), boxHeight);
635 assertEquals(od.getScrollCol(),
636 Math.round(od.getBoxX() * alwidth / od.getWidth()));
637 assertEquals(od.getScrollRow(), 0);*/
639 // click off end of alignment
640 // boxX and scrollCol adjusted for hidden cols, width normal
641 // TODO breaks as above test
645 Math.round((firstHidden - 1) * scalew * av.getCharWidth())
647 assertEquals(od.getBoxY(), 0);
648 assertEquals(od.getBoxWidth(), boxWidth);
649 assertEquals(od.getBoxHeight(), boxHeight);
650 assertEquals(od.getScrollCol(),
651 Math.round(od.getBoxX() * alwidth / od.getWidth()));
652 assertEquals(od.getScrollRow(), 0);*/
656 * Test that the box position is set correctly when set from the viewport,
657 * with no hidden rows or columns
659 @Test(groups = { "Functional" })
660 public void testSetBoxFromViewport()
662 // move viewport to start of alignment
664 assertEquals(od.getBoxX(), 0);
665 assertEquals(od.getBoxY(), 0);
666 assertEquals(od.getBoxWidth(), boxWidth);
667 assertEquals(od.getBoxHeight(), boxHeight);
669 // move viewport to right
671 assertEquals(od.getBoxX(),
672 Math.round((float) 70 * od.getWidth() / alwidth));
673 assertEquals(od.getBoxY(), 0);
674 assertEquals(od.getBoxWidth(), boxWidth);
675 assertEquals(od.getBoxHeight(), boxHeight);
677 // move viewport down
679 assertEquals(od.getBoxX(),
680 Math.round((float) 70 * od.getWidth() / alwidth));
681 assertEquals(od.getBoxY(),
682 Math.round(100 * od.getSequencesHeight() / alheight));
683 assertEquals(od.getBoxWidth(), boxWidth);
684 assertEquals(od.getBoxHeight(), boxHeight);
686 // move viewport to bottom right
687 moveViewport(98, 508);
688 assertEquals(od.getBoxX(),
689 Math.round((float) 98 * od.getWidth() / alwidth));
690 assertEquals(od.getBoxY(),
691 Math.round((float) 508 * od.getSequencesHeight() / alheight));
692 assertEquals(od.getBoxWidth(), boxWidth);
693 assertEquals(od.getBoxHeight(), boxHeight);
697 * Test that the box position is set correctly when there are hidden columns
700 @Test(groups = { "Functional" })
701 public void testSetBoxFromViewportHiddenColsAtStart()
705 hideColumns(firstHidden, lastHidden);
707 // move viewport to start of alignment
709 assertEquals(od.getBoxX(),
710 Math.round((float) (lastHidden + 1) * od.getWidth() / alwidth));
711 assertEquals(od.getBoxY(), 0);
712 assertEquals(od.getBoxWidth(), boxWidth);
713 assertEquals(od.getBoxHeight(), boxHeight);
715 // move viewport to end of alignment - need to make startRes by removing
716 // hidden cols because of how viewport/overview are implemented
717 moveViewport(98 - lastHidden - 1, 0);
718 assertEquals(od.getBoxX(),
719 Math.round((float) 98 * od.getWidth() / alwidth));
720 assertEquals(od.getBoxY(), 0);
721 assertEquals(od.getBoxWidth(), boxWidth);
722 assertEquals(od.getBoxHeight(), boxHeight);
726 * Test that the box position is set correctly when there are hidden columns
729 @Test(groups = { "Functional" })
730 public void testSetBoxFromViewportHiddenColsInMiddle()
732 int firstHidden = 68;
734 hideColumns(firstHidden, lastHidden);
736 // move viewport before hidden columns
739 assertEquals(od.getBoxX(),
740 Math.round((float) 3 * od.getWidth() / alwidth));
741 assertEquals(od.getBoxY(), 0);
742 System.out.println(od.getBoxWidth());
743 assertEquals(od.getBoxWidth(), boxWidth);
744 System.out.println(od.getBoxWidth());
745 assertEquals(od.getBoxHeight(), boxHeight);
747 // move viewport to left of hidden columns with overlap
749 assertEquals(od.getBoxX(),
750 Math.round((float) 10 * od.getWidth() / alwidth));
751 assertEquals(od.getBoxY(), 0);
755 + Math.round((float) (lastHidden - firstHidden + 1)
756 * od.getWidth() / alwidth));
757 assertEquals(od.getBoxHeight(), boxHeight);
759 // move viewport to straddle hidden columns
761 assertEquals(od.getBoxX(),
762 Math.round((float) 63 * od.getWidth() / alwidth));
763 assertEquals(od.getBoxY(), 0);
767 + Math.round((lastHidden - firstHidden + 1)
768 * od.getWidth() / alwidth));
769 assertEquals(od.getBoxHeight(), boxHeight);
771 // move viewport to right of hidden columns, no overlap
772 moveViewport(80 - (lastHidden - firstHidden + 1), 0);
773 assertEquals(od.getBoxX(),
774 Math.round((float) 80 * od.getWidth() / alwidth));
775 assertEquals(od.getBoxY(), 0);
776 assertEquals(od.getBoxWidth(), boxWidth);
777 assertEquals(od.getBoxHeight(), boxHeight);
782 * Test that the box position is set correctly when there are hidden columns
785 @Test(groups = { "Functional" })
786 public void testSetBoxFromViewportHiddenColsAtEnd()
788 int firstHidden = 152;
789 int lastHidden = 164;
790 hideColumns(firstHidden, lastHidden);
792 // move viewport before hidden columns
794 assertEquals(od.getBoxX(),
795 Math.round((float) 3 * od.getWidth() / alwidth));
796 assertEquals(od.getBoxY(), 0);
797 assertEquals(od.getBoxWidth(), boxWidth);
798 assertEquals(od.getBoxHeight(), boxHeight);
800 // move viewport to hidden columns
801 // TODO boxwidth includes hidden in overview panel (why?)
802 moveViewport(102, 0);
803 assertEquals(od.getBoxX(),
804 Math.round((float) 102 * od.getWidth() / alwidth));
805 assertEquals(od.getBoxY(), 0);
806 assertEquals(od.getBoxWidth(), boxWidth
807 + Math.round((float) (lastHidden - firstHidden)
808 * od.getWidth() / alwidth));
809 assertEquals(od.getBoxHeight(), boxHeight);
813 * Test that the box position is set correctly when there are hidden rows at
816 @Test(groups = { "Functional" })
817 public void testSetBoxFromViewportHiddenRowsAtStart()
821 hideSequences(firstHidden, lastHidden + 1, lastHidden + 1);
823 // move viewport to start of alignment:
824 // box moves to below hidden rows, height remains same
826 assertEquals(od.getBoxX(), 0);
827 assertEquals(od.getBoxY(),
828 Math.round((float) (lastHidden + 1) * od.getSequencesHeight()
830 assertEquals(od.getBoxWidth(), boxWidth);
831 assertEquals(od.getBoxHeight(), boxHeight);
833 // move viewport to end of alignment, need to account for hidden rows
834 // because of how alignment panel/overview panel are implemented
836 // AlignViewport adjusts endSeq using Alignment height which excludes hidden
837 // rows if we happen to be at the bottom of the alignment
838 // od.setBoxPosition adjusts endSeq to include hidden rows
839 // od.checkValid adjusts scroll position to exclude hidden rows
840 // TODO this test fails because of the above!
842 /* moveViewport(0, 525 - viewHeight - lastHidden - 1);
843 assertEquals(od.getBoxX(), 0);
844 assertEquals(od.getBoxY(),
845 (525 - viewHeight) * scaleh
846 * av.getCharHeight());
847 assertEquals(od.getBoxWidth(), boxWidth);
848 assertEquals(od.getBoxHeight(), boxHeight);*/
852 * Test that the box position is set correctly when there are hidden rows in
855 @Test(groups = { "Functional" })
856 public void testSetBoxFromViewportHiddenRowsInMiddle()
858 int firstHidden = 200;
859 int lastHidden = 210;
860 hideSequences(firstHidden, lastHidden + 1, lastHidden + 1);
862 // move viewport to start of alignment:
863 // box, height etc as in non-hidden case
864 // TODO fails with boxy=12 because that's what setBoxPosition sets it to!
865 /*moveViewport(0, 0);
866 assertEquals(od.getBoxX(), 0);
867 assertEquals(od.getBoxY(), 0);
868 assertEquals(od.getBoxWidth(), boxWidth);
869 assertEquals(od.getBoxHeight(), boxHeight);*/
871 // move viewport to straddle hidden rows
872 // TODO also fails with boxY out by 12
873 /*moveViewport(0, 198);
874 assertEquals(od.getBoxX(), 0);
875 assertEquals(od.getBoxY(), Math.round (198 * scaleh * av.getCharHeight()),
877 assertEquals(od.getBoxWidth(), boxWidth);
878 assertEquals(od.getBoxHeight(), boxHeight
879 + ((lastHidden - firstHidden) * scaleh * av.getCharHeight()),
884 * Test that the box position is set correctly when there are hidden rows at
887 @Test(groups = { "Functional" })
888 public void testSetBoxFromViewportHiddenRowsAtEnd()
890 int firstHidden = 500;
891 int lastHidden = 524;
892 hideSequences(firstHidden - 1, lastHidden, firstHidden - 1);
894 // move viewport to start of alignment:
895 // box, height etc as in non-hidden case
897 assertEquals(od.getBoxX(), 0);
898 assertEquals(od.getBoxY(), 0);
899 assertEquals(od.getBoxWidth(), boxWidth);
900 assertEquals(od.getBoxHeight(), boxHeight);
902 // move viewport to end of alignment
903 // TODO fails with wrong boxHeight who knows why
904 /*moveViewport(0, firstHidden - viewHeight - 1);
905 assertEquals(od.getBoxX(), 0);
906 assertEquals(od.getBoxY(),
907 Math.round ((firstHidden - viewHeight - 1)
908 * scaleh * av.getCharHeight()));
909 assertEquals(od.getBoxWidth(), boxWidth);
913 + Math.round ((lastHidden - firstHidden + 1) * scaleh * av
914 .getCharHeight()));*/
919 * Test setting of the box position, when there are hidden rows at the start
922 @Test(groups = { "Functional" })
923 public void testFromMouseWithHiddenRowsAtStart()
925 od.updateViewportFromMouse(0, 0,
926 av.getAlignment().getHiddenSequences(),
927 av.getColumnSelection(), av.getPosProps());
928 assertEquals(od.getBoxX(), 0);
929 assertEquals(od.getBoxY(), 0);
930 assertEquals(od.getBoxHeight(), boxHeight);
931 assertEquals(od.getBoxWidth(), boxWidth);
932 assertEquals(od.getScrollCol(), 0);
933 assertEquals(od.getScrollRow(), 0);
935 // hide rows at start and check updated box position is correct
936 // changes boxY but not boxheight
937 int lastHiddenRow = 30;
938 hideSequences(0, lastHiddenRow + 1, lastHiddenRow + 1);
940 od.setBoxPosition(av.getAlignment()
941 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
942 assertEquals(od.getBoxX(), 0);
943 assertEquals(od.getBoxY(),
944 Math.round((float) (lastHiddenRow + 1)
945 * od.getSequencesHeight() / alheight));
946 assertEquals(od.getBoxWidth(), boxWidth);
947 assertEquals(od.getBoxHeight(), boxHeight);
949 // click in hidden rows
950 // TODO fails because boxHeight is 27 not 25 (possible rounding issue)
951 /* mouseClick(od, 0, 0);
952 assertEquals(od.getBoxX(), 0);
953 assertEquals(od.getBoxY(), 0);
954 assertEquals(od.getBoxWidth(), boxWidth);
955 assertEquals(od.getBoxHeight(), boxHeight
956 + Math.round ((lastHiddenRow + 1) * scaleh * av.getCharHeight()),
959 // click below hidden rows
960 mouseClick(od, 0, 150);
961 assertEquals(od.getBoxX(), 0);
962 assertEquals(od.getBoxY(), 150);
963 assertEquals(od.getBoxWidth(), boxWidth);
964 assertEquals(od.getBoxHeight(), boxHeight);
968 * Test setting of the box position, when there are hidden rows at the middle
971 @Test(groups = { "Functional" })
972 public void testFromMouseWithHiddenRowsInMiddle()
974 od.updateViewportFromMouse(0, 0,
975 av.getAlignment().getHiddenSequences(),
976 av.getColumnSelection(), av.getPosProps());
978 assertEquals(od.getBoxX(), 0);
979 assertEquals(od.getBoxY(), 0);
980 assertEquals(od.getBoxWidth(), boxWidth);
981 assertEquals(od.getBoxHeight(), boxHeight);
982 assertEquals(od.getScrollCol(), 0);
983 assertEquals(od.getScrollRow(), 0);
985 // hide rows in middle and check updated box position is correct
987 int firstHiddenRow = 50;
988 int lastHiddenRow = 60;
989 hideSequences(firstHiddenRow, lastHiddenRow + 1, lastHiddenRow + 1);
991 od.setBoxPosition(av.getAlignment()
992 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
994 assertEquals(od.getBoxX(), 0);
995 assertEquals(od.getBoxY(), 0);
996 assertEquals(od.getBoxWidth(), boxWidth);
997 assertEquals(od.getBoxHeight(), boxHeight);
999 // click above hidden rows, so that box overlaps
1001 // TODO test fails because box does not change height - dealt with by scroll
1003 /* mouseClick(od, 0, Math.round (ypos * alheight / od.getSequencesHeight()));
1004 assertEquals(od.getBoxX(), 0);
1005 assertEquals(od.getBoxY(), Math.round (ypos * alheight / od.getSequencesHeight()),
1007 assertEquals(od.getBoxWidth(), boxWidth);
1011 + Math.round ((lastHiddenRow - firstHiddenRow + 1) / scaleh / av
1014 // click so that box straddles hidden rows
1016 // TODO test fails because box does not change height - dealt with by scroll
1018 /*mouseClick(od, 0, Math.round (ypos * alheight / od.getSequencesHeight()));
1019 assertEquals(od.getBoxX(), 0);
1020 assertEquals(od.getBoxY(), Math.round (ypos * alheight / od.getSequencesHeight()),
1022 assertEquals(od.getBoxWidth(), boxWidth);
1026 + Math.round ((lastHiddenRow - firstHiddenRow + 1) / scaleh / av
1027 .getCharHeight()));*/
1031 * Test setting of the box position, when there are hidden rows at the end of
1034 @Test(groups = { "Functional" })
1035 public void testFromMouseWithHiddenRowsAtEnd()
1037 od.updateViewportFromMouse(0, 0,
1038 av.getAlignment().getHiddenSequences(),
1039 av.getColumnSelection(), av.getPosProps());
1040 assertEquals(od.getBoxX(), 0);
1041 assertEquals(od.getBoxY(), 0);
1042 assertEquals(od.getBoxWidth(), boxWidth);
1043 assertEquals(od.getBoxHeight(), boxHeight);
1044 assertEquals(od.getScrollCol(), 0);
1045 assertEquals(od.getScrollRow(), 0);
1047 // hide rows at end and check updated box position is correct
1049 int firstHidden = 500;
1050 int lastHidden = 524;
1051 hideSequences(firstHidden - 1, lastHidden, firstHidden - 1);
1053 od.setBoxPosition(av.getAlignment()
1054 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
1055 assertEquals(od.getBoxX(), 0);
1056 assertEquals(od.getBoxY(), 0);
1057 assertEquals(od.getBoxWidth(), boxWidth);
1058 assertEquals(od.getBoxHeight(), boxHeight);
1060 // click above hidden rows
1061 int ypos = 40; // row 40
1063 Math.round((float) ypos * od.getSequencesHeight() / alheight));
1064 assertEquals(od.getBoxX(), 0);
1065 assertEquals(od.getBoxY(),
1066 Math.round((float) ypos * od.getSequencesHeight() / alheight));
1067 assertEquals(od.getBoxWidth(), boxWidth);
1068 assertEquals(od.getBoxHeight(), boxHeight);
1070 // click above hidden rows so box overlaps
1071 // boxY moved upwards, boxHeight remains same
1072 // TODO fails with boxY located at row 497 - correction done by
1074 /* ypos = 497; // row 497
1075 mouseClick(od, 0, Math.round (ypos * scaleh * av.getCharHeight()));
1076 assertEquals(od.getBoxX(), 0);
1079 Math.round ((firstHidden - viewHeight) * scaleh * av.getCharHeight()),
1081 assertEquals(od.getBoxWidth(), boxWidth);
1082 assertEquals(od.getBoxHeight(), boxHeight);*/
1084 // click within hidden rows
1086 // TODO: fails with wrong boxHeight - correction done by setScrollValues(?)
1087 /*mouseClick(od, 0, Math.round (ypos * scaleh * av.getCharHeight()));
1088 assertEquals(od.getBoxX(), 0);
1091 Math.round ((firstHidden - viewHeight) * scaleh * av.getCharHeight()),
1093 assertEquals(od.getBoxWidth(), boxWidth);
1094 assertEquals(od.getBoxHeight(), boxHeight);*/
1098 * Move viewport horizontally: startRes + previous width gives new horizontal extent. Vertical extent stays the same.
1100 private void moveViewportH(int startRes)
1102 av.setStartRes(startRes);
1103 av.setEndRes(startRes + viewWidth);
1104 od.setBoxPosition(av.getAlignment()
1105 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
1109 * Move viewport vertically: startSeq and endSeq give new vertical extent. Horizontal extent stays the same.
1111 private void moveViewportV(int startSeq)
1113 av.setStartSeq(startSeq);
1114 av.setEndSeq(startSeq + viewHeight);
1115 od.setBoxPosition(av.getAlignment()
1116 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
1120 * Move viewport horizontally and vertically.
1122 private void moveViewport(int startRes, int startSeq)
1124 av.setStartRes(startRes);
1125 av.setEndRes(startRes + viewWidth);
1126 av.setStartSeq(startSeq);
1127 av.setEndSeq(startSeq + viewHeight);
1128 od.setBoxPosition(av.getAlignment()
1129 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
1133 * Mouse click as position x,y in overview window
1135 private void mouseClick(OverviewDimensions od, int x, int y)
1137 od.updateViewportFromMouse(x, y,
1138 av.getAlignment().getHiddenSequences(),
1139 av.getColumnSelection(), av.getPosProps());
1140 // updates require an OverviewPanel to exist which it doesn't here
1141 // so call setBoxPosition() as it would be called by the AlignmentPanel
1143 // int width = av.getEndRes() - av.getStartRes();
1144 // int height = av.getEndSeq() - av.getStartSeq();
1145 av.setStartRes(od.getScrollCol());
1146 av.setEndRes(od.getScrollCol() + viewWidth);
1147 av.setStartSeq(od.getScrollRow());
1148 av.setEndSeq(od.getScrollRow() + viewHeight);
1149 od.setBoxPosition(av.getAlignment()
1150 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
1153 private void testBoxIsAtClickPoint(int xpos, int ypos)
1155 mouseClick(od, xpos, ypos);
1156 assertEquals(od.getBoxX(), xpos);
1157 assertEquals(od.getBoxY(), ypos);
1158 assertEquals(od.getBoxWidth(), boxWidth);
1159 assertEquals(od.getBoxHeight(), boxHeight);
1164 * Hide sequences between start and end, using hideseq to do the hiding
1165 * (start <= hideseq <= end. Sequence hideseq is not hidden but the others are
1167 private void hideSequences(int start, int end, int hideseq)
1169 SequenceGroup sg = new SequenceGroup();
1170 List<SequenceI> allseqs = av.getAlignment().getSequences();
1171 for (int i = start; i <= end; ++i)
1173 sg.addSequence(allseqs.get(i), false);
1175 av.setSelectionGroup(sg);
1180 av.hideSequences(allseqs.get(hideseq), true);
1182 while (av.isCalcInProgress())
1187 } catch (InterruptedException e)
1189 System.out.println("Hiding seqs interruption");
1194 private void hideColumns(int firstHidden, int lastHidden)
1196 av.hideColumns(firstHidden, lastHidden);
1198 while (av.isCalcInProgress())
1203 } catch (InterruptedException e)
1205 System.out.println("Hiding cols interruption");