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.HiddenColumns;
30 import jalview.datamodel.Sequence;
31 import jalview.datamodel.SequenceCollectionI;
32 import jalview.datamodel.SequenceGroup;
33 import jalview.datamodel.SequenceI;
35 import java.util.Hashtable;
37 import org.testng.annotations.AfterClass;
38 import org.testng.annotations.BeforeClass;
39 import org.testng.annotations.BeforeMethod;
40 import org.testng.annotations.Test;
42 @Test(singleThreaded = true)
43 public class OverviewDimensionsShowHiddenTest
46 OverviewDimensionsShowHidden od;
48 // cached widths and heights
56 ViewportRanges vpranges;
58 Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences = new Hashtable<>();
60 HiddenColumns hiddenCols = new HiddenColumns();
62 @BeforeClass(alwaysRun = true)
63 public void setUpAlignment()
65 // create random alignment
66 AlignmentGenerator gen = new AlignmentGenerator(false);
67 al = gen.generate(157, 525, 123, 5, 5);
70 @BeforeMethod(alwaysRun = true)
73 if (!hiddenRepSequences.isEmpty())
75 al.getHiddenSequences().showAll(hiddenRepSequences);
77 ColumnSelection colsel = new ColumnSelection();
78 hiddenCols.revealAllHiddenColumns(colsel);
80 vpranges = new ViewportRanges(al);
81 vpranges.setViewportStartAndHeight(0, 18);
82 vpranges.setViewportStartAndWidth(0, 63);
84 viewHeight = vpranges.getEndSeq() - vpranges.getStartSeq() + 1;
85 viewWidth = vpranges.getEndRes() - vpranges.getStartRes() + 1;
87 HiddenColumns hiddenCols = new HiddenColumns();
89 od = new OverviewDimensionsShowHidden(vpranges, true);
90 // Initial box sizing - default path through code
91 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
96 // calculate before hidden columns so we get absolute values
97 alheight = vpranges.getAbsoluteAlignmentHeight();
98 alwidth = vpranges.getAbsoluteAlignmentWidth();
100 boxWidth = Math.round((float) (vpranges.getEndRes()
101 - vpranges.getStartRes() + 1)
102 * od.getWidth() / alwidth);
103 boxHeight = Math.round((float) (vpranges.getEndSeq()
104 - vpranges.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 ViewportRanges props = new ViewportRanges(al1);
139 OverviewDimensions od = new OverviewDimensionsShowHidden(props, true);
140 int scaledHeight = 267;
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 ViewportRanges(al2);
151 od = new OverviewDimensionsShowHidden(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 ViewportRanges(al3);
164 od = new OverviewDimensionsShowHidden(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 ViewportRanges(al4);
176 od = new OverviewDimensionsShowHidden(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 ViewportRanges(al5);
185 od = new OverviewDimensionsShowHidden(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);
201 assertEquals(od.getBoxX(), 0);
202 assertEquals(od.getBoxY(), 0);
203 assertEquals(od.getBoxWidth(), boxWidth);
204 assertEquals(vpranges.getStartRes(), 0);
205 assertEquals(vpranges.getStartSeq(), 0);
207 // negative boxX value reset to 0
208 mouseClick(od, -5, 10);
209 assertEquals(od.getBoxX(), 0);
210 assertEquals(od.getBoxWidth(), boxWidth);
211 assertEquals(od.getBoxHeight(), boxHeight);
212 assertEquals(vpranges.getStartSeq() + vpranges.getViewportHeight() / 2,
213 Math.round((float) 10 * alheight / od.getSequencesHeight()));
214 assertEquals(vpranges.getStartRes(), 0);
216 // negative boxY value reset to 0
217 mouseClick(od, 6, -2);
218 assertEquals(od.getBoxY(), 0);
219 assertEquals(od.getBoxWidth(), boxWidth);
220 assertEquals(od.getBoxHeight(), boxHeight);
221 assertEquals(vpranges.getStartRes(), 0);
222 assertEquals(vpranges.getStartSeq(), 0);
224 // overly large boxX value reset to width-boxWidth
225 mouseClick(od, 101, 6);
226 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
227 assertEquals(od.getBoxY(), 1);
228 assertEquals(od.getBoxWidth(), boxWidth);
229 assertEquals(od.getBoxHeight(), boxHeight);
230 assertEquals(vpranges.getStartRes(),
231 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
233 vpranges.getStartSeq(),
234 Math.round((float) od.getBoxY() * alheight
235 / od.getSequencesHeight()));
237 // overly large boxY value reset to sequenceHeight - boxHeight
238 mouseClick(od, 10, 520);
239 assertEquals(od.getBoxX(), 0);
240 assertEquals(od.getBoxY(), od.getSequencesHeight() - od.getBoxHeight());
241 assertEquals(od.getBoxWidth(), boxWidth);
242 assertEquals(od.getBoxHeight(), boxHeight);
244 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
246 // here (float) od.getBoxY() * alheight / od.getSequencesHeight() = 507.5
247 // and round rounds to 508; however we get 507 working with row values
248 // hence the subtraction of 1
250 vpranges.getStartSeq(),
251 Math.round((float) od.getBoxY() * alheight
252 / od.getSequencesHeight()) - 1);
254 // click past end of alignment, as above
255 mouseClick(od, 3000, 5);
256 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
257 assertEquals(od.getBoxWidth(), boxWidth);
258 assertEquals(od.getBoxHeight(), boxHeight);
259 assertEquals(vpranges.getStartRes(),
260 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
262 vpranges.getStartSeq(),
263 Math.round((float) od.getBoxY() * alheight
264 / od.getSequencesHeight()));
266 // move viewport so startRes non-zero and then mouseclick
269 // click at viewport position
270 int oldboxx = od.getBoxX();
271 int oldboxy = od.getBoxY();
272 mouseClick(od, od.getBoxX() + od.getBoxWidth() / 2 + 6,
273 od.getBoxY() + od.getBoxHeight() / 2 + 3);
274 assertEquals(od.getBoxX(), oldboxx + 6);
275 assertEquals(od.getBoxWidth(), boxWidth);
276 assertEquals(od.getBoxHeight(), boxHeight);
277 assertEquals(vpranges.getStartRes(),
278 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
279 assertEquals(od.getBoxY(), oldboxy + 3);
281 vpranges.getStartSeq(),
282 Math.round((float) od.getBoxY() * alheight
283 / od.getSequencesHeight()));
285 // click at top corner
286 mouseClick(od, 0, 0);
287 assertEquals(od.getBoxX(), 0);
288 assertEquals(vpranges.getStartRes(), 0);
289 assertEquals(od.getBoxY(), 0);
290 assertEquals(vpranges.getStartSeq(), 0);
291 assertEquals(od.getBoxWidth(), boxWidth);
292 assertEquals(od.getBoxHeight(), boxHeight);
296 * Test setting of the box position, when there are hidden cols at the start
299 @Test(groups = { "Functional" })
300 public void testFromMouseWithHiddenColsAtStart()
302 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
303 assertEquals(od.getBoxX(), 0);
304 assertEquals(od.getBoxY(), 0);
305 assertEquals(od.getBoxWidth(), boxWidth);
306 assertEquals(vpranges.getStartRes(), 0);
307 assertEquals(vpranges.getStartSeq(), 0);
309 // hide cols at start and check updated box position is correct
310 // changes boxX but not boxwidth
311 int lastHiddenCol = 30;
312 hiddenCols.hideColumns(0, lastHiddenCol);
314 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
315 assertEquals(od.getBoxX(),
316 Math.round((float) (lastHiddenCol + 1) * od.getWidth()
318 assertEquals(od.getBoxWidth(), boxWidth);
319 assertEquals(od.getBoxHeight(), boxHeight);
321 // try to click in hidden cols, check box does not move
323 mouseClick(od, xpos, 0);
326 Math.round((float) (lastHiddenCol + 1) * od.getWidth()
328 assertEquals(od.getBoxY(), 0);
329 assertEquals(od.getBoxWidth(), boxWidth);
330 assertEquals(od.getBoxHeight(), boxHeight);
331 assertEquals(vpranges.getStartSeq(), 0);
332 assertEquals(vpranges.getStartRes(), 0);
334 // click to right of hidden columns, box moves to click point
335 mouseClick(od, 60 + boxWidth / 2, boxHeight / 2);
336 assertEquals(od.getBoxX(), 60);
337 assertEquals(od.getBoxY(), 0);
338 assertEquals(od.getBoxWidth(), boxWidth);
339 assertEquals(od.getBoxHeight(), boxHeight);
340 assertEquals(vpranges.getStartSeq(), 0);
341 assertEquals(vpranges.getStartRes(),
343 (float) 60 * alwidth / od.getWidth())
344 - (lastHiddenCol + 1));
346 // click to right of hidden columns such that box runs over right hand side
348 // box position is adjusted away from the edge
349 // overly large boxX value reset to width-boxWidth
351 mouseClick(od, xpos + boxWidth / 2, 5 + boxHeight / 2);
352 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
353 assertEquals(od.getBoxY(), 5);
354 assertEquals(od.getBoxWidth(), boxWidth);
355 assertEquals(od.getBoxHeight(), boxHeight);
356 assertEquals(vpranges.getStartRes(),
357 Math.round((float) od.getBoxX() * alwidth / od.getWidth())
358 - (lastHiddenCol + 1));
360 vpranges.getStartSeq(),
361 Math.round((float) od.getBoxY() * alheight
362 / od.getSequencesHeight()));
366 * Test setting of the box position, when there are hidden cols in the middle
369 @Test(groups = { "Functional" })
370 public void testFromMouseWithHiddenColsInMiddle()
372 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
373 assertEquals(od.getBoxX(), 0);
374 assertEquals(od.getBoxY(), 0);
375 assertEquals(od.getBoxWidth(), boxWidth);
376 assertEquals(vpranges.getStartRes(), 0);
377 assertEquals(vpranges.getStartSeq(), 0);
379 // hide columns 63-73, no change to box position or dimensions
380 int firstHidden = 63;
382 hiddenCols.hideColumns(firstHidden, lastHidden);
384 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
385 assertEquals(od.getBoxX(), 0);
386 assertEquals(od.getBoxY(), 0);
387 assertEquals(od.getBoxWidth(), boxWidth);
388 assertEquals(vpranges.getStartRes(), 0);
389 assertEquals(vpranges.getStartSeq(), 0);
391 // move box so that it overlaps with hidden cols on one side
392 // box width changes, boxX and scrollCol as for unhidden case
393 int xpos = 54 - boxWidth / 2; // 54 is position in overview approx halfway
394 // between cols 60 and 70
395 mouseClick(od, xpos, boxHeight / 2);
396 assertEquals(od.getBoxX(), xpos - boxWidth / 2);
397 assertEquals(od.getBoxY(), 0);
400 Math.round(boxWidth + (float) (lastHidden - firstHidden + 1)
401 * od.getWidth() / alwidth));
402 assertEquals(od.getBoxHeight(), boxHeight);
403 assertEquals(vpranges.getStartRes(),
404 Math.round((xpos - boxWidth / 2) * alwidth / od.getWidth())
405 + 1); // +1 for rounding
406 assertEquals(vpranges.getStartSeq(), 0);
408 // move box so that it completely covers hidden cols
409 // box width changes, boxX and scrollCol as for hidden case
410 xpos = 24 + boxWidth / 2;
411 mouseClick(od, xpos, 0);
412 assertEquals(od.getBoxX(), 24);
413 assertEquals(od.getBoxY(), 0);
416 Math.round(boxWidth + (float) (lastHidden - firstHidden + 1)
417 * od.getWidth() / alwidth));
418 assertEquals(od.getBoxHeight(), boxHeight);
419 assertEquals(vpranges.getStartRes(),
420 Math.round((float) 24 * alwidth / od.getWidth()));
421 assertEquals(vpranges.getStartSeq(), 0);
423 // move box so boxX is to right of hidden cols, but does not go beyond full
424 // width of alignment
425 // box width, boxX and scrollCol all as for non-hidden case
426 xpos = Math.round((float) 75 * od.getWidth() / alwidth) + boxWidth / 2;
427 mouseClick(od, xpos, boxHeight / 2);
428 assertEquals(od.getBoxX(), xpos - boxWidth / 2);
429 assertEquals(od.getBoxY(), 0);
430 assertEquals(od.getBoxWidth(), boxWidth);
431 assertEquals(od.getBoxHeight(), boxHeight);
432 assertEquals(vpranges.getStartSeq(), 0);
433 assertEquals(vpranges.getStartRes(),
434 75 - (lastHidden - firstHidden + 1));
436 // move box so it goes beyond full width of alignment
437 // boxX, scrollCol adjusted back, box width normal
439 mouseClick(od, xpos, 5);
440 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
441 assertEquals(od.getBoxY(), 0);
442 assertEquals(od.getBoxWidth(), boxWidth);
443 assertEquals(od.getBoxHeight(), boxHeight);
445 vpranges.getStartRes(),
446 Math.round(((float) od.getBoxX() * alwidth / od.getWidth())
447 - (lastHidden - firstHidden + 1)));
449 vpranges.getStartSeq(),
450 Math.round((float) od.getBoxY() * alheight
451 / od.getSequencesHeight()));
456 * Test setting of the box position, when there are hidden cols at the end of
459 @Test(groups = { "Functional" })
460 public void testFromMouseWithHiddenColsAtEnd()
462 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
463 assertEquals(od.getBoxX(), 0);
464 assertEquals(od.getBoxY(), 0);
465 assertEquals(od.getBoxWidth(), boxWidth);
466 assertEquals(vpranges.getStartRes(), 0);
467 assertEquals(vpranges.getStartSeq(), 0);
469 // hide columns 140-164, no change to box position or dimensions
470 int firstHidden = 140;
471 int lastHidden = 164;
472 hiddenCols.hideColumns(firstHidden, lastHidden);
473 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
474 assertEquals(od.getBoxX(), 0);
475 assertEquals(od.getBoxY(), 0);
476 assertEquals(od.getBoxWidth(), boxWidth);
477 assertEquals(vpranges.getStartRes(), 0);
478 assertEquals(vpranges.getStartSeq(), 0);
480 // click to left of hidden cols, without overlapping
481 // boxX, scrollCol and width as normal
484 testBoxIsAtClickPoint(xpos, ypos);
485 assertEquals(vpranges.getStartSeq(), Math
486 .round((float) (ypos - boxHeight / 2) * alheight
488 assertEquals(vpranges.getStartRes(), Math.round(
489 (float) (xpos - boxWidth / 2) * alwidth / od.getWidth()));
491 // click to left of hidden cols, with overlap
492 // boxX and scrollCol adjusted for hidden cols, width normal
493 xpos = Math.round((float) 145 * od.getWidth() / alwidth) - boxWidth;
494 mouseClick(od, xpos + boxWidth / 2, boxHeight / 2);
495 assertEquals(od.getBoxX(),
496 Math.round((float) (firstHidden - 1)
497 * od.getWidth() / alwidth)
499 assertEquals(od.getBoxY(), 0);
500 assertEquals(od.getBoxWidth(), boxWidth);
501 assertEquals(od.getBoxHeight(), boxHeight);
502 assertEquals(vpranges.getStartRes(),
503 Math.round((float) (od.getBoxX()) * alwidth
505 assertEquals(vpranges.getStartSeq(), 0);
507 // click in hidden cols
508 // boxX and scrollCol adjusted for hidden cols, width normal
510 assertEquals(od.getBoxX(),
511 Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth)
513 assertEquals(od.getBoxY(), 0);
514 assertEquals(od.getBoxWidth(), boxWidth);
515 assertEquals(od.getBoxHeight(), boxHeight);
516 assertEquals(vpranges.getStartRes(),
517 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
518 assertEquals(vpranges.getStartSeq(), 0);
520 // click off end of alignment
521 // boxX and scrollCol adjusted for hidden cols, width normal
523 assertEquals(od.getBoxX(),
524 Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth)
526 assertEquals(od.getBoxY(), 0);
527 assertEquals(od.getBoxWidth(), boxWidth);
528 assertEquals(od.getBoxHeight(), boxHeight);
529 assertEquals(vpranges.getStartRes(),
530 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
531 assertEquals(vpranges.getStartSeq(), 0);
535 * Test that the box position is set correctly when set from the viewport,
536 * with no hidden rows or columns
538 @Test(groups = { "Functional" })
539 public void testSetBoxFromViewport()
541 // move viewport to start of alignment
543 assertEquals(od.getBoxX(), 0);
544 assertEquals(od.getBoxY(), 0);
545 assertEquals(od.getBoxWidth(), boxWidth);
546 assertEquals(od.getBoxHeight(), boxHeight);
548 // move viewport to right
550 assertEquals(od.getBoxX(),
551 Math.round((float) 70 * od.getWidth() / alwidth));
552 assertEquals(od.getBoxY(), 0);
553 assertEquals(od.getBoxWidth(), boxWidth);
554 assertEquals(od.getBoxHeight(), boxHeight);
556 // move viewport down
558 assertEquals(od.getBoxX(),
559 Math.round((float) 70 * od.getWidth() / alwidth));
560 assertEquals(od.getBoxY(),
561 Math.round(100 * od.getSequencesHeight() / alheight));
562 assertEquals(od.getBoxWidth(), boxWidth);
563 assertEquals(od.getBoxHeight(), boxHeight);
565 // move viewport to bottom right
566 moveViewport(98, 508);
567 assertEquals(od.getBoxX(),
568 Math.round((float) 98 * od.getWidth() / alwidth));
569 assertEquals(od.getBoxY(),
570 Math.round((float) 508 * od.getSequencesHeight() / alheight));
571 assertEquals(od.getBoxWidth(), boxWidth);
572 assertEquals(od.getBoxHeight(), boxHeight);
576 * Test that the box position is set correctly when there are hidden columns
579 @Test(groups = { "Functional" })
580 public void testSetBoxFromViewportHiddenColsAtStart()
584 hiddenCols.hideColumns(firstHidden, lastHidden);
586 // move viewport to start of alignment
588 assertEquals(od.getBoxX(),
589 Math.round((float) (lastHidden + 1) * od.getWidth() / alwidth));
590 assertEquals(od.getBoxY(), 0);
591 assertEquals(od.getBoxWidth(), boxWidth);
592 assertEquals(od.getBoxHeight(), boxHeight);
594 // move viewport to end of alignment - need to make startRes by removing
595 // hidden cols because of how viewport/overview are implemented
596 moveViewport(98 - lastHidden - 1, 0);
597 assertEquals(od.getBoxX(),
598 Math.round((float) 98 * od.getWidth() / alwidth));
599 assertEquals(od.getBoxY(), 0);
600 assertEquals(od.getBoxWidth(), boxWidth);
601 assertEquals(od.getBoxHeight(), boxHeight);
605 * Test that the box position is set correctly when there are hidden columns
608 @Test(groups = { "Functional" })
609 public void testSetBoxFromViewportHiddenColsInMiddle()
611 int firstHidden = 68;
613 hiddenCols.hideColumns(firstHidden, lastHidden);
615 // move viewport before hidden columns
618 assertEquals(od.getBoxX(),
619 Math.round((float) 3 * od.getWidth() / alwidth));
620 assertEquals(od.getBoxY(), 0);
621 assertEquals(od.getBoxWidth(), boxWidth);
622 assertEquals(od.getBoxHeight(), boxHeight);
624 // move viewport to left of hidden columns with overlap
626 assertEquals(od.getBoxX(),
627 Math.round((float) 10 * od.getWidth() / alwidth));
628 assertEquals(od.getBoxY(), 0);
632 + Math.round((float) (lastHidden - firstHidden + 1)
633 * od.getWidth() / alwidth));
634 assertEquals(od.getBoxHeight(), boxHeight);
636 // move viewport to straddle hidden columns
638 assertEquals(od.getBoxX(),
639 Math.round((float) 63 * od.getWidth() / alwidth));
640 assertEquals(od.getBoxY(), 0);
644 + Math.round((lastHidden - firstHidden + 1)
645 * od.getWidth() / alwidth));
646 assertEquals(od.getBoxHeight(), boxHeight);
648 // move viewport to right of hidden columns, no overlap
649 moveViewport(80 - (lastHidden - firstHidden + 1), 0);
650 assertEquals(od.getBoxX(),
651 Math.round((float) 80 * od.getWidth() / alwidth));
652 assertEquals(od.getBoxY(), 0);
653 assertEquals(od.getBoxWidth(), boxWidth);
654 assertEquals(od.getBoxHeight(), boxHeight);
659 * Test that the box position is set correctly when there are hidden columns
662 @Test(groups = { "Functional" })
663 public void testSetBoxFromViewportHiddenColsAtEnd()
665 int firstHidden = 152;
666 int lastHidden = 164;
667 hiddenCols.hideColumns(firstHidden, lastHidden);
669 // move viewport before hidden columns
671 assertEquals(od.getBoxX(),
672 Math.round((float) 3 * od.getWidth() / alwidth));
673 assertEquals(od.getBoxY(), 0);
674 assertEquals(od.getBoxWidth(), boxWidth);
675 assertEquals(od.getBoxHeight(), boxHeight);
677 // move viewport to hidden columns
678 // viewport can't actually extend into hidden cols,
679 // so move to the far right edge of the viewport
680 moveViewport(firstHidden - viewWidth, 0);
681 assertEquals(od.getBoxX(),
682 Math.round((float) (firstHidden - viewWidth)
683 * od.getWidth() / alwidth));
684 assertEquals(od.getBoxY(), 0);
685 assertEquals(od.getBoxWidth(), boxWidth);
686 assertEquals(od.getBoxHeight(), boxHeight);
690 * Test that the box position is set correctly when there are hidden rows at
693 @Test(groups = { "Functional" })
694 public void testSetBoxFromViewportHiddenRowsAtStart()
698 hideSequences(firstHidden, lastHidden);
700 // move viewport to start of alignment:
701 // box moves to below hidden rows, height remains same
703 assertEquals(od.getBoxX(), 0);
704 assertEquals(od.getBoxY(),
705 Math.round((float) (lastHidden + 1) * od.getSequencesHeight()
707 assertEquals(od.getBoxWidth(), boxWidth);
708 assertEquals(od.getBoxHeight(), boxHeight);
710 // move viewport to end of alignment
711 moveViewport(0, 525 - viewHeight - lastHidden - 1);
712 assertEquals(od.getBoxX(), 0);
715 Math.round((float) (525 - viewHeight) * od.getSequencesHeight()
717 assertEquals(od.getBoxWidth(), boxWidth);
718 assertEquals(od.getBoxHeight(), boxHeight);
722 * Test that the box position is set correctly when there are hidden rows in
725 @Test(groups = { "Functional" })
726 public void testSetBoxFromViewportHiddenRowsInMiddle()
728 int firstHidden = 200;
729 int lastHidden = 210;
730 hideSequences(firstHidden, lastHidden);
732 // move viewport to start of alignment:
733 // box, height etc as in non-hidden case
735 assertEquals(od.getBoxX(), 0);
736 assertEquals(od.getBoxY(), 0);
737 assertEquals(od.getBoxWidth(), boxWidth);
738 assertEquals(od.getBoxHeight(), boxHeight);
740 // move viewport to straddle hidden rows
741 moveViewport(0, 198);
742 assertEquals(od.getBoxX(), 0);
743 assertEquals(od.getBoxY(), Math.round ((float)198 * od.getSequencesHeight()
745 assertEquals(od.getBoxWidth(), boxWidth);
748 Math.round((float) (viewHeight + lastHidden - firstHidden + 1)
749 * od.getSequencesHeight() / alheight));
753 * Test that the box position is set correctly when there are hidden rows at
756 @Test(groups = { "Functional" })
757 public void testSetBoxFromViewportHiddenRowsAtEnd()
759 int firstHidden = 500;
760 int lastHidden = 524;
761 hideSequences(firstHidden, lastHidden);
763 // move viewport to start of alignment:
764 // box, height etc as in non-hidden case
766 assertEquals(od.getBoxX(), 0);
767 assertEquals(od.getBoxY(), 0);
768 assertEquals(od.getBoxWidth(), boxWidth);
769 assertEquals(od.getBoxHeight(), boxHeight);
771 // move viewport to end of alignment
772 // viewport sits above hidden rows and does not include them
773 moveViewport(0, firstHidden - viewHeight - 1);
774 assertEquals(od.getBoxX(), 0);
777 Math.round((float) (firstHidden - viewHeight - 1)
778 * od.getSequencesHeight() / alheight));
779 assertEquals(od.getBoxWidth(), boxWidth);
780 assertEquals(od.getBoxHeight(), boxHeight);
785 * Test setting of the box position, when there are hidden rows at the start
788 @Test(groups = { "Functional" })
789 public void testFromMouseWithHiddenRowsAtStart()
791 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
792 assertEquals(od.getBoxX(), 0);
793 assertEquals(od.getBoxY(), 0);
794 assertEquals(od.getBoxHeight(), boxHeight);
795 assertEquals(od.getBoxWidth(), boxWidth);
796 assertEquals(vpranges.getStartRes(), 0);
797 assertEquals(vpranges.getStartSeq(), 0);
799 // hide rows at start and check updated box position is correct
800 // changes boxY but not boxheight
801 int lastHiddenRow = 30;
802 hideSequences(0, lastHiddenRow);
804 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
805 assertEquals(od.getBoxX(), 0);
806 assertEquals(od.getBoxY(),
807 Math.round((float) (lastHiddenRow + 1)
808 * od.getSequencesHeight() / alheight));
809 assertEquals(od.getBoxWidth(), boxWidth);
810 assertEquals(od.getBoxHeight(), boxHeight);
812 // click in hidden rows - same result
813 mouseClick(od, 0, 0);
814 assertEquals(od.getBoxX(), 0);
817 Math.round((float) (lastHiddenRow + 1)
818 * od.getSequencesHeight() / alheight));
819 assertEquals(od.getBoxWidth(), boxWidth);
820 assertEquals(od.getBoxHeight(), boxHeight);
822 // click below hidden rows
823 mouseClick(od, 0, 150 + boxHeight/2);
824 assertEquals(od.getBoxX(), 0);
825 assertEquals(od.getBoxY(), 150);
826 assertEquals(od.getBoxWidth(), boxWidth);
827 assertEquals(od.getBoxHeight(), boxHeight);
831 * Test setting of the box position, when there are hidden rows at the middle
834 @Test(groups = { "Functional" })
835 public void testFromMouseWithHiddenRowsInMiddle()
837 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
839 assertEquals(od.getBoxX(), 0);
840 assertEquals(od.getBoxY(), 0);
841 assertEquals(od.getBoxWidth(), boxWidth);
842 assertEquals(od.getBoxHeight(), boxHeight);
843 assertEquals(vpranges.getStartRes(), 0);
844 assertEquals(vpranges.getStartSeq(), 0);
846 // hide rows in middle and check updated box position is correct
848 int firstHiddenRow = 50;
849 int lastHiddenRow = 54;
850 hideSequences(firstHiddenRow, lastHiddenRow);
852 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
854 assertEquals(od.getBoxX(), 0);
855 assertEquals(od.getBoxY(), 0);
856 assertEquals(od.getBoxWidth(), boxWidth);
857 assertEquals(od.getBoxHeight(), boxHeight);
859 // click above hidden rows, so that box overlaps
860 int rowpos = 35; // row value in residues
861 int centrepos = 43; // centre row
863 Math.round((float) centrepos * od.getSequencesHeight()
865 assertEquals(od.getBoxX(), 0);
866 assertEquals(od.getBoxY(),
868 (float) rowpos * od.getSequencesHeight() / alheight));
869 assertEquals(od.getBoxWidth(), boxWidth);
873 + Math.round((float) (lastHiddenRow - firstHiddenRow + 1)
874 * od.getSequencesHeight() / alheight));
878 * Test setting of the box position, when there are hidden rows at the end of
881 @Test(groups = { "Functional" })
882 public void testFromMouseWithHiddenRowsAtEnd()
884 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
885 assertEquals(od.getBoxX(), 0);
886 assertEquals(od.getBoxY(), 0);
887 assertEquals(od.getBoxWidth(), boxWidth);
888 assertEquals(od.getBoxHeight(), boxHeight);
889 assertEquals(vpranges.getStartRes(), 0);
890 assertEquals(vpranges.getStartSeq(), 0);
892 // hide rows at end and check updated box position is correct
894 int firstHidden = 500;
895 int lastHidden = 524;
896 hideSequences(firstHidden, lastHidden);
898 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
899 assertEquals(od.getBoxX(), 0);
900 assertEquals(od.getBoxY(), 0);
901 assertEquals(od.getBoxWidth(), boxWidth);
902 assertEquals(od.getBoxHeight(), boxHeight);
904 // click above hidden rows, no overlap
905 int ypos = 40 + viewHeight / 2; // top is row 40
907 Math.round((float) ypos * od.getSequencesHeight() / alheight));
908 assertEquals(od.getBoxX(), 0);
909 assertEquals(od.getBoxY(),
910 Math.round((float) 40 * od.getSequencesHeight() / alheight));
911 assertEquals(od.getBoxWidth(), boxWidth);
912 assertEquals(od.getBoxHeight(), boxHeight);
914 // click above hidden rows so box overlaps
915 // boxY moved upwards, boxHeight remains same
916 ypos = 497 + viewHeight / 2; // row 497
918 Math.round((float) ypos * od.getSequencesHeight() / alheight));
919 assertEquals(od.getBoxX(), 0);
922 Math.round((float) (firstHidden - viewHeight)
923 * od.getSequencesHeight() / alheight));
924 assertEquals(od.getBoxWidth(), boxWidth);
925 assertEquals(od.getBoxHeight(), boxHeight);
927 // click within hidden rows
928 ypos = 505 + boxHeight / 2;
930 Math.round((float) ypos * od.getSequencesHeight() / alheight));
931 assertEquals(od.getBoxX(), 0);
934 Math.round((firstHidden - viewHeight) * od.getSequencesHeight()
936 assertEquals(od.getBoxWidth(), boxWidth);
937 assertEquals(od.getBoxHeight(), boxHeight);
941 * Move viewport horizontally: startRes + previous width gives new horizontal extent. Vertical extent stays the same.
943 private void moveViewportH(int startRes)
945 vpranges.setViewportStartAndWidth(startRes, viewWidth);
946 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
950 * Move viewport vertically: startSeq and endSeq give new vertical extent. Horizontal extent stays the same.
952 private void moveViewportV(int startSeq)
954 vpranges.setViewportStartAndHeight(startSeq, viewHeight);
955 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
959 * Move viewport horizontally and vertically.
961 private void moveViewport(int startRes, int startSeq)
963 vpranges.setViewportStartAndWidth(startRes, viewWidth);
964 vpranges.setViewportStartAndHeight(startSeq, viewHeight);
965 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
969 * Mouse click as position x,y in overview window
971 private void mouseClick(OverviewDimensions od, int x, int y)
973 od.updateViewportFromMouse(x, y, al.getHiddenSequences(), hiddenCols);
975 // updates require an OverviewPanel to exist which it doesn't here
976 // so call setBoxPosition() as it would be called by the AlignmentPanel
978 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
982 * Test that the box is positioned with the centre at xpos, ypos
983 * and with the original width and height
985 private void testBoxIsAtClickPoint(int xpos, int ypos)
987 mouseClick(od, xpos, ypos);
988 assertEquals(od.getBoxX() + od.getBoxWidth() / 2, xpos);
989 assertEquals(od.getBoxY() + od.getBoxHeight() / 2, ypos);
990 assertEquals(od.getBoxWidth(), boxWidth);
991 assertEquals(od.getBoxHeight(), boxHeight);
996 * Hide sequences between start and end
998 private void hideSequences(int start, int end)
1000 SequenceI[] allseqs = al.getSequencesArray();
1001 SequenceGroup theseSeqs = new SequenceGroup();
1003 for (int i = start; i <= end; i++)
1005 theseSeqs.addSequence(allseqs[i], false);
1006 al.getHiddenSequences().hideSequence(allseqs[i]);
1009 hiddenRepSequences.put(allseqs[start], theseSeqs);