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();
121 od = new OverviewDimensions(av.getPosProps(), true);
123 while (av.isCalcInProgress())
128 } catch (InterruptedException e)
134 // Initial box sizing - default path through code
135 od.setBoxPosition(av.getAlignment()
136 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
138 av.showAllHiddenColumns();
139 av.showAllHiddenSeqs();
140 av.setSelectionGroup(null);
141 // o/w hidden seqs retain selection group, causes problems later when hiding
144 // wait for conservation calc to complete again
145 while (av.isCalcInProgress())
150 } catch (InterruptedException e)
156 mouseClick(od, 0, 0);
159 viewHeight = av.getEndSeq() - av.getStartSeq();
160 viewWidth = av.getEndRes() - av.getStartRes();
162 // wait for gui to get set up
163 // this does actually appear to be necessary
164 while (viewHeight != 17 || viewWidth != 62)
169 av.getAlignPanel().setScrollValues(0, 0);
170 viewHeight = av.getEndSeq() - av.getStartSeq();
171 viewWidth = av.getEndRes() - av.getStartRes();
172 } catch (InterruptedException e)
178 // calculate before hidden columns so we get absolute values
179 alheight = av.getAlignment().getHeight();
180 alwidth = av.getAlignment().getWidth();
182 boxWidth = Math.round((float) (av.getEndRes() - av.getStartRes() + 1)
183 / alwidth * od.getWidth());
184 boxHeight = Math.round((float) (av.getEndSeq() - av.getStartSeq())
185 / alheight * od.getHeight());
186 System.out.println(boxHeight);
190 @AfterMethod(alwaysRun = true)
191 public void tearDown()
195 Desktop.instance.closeAll_actionPerformed(null);
198 @AfterClass(alwaysRun = true)
199 public void cleanUp()
205 * Test that the OverviewDimensions constructor sets width and height
208 @Test(groups = { "Functional" })
209 public void testConstructor()
211 SequenceI seqa = new Sequence("Seq1", "ABC");
212 SequenceI seqb = new Sequence("Seq2", "ABC");
213 SequenceI seqc = new Sequence("Seq3", "ABC");
214 SequenceI seqd = new Sequence("Seq4", "ABC");
215 SequenceI seqe = new Sequence("Seq5",
216 "ABCABCABCABCABCABCABCABCBACBACBACBAC");
218 int defaultGraphHeight = 20;
221 int maxSeqHeight = 300;
222 int minSeqHeight = 40;
224 // test for alignment with width > height
225 SequenceI[] seqs1 = new SequenceI[] { seqa, seqb };
226 Alignment al1 = new Alignment(seqs1);
227 al1.setDataset(null);
228 AlignViewport av1 = new AlignViewport(al1);
230 OverviewDimensions od = new OverviewDimensions(av1.getPosProps(), true);
231 int scaledHeight = 266;
232 assertEquals(od.getGraphHeight(), defaultGraphHeight);
233 assertEquals(od.getSequencesHeight(), scaledHeight);
234 assertEquals(od.getWidth(), maxWidth);
235 assertEquals(od.getHeight(), scaledHeight + defaultGraphHeight);
237 // test for alignment with width < height
238 SequenceI[] seqs2 = new SequenceI[] { seqa, seqb, seqc, seqd };
239 Alignment al2 = new Alignment(seqs2);
240 al2.setDataset(null);
241 AlignViewport av2 = new AlignViewport(al2);
243 od = new OverviewDimensions(av2.getPosProps(), true);
244 int scaledWidth = 300;
245 assertEquals(od.getGraphHeight(), defaultGraphHeight);
246 assertEquals(od.getSequencesHeight(), maxSeqHeight);
247 assertEquals(od.getWidth(), scaledWidth);
248 assertEquals(od.getHeight(), scaledWidth + defaultGraphHeight);
250 // test for alignment with width > height and sequence height scaled below
252 SequenceI[] seqs3 = new SequenceI[] { seqe };
253 Alignment al3 = new Alignment(seqs3);
254 al3.setDataset(null);
255 AlignViewport av3 = new AlignViewport(al3);
257 od = new OverviewDimensions(av3.getPosProps(), true);
258 assertEquals(od.getGraphHeight(), defaultGraphHeight);
259 assertEquals(od.getSequencesHeight(), minSeqHeight);
260 assertEquals(od.getWidth(), maxWidth);
261 assertEquals(od.getHeight(), minSeqHeight + defaultGraphHeight);
263 // test for alignment with width < height and width scaled below min value
264 SequenceI[] seqs4 = new SequenceI[] { seqa, seqb, seqc, seqd, seqa,
265 seqb, seqc, seqd, seqa, seqb, seqc, seqd, seqa, seqb, seqc, seqd };
266 Alignment al4 = new Alignment(seqs4);
267 al4.setDataset(null);
268 AlignViewport av4 = new AlignViewport(al4);
270 od = new OverviewDimensions(av4.getPosProps(), true);
271 assertEquals(od.getGraphHeight(), defaultGraphHeight);
272 assertEquals(od.getSequencesHeight(), maxSeqHeight);
273 assertEquals(od.getWidth(), minWidth);
274 assertEquals(od.getHeight(), maxSeqHeight + defaultGraphHeight);
276 Alignment al5 = new Alignment(seqs4);
277 al5.setDataset(null);
278 AlignViewport av5 = new AlignViewport(al5);
280 od = new OverviewDimensions(av5.getPosProps(), false);
281 assertEquals(od.getGraphHeight(), 0);
282 assertEquals(od.getSequencesHeight(), maxSeqHeight);
283 assertEquals(od.getWidth(), minWidth);
284 assertEquals(od.getHeight(), maxSeqHeight);
288 * Test that validation after mouse adjustments to boxX and boxY sets box
289 * dimensions and scroll values correctly, when there are no hidden rows or
292 * The current implementation uses multiple transformations between coordinate
293 * systems which often involve casting to int, which causes values to be
294 * truncated. As a result we can lose accuracy. The tests below use
295 * approximate test values where appropriate.
297 @Test(groups = { "Functional" })
298 public void testSetBoxFromMouseClick()
300 od.updateViewportFromMouse(0, 0,
301 av.getAlignment().getHiddenSequences(),
302 av.getColumnSelection(), av.getPosProps());
303 assertEquals(od.getBoxX(), 0);
304 assertEquals(od.getBoxY(), 0);
305 assertEquals(od.getBoxWidth(), boxWidth);
306 assertEquals(od.getScrollCol(), 0);
307 assertEquals(od.getScrollRow(), 0);
309 // negative boxX value reset to 0
310 mouseClick(od, -5, 10);
311 assertEquals(od.getBoxX(), 0);
312 assertEquals(od.getBoxWidth(), boxWidth);
313 assertEquals(od.getBoxHeight(), boxHeight);
314 assertEquals(od.getScrollRow(),
315 Math.round((float) 10 * alheight / od.getSequencesHeight()));
316 assertEquals(od.getScrollCol(), 0);
318 // negative boxY value reset to 0
319 mouseClick(od, 6, -2);
320 assertEquals(od.getBoxY(), 0);
321 assertEquals(od.getBoxWidth(), boxWidth);
322 assertEquals(od.getBoxHeight(), boxHeight);
323 assertEquals(od.getScrollCol(),
324 Math.round((float) 6 * alwidth / od.getWidth()));
325 assertEquals(od.getScrollRow(), 0);
327 // overly large boxX value reset to width-boxWidth
328 mouseClick(od, 100, 6);
329 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
330 assertEquals(od.getBoxY(), 6);
331 assertEquals(od.getBoxWidth(), boxWidth);
332 assertEquals(od.getBoxHeight(), boxHeight);
333 assertEquals(od.getScrollCol(),
334 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
335 assertEquals(od.getScrollRow(),
336 Math.round((float) od.getBoxY() * alheight
337 / od.getSequencesHeight()));
339 // overly large boxY value reset to sequenceHeight - boxHeight
340 mouseClick(od, 10, 520);
341 assertEquals(od.getBoxX(), 10);
342 assertEquals(od.getBoxY(), od.getSequencesHeight() - od.getBoxHeight());
343 assertEquals(od.getBoxWidth(), boxWidth);
344 assertEquals(od.getBoxHeight(), boxHeight);
345 assertEquals(od.getScrollCol(),
346 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
347 assertEquals(od.getScrollRow(),
348 Math.round((float) od.getBoxY() * alheight
349 / od.getSequencesHeight()));
351 // click past end of alignment, as above
352 mouseClick(od, 3000, 5);
353 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
354 assertEquals(od.getBoxWidth(), boxWidth);
355 assertEquals(od.getBoxHeight(), boxHeight);
356 assertEquals(od.getScrollCol(),
357 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
358 assertEquals(od.getScrollRow(),
359 Math.round((float) od.getBoxY() * alheight
360 / od.getSequencesHeight()));
362 // move viewport so startRes non-zero and then mouseclick
365 // click at viewport position
366 int oldboxx = od.getBoxX();
367 int oldboxy = od.getBoxY();
368 mouseClick(od, od.getBoxX() + 5, od.getBoxY() + 2);
369 assertEquals(od.getBoxX(), oldboxx + 5);
370 assertEquals(od.getBoxWidth(), boxWidth);
371 assertEquals(od.getBoxHeight(), boxHeight);
372 assertEquals(od.getScrollCol(),
373 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
374 assertEquals(od.getBoxY(), oldboxy + 2);
375 assertEquals(od.getScrollRow(),
376 Math.round((float) od.getBoxY() * alheight
377 / od.getSequencesHeight()));
379 // click at top corner
380 mouseClick(od, 0, 0);
381 assertEquals(od.getBoxX(), 0);
382 assertEquals(od.getScrollCol(), 0);
383 assertEquals(od.getBoxY(), 0);
384 assertEquals(od.getScrollRow(), 0);
385 assertEquals(od.getBoxWidth(), boxWidth);
386 assertEquals(od.getBoxHeight(), boxHeight);
390 * Test setting of the box position, when there are hidden cols at the start
393 @Test(groups = { "Functional" })
394 public void testFromMouseWithHiddenColsAtStart()
396 od.updateViewportFromMouse(0, 0,
397 av.getAlignment().getHiddenSequences(),
398 av.getColumnSelection(), av.getPosProps());
399 assertEquals(od.getBoxX(), 0);
400 assertEquals(od.getBoxY(), 0);
401 assertEquals(od.getBoxWidth(), boxWidth);
402 assertEquals(od.getScrollCol(), 0);
403 assertEquals(od.getScrollRow(), 0);
405 // hide cols at start and check updated box position is correct
406 // changes boxX but not boxwidth
407 int lastHiddenCol = 30;
408 hideColumns(0, lastHiddenCol);
410 od.setBoxPosition(av.getAlignment()
411 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
412 assertEquals(od.getBoxX(),
413 Math.round((float) (lastHiddenCol + 1) * od.getWidth()
415 assertEquals(od.getBoxWidth(), boxWidth);
416 assertEquals(od.getBoxHeight(), boxHeight);
418 // try to click in hidden cols, check box does not move
419 // this test currently fails as the overview box does not behave like this!
421 mouseClick(od, xpos, 0);
424 Math.round((float) (lastHiddenCol + 1) * od.getWidth()
426 assertEquals(od.getBoxY(), 0);
427 assertEquals(od.getBoxWidth(), boxWidth);
428 assertEquals(od.getBoxHeight(), boxHeight);
429 assertEquals(od.getScrollRow(), 0);
430 assertEquals(od.getScrollCol(), 0);
432 // click to right of hidden columns, box moves to click point
433 testBoxIsAtClickPoint(40, 0);
434 assertEquals(od.getScrollRow(), 0);
435 assertEquals(od.getScrollCol(),
436 Math.round((float) 40 * alwidth / od.getWidth())
437 - (lastHiddenCol + 1));
439 // click to right of hidden columns such that box runs over right hand side
441 // box position is adjusted away from the edge
442 // overly large boxX value reset to width-boxWidth
444 mouseClick(od, xpos, 5);
445 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
446 assertEquals(od.getBoxY(), 5);
447 assertEquals(od.getBoxWidth(), boxWidth);
448 assertEquals(od.getBoxHeight(), boxHeight);
449 assertEquals(od.getScrollCol(),
450 Math.round((float) od.getBoxX() * alwidth / od.getWidth())
451 - (lastHiddenCol + 1));
452 assertEquals(od.getScrollRow(),
453 Math.round((float) od.getBoxY() * alheight
454 / od.getSequencesHeight()));
458 * Test setting of the box position, when there are hidden cols in the middle
461 @Test(groups = { "Functional" })
462 public void testFromMouseWithHiddenColsInMiddle()
464 od.updateViewportFromMouse(0, 0,
465 av.getAlignment().getHiddenSequences(),
466 av.getColumnSelection(), av.getPosProps());
467 assertEquals(od.getBoxX(), 0);
468 assertEquals(od.getBoxY(), 0);
469 assertEquals(od.getBoxWidth(), boxWidth);
470 assertEquals(od.getScrollCol(), 0);
471 assertEquals(od.getScrollRow(), 0);
473 // hide columns 63-73, no change to box position or dimensions
474 int firstHidden = 63;
476 hideColumns(firstHidden, lastHidden);
478 od.setBoxPosition(av.getAlignment()
479 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
480 assertEquals(od.getBoxX(), 0);
481 assertEquals(od.getBoxY(), 0);
482 assertEquals(od.getBoxWidth(), boxWidth);
483 assertEquals(od.getScrollCol(), 0);
484 assertEquals(od.getScrollRow(), 0);
486 // move box so that it overlaps with hidden cols on one side
487 // box width changes, boxX and scrollCol as for unhidden case
488 int xpos = 55 - boxWidth; // 55 is position in overview approx halfway
489 // between cols 60 and 70
490 mouseClick(od, xpos, 0);
491 assertEquals(od.getBoxX(), xpos);
492 assertEquals(od.getBoxY(), 0);
495 Math.round(boxWidth + (float) (lastHidden - firstHidden + 1)
496 * od.getWidth() / alwidth));
497 assertEquals(od.getBoxHeight(), boxHeight);
498 assertEquals(od.getScrollCol(),
499 Math.round(xpos * alwidth / od.getWidth()));
500 assertEquals(od.getScrollRow(), 0);
502 // move box so that it completely covers hidden cols
503 // box width changes, boxX and scrollCol as for hidden case
505 mouseClick(od, xpos, 0);
506 assertEquals(od.getBoxX(), xpos);
507 assertEquals(od.getBoxY(), 0);
510 Math.round(boxWidth + (float) (lastHidden - firstHidden + 1)
511 * od.getWidth() / alwidth));
512 assertEquals(od.getBoxHeight(), boxHeight);
513 assertEquals(od.getScrollCol(),
514 Math.round((float) xpos * alwidth / od.getWidth()));
515 assertEquals(od.getScrollRow(), 0);
517 // move box so boxX is in hidden cols, box overhangs at right
518 // boxX and scrollCol at left of hidden area, box width extends across
521 mouseClick(od, xpos, 0);
522 assertEquals(od.getBoxX(),
523 Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth));
524 assertEquals(od.getBoxY(), 0);
528 + Math.round((float) (lastHidden - firstHidden + 1)
529 * od.getWidth() / alwidth));
530 assertEquals(od.getBoxHeight(), boxHeight);
531 assertEquals(od.getScrollCol(), firstHidden - 1);
532 assertEquals(od.getScrollRow(), 0);
534 // move box so boxX is to right of hidden cols, but does not go beyond full
535 // width of alignment
536 // box width, boxX and scrollCol all as for non-hidden case
538 testBoxIsAtClickPoint(xpos, 0);
539 assertEquals(od.getScrollRow(), 0);
540 assertEquals(od.getScrollCol(),
541 Math.round(xpos * alwidth / od.getWidth())
542 - (lastHidden - firstHidden + 1));
544 // move box so it goes beyond full width of alignment
545 // boxX, scrollCol adjusted back, box width normal
547 mouseClick(od, xpos, 5);
548 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
549 assertEquals(od.getBoxY(), 5);
550 assertEquals(od.getBoxWidth(), boxWidth);
551 assertEquals(od.getBoxHeight(), boxHeight);
552 assertEquals(od.getScrollCol(),
553 Math.round(((float) od.getBoxX() * alwidth / od.getWidth())
554 - (lastHidden - firstHidden + 1)));
555 assertEquals(od.getScrollRow(),
556 Math.round((float) od.getBoxY() * alheight
557 / od.getSequencesHeight()));
562 * Test setting of the box position, when there are hidden cols at the end of
565 @Test(groups = { "Functional" })
566 public void testFromMouseWithHiddenColsAtEnd()
568 od.updateViewportFromMouse(0, 0,
569 av.getAlignment().getHiddenSequences(),
570 av.getColumnSelection(), av.getPosProps());
571 assertEquals(od.getBoxX(), 0);
572 assertEquals(od.getBoxY(), 0);
573 assertEquals(od.getBoxWidth(), boxWidth);
574 assertEquals(od.getScrollCol(), 0);
575 assertEquals(od.getScrollRow(), 0);
577 // hide columns 140-164, no change to box position or dimensions
578 int firstHidden = 140;
579 int lastHidden = 164;
580 hideColumns(firstHidden, lastHidden);
581 od.setBoxPosition(av.getAlignment()
582 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
583 assertEquals(od.getBoxX(), 0);
584 assertEquals(od.getBoxY(), 0);
585 assertEquals(od.getBoxWidth(), boxWidth);
586 assertEquals(od.getScrollCol(), 0);
587 assertEquals(od.getScrollRow(), 0);
589 // click to left of hidden cols, without overlapping
590 // boxX, scrollCol and width as normal
592 testBoxIsAtClickPoint(xpos, 0);
593 assertEquals(od.getScrollRow(), 0);
594 assertEquals(od.getScrollCol(),
595 Math.round((float) xpos * alwidth / od.getWidth()));
597 // click to left of hidden cols, with overlap
598 // boxX and scrollCol adjusted for hidden cols, width normal
599 /* xpos = Math.round((float) 145 * od.getWidth() / alwidth) - boxWidth;
600 mouseClick(od, xpos, 0);
603 Math.round((firstHidden - 1) * od.getWidth() / alwidth)
605 assertEquals(od.getBoxY(), 0);
606 assertEquals(od.getBoxWidth(), boxWidth);
607 assertEquals(od.getBoxHeight(), boxHeight);
608 assertEquals(od.getScrollCol(),
609 Math.round(od.getBoxX() * alwidth / od.getWidth()));
610 assertEquals(od.getScrollRow(), 0);
612 // click in hidden cols
613 // boxX and scrollCol adjusted for hidden cols, width normal
614 // TODO breaks as above test
618 Math.round((firstHidden - 1) * scalew * av.getCharWidth())
620 assertEquals(od.getBoxY(), 0);
621 assertEquals(od.getBoxWidth(), boxWidth);
622 assertEquals(od.getBoxHeight(), boxHeight);
623 assertEquals(od.getScrollCol(),
624 Math.round(od.getBoxX() * alwidth / od.getWidth()));
625 assertEquals(od.getScrollRow(), 0);*/
627 // click off end of alignment
628 // boxX and scrollCol adjusted for hidden cols, width normal
629 // TODO breaks as above test
633 Math.round((firstHidden - 1) * scalew * av.getCharWidth())
635 assertEquals(od.getBoxY(), 0);
636 assertEquals(od.getBoxWidth(), boxWidth);
637 assertEquals(od.getBoxHeight(), boxHeight);
638 assertEquals(od.getScrollCol(),
639 Math.round(od.getBoxX() * alwidth / od.getWidth()));
640 assertEquals(od.getScrollRow(), 0);*/
644 * Test that the box position is set correctly when set from the viewport,
645 * with no hidden rows or columns
647 @Test(groups = { "Functional" })
648 public void testSetBoxFromViewport()
650 // move viewport to start of alignment
652 assertEquals(od.getBoxX(), 0);
653 assertEquals(od.getBoxY(), 0);
654 assertEquals(od.getBoxWidth(), boxWidth);
655 assertEquals(od.getBoxHeight(), boxHeight);
657 // move viewport to right
659 assertEquals(od.getBoxX(),
660 Math.round((float) 70 * od.getWidth() / alwidth));
661 assertEquals(od.getBoxY(), 0);
662 assertEquals(od.getBoxWidth(), boxWidth);
663 assertEquals(od.getBoxHeight(), boxHeight);
665 // move viewport down
667 assertEquals(od.getBoxX(),
668 Math.round((float) 70 * od.getWidth() / alwidth));
669 assertEquals(od.getBoxY(),
670 Math.round(100 * od.getSequencesHeight() / alheight));
671 assertEquals(od.getBoxWidth(), boxWidth);
672 assertEquals(od.getBoxHeight(), boxHeight);
674 // move viewport to bottom right
675 moveViewport(98, 508);
676 assertEquals(od.getBoxX(),
677 Math.round((float) 98 * od.getWidth() / alwidth));
678 assertEquals(od.getBoxY(),
679 Math.round((float) 508 * od.getSequencesHeight() / alheight));
680 assertEquals(od.getBoxWidth(), boxWidth);
681 assertEquals(od.getBoxHeight(), boxHeight);
685 * Test that the box position is set correctly when there are hidden columns
688 @Test(groups = { "Functional" })
689 public void testSetBoxFromViewportHiddenColsAtStart()
693 hideColumns(firstHidden, lastHidden);
695 // move viewport to start of alignment
697 assertEquals(od.getBoxX(),
698 Math.round((float) (lastHidden + 1) * od.getWidth() / alwidth));
699 assertEquals(od.getBoxY(), 0);
700 assertEquals(od.getBoxWidth(), boxWidth);
701 assertEquals(od.getBoxHeight(), boxHeight);
703 // move viewport to end of alignment - need to make startRes by removing
704 // hidden cols because of how viewport/overview are implemented
705 moveViewport(98 - lastHidden - 1, 0);
706 assertEquals(od.getBoxX(),
707 Math.round((float) 98 * od.getWidth() / alwidth));
708 assertEquals(od.getBoxY(), 0);
709 assertEquals(od.getBoxWidth(), boxWidth);
710 assertEquals(od.getBoxHeight(), boxHeight);
714 * Test that the box position is set correctly when there are hidden columns
717 @Test(groups = { "Functional" })
718 public void testSetBoxFromViewportHiddenColsInMiddle()
720 int firstHidden = 68;
722 hideColumns(firstHidden, lastHidden);
724 // move viewport before hidden columns
727 assertEquals(od.getBoxX(),
728 Math.round((float) 3 * od.getWidth() / alwidth));
729 assertEquals(od.getBoxY(), 0);
730 System.out.println(od.getBoxWidth());
731 assertEquals(od.getBoxWidth(), boxWidth);
732 System.out.println(od.getBoxWidth());
733 assertEquals(od.getBoxHeight(), boxHeight);
735 // move viewport to left of hidden columns with overlap
737 assertEquals(od.getBoxX(),
738 Math.round((float) 10 * od.getWidth() / alwidth));
739 assertEquals(od.getBoxY(), 0);
743 + Math.round((float) (lastHidden - firstHidden + 1)
744 * od.getWidth() / alwidth));
745 assertEquals(od.getBoxHeight(), boxHeight);
747 // move viewport to straddle hidden columns
749 assertEquals(od.getBoxX(),
750 Math.round((float) 63 * od.getWidth() / alwidth));
751 assertEquals(od.getBoxY(), 0);
755 + Math.round((lastHidden - firstHidden + 1)
756 * od.getWidth() / alwidth));
757 assertEquals(od.getBoxHeight(), boxHeight);
759 // move viewport to right of hidden columns, no overlap
760 moveViewport(80 - (lastHidden - firstHidden + 1), 0);
761 assertEquals(od.getBoxX(),
762 Math.round((float) 80 * od.getWidth() / alwidth));
763 assertEquals(od.getBoxY(), 0);
764 assertEquals(od.getBoxWidth(), boxWidth);
765 assertEquals(od.getBoxHeight(), boxHeight);
770 * Test that the box position is set correctly when there are hidden columns
773 @Test(groups = { "Functional" })
774 public void testSetBoxFromViewportHiddenColsAtEnd()
776 int firstHidden = 152;
777 int lastHidden = 164;
778 hideColumns(firstHidden, lastHidden);
780 // move viewport before hidden columns
782 assertEquals(od.getBoxX(),
783 Math.round((float) 3 * od.getWidth() / alwidth));
784 assertEquals(od.getBoxY(), 0);
785 assertEquals(od.getBoxWidth(), boxWidth);
786 assertEquals(od.getBoxHeight(), boxHeight);
788 // move viewport to hidden columns
789 // TODO boxwidth includes hidden in overview panel (why?)
790 moveViewport(102, 0);
791 assertEquals(od.getBoxX(),
792 Math.round((float) 102 * od.getWidth() / alwidth));
793 assertEquals(od.getBoxY(), 0);
794 assertEquals(od.getBoxWidth(), boxWidth
795 + Math.round((float) (lastHidden - firstHidden)
796 * od.getWidth() / alwidth));
797 assertEquals(od.getBoxHeight(), boxHeight);
801 * Test that the box position is set correctly when there are hidden rows at
804 @Test(groups = { "Functional" })
805 public void testSetBoxFromViewportHiddenRowsAtStart()
809 hideSequences(firstHidden, lastHidden + 1, lastHidden + 1);
811 // move viewport to start of alignment:
812 // box moves to below hidden rows, height remains same
814 assertEquals(od.getBoxX(), 0);
815 assertEquals(od.getBoxY(),
816 Math.round((float) (lastHidden + 1) * od.getSequencesHeight()
818 assertEquals(od.getBoxWidth(), boxWidth);
819 assertEquals(od.getBoxHeight(), boxHeight);
821 // move viewport to end of alignment
822 moveViewport(0, 525 - viewHeight - lastHidden - 1);
823 assertEquals(od.getBoxX(), 0);
826 Math.round((float) (525 - viewHeight) * od.getSequencesHeight()
828 assertEquals(od.getBoxWidth(), boxWidth);
829 assertEquals(od.getBoxHeight(), boxHeight);
833 * Test that the box position is set correctly when there are hidden rows in
836 @Test(groups = { "Functional" })
837 public void testSetBoxFromViewportHiddenRowsInMiddle()
839 int firstHidden = 200;
840 int lastHidden = 210;
841 hideSequences(firstHidden, lastHidden + 1, lastHidden + 1);
843 // move viewport to start of alignment:
844 // box, height etc as in non-hidden case
846 assertEquals(od.getBoxX(), 0);
847 assertEquals(od.getBoxY(), 0);
848 assertEquals(od.getBoxWidth(), boxWidth);
849 assertEquals(od.getBoxHeight(), boxHeight);
851 // move viewport to straddle hidden rows
852 moveViewport(0, 198);
853 assertEquals(od.getBoxX(), 0);
854 assertEquals(od.getBoxY(), Math.round ((float)198 * od.getSequencesHeight()
856 assertEquals(od.getBoxWidth(), boxWidth);
857 assertEquals(od.getBoxHeight(), boxHeight
858 + Math.round((float) (lastHidden - firstHidden + 1)
859 * od.getSequencesHeight()
864 * Test that the box position is set correctly when there are hidden rows at
867 @Test(groups = { "Functional" })
868 public void testSetBoxFromViewportHiddenRowsAtEnd()
870 int firstHidden = 500;
871 int lastHidden = 524;
872 hideSequences(firstHidden - 1, lastHidden, firstHidden - 1);
874 // move viewport to start of alignment:
875 // box, height etc as in non-hidden case
877 assertEquals(od.getBoxX(), 0);
878 assertEquals(od.getBoxY(), 0);
879 assertEquals(od.getBoxWidth(), boxWidth);
880 assertEquals(od.getBoxHeight(), boxHeight);
882 // move viewport to end of alignment
883 // viewport sits above hidden rows and does not include them
884 moveViewport(0, firstHidden - viewHeight - 1);
885 assertEquals(od.getBoxX(), 0);
888 Math.round((float) (firstHidden - viewHeight - 1)
889 * od.getSequencesHeight() / alheight));
890 assertEquals(od.getBoxWidth(), boxWidth);
891 assertEquals(od.getBoxHeight(), boxHeight);
896 * Test setting of the box position, when there are hidden rows at the start
899 @Test(groups = { "Functional" })
900 public void testFromMouseWithHiddenRowsAtStart()
902 od.updateViewportFromMouse(0, 0,
903 av.getAlignment().getHiddenSequences(),
904 av.getColumnSelection(), av.getPosProps());
905 assertEquals(od.getBoxX(), 0);
906 assertEquals(od.getBoxY(), 0);
907 assertEquals(od.getBoxHeight(), boxHeight);
908 assertEquals(od.getBoxWidth(), boxWidth);
909 assertEquals(od.getScrollCol(), 0);
910 assertEquals(od.getScrollRow(), 0);
912 // hide rows at start and check updated box position is correct
913 // changes boxY but not boxheight
914 int lastHiddenRow = 30;
915 hideSequences(0, lastHiddenRow + 1, lastHiddenRow + 1);
917 od.setBoxPosition(av.getAlignment()
918 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
919 assertEquals(od.getBoxX(), 0);
920 assertEquals(od.getBoxY(),
921 Math.round((float) (lastHiddenRow + 1)
922 * od.getSequencesHeight() / alheight));
923 assertEquals(od.getBoxWidth(), boxWidth);
924 assertEquals(od.getBoxHeight(), boxHeight);
926 // click in hidden rows - same result
927 mouseClick(od, 0, 0);
928 assertEquals(od.getBoxX(), 0);
931 Math.round((float) (lastHiddenRow + 1)
932 * od.getSequencesHeight() / alheight));
933 assertEquals(od.getBoxWidth(), boxWidth);
934 assertEquals(od.getBoxHeight(), boxHeight);
936 // click below hidden rows
937 mouseClick(od, 0, 150);
938 assertEquals(od.getBoxX(), 0);
939 assertEquals(od.getBoxY(), 150);
940 assertEquals(od.getBoxWidth(), boxWidth);
941 assertEquals(od.getBoxHeight(), boxHeight);
945 * Test setting of the box position, when there are hidden rows at the middle
948 @Test(groups = { "Functional" })
949 public void testFromMouseWithHiddenRowsInMiddle()
951 od.updateViewportFromMouse(0, 0,
952 av.getAlignment().getHiddenSequences(),
953 av.getColumnSelection(), av.getPosProps());
955 assertEquals(od.getBoxX(), 0);
956 assertEquals(od.getBoxY(), 0);
957 assertEquals(od.getBoxWidth(), boxWidth);
958 assertEquals(od.getBoxHeight(), boxHeight);
959 assertEquals(od.getScrollCol(), 0);
960 assertEquals(od.getScrollRow(), 0);
962 // hide rows in middle and check updated box position is correct
964 int firstHiddenRow = 50;
965 int lastHiddenRow = 60;
966 hideSequences(firstHiddenRow, lastHiddenRow + 1, lastHiddenRow + 1);
968 od.setBoxPosition(av.getAlignment()
969 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
971 assertEquals(od.getBoxX(), 0);
972 assertEquals(od.getBoxY(), 0);
973 assertEquals(od.getBoxWidth(), boxWidth);
974 assertEquals(od.getBoxHeight(), boxHeight);
976 // click above hidden rows, so that box overlaps
978 // TODO test fails because box does not change height - dealt with by scroll
980 /* mouseClick(od, 0, Math.round (ypos * alheight / od.getSequencesHeight()));
981 assertEquals(od.getBoxX(), 0);
982 assertEquals(od.getBoxY(), Math.round (ypos * alheight / od.getSequencesHeight()),
984 assertEquals(od.getBoxWidth(), boxWidth);
988 + Math.round ((lastHiddenRow - firstHiddenRow + 1) / scaleh / av
991 // click so that box straddles hidden rows
993 // TODO test fails because box does not change height - dealt with by scroll
995 /*mouseClick(od, 0, Math.round (ypos * alheight / od.getSequencesHeight()));
996 assertEquals(od.getBoxX(), 0);
997 assertEquals(od.getBoxY(), Math.round (ypos * alheight / od.getSequencesHeight()),
999 assertEquals(od.getBoxWidth(), boxWidth);
1003 + Math.round ((lastHiddenRow - firstHiddenRow + 1) / scaleh / av
1004 .getCharHeight()));*/
1008 * Test setting of the box position, when there are hidden rows at the end of
1011 @Test(groups = { "Functional" })
1012 public void testFromMouseWithHiddenRowsAtEnd()
1014 od.updateViewportFromMouse(0, 0,
1015 av.getAlignment().getHiddenSequences(),
1016 av.getColumnSelection(), av.getPosProps());
1017 assertEquals(od.getBoxX(), 0);
1018 assertEquals(od.getBoxY(), 0);
1019 assertEquals(od.getBoxWidth(), boxWidth);
1020 assertEquals(od.getBoxHeight(), boxHeight);
1021 assertEquals(od.getScrollCol(), 0);
1022 assertEquals(od.getScrollRow(), 0);
1024 // hide rows at end and check updated box position is correct
1026 int firstHidden = 500;
1027 int lastHidden = 524;
1028 hideSequences(firstHidden - 1, lastHidden, firstHidden - 1);
1030 od.setBoxPosition(av.getAlignment()
1031 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
1032 assertEquals(od.getBoxX(), 0);
1033 assertEquals(od.getBoxY(), 0);
1034 assertEquals(od.getBoxWidth(), boxWidth);
1035 assertEquals(od.getBoxHeight(), boxHeight);
1037 // click above hidden rows
1038 int ypos = 40; // row 40
1040 Math.round((float) ypos * od.getSequencesHeight() / alheight));
1041 assertEquals(od.getBoxX(), 0);
1042 assertEquals(od.getBoxY(),
1043 Math.round((float) ypos * od.getSequencesHeight() / alheight));
1044 assertEquals(od.getBoxWidth(), boxWidth);
1045 assertEquals(od.getBoxHeight(), boxHeight);
1047 // click above hidden rows so box overlaps
1048 // boxY moved upwards, boxHeight remains same
1049 // TODO fails with boxY located at row 497 - correction done by
1051 /* ypos = 497; // row 497
1052 mouseClick(od, 0, Math.round (ypos * scaleh * av.getCharHeight()));
1053 assertEquals(od.getBoxX(), 0);
1056 Math.round ((firstHidden - viewHeight) * scaleh * av.getCharHeight()),
1058 assertEquals(od.getBoxWidth(), boxWidth);
1059 assertEquals(od.getBoxHeight(), boxHeight);*/
1061 // click within hidden rows
1063 // TODO: fails with wrong boxHeight - correction done by setScrollValues(?)
1064 /*mouseClick(od, 0, Math.round (ypos * scaleh * av.getCharHeight()));
1065 assertEquals(od.getBoxX(), 0);
1068 Math.round ((firstHidden - viewHeight) * scaleh * av.getCharHeight()),
1070 assertEquals(od.getBoxWidth(), boxWidth);
1071 assertEquals(od.getBoxHeight(), boxHeight);*/
1075 * Move viewport horizontally: startRes + previous width gives new horizontal extent. Vertical extent stays the same.
1077 private void moveViewportH(int startRes)
1079 av.setStartRes(startRes);
1080 av.setEndRes(startRes + viewWidth);
1081 od.setBoxPosition(av.getAlignment()
1082 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
1086 * Move viewport vertically: startSeq and endSeq give new vertical extent. Horizontal extent stays the same.
1088 private void moveViewportV(int startSeq)
1090 av.setStartSeq(startSeq);
1091 av.setEndSeq(startSeq + viewHeight);
1092 od.setBoxPosition(av.getAlignment()
1093 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
1097 * Move viewport horizontally and vertically.
1099 private void moveViewport(int startRes, int startSeq)
1101 av.setStartRes(startRes);
1102 av.setEndRes(startRes + viewWidth);
1103 av.setStartSeq(startSeq);
1104 av.setEndSeq(startSeq + viewHeight);
1105 od.setBoxPosition(av.getAlignment()
1106 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
1110 * Mouse click as position x,y in overview window
1112 private void mouseClick(OverviewDimensions od, int x, int y)
1114 od.updateViewportFromMouse(x, y,
1115 av.getAlignment().getHiddenSequences(),
1116 av.getColumnSelection(), av.getPosProps());
1117 // updates require an OverviewPanel to exist which it doesn't here
1118 // so call setBoxPosition() as it would be called by the AlignmentPanel
1120 // int width = av.getEndRes() - av.getStartRes();
1121 // int height = av.getEndSeq() - av.getStartSeq();
1122 av.setStartRes(od.getScrollCol());
1123 av.setEndRes(od.getScrollCol() + viewWidth);
1124 av.setStartSeq(od.getScrollRow());
1125 av.setEndSeq(od.getScrollRow() + viewHeight);
1126 od.setBoxPosition(av.getAlignment()
1127 .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
1130 private void testBoxIsAtClickPoint(int xpos, int ypos)
1132 mouseClick(od, xpos, ypos);
1133 assertEquals(od.getBoxX(), xpos);
1134 assertEquals(od.getBoxY(), ypos);
1135 assertEquals(od.getBoxWidth(), boxWidth);
1136 assertEquals(od.getBoxHeight(), boxHeight);
1141 * Hide sequences between start and end, using hideseq to do the hiding
1142 * (start <= hideseq <= end. Sequence hideseq is not hidden but the others are
1144 private void hideSequences(int start, int end, int hideseq)
1146 SequenceGroup sg = new SequenceGroup();
1147 List<SequenceI> allseqs = av.getAlignment().getSequences();
1148 for (int i = start; i <= end; ++i)
1150 sg.addSequence(allseqs.get(i), false);
1152 av.setSelectionGroup(sg);
1157 av.hideSequences(allseqs.get(hideseq), true);
1159 while (av.isCalcInProgress())
1164 } catch (InterruptedException e)
1166 System.out.println("Hiding seqs interruption");
1171 private void hideColumns(int firstHidden, int lastHidden)
1173 av.hideColumns(firstHidden, lastHidden);
1175 while (av.isCalcInProgress())
1180 } catch (InterruptedException e)
1182 System.out.println("Hiding cols interruption");