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;
24 import static org.testng.Assert.assertFalse;
25 import static org.testng.Assert.assertTrue;
27 import jalview.analysis.AlignmentGenerator;
28 import jalview.datamodel.Alignment;
29 import jalview.datamodel.AlignmentI;
30 import jalview.datamodel.ColumnSelection;
31 import jalview.datamodel.HiddenColumns;
32 import jalview.datamodel.Sequence;
33 import jalview.datamodel.SequenceCollectionI;
34 import jalview.datamodel.SequenceGroup;
35 import jalview.datamodel.SequenceI;
37 import java.util.Hashtable;
39 import org.testng.annotations.AfterClass;
40 import org.testng.annotations.BeforeClass;
41 import org.testng.annotations.BeforeMethod;
42 import org.testng.annotations.Test;
44 @Test(singleThreaded = true)
45 public class OverviewDimensionsHideHiddenTest
49 OverviewDimensionsHideHidden od;
51 // cached widths and heights
59 ViewportRanges vpranges;
61 Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences = new Hashtable<>();
63 HiddenColumns hiddenCols = new HiddenColumns();
65 @BeforeClass(alwaysRun = true)
66 public void setUpAlignment()
68 // create random alignment
69 AlignmentGenerator gen = new AlignmentGenerator(false);
70 al = gen.generate(157, 525, 123, 5, 5);
73 @BeforeMethod(alwaysRun = true)
76 if (!hiddenRepSequences.isEmpty())
78 al.getHiddenSequences().showAll(hiddenRepSequences);
80 ColumnSelection colsel = new ColumnSelection();
81 hiddenCols.revealAllHiddenColumns(colsel);
83 vpranges = new ViewportRanges(al);
84 vpranges.setViewportStartAndHeight(0, 18);
85 vpranges.setViewportStartAndWidth(0, 63);
87 viewHeight = vpranges.getEndSeq() - vpranges.getStartSeq() + 1;
88 viewWidth = vpranges.getEndRes() - vpranges.getStartRes() + 1;
90 HiddenColumns hiddenCols = new HiddenColumns();
92 od = new OverviewDimensionsHideHidden(vpranges, true);
93 // Initial box sizing - default path through code
94 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
99 // calculate with visible values
100 alheight = vpranges.getVisibleAlignmentHeight();
101 alwidth = vpranges.getVisibleAlignmentWidth();
103 boxWidth = Math.round((float) (vpranges.getEndRes()
104 - vpranges.getStartRes() + 1)
105 * od.getWidth() / alwidth);
106 boxHeight = Math.round((float) (vpranges.getEndSeq()
107 - vpranges.getStartSeq() + 1)
108 * od.getSequencesHeight() / alheight);
111 @AfterClass(alwaysRun = true)
112 public void cleanUp()
118 * Test that the OverviewDimensions constructor sets width and height
121 @Test(groups = { "Functional" })
122 public void testConstructor()
124 SequenceI seqa = new Sequence("Seq1", "ABC");
125 SequenceI seqb = new Sequence("Seq2", "ABC");
126 SequenceI seqc = new Sequence("Seq3", "ABC");
127 SequenceI seqd = new Sequence("Seq4", "ABC");
128 SequenceI seqe = new Sequence("Seq5",
129 "ABCABCABCABCABCABCABCABCBACBACBACBAC");
131 int defaultGraphHeight = 20;
134 int maxSeqHeight = 300;
135 int minSeqHeight = 40;
137 // test for alignment with width > height
138 SequenceI[] seqs1 = new SequenceI[] { seqa, seqb };
139 Alignment al1 = new Alignment(seqs1);
140 ViewportRanges props = new ViewportRanges(al1);
142 OverviewDimensions od = new OverviewDimensionsHideHidden(props, true);
143 int scaledHeight = 267;
144 assertEquals(od.getGraphHeight(), defaultGraphHeight);
145 assertEquals(od.getSequencesHeight(), scaledHeight);
146 assertEquals(od.getWidth(), maxWidth);
147 assertEquals(od.getHeight(), scaledHeight + defaultGraphHeight);
149 // test for alignment with width < height
150 SequenceI[] seqs2 = new SequenceI[] { seqa, seqb, seqc, seqd };
151 Alignment al2 = new Alignment(seqs2);
152 props = new ViewportRanges(al2);
154 od = new OverviewDimensionsHideHidden(props, true);
155 int scaledWidth = 300;
156 assertEquals(od.getGraphHeight(), defaultGraphHeight);
157 assertEquals(od.getSequencesHeight(), maxSeqHeight);
158 assertEquals(od.getWidth(), scaledWidth);
159 assertEquals(od.getHeight(), scaledWidth + defaultGraphHeight);
161 // test for alignment with width > height and sequence height scaled below
163 SequenceI[] seqs3 = new SequenceI[] { seqe };
164 Alignment al3 = new Alignment(seqs3);
165 props = new ViewportRanges(al3);
167 od = new OverviewDimensionsHideHidden(props, true);
168 assertEquals(od.getGraphHeight(), defaultGraphHeight);
169 assertEquals(od.getSequencesHeight(), minSeqHeight);
170 assertEquals(od.getWidth(), maxWidth);
171 assertEquals(od.getHeight(), minSeqHeight + defaultGraphHeight);
173 // test for alignment with width < height and width scaled below min value
174 SequenceI[] seqs4 = new SequenceI[] { seqa, seqb, seqc, seqd, seqa,
175 seqb, seqc, seqd, seqa, seqb, seqc, seqd, seqa, seqb, seqc, seqd };
176 Alignment al4 = new Alignment(seqs4);
177 props = new ViewportRanges(al4);
179 od = new OverviewDimensionsHideHidden(props, true);
180 assertEquals(od.getGraphHeight(), defaultGraphHeight);
181 assertEquals(od.getSequencesHeight(), maxSeqHeight);
182 assertEquals(od.getWidth(), minWidth);
183 assertEquals(od.getHeight(), maxSeqHeight + defaultGraphHeight);
185 Alignment al5 = new Alignment(seqs4);
186 props = new ViewportRanges(al5);
188 od = new OverviewDimensionsHideHidden(props, false);
189 assertEquals(od.getGraphHeight(), 0);
190 assertEquals(od.getSequencesHeight(), maxSeqHeight);
191 assertEquals(od.getWidth(), minWidth);
192 assertEquals(od.getHeight(), maxSeqHeight);
196 * Test that validation after mouse adjustments to boxX and boxY sets box
197 * dimensions and scroll values correctly, when there are no hidden rows or
200 @Test(groups = { "Functional" })
201 public void testSetBoxFromMouseClick()
203 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
204 assertEquals(od.getBoxX(), 0);
205 assertEquals(od.getBoxY(), 0);
206 assertEquals(od.getBoxWidth(), boxWidth);
207 assertEquals(vpranges.getStartRes(), 0);
208 assertEquals(vpranges.getStartSeq(), 0);
210 // negative boxX value reset to 0
211 mouseClick(od, -5, 10);
212 assertEquals(od.getBoxX(), 0);
213 assertEquals(od.getBoxWidth(), boxWidth);
214 assertEquals(od.getBoxHeight(), boxHeight);
215 assertEquals(vpranges.getStartSeq(),
216 Math.round((float) 10 * alheight / od.getSequencesHeight()));
217 assertEquals(vpranges.getStartRes(), 0);
219 // negative boxY value reset to 0
220 mouseClick(od, 6, -2);
221 assertEquals(od.getBoxY(), 0);
222 assertEquals(od.getBoxWidth(), boxWidth);
223 assertEquals(od.getBoxHeight(), boxHeight);
224 assertEquals(vpranges.getStartRes(),
225 Math.round((float) 6 * alwidth / od.getWidth()));
226 assertEquals(vpranges.getStartSeq(), 0);
228 // overly large boxX value reset to width-boxWidth
229 mouseClick(od, 100, 6);
230 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
231 assertEquals(od.getBoxY(), 6);
232 assertEquals(od.getBoxWidth(), boxWidth);
233 assertEquals(od.getBoxHeight(), boxHeight);
234 assertEquals(vpranges.getStartRes(),
235 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
237 vpranges.getStartSeq(),
238 Math.round((float) od.getBoxY() * alheight
239 / od.getSequencesHeight()));
241 // overly large boxY value reset to sequenceHeight - boxHeight
242 mouseClick(od, 10, 520);
243 assertEquals(od.getBoxX(), 10);
244 assertEquals(od.getBoxY(), od.getSequencesHeight() - od.getBoxHeight());
245 assertEquals(od.getBoxWidth(), boxWidth);
246 assertEquals(od.getBoxHeight(), boxHeight);
247 assertEquals(vpranges.getStartRes(),
248 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
250 // here (float) od.getBoxY() * alheight / od.getSequencesHeight() = 507.5
251 // and round rounds to 508; however we get 507 working with row values
252 // hence the subtraction of 1
254 vpranges.getStartSeq(),
255 Math.round((float) od.getBoxY() * alheight
256 / od.getSequencesHeight()) - 1);
258 // click past end of alignment, as above
259 mouseClick(od, 3000, 5);
260 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
261 assertEquals(od.getBoxWidth(), boxWidth);
262 assertEquals(od.getBoxHeight(), boxHeight);
263 assertEquals(vpranges.getStartRes(),
264 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
266 vpranges.getStartSeq(),
267 Math.round((float) od.getBoxY() * alheight
268 / od.getSequencesHeight()));
270 // move viewport so startRes non-zero and then mouseclick
273 // click at viewport position
274 int oldboxx = od.getBoxX();
275 int oldboxy = od.getBoxY();
276 mouseClick(od, od.getBoxX() + 5, od.getBoxY() + 2);
277 assertEquals(od.getBoxX(), oldboxx + 5);
278 assertEquals(od.getBoxWidth(), boxWidth);
279 assertEquals(od.getBoxHeight(), boxHeight);
280 assertEquals(vpranges.getStartRes(),
281 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
282 assertEquals(od.getBoxY(), oldboxy + 2);
284 vpranges.getStartSeq(),
285 Math.round((float) od.getBoxY() * alheight
286 / od.getSequencesHeight()));
288 // click at top corner
289 mouseClick(od, 0, 0);
290 assertEquals(od.getBoxX(), 0);
291 assertEquals(vpranges.getStartRes(), 0);
292 assertEquals(od.getBoxY(), 0);
293 assertEquals(vpranges.getStartSeq(), 0);
294 assertEquals(od.getBoxWidth(), boxWidth);
295 assertEquals(od.getBoxHeight(), boxHeight);
299 * Test setting of the box position, when there are hidden cols at the start
302 @Test(groups = { "Functional" })
303 public void testFromMouseWithHiddenColsAtStart()
305 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
306 assertEquals(od.getBoxX(), 0);
307 assertEquals(od.getBoxY(), 0);
308 assertEquals(od.getBoxWidth(), boxWidth);
309 assertEquals(vpranges.getStartRes(), 0);
310 assertEquals(vpranges.getStartSeq(), 0);
312 // hide cols at start and check updated box position is correct
313 int lastHiddenCol = 30;
314 hiddenCols.hideColumns(0, lastHiddenCol);
316 testBoxIsAtClickPoint(0, 0);
318 // click to right of hidden columns, box moves to click point
319 testBoxIsAtClickPoint(40, 0);
320 assertEquals(vpranges.getStartSeq(), 0);
321 assertEquals(vpranges.getStartRes(),
322 Math.round((float) 40 * alwidth / od.getWidth()));
324 // click to right of hidden columns such that box runs over right hand side
326 // box position is adjusted away from the edge
327 // overly large boxX value reset to width-boxWidth
329 mouseClick(od, xpos, 0);
330 assertEquals(od.getBoxX(), Math.round(od.getWidth()) - boxWidth);
331 assertEquals(od.getBoxY(), 0);
332 assertEquals(od.getBoxWidth(), boxWidth);
333 assertEquals(od.getBoxHeight(), boxHeight);
334 assertEquals(vpranges.getStartRes(),
335 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
336 assertEquals(vpranges.getStartSeq(), 0);
340 * Test setting of the box position, when there are hidden cols in the middle
343 @Test(groups = { "Functional" })
344 public void testFromMouseWithHiddenColsInMiddle()
346 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
347 testBoxIsAtClickPoint(0, 0);
348 assertEquals(od.getBoxX(), 0);
349 assertEquals(od.getBoxY(), 0);
350 assertEquals(od.getBoxWidth(), boxWidth);
351 assertEquals(vpranges.getStartRes(), 0);
352 assertEquals(vpranges.getStartSeq(), 0);
354 // hide columns 63-73, no change to box position or dimensions
355 int firstHidden = 63;
357 hiddenCols.hideColumns(firstHidden, lastHidden);
359 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
360 testBoxIsAtClickPoint(0, 0);
361 assertEquals(od.getBoxX(), 0);
362 assertEquals(od.getBoxY(), 0);
363 assertEquals(od.getBoxWidth(), boxWidth);
364 assertEquals(vpranges.getStartRes(), 0);
365 assertEquals(vpranges.getStartSeq(), 0);
367 // move box so that it overlaps with hidden cols on one side
368 // box width, boxX and scrollCol as for unhidden case
369 int xpos = 55 - boxWidth; // 55 is position in overview approx halfway
370 // between cols 60 and 70
371 mouseClick(od, xpos, 0);
372 testBoxIsAtClickPoint(xpos, 0);
373 assertEquals(vpranges.getStartRes(),
374 Math.round(xpos * alwidth / od.getWidth()));
375 assertEquals(vpranges.getStartSeq(), 0);
377 // move box so that it completely covers hidden cols
378 // box width, boxX and scrollCol as for unhidden case
380 mouseClick(od, xpos, 0);
381 testBoxIsAtClickPoint(xpos, 0);
382 assertEquals(vpranges.getStartRes(),
383 Math.round((float) xpos * alwidth / od.getWidth()));
384 assertEquals(vpranges.getStartSeq(), 0);
386 // move box so boxX is in hidden cols, box overhangs at right
387 // boxX and scrollCol at left of hidden area, box width unchanged
389 mouseClick(od, xpos, 0);
390 testBoxIsAtClickPoint(xpos, 0);
391 assertEquals(vpranges.getStartRes(),
392 Math.round((float) xpos * alwidth / od.getWidth()));
393 assertEquals(vpranges.getStartSeq(), 0);
395 // move box so boxX is to right of hidden cols, but does not go beyond full
396 // width of alignment
397 // box width, boxX and scrollCol all as for non-hidden case
399 testBoxIsAtClickPoint(xpos, 0);
400 assertEquals(vpranges.getStartSeq(), 0);
401 assertEquals(vpranges.getStartRes(),
402 Math.round(xpos * alwidth / od.getWidth()));
404 // move box so it goes beyond full width of alignment
405 // boxX, scrollCol adjusted back, box width normal
407 mouseClick(od, xpos, 0);
408 assertEquals(od.getBoxX(), Math.round(od.getWidth()) - boxWidth);
409 assertEquals(od.getBoxY(), 0);
410 assertEquals(od.getBoxWidth(), boxWidth);
411 assertEquals(od.getBoxHeight(), boxHeight);
412 assertEquals(vpranges.getStartRes(),
413 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
414 assertEquals(vpranges.getStartSeq(), 0);
419 * Test setting of the box position, when there are hidden cols at the end of
422 @Test(groups = { "Functional" })
423 public void testFromMouseWithHiddenColsAtEnd()
425 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
426 assertEquals(od.getBoxX(), 0);
427 assertEquals(od.getBoxY(), 0);
428 assertEquals(od.getBoxWidth(), boxWidth);
429 assertEquals(vpranges.getStartRes(), 0);
430 assertEquals(vpranges.getStartSeq(), 0);
432 // hide columns 140-164, no change to box position or dimensions
433 int firstHidden = 140;
434 int lastHidden = 164;
435 hiddenCols.hideColumns(firstHidden, lastHidden);
436 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
437 assertEquals(od.getBoxX(), 0);
438 assertEquals(od.getBoxY(), 0);
439 assertEquals(od.getBoxWidth(), boxWidth);
440 assertEquals(vpranges.getStartRes(), 0);
441 assertEquals(vpranges.getStartSeq(), 0);
443 // click to left of hidden cols, without overlapping
444 // boxX, scrollCol and width as normal
446 testBoxIsAtClickPoint(xpos, 0);
447 assertEquals(vpranges.getStartSeq(), 0);
448 assertEquals(vpranges.getStartRes(),
449 Math.round((float) xpos * alwidth / od.getWidth()));
451 // click to left of hidden cols, with overlap
452 // boxX and scrollCol adjusted for hidden cols, width normal
453 xpos = Math.round((float) 145 * od.getWidth() / alwidth) - boxWidth;
454 mouseClick(od, xpos, 0);
455 testBoxIsAtClickPoint(xpos, 0);
456 assertEquals(vpranges.getStartRes(),
457 Math.round((float) xpos * alwidth / od.getWidth()));
458 assertEquals(vpranges.getStartSeq(), 0);
460 // click off end of alignment
461 // boxX and scrollCol adjusted backwards, width normal
463 mouseClick(od, xpos, 0);
464 assertEquals(od.getBoxX(), Math.round(od.getWidth()) - boxWidth);
465 assertEquals(od.getBoxY(), 0);
466 assertEquals(od.getBoxWidth(), boxWidth);
467 assertEquals(od.getBoxHeight(), boxHeight);
468 assertEquals(vpranges.getStartRes(),
469 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
470 assertEquals(vpranges.getStartSeq(), 0);
474 * Test that the box position is set correctly when set from the viewport,
475 * with no hidden rows or columns
477 @Test(groups = { "Functional" })
478 public void testSetBoxFromViewport()
480 // move viewport to start of alignment
482 assertEquals(od.getBoxX(), 0);
483 assertEquals(od.getBoxY(), 0);
484 assertEquals(od.getBoxWidth(), boxWidth);
485 assertEquals(od.getBoxHeight(), boxHeight);
487 // move viewport to right
489 assertEquals(od.getBoxX(),
490 Math.round((float) 70 * od.getWidth() / alwidth));
491 assertEquals(od.getBoxY(), 0);
492 assertEquals(od.getBoxWidth(), boxWidth);
493 assertEquals(od.getBoxHeight(), boxHeight);
495 // move viewport down
497 assertEquals(od.getBoxX(),
498 Math.round((float) 70 * od.getWidth() / alwidth));
499 assertEquals(od.getBoxY(),
500 Math.round(100 * od.getSequencesHeight() / alheight));
501 assertEquals(od.getBoxWidth(), boxWidth);
502 assertEquals(od.getBoxHeight(), boxHeight);
504 // move viewport to bottom right
505 moveViewport(98, 508);
506 assertEquals(od.getBoxX(),
507 Math.round((float) 98 * od.getWidth() / alwidth));
508 assertEquals(od.getBoxY(),
509 Math.round((float) 508 * od.getSequencesHeight() / alheight));
510 assertEquals(od.getBoxWidth(), boxWidth);
511 assertEquals(od.getBoxHeight(), boxHeight);
515 * Test that the box position is set correctly when there are hidden columns
518 @Test(groups = { "Functional" })
519 public void testSetBoxFromViewportHiddenColsAtStart()
523 hiddenCols.hideColumns(firstHidden, lastHidden);
525 // move viewport to start of alignment
527 assertEquals(od.getBoxX(), 0);
528 assertEquals(od.getBoxY(), 0);
529 assertEquals(od.getBoxWidth(), boxWidth);
530 assertEquals(od.getBoxHeight(), boxHeight);
532 // move viewport to end of alignment - need to make startRes by removing
533 // hidden cols because of how viewport/overview are implemented
534 moveViewport(98 - lastHidden - 1, 0);
535 assertEquals(od.getBoxX(),
536 Math.round((float) (98 - lastHidden - 1) * od.getWidth()
538 assertEquals(od.getBoxY(), 0);
539 assertEquals(od.getBoxWidth(), boxWidth);
540 assertEquals(od.getBoxHeight(), boxHeight);
544 * Test that the box position is set correctly when there are hidden columns
547 @Test(groups = { "Functional" })
548 public void testSetBoxFromViewportHiddenColsInMiddle()
550 int firstHidden = 68;
552 hiddenCols.hideColumns(firstHidden, lastHidden);
554 // move viewport before hidden columns
557 assertEquals(od.getBoxX(),
558 Math.round((float) 3 * od.getWidth() / alwidth));
559 assertEquals(od.getBoxY(), 0);
560 assertEquals(od.getBoxWidth(), boxWidth);
561 assertEquals(od.getBoxHeight(), boxHeight);
563 // move viewport to left of hidden columns with overlap
565 assertEquals(od.getBoxX(),
566 Math.round((float) 10 * od.getWidth() / alwidth));
567 assertEquals(od.getBoxY(), 0);
568 assertEquals(od.getBoxWidth(), boxWidth);
569 assertEquals(od.getBoxHeight(), boxHeight);
571 // move viewport to straddle hidden columns
573 assertEquals(od.getBoxX(),
574 Math.round((float) 63 * od.getWidth() / alwidth));
575 assertEquals(od.getBoxY(), 0);
576 assertEquals(od.getBoxWidth(), boxWidth);
577 assertEquals(od.getBoxHeight(), boxHeight);
579 // move viewport to right of hidden columns, no overlap
580 moveViewport(80 - (lastHidden - firstHidden + 1), 0);
581 assertEquals(od.getBoxX(),
582 Math.round((float) (80 - (lastHidden - firstHidden + 1))
583 * od.getWidth() / alwidth));
584 assertEquals(od.getBoxY(), 0);
585 assertEquals(od.getBoxWidth(), boxWidth);
586 assertEquals(od.getBoxHeight(), boxHeight);
591 * Test that the box position is set correctly when there are hidden columns
594 @Test(groups = { "Functional" })
595 public void testSetBoxFromViewportHiddenColsAtEnd()
597 int firstHidden = 152;
598 int lastHidden = 164;
599 hiddenCols.hideColumns(firstHidden, lastHidden);
601 // move viewport before hidden columns
603 assertEquals(od.getBoxX(),
604 Math.round((float) 3 * od.getWidth() / alwidth));
605 assertEquals(od.getBoxY(), 0);
606 assertEquals(od.getBoxWidth(), boxWidth);
607 assertEquals(od.getBoxHeight(), boxHeight);
609 // move viewport to hidden columns
610 // viewport can't actually extend into hidden cols,
611 // so move to the far right edge of the viewport
612 moveViewport(firstHidden - viewWidth, 0);
613 assertEquals(od.getBoxX(),
614 Math.round((float) (firstHidden - viewWidth)
615 * od.getWidth() / alwidth));
616 assertEquals(od.getBoxY(), 0);
617 assertEquals(od.getBoxWidth(), boxWidth);
618 assertEquals(od.getBoxHeight(), boxHeight);
622 * Test that the box position is set correctly when there are hidden rows at
625 @Test(groups = { "Functional" })
626 public void testSetBoxFromViewportHiddenRowsAtStart()
630 hideSequences(firstHidden, lastHidden);
632 // calculate with visible values
633 alheight = vpranges.getVisibleAlignmentHeight();
634 alwidth = vpranges.getVisibleAlignmentWidth();
636 boxWidth = Math.round((float) (vpranges.getEndRes()
637 - vpranges.getStartRes() + 1)
638 * od.getWidth() / alwidth);
639 boxHeight = Math.round((float) (vpranges.getEndSeq()
640 - vpranges.getStartSeq() + 1)
641 * od.getSequencesHeight() / alheight);
643 // move viewport to start of alignment:
644 // box moves to below hidden rows, height remains same
646 assertEquals(od.getBoxX(), 0);
647 assertEquals(od.getBoxY(), 0);
648 assertEquals(od.getBoxWidth(), boxWidth);
649 assertEquals(od.getBoxHeight(), boxHeight);
651 // move viewport to end of alignment
652 moveViewport(0, 525 - viewHeight - lastHidden - 1);
653 assertEquals(od.getBoxX(), 0);
656 Math.round((float) (525 - viewHeight - lastHidden - 1)
657 * od.getSequencesHeight()
659 assertEquals(od.getBoxWidth(), boxWidth);
660 assertEquals(od.getBoxHeight(), boxHeight);
664 * Test that the box position is set correctly when there are hidden rows in
667 @Test(groups = { "Functional" })
668 public void testSetBoxFromViewportHiddenRowsInMiddle()
670 int firstHidden = 200;
671 int lastHidden = 210;
672 hideSequences(firstHidden, lastHidden);
674 // calculate with visible values
675 alheight = vpranges.getVisibleAlignmentHeight();
676 alwidth = vpranges.getVisibleAlignmentWidth();
678 boxWidth = Math.round((float) (vpranges.getEndRes()
679 - vpranges.getStartRes() + 1)
680 * od.getWidth() / alwidth);
681 boxHeight = Math.round((float) (vpranges.getEndSeq()
682 - vpranges.getStartSeq() + 1)
683 * od.getSequencesHeight() / alheight);
685 // move viewport to start of alignment:
686 // box, height etc as in non-hidden case
688 assertEquals(od.getBoxX(), 0);
689 assertEquals(od.getBoxY(), 0);
690 assertEquals(od.getBoxWidth(), boxWidth);
691 assertEquals(od.getBoxHeight(), boxHeight);
693 // move viewport to straddle hidden rows
694 moveViewport(0, 198);
695 assertEquals(od.getBoxX(), 0);
696 assertEquals(od.getBoxY(), Math.round ((float)198 * od.getSequencesHeight()
698 assertEquals(od.getBoxWidth(), boxWidth);
699 assertEquals(od.getBoxHeight(), boxHeight);
703 * Test that the box position is set correctly when there are hidden rows at
706 @Test(groups = { "Functional" })
707 public void testSetBoxFromViewportHiddenRowsAtEnd()
709 int firstHidden = 500;
710 int lastHidden = 524;
711 hideSequences(firstHidden, lastHidden);
713 // calculate with visible values
714 alheight = vpranges.getVisibleAlignmentHeight();
715 alwidth = vpranges.getVisibleAlignmentWidth();
717 boxWidth = Math.round((float) (vpranges.getEndRes()
718 - vpranges.getStartRes() + 1)
719 * od.getWidth() / alwidth);
720 boxHeight = Math.round((float) (vpranges.getEndSeq()
721 - vpranges.getStartSeq() + 1)
722 * od.getSequencesHeight() / alheight);
724 // move viewport to start of alignment:
725 // box, height etc as in non-hidden case
727 assertEquals(od.getBoxX(), 0);
728 assertEquals(od.getBoxY(), 0);
729 assertEquals(od.getBoxWidth(), boxWidth);
730 assertEquals(od.getBoxHeight(), boxHeight);
732 // move viewport to end of alignment
733 // viewport sits above hidden rows and does not include them
734 moveViewport(0, firstHidden - viewHeight - 1);
735 assertEquals(od.getBoxX(), 0);
738 Math.round((float) (firstHidden - viewHeight - 1)
739 * od.getSequencesHeight() / alheight));
740 assertEquals(od.getBoxWidth(), boxWidth);
741 assertEquals(od.getBoxHeight(), boxHeight);
746 * Test setting of the box position, when there are hidden rows at the start
749 @Test(groups = { "Functional" })
750 public void testFromMouseWithHiddenRowsAtStart()
752 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
753 assertEquals(od.getBoxX(), 0);
754 assertEquals(od.getBoxY(), 0);
755 assertEquals(od.getBoxHeight(), boxHeight);
756 assertEquals(od.getBoxWidth(), boxWidth);
757 assertEquals(vpranges.getStartRes(), 0);
758 assertEquals(vpranges.getStartSeq(), 0);
760 // hide rows at start and check updated box position is correct
761 int lastHiddenRow = 30;
762 hideSequences(0, lastHiddenRow);
764 // calculate with visible values
765 alheight = vpranges.getVisibleAlignmentHeight();
766 alwidth = vpranges.getVisibleAlignmentWidth();
768 boxWidth = Math.round((float) (vpranges.getEndRes()
769 - vpranges.getStartRes() + 1)
770 * od.getWidth() / alwidth);
771 boxHeight = Math.round((float) (vpranges.getEndSeq()
772 - vpranges.getStartSeq() + 1)
773 * od.getSequencesHeight() / alheight);
775 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
776 assertEquals(od.getBoxX(), 0);
777 assertEquals(od.getBoxY(), 0);
778 assertEquals(od.getBoxWidth(), boxWidth);
779 assertEquals(od.getBoxHeight(), boxHeight);
781 // click below hidden rows
782 mouseClick(od, 0, 150);
783 assertEquals(od.getBoxX(), 0);
784 assertEquals(od.getBoxY(), 150);
785 assertEquals(od.getBoxWidth(), boxWidth);
786 assertEquals(od.getBoxHeight(), boxHeight);
790 * Test setting of the box position, when there are hidden rows at the middle
793 @Test(groups = { "Functional" })
794 public void testFromMouseWithHiddenRowsInMiddle()
796 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
798 assertEquals(od.getBoxX(), 0);
799 assertEquals(od.getBoxY(), 0);
800 assertEquals(od.getBoxWidth(), boxWidth);
801 assertEquals(od.getBoxHeight(), boxHeight);
802 assertEquals(vpranges.getStartRes(), 0);
803 assertEquals(vpranges.getStartSeq(), 0);
805 // hide rows in middle and check updated box position is correct
807 int firstHiddenRow = 50;
808 int lastHiddenRow = 54;
809 hideSequences(firstHiddenRow, lastHiddenRow);
811 // calculate with visible values
812 alheight = vpranges.getVisibleAlignmentHeight();
813 alwidth = vpranges.getVisibleAlignmentWidth();
815 boxWidth = Math.round((float) (vpranges.getEndRes()
816 - vpranges.getStartRes() + 1)
817 * od.getWidth() / alwidth);
818 boxHeight = Math.round((float) (vpranges.getEndSeq()
819 - vpranges.getStartSeq() + 1)
820 * od.getSequencesHeight() / alheight);
822 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
824 assertEquals(od.getBoxX(), 0);
825 assertEquals(od.getBoxY(), 0);
826 assertEquals(od.getBoxWidth(), boxWidth);
827 assertEquals(od.getBoxHeight(), boxHeight);
829 // click above hidden rows, so that box overlaps
830 int ypos = 35; // column value in residues
832 Math.round((float) ypos * od.getSequencesHeight() / alheight));
833 assertEquals(od.getBoxX(), 0);
834 assertEquals(od.getBoxY(),
835 Math.round((float) ypos * od.getSequencesHeight() / alheight));
836 assertEquals(od.getBoxWidth(), boxWidth);
837 assertEquals(od.getBoxHeight(), boxHeight);
839 // click so that box straddles hidden rows
840 ypos = 44; // column value in residues
842 Math.round((float) ypos * od.getSequencesHeight() / alheight));
843 assertEquals(od.getBoxX(), 0);
844 assertEquals(od.getBoxY(),
845 Math.round((float) ypos * od.getSequencesHeight() / alheight));
846 assertEquals(od.getBoxWidth(), boxWidth);
847 assertEquals(od.getBoxHeight(), boxHeight);
851 * Test setting of the box position, when there are hidden rows at the end of
854 @Test(groups = { "Functional" })
855 public void testFromMouseWithHiddenRowsAtEnd()
857 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
858 assertEquals(od.getBoxX(), 0);
859 assertEquals(od.getBoxY(), 0);
860 assertEquals(od.getBoxWidth(), boxWidth);
861 assertEquals(od.getBoxHeight(), boxHeight);
862 assertEquals(vpranges.getStartRes(), 0);
863 assertEquals(vpranges.getStartSeq(), 0);
865 // hide rows at end and check updated box position is correct
867 int firstHidden = 500;
868 int lastHidden = 524;
869 hideSequences(firstHidden, lastHidden);
871 // calculate with visible values
872 alheight = vpranges.getVisibleAlignmentHeight();
873 alwidth = vpranges.getVisibleAlignmentWidth();
875 boxWidth = Math.round((float) (vpranges.getEndRes()
876 - vpranges.getStartRes() + 1)
877 * od.getWidth() / alwidth);
878 boxHeight = Math.round((float) (vpranges.getEndSeq()
879 - vpranges.getStartSeq() + 1)
880 * od.getSequencesHeight() / alheight);
882 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
883 assertEquals(od.getBoxX(), 0);
884 assertEquals(od.getBoxY(), 0);
885 assertEquals(od.getBoxWidth(), boxWidth);
886 assertEquals(od.getBoxHeight(), boxHeight);
888 // click above hidden rows
889 int ypos = 40; // row 40
891 Math.round((float) ypos * od.getSequencesHeight() / alheight));
892 assertEquals(od.getBoxX(), 0);
893 assertEquals(od.getBoxY(),
894 Math.round((float) ypos * od.getSequencesHeight() / alheight));
895 assertEquals(od.getBoxWidth(), boxWidth);
896 assertEquals(od.getBoxHeight(), boxHeight);
898 // click above hidden rows so box overlaps
899 // boxY, boxHeight remains same
900 ypos = 497; // row 497
902 Math.round((float) ypos * od.getSequencesHeight() / alheight));
903 assertEquals(od.getBoxX(), 0);
906 Math.round((float) firstHidden * od.getSequencesHeight()
909 assertEquals(od.getBoxWidth(), boxWidth);
910 assertEquals(od.getBoxHeight(), boxHeight);
914 * Test the function to determine if a point is in the overview's box or not
916 @Test(groups = { "Functional" })
917 public void testPositionInBox()
919 assertFalse(od.isPositionInBox(0, 0));
920 assertTrue(od.isPositionInBox(10, 9));
921 assertFalse(od.isPositionInBox(0, 9));
922 assertFalse(od.isPositionInBox(9, 0));
923 assertFalse(od.isPositionInBox(75, 20));
927 * Move viewport horizontally: startRes + previous width gives new horizontal extent. Vertical extent stays the same.
929 private void moveViewportH(int startRes)
931 vpranges.setViewportStartAndWidth(startRes, viewWidth);
932 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
936 * Move viewport vertically: startSeq and endSeq give new vertical extent. Horizontal extent stays the same.
938 private void moveViewportV(int startSeq)
940 vpranges.setViewportStartAndHeight(startSeq, viewHeight);
941 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
945 * Move viewport horizontally and vertically.
947 private void moveViewport(int startRes, int startSeq)
949 vpranges.setViewportStartAndWidth(startRes, viewWidth);
950 vpranges.setViewportStartAndHeight(startSeq, viewHeight);
951 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
955 * Mouse click as position x,y in overview window
957 private void mouseClick(OverviewDimensions od, int x, int y)
959 od.updateViewportFromMouse(x, y, al.getHiddenSequences(), hiddenCols);
961 // updates require an OverviewPanel to exist which it doesn't here
962 // so call setBoxPosition() as it would be called by the AlignmentPanel
964 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
968 * Test that the box is positioned with the top left corner at xpos, ypos
969 * and with the original width and height
971 private void testBoxIsAtClickPoint(int xpos, int ypos)
973 mouseClick(od, xpos, ypos);
974 assertEquals(od.getBoxX(), xpos);
975 assertEquals(od.getBoxY(), ypos);
976 assertEquals(od.getBoxWidth(), boxWidth);
977 assertEquals(od.getBoxHeight(), boxHeight);
982 * Hide sequences between start and end
984 private void hideSequences(int start, int end)
986 SequenceI[] allseqs = al.getSequencesArray();
987 SequenceGroup theseSeqs = new SequenceGroup();
989 for (int i = start; i <= end; i++)
991 theseSeqs.addSequence(allseqs[i], false);
992 al.getHiddenSequences().hideSequence(allseqs[i]);
995 hiddenRepSequences.put(allseqs[start], theseSeqs);