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.datamodel.Alignment;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.ColumnSelection;
29 import jalview.datamodel.Sequence;
30 import jalview.datamodel.SequenceCollectionI;
31 import jalview.datamodel.SequenceGroup;
32 import jalview.datamodel.SequenceI;
34 import java.util.Hashtable;
36 import org.testng.annotations.AfterClass;
37 import org.testng.annotations.BeforeClass;
38 import org.testng.annotations.BeforeMethod;
39 import org.testng.annotations.Test;
41 @Test(singleThreaded = true)
42 public class OverviewDimensionsTest
45 OverviewDimensions od;
47 // cached widths and heights
55 ViewportPositionProps posProps;
57 Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
59 ColumnSelection hiddenCols = new ColumnSelection();
61 @BeforeClass(alwaysRun = true)
62 public void setUpJvOptionPane()
64 // create random alignment
65 AlignmentGenerator gen = new AlignmentGenerator(false);
66 al = gen.generate(157, 525, 123, 5, 5);
69 @BeforeMethod(alwaysRun = true)
72 if (!hiddenRepSequences.isEmpty())
74 al.getHiddenSequences().showAll(hiddenRepSequences);
76 hiddenCols.revealAllHiddenColumns();
78 posProps = new ViewportPositionProps(al);
79 posProps.setStartRes(0);
80 posProps.setEndRes(62);
81 posProps.setStartSeq(0);
82 posProps.setEndSeq(17);
84 viewHeight = posProps.getEndSeq() - posProps.getStartSeq() + 1;
85 viewWidth = posProps.getEndRes() - posProps.getStartRes() + 1;
87 ColumnSelection hiddenCols = new ColumnSelection();
89 od = new OverviewDimensions(posProps, true);
90 // Initial box sizing - default path through code
91 od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps);
96 // calculate before hidden columns so we get absolute values
97 alheight = posProps.getAbsoluteAlignmentHeight();
98 alwidth = posProps.getAbsoluteAlignmentWidth();
100 boxWidth = Math.round((float) (posProps.getEndRes()
101 - posProps.getStartRes() + 1)
102 * od.getWidth() / alwidth);
103 boxHeight = Math.round((float) (posProps.getEndSeq()
104 - posProps.getStartSeq() + 1)
105 * od.getSequencesHeight() / alheight);
108 @AfterClass(alwaysRun = true)
109 public void cleanUp()
115 * Test that the OverviewDimensions constructor sets width and height
118 @Test(groups = { "Functional" })
119 public void testConstructor()
121 SequenceI seqa = new Sequence("Seq1", "ABC");
122 SequenceI seqb = new Sequence("Seq2", "ABC");
123 SequenceI seqc = new Sequence("Seq3", "ABC");
124 SequenceI seqd = new Sequence("Seq4", "ABC");
125 SequenceI seqe = new Sequence("Seq5",
126 "ABCABCABCABCABCABCABCABCBACBACBACBAC");
128 int defaultGraphHeight = 20;
131 int maxSeqHeight = 300;
132 int minSeqHeight = 40;
134 // test for alignment with width > height
135 SequenceI[] seqs1 = new SequenceI[] { seqa, seqb };
136 Alignment al1 = new Alignment(seqs1);
137 ViewportPositionProps props = new ViewportPositionProps(al1);
139 OverviewDimensions od = new OverviewDimensions(props, true);
140 int scaledHeight = 266;
141 assertEquals(od.getGraphHeight(), defaultGraphHeight);
142 assertEquals(od.getSequencesHeight(), scaledHeight);
143 assertEquals(od.getWidth(), maxWidth);
144 assertEquals(od.getHeight(), scaledHeight + defaultGraphHeight);
146 // test for alignment with width < height
147 SequenceI[] seqs2 = new SequenceI[] { seqa, seqb, seqc, seqd };
148 Alignment al2 = new Alignment(seqs2);
149 props = new ViewportPositionProps(al2);
151 od = new OverviewDimensions(props, true);
152 int scaledWidth = 300;
153 assertEquals(od.getGraphHeight(), defaultGraphHeight);
154 assertEquals(od.getSequencesHeight(), maxSeqHeight);
155 assertEquals(od.getWidth(), scaledWidth);
156 assertEquals(od.getHeight(), scaledWidth + defaultGraphHeight);
158 // test for alignment with width > height and sequence height scaled below
160 SequenceI[] seqs3 = new SequenceI[] { seqe };
161 Alignment al3 = new Alignment(seqs3);
162 props = new ViewportPositionProps(al3);
164 od = new OverviewDimensions(props, true);
165 assertEquals(od.getGraphHeight(), defaultGraphHeight);
166 assertEquals(od.getSequencesHeight(), minSeqHeight);
167 assertEquals(od.getWidth(), maxWidth);
168 assertEquals(od.getHeight(), minSeqHeight + defaultGraphHeight);
170 // test for alignment with width < height and width scaled below min value
171 SequenceI[] seqs4 = new SequenceI[] { seqa, seqb, seqc, seqd, seqa,
172 seqb, seqc, seqd, seqa, seqb, seqc, seqd, seqa, seqb, seqc, seqd };
173 Alignment al4 = new Alignment(seqs4);
174 props = new ViewportPositionProps(al4);
176 od = new OverviewDimensions(props, true);
177 assertEquals(od.getGraphHeight(), defaultGraphHeight);
178 assertEquals(od.getSequencesHeight(), maxSeqHeight);
179 assertEquals(od.getWidth(), minWidth);
180 assertEquals(od.getHeight(), maxSeqHeight + defaultGraphHeight);
182 Alignment al5 = new Alignment(seqs4);
183 props = new ViewportPositionProps(al5);
185 od = new OverviewDimensions(props, false);
186 assertEquals(od.getGraphHeight(), 0);
187 assertEquals(od.getSequencesHeight(), maxSeqHeight);
188 assertEquals(od.getWidth(), minWidth);
189 assertEquals(od.getHeight(), maxSeqHeight);
193 * Test that validation after mouse adjustments to boxX and boxY sets box
194 * dimensions and scroll values correctly, when there are no hidden rows or
197 @Test(groups = { "Functional" })
198 public void testSetBoxFromMouseClick()
200 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols,
202 assertEquals(od.getBoxX(), 0);
203 assertEquals(od.getBoxY(), 0);
204 assertEquals(od.getBoxWidth(), boxWidth);
205 assertEquals(od.getScrollCol(), 0);
206 assertEquals(od.getScrollRow(), 0);
208 // negative boxX value reset to 0
209 mouseClick(od, -5, 10);
210 assertEquals(od.getBoxX(), 0);
211 assertEquals(od.getBoxWidth(), boxWidth);
212 assertEquals(od.getBoxHeight(), boxHeight);
213 assertEquals(od.getScrollRow(),
214 Math.round((float) 10 * alheight / od.getSequencesHeight()));
215 assertEquals(od.getScrollCol(), 0);
217 // negative boxY value reset to 0
218 mouseClick(od, 6, -2);
219 assertEquals(od.getBoxY(), 0);
220 assertEquals(od.getBoxWidth(), boxWidth);
221 assertEquals(od.getBoxHeight(), boxHeight);
222 assertEquals(od.getScrollCol(),
223 Math.round((float) 6 * alwidth / od.getWidth()));
224 assertEquals(od.getScrollRow(), 0);
226 // overly large boxX value reset to width-boxWidth
227 mouseClick(od, 100, 6);
228 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth() + 1);
229 assertEquals(od.getBoxY(), 6);
230 assertEquals(od.getBoxWidth(), boxWidth);
231 assertEquals(od.getBoxHeight(), boxHeight);
232 assertEquals(od.getScrollCol(),
233 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
234 assertEquals(od.getScrollRow(),
235 Math.round((float) od.getBoxY() * alheight
236 / od.getSequencesHeight()));
238 // overly large boxY value reset to sequenceHeight - boxHeight
239 mouseClick(od, 10, 520);
240 assertEquals(od.getBoxX(), 10);
241 assertEquals(od.getBoxY(), od.getSequencesHeight() - od.getBoxHeight());
242 assertEquals(od.getBoxWidth(), boxWidth);
243 assertEquals(od.getBoxHeight(), boxHeight);
244 assertEquals(od.getScrollCol(),
245 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
246 assertEquals(od.getScrollRow(),
247 Math.round((float) od.getBoxY() * alheight
248 / od.getSequencesHeight()));
250 // click past end of alignment, as above
251 mouseClick(od, 3000, 5);
252 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth() + 1);
253 assertEquals(od.getBoxWidth(), boxWidth);
254 assertEquals(od.getBoxHeight(), boxHeight);
255 assertEquals(od.getScrollCol(),
256 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
257 assertEquals(od.getScrollRow(),
258 Math.round((float) od.getBoxY() * alheight
259 / od.getSequencesHeight()));
261 // move viewport so startRes non-zero and then mouseclick
264 // click at viewport position
265 int oldboxx = od.getBoxX();
266 int oldboxy = od.getBoxY();
267 mouseClick(od, od.getBoxX() + 5, od.getBoxY() + 2);
268 assertEquals(od.getBoxX(), oldboxx + 5);
269 assertEquals(od.getBoxWidth(), boxWidth);
270 assertEquals(od.getBoxHeight(), boxHeight);
271 assertEquals(od.getScrollCol(),
272 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
273 assertEquals(od.getBoxY(), oldboxy + 2);
274 assertEquals(od.getScrollRow(),
275 Math.round((float) od.getBoxY() * alheight
276 / od.getSequencesHeight()));
278 // click at top corner
279 mouseClick(od, 0, 0);
280 assertEquals(od.getBoxX(), 0);
281 assertEquals(od.getScrollCol(), 0);
282 assertEquals(od.getBoxY(), 0);
283 assertEquals(od.getScrollRow(), 0);
284 assertEquals(od.getBoxWidth(), boxWidth);
285 assertEquals(od.getBoxHeight(), boxHeight);
289 * Test setting of the box position, when there are hidden cols at the start
292 @Test(groups = { "Functional" })
293 public void testFromMouseWithHiddenColsAtStart()
295 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols,
297 assertEquals(od.getBoxX(), 0);
298 assertEquals(od.getBoxY(), 0);
299 assertEquals(od.getBoxWidth(), boxWidth);
300 assertEquals(od.getScrollCol(), 0);
301 assertEquals(od.getScrollRow(), 0);
303 // hide cols at start and check updated box position is correct
304 // changes boxX but not boxwidth
305 int lastHiddenCol = 30;
306 hiddenCols.hideColumns(0, lastHiddenCol);
308 od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps);
309 assertEquals(od.getBoxX(),
310 Math.round((float) (lastHiddenCol + 1) * od.getWidth()
312 assertEquals(od.getBoxWidth(), boxWidth);
313 assertEquals(od.getBoxHeight(), boxHeight);
315 // try to click in hidden cols, check box does not move
316 // this test currently fails as the overview box does not behave like this!
318 mouseClick(od, xpos, 0);
321 Math.round((float) (lastHiddenCol + 1) * od.getWidth()
323 assertEquals(od.getBoxY(), 0);
324 assertEquals(od.getBoxWidth(), boxWidth);
325 assertEquals(od.getBoxHeight(), boxHeight);
326 assertEquals(od.getScrollRow(), 0);
327 assertEquals(od.getScrollCol(), 0);
329 // click to right of hidden columns, box moves to click point
330 testBoxIsAtClickPoint(40, 0);
331 assertEquals(od.getScrollRow(), 0);
332 assertEquals(od.getScrollCol(),
333 Math.round((float) 40 * alwidth / od.getWidth())
334 - (lastHiddenCol + 1));
336 // click to right of hidden columns such that box runs over right hand side
338 // box position is adjusted away from the edge
339 // overly large boxX value reset to width-boxWidth
341 mouseClick(od, xpos, 5);
342 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth() + 1);
343 assertEquals(od.getBoxY(), 5);
344 assertEquals(od.getBoxWidth(), boxWidth);
345 assertEquals(od.getBoxHeight(), boxHeight);
346 assertEquals(od.getScrollCol(),
347 Math.round((float) od.getBoxX() * alwidth / od.getWidth())
348 - (lastHiddenCol + 1));
349 assertEquals(od.getScrollRow(),
350 Math.round((float) od.getBoxY() * alheight
351 / od.getSequencesHeight()));
355 * Test setting of the box position, when there are hidden cols in the middle
358 @Test(groups = { "Functional" })
359 public void testFromMouseWithHiddenColsInMiddle()
361 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols,
363 assertEquals(od.getBoxX(), 0);
364 assertEquals(od.getBoxY(), 0);
365 assertEquals(od.getBoxWidth(), boxWidth);
366 assertEquals(od.getScrollCol(), 0);
367 assertEquals(od.getScrollRow(), 0);
369 // hide columns 63-73, no change to box position or dimensions
370 int firstHidden = 63;
372 hiddenCols.hideColumns(firstHidden, lastHidden);
374 od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps);
375 assertEquals(od.getBoxX(), 0);
376 assertEquals(od.getBoxY(), 0);
377 assertEquals(od.getBoxWidth(), boxWidth);
378 assertEquals(od.getScrollCol(), 0);
379 assertEquals(od.getScrollRow(), 0);
381 // move box so that it overlaps with hidden cols on one side
382 // box width changes, boxX and scrollCol as for unhidden case
383 int xpos = 55 - boxWidth; // 55 is position in overview approx halfway
384 // between cols 60 and 70
385 mouseClick(od, xpos, 0);
386 assertEquals(od.getBoxX(), xpos);
387 assertEquals(od.getBoxY(), 0);
390 Math.round(boxWidth + (float) (lastHidden - firstHidden + 1)
391 * od.getWidth() / alwidth));
392 assertEquals(od.getBoxHeight(), boxHeight);
393 assertEquals(od.getScrollCol(),
394 Math.round(xpos * alwidth / od.getWidth()));
395 assertEquals(od.getScrollRow(), 0);
397 // move box so that it completely covers hidden cols
398 // box width changes, boxX and scrollCol as for hidden case
400 mouseClick(od, xpos, 0);
401 assertEquals(od.getBoxX(), xpos);
402 assertEquals(od.getBoxY(), 0);
405 Math.round(boxWidth + (float) (lastHidden - firstHidden + 1)
406 * od.getWidth() / alwidth));
407 assertEquals(od.getBoxHeight(), boxHeight);
408 assertEquals(od.getScrollCol(),
409 Math.round((float) xpos * alwidth / od.getWidth()));
410 assertEquals(od.getScrollRow(), 0);
412 // move box so boxX is in hidden cols, box overhangs at right
413 // boxX and scrollCol at left of hidden area, box width extends across
416 mouseClick(od, xpos, 0);
417 assertEquals(od.getBoxX(),
418 Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth));
419 assertEquals(od.getBoxY(), 0);
423 + Math.round((float) (lastHidden - firstHidden + 1)
424 * od.getWidth() / alwidth));
425 assertEquals(od.getBoxHeight(), boxHeight);
426 assertEquals(od.getScrollCol(), firstHidden - 1);
427 assertEquals(od.getScrollRow(), 0);
429 // move box so boxX is to right of hidden cols, but does not go beyond full
430 // width of alignment
431 // box width, boxX and scrollCol all as for non-hidden case
433 testBoxIsAtClickPoint(xpos, 0);
434 assertEquals(od.getScrollRow(), 0);
435 assertEquals(od.getScrollCol(),
436 Math.round(xpos * alwidth / od.getWidth())
437 - (lastHidden - firstHidden + 1));
439 // move box so it goes beyond full width of alignment
440 // boxX, scrollCol adjusted back, box width normal
442 mouseClick(od, xpos, 5);
443 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth() + 1);
444 assertEquals(od.getBoxY(), 5);
445 assertEquals(od.getBoxWidth(), boxWidth);
446 assertEquals(od.getBoxHeight(), boxHeight);
447 assertEquals(od.getScrollCol(),
448 Math.round(((float) od.getBoxX() * alwidth / od.getWidth())
449 - (lastHidden - firstHidden + 1)));
450 assertEquals(od.getScrollRow(),
451 Math.round((float) od.getBoxY() * alheight
452 / od.getSequencesHeight()));
457 * Test setting of the box position, when there are hidden cols at the end of
460 @Test(groups = { "Functional" })
461 public void testFromMouseWithHiddenColsAtEnd()
463 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols,
465 assertEquals(od.getBoxX(), 0);
466 assertEquals(od.getBoxY(), 0);
467 assertEquals(od.getBoxWidth(), boxWidth);
468 assertEquals(od.getScrollCol(), 0);
469 assertEquals(od.getScrollRow(), 0);
471 // hide columns 140-164, no change to box position or dimensions
472 int firstHidden = 140;
473 int lastHidden = 164;
474 hiddenCols.hideColumns(firstHidden, lastHidden);
475 od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps);
476 assertEquals(od.getBoxX(), 0);
477 assertEquals(od.getBoxY(), 0);
478 assertEquals(od.getBoxWidth(), boxWidth);
479 assertEquals(od.getScrollCol(), 0);
480 assertEquals(od.getScrollRow(), 0);
482 // click to left of hidden cols, without overlapping
483 // boxX, scrollCol and width as normal
485 testBoxIsAtClickPoint(xpos, 0);
486 assertEquals(od.getScrollRow(), 0);
487 assertEquals(od.getScrollCol(),
488 Math.round((float) xpos * alwidth / od.getWidth()));
490 // click to left of hidden cols, with overlap
491 // boxX and scrollCol adjusted for hidden cols, width normal
492 xpos = Math.round((float) 145 * od.getWidth() / alwidth) - boxWidth;
493 mouseClick(od, xpos, 0);
494 assertEquals(od.getBoxX(),
495 Math.round((firstHidden - 1) * od.getWidth() / alwidth)
497 assertEquals(od.getBoxY(), 0);
498 assertEquals(od.getBoxWidth(), boxWidth);
499 assertEquals(od.getBoxHeight(), boxHeight);
500 assertEquals(od.getScrollCol(),
501 Math.round(od.getBoxX() * alwidth / od.getWidth()));
502 assertEquals(od.getScrollRow(), 0);
504 // click in hidden cols
505 // boxX and scrollCol adjusted for hidden cols, width normal
506 // TODO breaks as above test
510 Math.round((firstHidden - 1) * scalew * av.getCharWidth())
512 assertEquals(od.getBoxY(), 0);
513 assertEquals(od.getBoxWidth(), boxWidth);
514 assertEquals(od.getBoxHeight(), boxHeight);
515 assertEquals(od.getScrollCol(),
516 Math.round(od.getBoxX() * alwidth / od.getWidth()));
517 assertEquals(od.getScrollRow(), 0);*/
519 // click off end of alignment
520 // boxX and scrollCol adjusted for hidden cols, width normal
521 // TODO breaks as above test
525 Math.round((firstHidden - 1) * scalew * av.getCharWidth())
527 assertEquals(od.getBoxY(), 0);
528 assertEquals(od.getBoxWidth(), boxWidth);
529 assertEquals(od.getBoxHeight(), boxHeight);
530 assertEquals(od.getScrollCol(),
531 Math.round(od.getBoxX() * alwidth / od.getWidth()));
532 assertEquals(od.getScrollRow(), 0);*/
536 * Test that the box position is set correctly when set from the viewport,
537 * with no hidden rows or columns
539 @Test(groups = { "Functional" })
540 public void testSetBoxFromViewport()
542 // move viewport to start of alignment
544 assertEquals(od.getBoxX(), 0);
545 assertEquals(od.getBoxY(), 0);
546 assertEquals(od.getBoxWidth(), boxWidth);
547 assertEquals(od.getBoxHeight(), boxHeight);
549 // move viewport to right
551 assertEquals(od.getBoxX(),
552 Math.round((float) 70 * od.getWidth() / alwidth));
553 assertEquals(od.getBoxY(), 0);
554 assertEquals(od.getBoxWidth(), boxWidth);
555 assertEquals(od.getBoxHeight(), boxHeight);
557 // move viewport down
559 assertEquals(od.getBoxX(),
560 Math.round((float) 70 * od.getWidth() / alwidth));
561 assertEquals(od.getBoxY(),
562 Math.round(100 * od.getSequencesHeight() / alheight));
563 assertEquals(od.getBoxWidth(), boxWidth);
564 assertEquals(od.getBoxHeight(), boxHeight);
566 // move viewport to bottom right
567 moveViewport(98, 508);
568 assertEquals(od.getBoxX(),
569 Math.round((float) 98 * od.getWidth() / alwidth));
570 assertEquals(od.getBoxY(),
571 Math.round((float) 508 * od.getSequencesHeight() / alheight));
572 assertEquals(od.getBoxWidth(), boxWidth);
573 assertEquals(od.getBoxHeight(), boxHeight);
577 * Test that the box position is set correctly when there are hidden columns
580 @Test(groups = { "Functional" })
581 public void testSetBoxFromViewportHiddenColsAtStart()
585 hiddenCols.hideColumns(firstHidden, lastHidden);
587 // move viewport to start of alignment
589 assertEquals(od.getBoxX(),
590 Math.round((float) (lastHidden + 1) * od.getWidth() / alwidth));
591 assertEquals(od.getBoxY(), 0);
592 assertEquals(od.getBoxWidth(), boxWidth);
593 assertEquals(od.getBoxHeight(), boxHeight);
595 // move viewport to end of alignment - need to make startRes by removing
596 // hidden cols because of how viewport/overview are implemented
597 moveViewport(98 - lastHidden - 1, 0);
598 assertEquals(od.getBoxX(),
599 Math.round((float) 98 * od.getWidth() / alwidth));
600 assertEquals(od.getBoxY(), 0);
601 assertEquals(od.getBoxWidth(), boxWidth);
602 assertEquals(od.getBoxHeight(), boxHeight);
606 * Test that the box position is set correctly when there are hidden columns
609 @Test(groups = { "Functional" })
610 public void testSetBoxFromViewportHiddenColsInMiddle()
612 int firstHidden = 68;
614 hiddenCols.hideColumns(firstHidden, lastHidden);
616 // move viewport before hidden columns
619 assertEquals(od.getBoxX(),
620 Math.round((float) 3 * od.getWidth() / alwidth));
621 assertEquals(od.getBoxY(), 0);
622 System.out.println(od.getBoxWidth());
623 assertEquals(od.getBoxWidth(), boxWidth);
624 System.out.println(od.getBoxWidth());
625 assertEquals(od.getBoxHeight(), boxHeight);
627 // move viewport to left of hidden columns with overlap
629 assertEquals(od.getBoxX(),
630 Math.round((float) 10 * od.getWidth() / alwidth));
631 assertEquals(od.getBoxY(), 0);
635 + Math.round((float) (lastHidden - firstHidden + 1)
636 * od.getWidth() / alwidth));
637 assertEquals(od.getBoxHeight(), boxHeight);
639 // move viewport to straddle hidden columns
641 assertEquals(od.getBoxX(),
642 Math.round((float) 63 * od.getWidth() / alwidth));
643 assertEquals(od.getBoxY(), 0);
647 + Math.round((lastHidden - firstHidden + 1)
648 * od.getWidth() / alwidth));
649 assertEquals(od.getBoxHeight(), boxHeight);
651 // move viewport to right of hidden columns, no overlap
652 moveViewport(80 - (lastHidden - firstHidden + 1), 0);
653 assertEquals(od.getBoxX(),
654 Math.round((float) 80 * od.getWidth() / alwidth));
655 assertEquals(od.getBoxY(), 0);
656 assertEquals(od.getBoxWidth(), boxWidth);
657 assertEquals(od.getBoxHeight(), boxHeight);
662 * Test that the box position is set correctly when there are hidden columns
665 @Test(groups = { "Functional" })
666 public void testSetBoxFromViewportHiddenColsAtEnd()
668 int firstHidden = 152;
669 int lastHidden = 164;
670 hiddenCols.hideColumns(firstHidden, lastHidden);
672 // move viewport before hidden columns
674 assertEquals(od.getBoxX(),
675 Math.round((float) 3 * od.getWidth() / alwidth));
676 assertEquals(od.getBoxY(), 0);
677 assertEquals(od.getBoxWidth(), boxWidth);
678 assertEquals(od.getBoxHeight(), boxHeight);
680 // move viewport to hidden columns
681 moveViewport(102, 0);
682 assertEquals(od.getBoxX(),
683 Math.round((float) 102 * od.getWidth() / alwidth));
684 assertEquals(od.getBoxY(), 0);
685 assertEquals(od.getBoxWidth(), boxWidth
686 + Math.round((float) (lastHidden - firstHidden)
687 * od.getWidth() / alwidth));
688 assertEquals(od.getBoxHeight(), boxHeight);
692 * Test that the box position is set correctly when there are hidden rows at
695 @Test(groups = { "Functional" })
696 public void testSetBoxFromViewportHiddenRowsAtStart()
700 hideSequences(firstHidden, lastHidden);
702 // move viewport to start of alignment:
703 // box moves to below hidden rows, height remains same
705 assertEquals(od.getBoxX(), 0);
706 assertEquals(od.getBoxY(),
707 Math.round((float) (lastHidden + 1) * od.getSequencesHeight()
709 assertEquals(od.getBoxWidth(), boxWidth);
710 assertEquals(od.getBoxHeight(), boxHeight);
712 // move viewport to end of alignment
713 moveViewport(0, 525 - viewHeight - lastHidden - 1);
714 assertEquals(od.getBoxX(), 0);
717 Math.round((float) (525 - viewHeight) * od.getSequencesHeight()
719 assertEquals(od.getBoxWidth(), boxWidth);
720 assertEquals(od.getBoxHeight(), boxHeight);
724 * Test that the box position is set correctly when there are hidden rows in
727 @Test(groups = { "Functional" })
728 public void testSetBoxFromViewportHiddenRowsInMiddle()
730 int firstHidden = 200;
731 int lastHidden = 210;
732 hideSequences(firstHidden, lastHidden);
734 // move viewport to start of alignment:
735 // box, height etc as in non-hidden case
737 assertEquals(od.getBoxX(), 0);
738 assertEquals(od.getBoxY(), 0);
739 assertEquals(od.getBoxWidth(), boxWidth);
740 assertEquals(od.getBoxHeight(), boxHeight);
742 // move viewport to straddle hidden rows
743 moveViewport(0, 198);
744 assertEquals(od.getBoxX(), 0);
745 assertEquals(od.getBoxY(), Math.round ((float)198 * od.getSequencesHeight()
747 assertEquals(od.getBoxWidth(), boxWidth);
750 Math.round((float) (viewHeight + lastHidden - firstHidden + 1)
751 * od.getSequencesHeight() / alheight));
755 * Test that the box position is set correctly when there are hidden rows at
758 @Test(groups = { "Functional" })
759 public void testSetBoxFromViewportHiddenRowsAtEnd()
761 int firstHidden = 500;
762 int lastHidden = 524;
763 hideSequences(firstHidden, lastHidden);
765 // move viewport to start of alignment:
766 // box, height etc as in non-hidden case
768 assertEquals(od.getBoxX(), 0);
769 assertEquals(od.getBoxY(), 0);
770 assertEquals(od.getBoxWidth(), boxWidth);
771 assertEquals(od.getBoxHeight(), boxHeight);
773 // move viewport to end of alignment
774 // viewport sits above hidden rows and does not include them
775 moveViewport(0, firstHidden - viewHeight - 1);
776 assertEquals(od.getBoxX(), 0);
779 Math.round((float) (firstHidden - viewHeight - 1)
780 * od.getSequencesHeight() / alheight));
781 assertEquals(od.getBoxWidth(), boxWidth);
782 assertEquals(od.getBoxHeight(), boxHeight);
787 * Test setting of the box position, when there are hidden rows at the start
790 @Test(groups = { "Functional" })
791 public void testFromMouseWithHiddenRowsAtStart()
793 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols,
795 assertEquals(od.getBoxX(), 0);
796 assertEquals(od.getBoxY(), 0);
797 assertEquals(od.getBoxHeight(), boxHeight);
798 assertEquals(od.getBoxWidth(), boxWidth);
799 assertEquals(od.getScrollCol(), 0);
800 assertEquals(od.getScrollRow(), 0);
802 // hide rows at start and check updated box position is correct
803 // changes boxY but not boxheight
804 int lastHiddenRow = 30;
805 hideSequences(0, lastHiddenRow);
807 od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps);
808 assertEquals(od.getBoxX(), 0);
809 assertEquals(od.getBoxY(),
810 Math.round((float) (lastHiddenRow + 1)
811 * od.getSequencesHeight() / alheight));
812 assertEquals(od.getBoxWidth(), boxWidth);
813 assertEquals(od.getBoxHeight(), boxHeight);
815 // click in hidden rows - same result
816 mouseClick(od, 0, 0);
817 assertEquals(od.getBoxX(), 0);
820 Math.round((float) (lastHiddenRow + 1)
821 * od.getSequencesHeight() / alheight));
822 assertEquals(od.getBoxWidth(), boxWidth);
823 assertEquals(od.getBoxHeight(), boxHeight);
825 // click below hidden rows
826 mouseClick(od, 0, 150);
827 assertEquals(od.getBoxX(), 0);
828 assertEquals(od.getBoxY(), 150);
829 assertEquals(od.getBoxWidth(), boxWidth);
830 assertEquals(od.getBoxHeight(), boxHeight);
834 * Test setting of the box position, when there are hidden rows at the middle
837 @Test(groups = { "Functional" })
838 public void testFromMouseWithHiddenRowsInMiddle()
840 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols,
843 assertEquals(od.getBoxX(), 0);
844 assertEquals(od.getBoxY(), 0);
845 assertEquals(od.getBoxWidth(), boxWidth);
846 assertEquals(od.getBoxHeight(), boxHeight);
847 assertEquals(od.getScrollCol(), 0);
848 assertEquals(od.getScrollRow(), 0);
850 // hide rows in middle and check updated box position is correct
852 int firstHiddenRow = 50;
853 int lastHiddenRow = 60;
854 hideSequences(firstHiddenRow, lastHiddenRow);
856 od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps);
858 assertEquals(od.getBoxX(), 0);
859 assertEquals(od.getBoxY(), 0);
860 assertEquals(od.getBoxWidth(), boxWidth);
861 assertEquals(od.getBoxHeight(), boxHeight);
863 // click above hidden rows, so that box overlaps
865 // TODO test fails because box does not change height - dealt with by scroll
867 /* mouseClick(od, 0, Math.round (ypos * alheight / od.getSequencesHeight()));
868 assertEquals(od.getBoxX(), 0);
869 assertEquals(od.getBoxY(), Math.round (ypos * alheight / od.getSequencesHeight()),
871 assertEquals(od.getBoxWidth(), boxWidth);
875 + Math.round ((lastHiddenRow - firstHiddenRow + 1) / scaleh / av
878 // click so that box straddles hidden rows
880 // TODO test fails because box does not change height - dealt with by scroll
882 /*mouseClick(od, 0, Math.round (ypos * alheight / od.getSequencesHeight()));
883 assertEquals(od.getBoxX(), 0);
884 assertEquals(od.getBoxY(), Math.round (ypos * alheight / od.getSequencesHeight()),
886 assertEquals(od.getBoxWidth(), boxWidth);
890 + Math.round ((lastHiddenRow - firstHiddenRow + 1) / scaleh / av
891 .getCharHeight()));*/
895 * Test setting of the box position, when there are hidden rows at the end of
898 @Test(groups = { "Functional" })
899 public void testFromMouseWithHiddenRowsAtEnd()
901 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols,
903 assertEquals(od.getBoxX(), 0);
904 assertEquals(od.getBoxY(), 0);
905 assertEquals(od.getBoxWidth(), boxWidth);
906 assertEquals(od.getBoxHeight(), boxHeight);
907 assertEquals(od.getScrollCol(), 0);
908 assertEquals(od.getScrollRow(), 0);
910 // hide rows at end and check updated box position is correct
912 int firstHidden = 500;
913 int lastHidden = 524;
914 hideSequences(firstHidden, lastHidden);
916 od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps);
917 assertEquals(od.getBoxX(), 0);
918 assertEquals(od.getBoxY(), 0);
919 assertEquals(od.getBoxWidth(), boxWidth);
920 assertEquals(od.getBoxHeight(), boxHeight);
922 // click above hidden rows
923 int ypos = 40; // row 40
925 Math.round((float) ypos * od.getSequencesHeight() / alheight));
926 assertEquals(od.getBoxX(), 0);
927 assertEquals(od.getBoxY(),
928 Math.round((float) ypos * od.getSequencesHeight() / alheight));
929 assertEquals(od.getBoxWidth(), boxWidth);
930 assertEquals(od.getBoxHeight(), boxHeight);
932 // click above hidden rows so box overlaps
933 // boxY moved upwards, boxHeight remains same
934 // TODO fails with boxY located at row 497 - correction done by
936 /* ypos = 497; // row 497
937 mouseClick(od, 0, Math.round (ypos * scaleh * av.getCharHeight()));
938 assertEquals(od.getBoxX(), 0);
941 Math.round ((firstHidden - viewHeight) * scaleh * av.getCharHeight()),
943 assertEquals(od.getBoxWidth(), boxWidth);
944 assertEquals(od.getBoxHeight(), boxHeight);*/
946 // click within hidden rows
948 // TODO: fails with wrong boxHeight - correction done by setScrollValues(?)
949 /*mouseClick(od, 0, Math.round (ypos * scaleh * av.getCharHeight()));
950 assertEquals(od.getBoxX(), 0);
953 Math.round ((firstHidden - viewHeight) * scaleh * av.getCharHeight()),
955 assertEquals(od.getBoxWidth(), boxWidth);
956 assertEquals(od.getBoxHeight(), boxHeight);*/
960 * Move viewport horizontally: startRes + previous width gives new horizontal extent. Vertical extent stays the same.
962 private void moveViewportH(int startRes)
964 posProps.setStartRes(startRes);
965 posProps.setEndRes(startRes + viewWidth - 1);
966 od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps);
970 * Move viewport vertically: startSeq and endSeq give new vertical extent. Horizontal extent stays the same.
972 private void moveViewportV(int startSeq)
974 posProps.setStartSeq(startSeq);
975 posProps.setEndSeq(startSeq + viewHeight - 1);
976 od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps);
980 * Move viewport horizontally and vertically.
982 private void moveViewport(int startRes, int startSeq)
984 posProps.setStartRes(startRes);
985 posProps.setEndRes(startRes + viewWidth - 1);
986 posProps.setStartSeq(startSeq);
987 posProps.setEndSeq(startSeq + viewHeight - 1);
988 od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps);
992 * Mouse click as position x,y in overview window
994 private void mouseClick(OverviewDimensions od, int x, int y)
996 od.updateViewportFromMouse(x, y, al.getHiddenSequences(), hiddenCols,
999 // updates require an OverviewPanel to exist which it doesn't here
1000 // so call setBoxPosition() as it would be called by the AlignmentPanel
1003 posProps.setStartRes(od.getScrollCol());
1004 posProps.setEndRes(od.getScrollCol() + viewWidth - 1);
1005 posProps.setStartSeq(od.getScrollRow());
1006 posProps.setEndSeq(od.getScrollRow() + viewHeight - 1);
1007 od.setBoxPosition(al.getHiddenSequences(), hiddenCols, posProps);
1011 * Test that the box is positioned with the top left corner at xpos, ypos
1012 * and with the original width and height
1014 private void testBoxIsAtClickPoint(int xpos, int ypos)
1016 mouseClick(od, xpos, ypos);
1017 assertEquals(od.getBoxX(), xpos);
1018 assertEquals(od.getBoxY(), ypos);
1019 assertEquals(od.getBoxWidth(), boxWidth);
1020 assertEquals(od.getBoxHeight(), boxHeight);
1025 * Hide sequences between start and end
1027 private void hideSequences(int start, int end)
1029 SequenceI[] allseqs = al.getSequencesArray();
1030 SequenceGroup theseSeqs = new SequenceGroup();
1032 for (int i = start; i <= end; i++)
1034 theseSeqs.addSequence(allseqs[i], false);
1035 al.getHiddenSequences().hideSequence(allseqs[i]);
1038 hiddenRepSequences.put(allseqs[start], theseSeqs);