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.Jalview;
27 import jalview.datamodel.Alignment;
28 import jalview.datamodel.AlignmentI;
29 import jalview.datamodel.Sequence;
30 import jalview.datamodel.SequenceGroup;
31 import jalview.datamodel.SequenceI;
32 import jalview.gui.AlignFrame;
33 import jalview.gui.AlignViewport;
34 import jalview.gui.Desktop;
35 import jalview.gui.JvOptionPane;
36 import jalview.io.DataSourceType;
37 import jalview.io.FileLoader;
39 import java.util.List;
41 import org.testng.annotations.AfterClass;
42 import org.testng.annotations.AfterMethod;
43 import org.testng.annotations.BeforeClass;
44 import org.testng.annotations.BeforeMethod;
45 import org.testng.annotations.Test;
47 @Test(singleThreaded = true)
48 public class OverviewDimensionsTest {
50 SequenceI seq1 = new Sequence(
52 "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
54 SequenceI seq2 = new Sequence(
56 "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
58 SequenceI seq3 = new Sequence(
60 "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
62 SequenceI seq4 = new Sequence(
64 "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
66 SequenceI seq5 = new Sequence(
68 "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
73 OverviewDimensions od;
75 // cached widths and heights
83 @BeforeClass(alwaysRun = true)
84 public void setUpJvOptionPane()
86 JvOptionPane.setInteractiveMode(false);
87 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
89 // create random alignment
90 AlignmentGenerator gen = new AlignmentGenerator(false);
91 al = gen.generate(157, 525, 123, 5, 5);
94 @BeforeMethod(alwaysRun = true)
97 Jalview.main(new String[] { "-nonews", "-props",
98 "test/jalview/testProps.jvprops" });
100 af = new FileLoader().LoadFileWaitTillLoaded(al.toString(),
101 DataSourceType.PASTE);
104 * wait for Consensus thread to complete
108 while (af.getViewport().getConsensusSeq() == null)
113 } catch (InterruptedException e)
119 av = af.getViewport();
123 while (av.isCalcInProgress())
128 } catch (InterruptedException e)
134 av.showAllHiddenColumns();
135 av.showAllHiddenSeqs();
136 av.setSelectionGroup(null);
137 // o/w hidden seqs retain selection group, causes problems later when hiding
140 // wait for conservation calc to complete again
141 while (av.isCalcInProgress())
146 } catch (InterruptedException e)
152 viewHeight = av.getEndSeq() - av.getStartSeq() + 1;
153 viewWidth = av.getEndRes() - av.getStartRes() + 1;
155 // wait for gui to get set up
156 // this does actually appear to be necessary
157 while (viewHeight != 18 || viewWidth != 63)
162 av.getAlignPanel().setScrollValues(0, 1);
163 av.getAlignPanel().setScrollValues(1, 0);
164 viewHeight = av.getEndSeq() - av.getStartSeq() + 1;
165 viewWidth = av.getEndRes() - av.getStartRes() + 1;
166 } catch (InterruptedException e)
172 od = new OverviewDimensions(av.getPosProps(), true);
173 // Initial box sizing - default path through code
174 od.setBoxPosition(av.getAlignment().getHiddenSequences(),
175 av.getColumnSelection(), av.getPosProps());
177 mouseClick(od, 0, 0);
180 // calculate before hidden columns so we get absolute values
181 alheight = av.getAlignment().getHeight();
182 alwidth = av.getAlignment().getWidth();
184 boxWidth = Math.round((float) (av.getEndRes() - av.getStartRes() + 1)
185 * od.getWidth() / alwidth);
186 boxHeight = Math.round((float) (av.getEndSeq() - av.getStartSeq() + 1)
187 * od.getSequencesHeight() / alheight);
188 System.out.println(boxHeight);
192 @AfterMethod(alwaysRun = true)
193 public void tearDown()
197 Desktop.instance.closeAll_actionPerformed(null);
200 @AfterClass(alwaysRun = true)
201 public void cleanUp()
207 * Test that the OverviewDimensions constructor sets width and height
210 @Test(groups = { "Functional" })
211 public void testConstructor()
213 SequenceI seqa = new Sequence("Seq1", "ABC");
214 SequenceI seqb = new Sequence("Seq2", "ABC");
215 SequenceI seqc = new Sequence("Seq3", "ABC");
216 SequenceI seqd = new Sequence("Seq4", "ABC");
217 SequenceI seqe = new Sequence("Seq5",
218 "ABCABCABCABCABCABCABCABCBACBACBACBAC");
220 int defaultGraphHeight = 20;
223 int maxSeqHeight = 300;
224 int minSeqHeight = 40;
226 // test for alignment with width > height
227 SequenceI[] seqs1 = new SequenceI[] { seqa, seqb };
228 Alignment al1 = new Alignment(seqs1);
229 al1.setDataset(null);
230 AlignViewport av1 = new AlignViewport(al1);
232 OverviewDimensions od = new OverviewDimensions(av1.getPosProps(), true);
233 int scaledHeight = 266;
234 assertEquals(od.getGraphHeight(), defaultGraphHeight);
235 assertEquals(od.getSequencesHeight(), scaledHeight);
236 assertEquals(od.getWidth(), maxWidth);
237 assertEquals(od.getHeight(), scaledHeight + defaultGraphHeight);
239 // test for alignment with width < height
240 SequenceI[] seqs2 = new SequenceI[] { seqa, seqb, seqc, seqd };
241 Alignment al2 = new Alignment(seqs2);
242 al2.setDataset(null);
243 AlignViewport av2 = new AlignViewport(al2);
245 od = new OverviewDimensions(av2.getPosProps(), true);
246 int scaledWidth = 300;
247 assertEquals(od.getGraphHeight(), defaultGraphHeight);
248 assertEquals(od.getSequencesHeight(), maxSeqHeight);
249 assertEquals(od.getWidth(), scaledWidth);
250 assertEquals(od.getHeight(), scaledWidth + defaultGraphHeight);
252 // test for alignment with width > height and sequence height scaled below
254 SequenceI[] seqs3 = new SequenceI[] { seqe };
255 Alignment al3 = new Alignment(seqs3);
256 al3.setDataset(null);
257 AlignViewport av3 = new AlignViewport(al3);
259 od = new OverviewDimensions(av3.getPosProps(), true);
260 assertEquals(od.getGraphHeight(), defaultGraphHeight);
261 assertEquals(od.getSequencesHeight(), minSeqHeight);
262 assertEquals(od.getWidth(), maxWidth);
263 assertEquals(od.getHeight(), minSeqHeight + defaultGraphHeight);
265 // test for alignment with width < height and width scaled below min value
266 SequenceI[] seqs4 = new SequenceI[] { seqa, seqb, seqc, seqd, seqa,
267 seqb, seqc, seqd, seqa, seqb, seqc, seqd, seqa, seqb, seqc, seqd };
268 Alignment al4 = new Alignment(seqs4);
269 al4.setDataset(null);
270 AlignViewport av4 = new AlignViewport(al4);
272 od = new OverviewDimensions(av4.getPosProps(), true);
273 assertEquals(od.getGraphHeight(), defaultGraphHeight);
274 assertEquals(od.getSequencesHeight(), maxSeqHeight);
275 assertEquals(od.getWidth(), minWidth);
276 assertEquals(od.getHeight(), maxSeqHeight + defaultGraphHeight);
278 Alignment al5 = new Alignment(seqs4);
279 al5.setDataset(null);
280 AlignViewport av5 = new AlignViewport(al5);
282 od = new OverviewDimensions(av5.getPosProps(), false);
283 assertEquals(od.getGraphHeight(), 0);
284 assertEquals(od.getSequencesHeight(), maxSeqHeight);
285 assertEquals(od.getWidth(), minWidth);
286 assertEquals(od.getHeight(), maxSeqHeight);
290 * Test that validation after mouse adjustments to boxX and boxY sets box
291 * dimensions and scroll values correctly, when there are no hidden rows or
294 * The current implementation uses multiple transformations between coordinate
295 * systems which often involve casting to int, which causes values to be
296 * truncated. As a result we can lose accuracy. The tests below use
297 * approximate test values where appropriate.
299 @Test(groups = { "Functional" })
300 public void testSetBoxFromMouseClick()
302 od.updateViewportFromMouse(0, 0,
303 av.getAlignment().getHiddenSequences(),
304 av.getColumnSelection(), av.getPosProps());
305 assertEquals(od.getBoxX(), 0);
306 assertEquals(od.getBoxY(), 0);
307 assertEquals(od.getBoxWidth(), boxWidth);
308 assertEquals(od.getScrollCol(), 0);
309 assertEquals(od.getScrollRow(), 0);
311 // negative boxX value reset to 0
312 mouseClick(od, -5, 10);
313 assertEquals(od.getBoxX(), 0);
314 assertEquals(od.getBoxWidth(), boxWidth);
315 assertEquals(od.getBoxHeight(), boxHeight);
316 assertEquals(od.getScrollRow(),
317 Math.round((float) 10 * alheight / od.getSequencesHeight()));
318 assertEquals(od.getScrollCol(), 0);
320 // negative boxY value reset to 0
321 mouseClick(od, 6, -2);
322 assertEquals(od.getBoxY(), 0);
323 assertEquals(od.getBoxWidth(), boxWidth);
324 assertEquals(od.getBoxHeight(), boxHeight);
325 assertEquals(od.getScrollCol(),
326 Math.round((float) 6 * alwidth / od.getWidth()));
327 assertEquals(od.getScrollRow(), 0);
329 // overly large boxX value reset to width-boxWidth
330 mouseClick(od, 100, 6);
331 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth() + 1);
332 assertEquals(od.getBoxY(), 6);
333 assertEquals(od.getBoxWidth(), boxWidth);
334 assertEquals(od.getBoxHeight(), boxHeight);
335 assertEquals(od.getScrollCol(),
336 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
337 assertEquals(od.getScrollRow(),
338 Math.round((float) od.getBoxY() * alheight
339 / od.getSequencesHeight()));
341 // overly large boxY value reset to sequenceHeight - boxHeight
342 mouseClick(od, 10, 520);
343 assertEquals(od.getBoxX(), 10);
344 assertEquals(od.getBoxY(), od.getSequencesHeight() - od.getBoxHeight());
345 assertEquals(od.getBoxWidth(), boxWidth);
346 assertEquals(od.getBoxHeight(), boxHeight);
347 assertEquals(od.getScrollCol(),
348 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
349 assertEquals(od.getScrollRow(),
350 Math.round((float) od.getBoxY() * alheight
351 / od.getSequencesHeight()));
353 // click past end of alignment, as above
354 mouseClick(od, 3000, 5);
355 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth() + 1);
356 assertEquals(od.getBoxWidth(), boxWidth);
357 assertEquals(od.getBoxHeight(), boxHeight);
358 assertEquals(od.getScrollCol(),
359 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
360 assertEquals(od.getScrollRow(),
361 Math.round((float) od.getBoxY() * alheight
362 / od.getSequencesHeight()));
364 // move viewport so startRes non-zero and then mouseclick
367 // click at viewport position
368 int oldboxx = od.getBoxX();
369 int oldboxy = od.getBoxY();
370 mouseClick(od, od.getBoxX() + 5, od.getBoxY() + 2);
371 assertEquals(od.getBoxX(), oldboxx + 5);
372 assertEquals(od.getBoxWidth(), boxWidth);
373 assertEquals(od.getBoxHeight(), boxHeight);
374 assertEquals(od.getScrollCol(),
375 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
376 assertEquals(od.getBoxY(), oldboxy + 2);
377 assertEquals(od.getScrollRow(),
378 Math.round((float) od.getBoxY() * alheight
379 / od.getSequencesHeight()));
381 // click at top corner
382 mouseClick(od, 0, 0);
383 assertEquals(od.getBoxX(), 0);
384 assertEquals(od.getScrollCol(), 0);
385 assertEquals(od.getBoxY(), 0);
386 assertEquals(od.getScrollRow(), 0);
387 assertEquals(od.getBoxWidth(), boxWidth);
388 assertEquals(od.getBoxHeight(), boxHeight);
392 * Test setting of the box position, when there are hidden cols at the start
395 @Test(groups = { "Functional" })
396 public void testFromMouseWithHiddenColsAtStart()
398 od.updateViewportFromMouse(0, 0,
399 av.getAlignment().getHiddenSequences(),
400 av.getColumnSelection(), av.getPosProps());
401 assertEquals(od.getBoxX(), 0);
402 assertEquals(od.getBoxY(), 0);
403 assertEquals(od.getBoxWidth(), boxWidth);
404 assertEquals(od.getScrollCol(), 0);
405 assertEquals(od.getScrollRow(), 0);
407 // hide cols at start and check updated box position is correct
408 // changes boxX but not boxwidth
409 int lastHiddenCol = 30;
410 hideColumns(0, lastHiddenCol);
412 od.setBoxPosition(av.getAlignment()
413 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
414 assertEquals(od.getBoxX(),
415 Math.round((float) (lastHiddenCol + 1) * od.getWidth()
417 assertEquals(od.getBoxWidth(), boxWidth);
418 assertEquals(od.getBoxHeight(), boxHeight);
420 // try to click in hidden cols, check box does not move
421 // this test currently fails as the overview box does not behave like this!
423 mouseClick(od, xpos, 0);
426 Math.round((float) (lastHiddenCol + 1) * od.getWidth()
428 assertEquals(od.getBoxY(), 0);
429 assertEquals(od.getBoxWidth(), boxWidth);
430 assertEquals(od.getBoxHeight(), boxHeight);
431 assertEquals(od.getScrollRow(), 0);
432 assertEquals(od.getScrollCol(), 0);
434 // click to right of hidden columns, box moves to click point
435 testBoxIsAtClickPoint(40, 0);
436 assertEquals(od.getScrollRow(), 0);
437 assertEquals(od.getScrollCol(),
438 Math.round((float) 40 * alwidth / od.getWidth())
439 - (lastHiddenCol + 1));
441 // click to right of hidden columns such that box runs over right hand side
443 // box position is adjusted away from the edge
444 // overly large boxX value reset to width-boxWidth
446 mouseClick(od, xpos, 5);
447 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth() + 1);
448 assertEquals(od.getBoxY(), 5);
449 assertEquals(od.getBoxWidth(), boxWidth);
450 assertEquals(od.getBoxHeight(), boxHeight);
451 assertEquals(od.getScrollCol(),
452 Math.round((float) od.getBoxX() * alwidth / od.getWidth())
453 - (lastHiddenCol + 1));
454 assertEquals(od.getScrollRow(),
455 Math.round((float) od.getBoxY() * alheight
456 / od.getSequencesHeight()));
460 * Test setting of the box position, when there are hidden cols in the middle
463 @Test(groups = { "Functional" })
464 public void testFromMouseWithHiddenColsInMiddle()
466 od.updateViewportFromMouse(0, 0,
467 av.getAlignment().getHiddenSequences(),
468 av.getColumnSelection(), av.getPosProps());
469 assertEquals(od.getBoxX(), 0);
470 assertEquals(od.getBoxY(), 0);
471 assertEquals(od.getBoxWidth(), boxWidth);
472 assertEquals(od.getScrollCol(), 0);
473 assertEquals(od.getScrollRow(), 0);
475 // hide columns 63-73, no change to box position or dimensions
476 int firstHidden = 63;
478 hideColumns(firstHidden, lastHidden);
480 od.setBoxPosition(av.getAlignment()
481 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
482 assertEquals(od.getBoxX(), 0);
483 assertEquals(od.getBoxY(), 0);
484 assertEquals(od.getBoxWidth(), boxWidth);
485 assertEquals(od.getScrollCol(), 0);
486 assertEquals(od.getScrollRow(), 0);
488 // move box so that it overlaps with hidden cols on one side
489 // box width changes, boxX and scrollCol as for unhidden case
490 int xpos = 55 - boxWidth; // 55 is position in overview approx halfway
491 // between cols 60 and 70
492 mouseClick(od, xpos, 0);
493 assertEquals(od.getBoxX(), xpos);
494 assertEquals(od.getBoxY(), 0);
497 Math.round(boxWidth + (float) (lastHidden - firstHidden + 1)
498 * od.getWidth() / alwidth));
499 assertEquals(od.getBoxHeight(), boxHeight);
500 assertEquals(od.getScrollCol(),
501 Math.round(xpos * alwidth / od.getWidth()));
502 assertEquals(od.getScrollRow(), 0);
504 // move box so that it completely covers hidden cols
505 // box width changes, boxX and scrollCol as for hidden case
507 mouseClick(od, xpos, 0);
508 assertEquals(od.getBoxX(), xpos);
509 assertEquals(od.getBoxY(), 0);
512 Math.round(boxWidth + (float) (lastHidden - firstHidden + 1)
513 * od.getWidth() / alwidth));
514 assertEquals(od.getBoxHeight(), boxHeight);
515 assertEquals(od.getScrollCol(),
516 Math.round((float) xpos * alwidth / od.getWidth()));
517 assertEquals(od.getScrollRow(), 0);
519 // move box so boxX is in hidden cols, box overhangs at right
520 // boxX and scrollCol at left of hidden area, box width extends across
523 mouseClick(od, xpos, 0);
524 assertEquals(od.getBoxX(),
525 Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth));
526 assertEquals(od.getBoxY(), 0);
530 + Math.round((float) (lastHidden - firstHidden + 1)
531 * od.getWidth() / alwidth));
532 assertEquals(od.getBoxHeight(), boxHeight);
533 assertEquals(od.getScrollCol(), firstHidden - 1);
534 assertEquals(od.getScrollRow(), 0);
536 // move box so boxX is to right of hidden cols, but does not go beyond full
537 // width of alignment
538 // box width, boxX and scrollCol all as for non-hidden case
540 testBoxIsAtClickPoint(xpos, 0);
541 assertEquals(od.getScrollRow(), 0);
542 assertEquals(od.getScrollCol(),
543 Math.round(xpos * alwidth / od.getWidth())
544 - (lastHidden - firstHidden + 1));
546 // move box so it goes beyond full width of alignment
547 // boxX, scrollCol adjusted back, box width normal
549 mouseClick(od, xpos, 5);
550 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth() + 1);
551 assertEquals(od.getBoxY(), 5);
552 assertEquals(od.getBoxWidth(), boxWidth);
553 assertEquals(od.getBoxHeight(), boxHeight);
554 assertEquals(od.getScrollCol(),
555 Math.round(((float) od.getBoxX() * alwidth / od.getWidth())
556 - (lastHidden - firstHidden + 1)));
557 assertEquals(od.getScrollRow(),
558 Math.round((float) od.getBoxY() * alheight
559 / od.getSequencesHeight()));
564 * Test setting of the box position, when there are hidden cols at the end of
567 @Test(groups = { "Functional" })
568 public void testFromMouseWithHiddenColsAtEnd()
570 od.updateViewportFromMouse(0, 0,
571 av.getAlignment().getHiddenSequences(),
572 av.getColumnSelection(), av.getPosProps());
573 assertEquals(od.getBoxX(), 0);
574 assertEquals(od.getBoxY(), 0);
575 assertEquals(od.getBoxWidth(), boxWidth);
576 assertEquals(od.getScrollCol(), 0);
577 assertEquals(od.getScrollRow(), 0);
579 // hide columns 140-164, no change to box position or dimensions
580 int firstHidden = 140;
581 int lastHidden = 164;
582 hideColumns(firstHidden, lastHidden);
583 od.setBoxPosition(av.getAlignment()
584 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
585 assertEquals(od.getBoxX(), 0);
586 assertEquals(od.getBoxY(), 0);
587 assertEquals(od.getBoxWidth(), boxWidth);
588 assertEquals(od.getScrollCol(), 0);
589 assertEquals(od.getScrollRow(), 0);
591 // click to left of hidden cols, without overlapping
592 // boxX, scrollCol and width as normal
594 testBoxIsAtClickPoint(xpos, 0);
595 assertEquals(od.getScrollRow(), 0);
596 assertEquals(od.getScrollCol(),
597 Math.round((float) xpos * alwidth / od.getWidth()));
599 // click to left of hidden cols, with overlap
600 // boxX and scrollCol adjusted for hidden cols, width normal
601 /* xpos = Math.round((float) 145 * od.getWidth() / alwidth) - boxWidth;
602 mouseClick(od, xpos, 0);
605 Math.round((firstHidden - 1) * od.getWidth() / alwidth)
607 assertEquals(od.getBoxY(), 0);
608 assertEquals(od.getBoxWidth(), boxWidth);
609 assertEquals(od.getBoxHeight(), boxHeight);
610 assertEquals(od.getScrollCol(),
611 Math.round(od.getBoxX() * alwidth / od.getWidth()));
612 assertEquals(od.getScrollRow(), 0);
614 // click in hidden cols
615 // boxX and scrollCol adjusted for hidden cols, width normal
616 // TODO breaks as above test
620 Math.round((firstHidden - 1) * scalew * av.getCharWidth())
622 assertEquals(od.getBoxY(), 0);
623 assertEquals(od.getBoxWidth(), boxWidth);
624 assertEquals(od.getBoxHeight(), boxHeight);
625 assertEquals(od.getScrollCol(),
626 Math.round(od.getBoxX() * alwidth / od.getWidth()));
627 assertEquals(od.getScrollRow(), 0);*/
629 // click off end of alignment
630 // boxX and scrollCol adjusted for hidden cols, width normal
631 // TODO breaks as above test
635 Math.round((firstHidden - 1) * scalew * av.getCharWidth())
637 assertEquals(od.getBoxY(), 0);
638 assertEquals(od.getBoxWidth(), boxWidth);
639 assertEquals(od.getBoxHeight(), boxHeight);
640 assertEquals(od.getScrollCol(),
641 Math.round(od.getBoxX() * alwidth / od.getWidth()));
642 assertEquals(od.getScrollRow(), 0);*/
646 * Test that the box position is set correctly when set from the viewport,
647 * with no hidden rows or columns
649 @Test(groups = { "Functional" })
650 public void testSetBoxFromViewport()
652 // move viewport to start of alignment
654 assertEquals(od.getBoxX(), 0);
655 assertEquals(od.getBoxY(), 0);
656 assertEquals(od.getBoxWidth(), boxWidth);
657 assertEquals(od.getBoxHeight(), boxHeight);
659 // move viewport to right
661 assertEquals(od.getBoxX(),
662 Math.round((float) 70 * od.getWidth() / alwidth));
663 assertEquals(od.getBoxY(), 0);
664 assertEquals(od.getBoxWidth(), boxWidth);
665 assertEquals(od.getBoxHeight(), boxHeight);
667 // move viewport down
669 assertEquals(od.getBoxX(),
670 Math.round((float) 70 * od.getWidth() / alwidth));
671 assertEquals(od.getBoxY(),
672 Math.round(100 * od.getSequencesHeight() / alheight));
673 assertEquals(od.getBoxWidth(), boxWidth);
674 assertEquals(od.getBoxHeight(), boxHeight);
676 // move viewport to bottom right
677 moveViewport(98, 508);
678 assertEquals(od.getBoxX(),
679 Math.round((float) 98 * od.getWidth() / alwidth));
680 assertEquals(od.getBoxY(),
681 Math.round((float) 508 * od.getSequencesHeight() / alheight));
682 assertEquals(od.getBoxWidth(), boxWidth);
683 assertEquals(od.getBoxHeight(), boxHeight);
687 * Test that the box position is set correctly when there are hidden columns
690 @Test(groups = { "Functional" })
691 public void testSetBoxFromViewportHiddenColsAtStart()
695 hideColumns(firstHidden, lastHidden);
697 // move viewport to start of alignment
699 assertEquals(od.getBoxX(),
700 Math.round((float) (lastHidden + 1) * od.getWidth() / alwidth));
701 assertEquals(od.getBoxY(), 0);
702 assertEquals(od.getBoxWidth(), boxWidth);
703 assertEquals(od.getBoxHeight(), boxHeight);
705 // move viewport to end of alignment - need to make startRes by removing
706 // hidden cols because of how viewport/overview are implemented
707 moveViewport(98 - lastHidden - 1, 0);
708 assertEquals(od.getBoxX(),
709 Math.round((float) 98 * od.getWidth() / alwidth));
710 assertEquals(od.getBoxY(), 0);
711 assertEquals(od.getBoxWidth(), boxWidth);
712 assertEquals(od.getBoxHeight(), boxHeight);
716 * Test that the box position is set correctly when there are hidden columns
719 @Test(groups = { "Functional" })
720 public void testSetBoxFromViewportHiddenColsInMiddle()
722 int firstHidden = 68;
724 hideColumns(firstHidden, lastHidden);
726 // move viewport before hidden columns
729 assertEquals(od.getBoxX(),
730 Math.round((float) 3 * od.getWidth() / alwidth));
731 assertEquals(od.getBoxY(), 0);
732 System.out.println(od.getBoxWidth());
733 assertEquals(od.getBoxWidth(), boxWidth);
734 System.out.println(od.getBoxWidth());
735 assertEquals(od.getBoxHeight(), boxHeight);
737 // move viewport to left of hidden columns with overlap
739 assertEquals(od.getBoxX(),
740 Math.round((float) 10 * od.getWidth() / alwidth));
741 assertEquals(od.getBoxY(), 0);
745 + Math.round((float) (lastHidden - firstHidden + 1)
746 * od.getWidth() / alwidth));
747 assertEquals(od.getBoxHeight(), boxHeight);
749 // move viewport to straddle hidden columns
751 assertEquals(od.getBoxX(),
752 Math.round((float) 63 * od.getWidth() / alwidth));
753 assertEquals(od.getBoxY(), 0);
757 + Math.round((lastHidden - firstHidden + 1)
758 * od.getWidth() / alwidth));
759 assertEquals(od.getBoxHeight(), boxHeight);
761 // move viewport to right of hidden columns, no overlap
762 moveViewport(80 - (lastHidden - firstHidden + 1), 0);
763 assertEquals(od.getBoxX(),
764 Math.round((float) 80 * od.getWidth() / alwidth));
765 assertEquals(od.getBoxY(), 0);
766 assertEquals(od.getBoxWidth(), boxWidth);
767 assertEquals(od.getBoxHeight(), boxHeight);
772 * Test that the box position is set correctly when there are hidden columns
775 @Test(groups = { "Functional" })
776 public void testSetBoxFromViewportHiddenColsAtEnd()
778 int firstHidden = 152;
779 int lastHidden = 164;
780 hideColumns(firstHidden, lastHidden);
782 // move viewport before hidden columns
784 assertEquals(od.getBoxX(),
785 Math.round((float) 3 * od.getWidth() / alwidth));
786 assertEquals(od.getBoxY(), 0);
787 assertEquals(od.getBoxWidth(), boxWidth);
788 assertEquals(od.getBoxHeight(), boxHeight);
790 // move viewport to hidden columns
791 moveViewport(102, 0);
792 assertEquals(od.getBoxX(),
793 Math.round((float) 102 * od.getWidth() / alwidth));
794 assertEquals(od.getBoxY(), 0);
795 assertEquals(od.getBoxWidth(), boxWidth
796 + Math.round((float) (lastHidden - firstHidden)
797 * od.getWidth() / alwidth));
798 assertEquals(od.getBoxHeight(), boxHeight);
802 * Test that the box position is set correctly when there are hidden rows at
805 @Test(groups = { "Functional" })
806 public void testSetBoxFromViewportHiddenRowsAtStart()
810 hideSequences(firstHidden, lastHidden + 1, lastHidden + 1);
812 // move viewport to start of alignment:
813 // box moves to below hidden rows, height remains same
815 assertEquals(od.getBoxX(), 0);
816 assertEquals(od.getBoxY(),
817 Math.round((float) (lastHidden + 1) * od.getSequencesHeight()
819 assertEquals(od.getBoxWidth(), boxWidth);
820 assertEquals(od.getBoxHeight(), boxHeight);
822 // move viewport to end of alignment
823 moveViewport(0, 525 - viewHeight - lastHidden - 1);
824 assertEquals(od.getBoxX(), 0);
827 Math.round((float) (525 - viewHeight) * od.getSequencesHeight()
829 assertEquals(od.getBoxWidth(), boxWidth);
830 assertEquals(od.getBoxHeight(), boxHeight);
834 * Test that the box position is set correctly when there are hidden rows in
837 @Test(groups = { "Functional" })
838 public void testSetBoxFromViewportHiddenRowsInMiddle()
840 int firstHidden = 200;
841 int lastHidden = 210;
842 hideSequences(firstHidden, lastHidden + 1, lastHidden + 1);
844 // move viewport to start of alignment:
845 // box, height etc as in non-hidden case
847 assertEquals(od.getBoxX(), 0);
848 assertEquals(od.getBoxY(), 0);
849 assertEquals(od.getBoxWidth(), boxWidth);
850 assertEquals(od.getBoxHeight(), boxHeight);
852 // move viewport to straddle hidden rows
853 moveViewport(0, 198);
854 assertEquals(od.getBoxX(), 0);
855 assertEquals(od.getBoxY(), Math.round ((float)198 * od.getSequencesHeight()
857 assertEquals(od.getBoxWidth(), boxWidth);
860 Math.round((float) (viewHeight + lastHidden - firstHidden + 1)
861 * od.getSequencesHeight() / alheight));
865 * Test that the box position is set correctly when there are hidden rows at
868 @Test(groups = { "Functional" })
869 public void testSetBoxFromViewportHiddenRowsAtEnd()
871 int firstHidden = 500;
872 int lastHidden = 524;
873 hideSequences(firstHidden - 1, lastHidden, firstHidden - 1);
875 // move viewport to start of alignment:
876 // box, height etc as in non-hidden case
878 assertEquals(od.getBoxX(), 0);
879 assertEquals(od.getBoxY(), 0);
880 assertEquals(od.getBoxWidth(), boxWidth);
881 assertEquals(od.getBoxHeight(), boxHeight);
883 // move viewport to end of alignment
884 // viewport sits above hidden rows and does not include them
885 moveViewport(0, firstHidden - viewHeight - 1);
886 assertEquals(od.getBoxX(), 0);
889 Math.round((float) (firstHidden - viewHeight - 1)
890 * od.getSequencesHeight() / alheight));
891 assertEquals(od.getBoxWidth(), boxWidth);
892 assertEquals(od.getBoxHeight(), boxHeight);
897 * Test setting of the box position, when there are hidden rows at the start
900 @Test(groups = { "Functional" })
901 public void testFromMouseWithHiddenRowsAtStart()
903 od.updateViewportFromMouse(0, 0,
904 av.getAlignment().getHiddenSequences(),
905 av.getColumnSelection(), av.getPosProps());
906 assertEquals(od.getBoxX(), 0);
907 assertEquals(od.getBoxY(), 0);
908 assertEquals(od.getBoxHeight(), boxHeight);
909 assertEquals(od.getBoxWidth(), boxWidth);
910 assertEquals(od.getScrollCol(), 0);
911 assertEquals(od.getScrollRow(), 0);
913 // hide rows at start and check updated box position is correct
914 // changes boxY but not boxheight
915 int lastHiddenRow = 30;
916 hideSequences(0, lastHiddenRow + 1, lastHiddenRow + 1);
918 od.setBoxPosition(av.getAlignment()
919 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
920 assertEquals(od.getBoxX(), 0);
921 assertEquals(od.getBoxY(),
922 Math.round((float) (lastHiddenRow + 1)
923 * od.getSequencesHeight() / alheight));
924 assertEquals(od.getBoxWidth(), boxWidth);
925 assertEquals(od.getBoxHeight(), boxHeight);
927 // click in hidden rows - same result
928 mouseClick(od, 0, 0);
929 assertEquals(od.getBoxX(), 0);
932 Math.round((float) (lastHiddenRow + 1)
933 * od.getSequencesHeight() / alheight));
934 assertEquals(od.getBoxWidth(), boxWidth);
935 assertEquals(od.getBoxHeight(), boxHeight);
937 // click below hidden rows
938 mouseClick(od, 0, 150);
939 assertEquals(od.getBoxX(), 0);
940 assertEquals(od.getBoxY(), 150);
941 assertEquals(od.getBoxWidth(), boxWidth);
942 assertEquals(od.getBoxHeight(), boxHeight);
946 * Test setting of the box position, when there are hidden rows at the middle
949 @Test(groups = { "Functional" })
950 public void testFromMouseWithHiddenRowsInMiddle()
952 od.updateViewportFromMouse(0, 0,
953 av.getAlignment().getHiddenSequences(),
954 av.getColumnSelection(), av.getPosProps());
956 assertEquals(od.getBoxX(), 0);
957 assertEquals(od.getBoxY(), 0);
958 assertEquals(od.getBoxWidth(), boxWidth);
959 assertEquals(od.getBoxHeight(), boxHeight);
960 assertEquals(od.getScrollCol(), 0);
961 assertEquals(od.getScrollRow(), 0);
963 // hide rows in middle and check updated box position is correct
965 int firstHiddenRow = 50;
966 int lastHiddenRow = 60;
967 hideSequences(firstHiddenRow, lastHiddenRow + 1, lastHiddenRow + 1);
969 od.setBoxPosition(av.getAlignment()
970 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
972 assertEquals(od.getBoxX(), 0);
973 assertEquals(od.getBoxY(), 0);
974 assertEquals(od.getBoxWidth(), boxWidth);
975 assertEquals(od.getBoxHeight(), boxHeight);
977 // click above hidden rows, so that box overlaps
979 // TODO test fails because box does not change height - dealt with by scroll
981 /* mouseClick(od, 0, Math.round (ypos * alheight / od.getSequencesHeight()));
982 assertEquals(od.getBoxX(), 0);
983 assertEquals(od.getBoxY(), Math.round (ypos * alheight / od.getSequencesHeight()),
985 assertEquals(od.getBoxWidth(), boxWidth);
989 + Math.round ((lastHiddenRow - firstHiddenRow + 1) / scaleh / av
992 // click so that box straddles hidden rows
994 // TODO test fails because box does not change height - dealt with by scroll
996 /*mouseClick(od, 0, Math.round (ypos * alheight / od.getSequencesHeight()));
997 assertEquals(od.getBoxX(), 0);
998 assertEquals(od.getBoxY(), Math.round (ypos * alheight / od.getSequencesHeight()),
1000 assertEquals(od.getBoxWidth(), boxWidth);
1004 + Math.round ((lastHiddenRow - firstHiddenRow + 1) / scaleh / av
1005 .getCharHeight()));*/
1009 * Test setting of the box position, when there are hidden rows at the end of
1012 @Test(groups = { "Functional" })
1013 public void testFromMouseWithHiddenRowsAtEnd()
1015 od.updateViewportFromMouse(0, 0,
1016 av.getAlignment().getHiddenSequences(),
1017 av.getColumnSelection(), av.getPosProps());
1018 assertEquals(od.getBoxX(), 0);
1019 assertEquals(od.getBoxY(), 0);
1020 assertEquals(od.getBoxWidth(), boxWidth);
1021 assertEquals(od.getBoxHeight(), boxHeight);
1022 assertEquals(od.getScrollCol(), 0);
1023 assertEquals(od.getScrollRow(), 0);
1025 // hide rows at end and check updated box position is correct
1027 int firstHidden = 500;
1028 int lastHidden = 524;
1029 hideSequences(firstHidden - 1, lastHidden, firstHidden - 1);
1031 od.setBoxPosition(av.getAlignment()
1032 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
1033 assertEquals(od.getBoxX(), 0);
1034 assertEquals(od.getBoxY(), 0);
1035 assertEquals(od.getBoxWidth(), boxWidth);
1036 assertEquals(od.getBoxHeight(), boxHeight);
1038 // click above hidden rows
1039 int ypos = 40; // row 40
1041 Math.round((float) ypos * od.getSequencesHeight() / alheight));
1042 assertEquals(od.getBoxX(), 0);
1043 assertEquals(od.getBoxY(),
1044 Math.round((float) ypos * od.getSequencesHeight() / alheight));
1045 assertEquals(od.getBoxWidth(), boxWidth);
1046 assertEquals(od.getBoxHeight(), boxHeight);
1048 // click above hidden rows so box overlaps
1049 // boxY moved upwards, boxHeight remains same
1050 // TODO fails with boxY located at row 497 - correction done by
1052 /* ypos = 497; // row 497
1053 mouseClick(od, 0, Math.round (ypos * scaleh * av.getCharHeight()));
1054 assertEquals(od.getBoxX(), 0);
1057 Math.round ((firstHidden - viewHeight) * scaleh * av.getCharHeight()),
1059 assertEquals(od.getBoxWidth(), boxWidth);
1060 assertEquals(od.getBoxHeight(), boxHeight);*/
1062 // click within hidden rows
1064 // TODO: fails with wrong boxHeight - correction done by setScrollValues(?)
1065 /*mouseClick(od, 0, Math.round (ypos * scaleh * av.getCharHeight()));
1066 assertEquals(od.getBoxX(), 0);
1069 Math.round ((firstHidden - viewHeight) * scaleh * av.getCharHeight()),
1071 assertEquals(od.getBoxWidth(), boxWidth);
1072 assertEquals(od.getBoxHeight(), boxHeight);*/
1076 * Move viewport horizontally: startRes + previous width gives new horizontal extent. Vertical extent stays the same.
1078 private void moveViewportH(int startRes)
1080 av.setStartRes(startRes);
1081 av.setEndRes(startRes + viewWidth - 1);
1082 od.setBoxPosition(av.getAlignment()
1083 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
1087 * Move viewport vertically: startSeq and endSeq give new vertical extent. Horizontal extent stays the same.
1089 private void moveViewportV(int startSeq)
1091 av.setStartSeq(startSeq);
1092 av.setEndSeq(startSeq + viewHeight - 1);
1093 od.setBoxPosition(av.getAlignment()
1094 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
1098 * Move viewport horizontally and vertically.
1100 private void moveViewport(int startRes, int startSeq)
1102 av.setStartRes(startRes);
1103 av.setEndRes(startRes + viewWidth - 1);
1104 av.setStartSeq(startSeq);
1105 av.setEndSeq(startSeq + viewHeight - 1);
1106 od.setBoxPosition(av.getAlignment()
1107 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
1111 * Mouse click as position x,y in overview window
1113 private void mouseClick(OverviewDimensions od, int x, int y)
1115 od.updateViewportFromMouse(x, y,
1116 av.getAlignment().getHiddenSequences(),
1117 av.getColumnSelection(), av.getPosProps());
1118 // updates require an OverviewPanel to exist which it doesn't here
1119 // so call setBoxPosition() as it would be called by the AlignmentPanel
1121 // int width = av.getEndRes() - av.getStartRes();
1122 // int height = av.getEndSeq() - av.getStartSeq();
1123 av.setStartRes(od.getScrollCol());
1124 av.setEndRes(od.getScrollCol() + viewWidth - 1);
1125 av.setStartSeq(od.getScrollRow());
1126 av.setEndSeq(od.getScrollRow() + viewHeight - 1);
1127 od.setBoxPosition(av.getAlignment()
1128 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
1131 private void testBoxIsAtClickPoint(int xpos, int ypos)
1133 mouseClick(od, xpos, ypos);
1134 assertEquals(od.getBoxX(), xpos);
1135 assertEquals(od.getBoxY(), ypos);
1136 assertEquals(od.getBoxWidth(), boxWidth);
1137 assertEquals(od.getBoxHeight(), boxHeight);
1142 * Hide sequences between start and end, using hideseq to do the hiding
1143 * (start <= hideseq <= end. Sequence hideseq is not hidden but the others are
1145 private void hideSequences(int start, int end, int hideseq)
1147 SequenceGroup sg = new SequenceGroup();
1148 List<SequenceI> allseqs = av.getAlignment().getSequences();
1149 for (int i = start; i <= end; ++i)
1151 sg.addSequence(allseqs.get(i), false);
1153 av.setSelectionGroup(sg);
1158 av.hideSequences(allseqs.get(hideseq), true);
1160 while (av.isCalcInProgress())
1165 } catch (InterruptedException e)
1167 System.out.println("Hiding seqs interruption");
1172 private void hideColumns(int firstHidden, int lastHidden)
1174 av.hideColumns(firstHidden, lastHidden);
1176 while (av.isCalcInProgress())
1181 } catch (InterruptedException e)
1183 System.out.println("Hiding cols interruption");