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 OverviewDimensionsShowHiddenTest
49 OverviewDimensionsShowHidden od;
51 // cached widths and heights
64 ViewportRanges vpranges;
66 Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences = new Hashtable<>();
68 HiddenColumns hiddenCols = new HiddenColumns();
70 @BeforeClass(alwaysRun = true)
71 public void setUpAlignment()
73 // create random alignment
74 AlignmentGenerator gen = new AlignmentGenerator(false);
75 al = gen.generate(157, 525, 123, 5, 5);
78 @BeforeMethod(alwaysRun = true)
81 if (!hiddenRepSequences.isEmpty())
83 al.getHiddenSequences().showAll(hiddenRepSequences);
85 ColumnSelection colsel = new ColumnSelection();
86 hiddenCols.revealAllHiddenColumns(colsel);
88 vpranges = new ViewportRanges(al);
89 vpranges.setViewportStartAndHeight(0, 18);
90 vpranges.setViewportStartAndWidth(0, 63);
92 viewHeight = vpranges.getEndSeq() - vpranges.getStartSeq() + 1;
93 viewWidth = vpranges.getEndRes() - vpranges.getStartRes() + 1;
95 HiddenColumns hiddenCols = new HiddenColumns();
97 od = new OverviewDimensionsShowHidden(vpranges, true);
98 // Initial box sizing - default path through code
99 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
101 mouseClick(od, 0, 0);
104 // calculate before hidden columns so we get absolute values
105 alheight = vpranges.getAbsoluteAlignmentHeight();
106 alwidth = vpranges.getAbsoluteAlignmentWidth();
108 boxWidth = Math.round(
109 (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
110 * od.getWidth() / alwidth);
111 boxHeight = Math.round(
112 (float) (vpranges.getEndSeq() - vpranges.getStartSeq() + 1)
113 * od.getSequencesHeight() / alheight);
116 @AfterClass(alwaysRun = true)
117 public void cleanUp()
123 * Test that the OverviewDimensions constructor sets width and height
126 @Test(groups = { "Functional" })
127 public void testConstructor()
129 SequenceI seqa = new Sequence("Seq1", "ABC");
130 SequenceI seqb = new Sequence("Seq2", "ABC");
131 SequenceI seqc = new Sequence("Seq3", "ABC");
132 SequenceI seqd = new Sequence("Seq4", "ABC");
133 SequenceI seqe = new Sequence("Seq5",
134 "ABCABCABCABCABCABCABCABCBACBACBACBAC");
136 int defaultGraphHeight = 20;
139 int maxSeqHeight = 300;
140 int minSeqHeight = 40;
142 // test for alignment with width > height
143 SequenceI[] seqs1 = new SequenceI[] { seqa, seqb };
144 Alignment al1 = new Alignment(seqs1);
145 ViewportRanges props = new ViewportRanges(al1);
147 OverviewDimensions od = new OverviewDimensionsShowHidden(props, true);
148 int scaledHeight = 267;
149 assertEquals(od.getGraphHeight(), defaultGraphHeight);
150 assertEquals(od.getSequencesHeight(), scaledHeight);
151 assertEquals(od.getWidth(), maxWidth);
152 assertEquals(od.getHeight(), scaledHeight + defaultGraphHeight);
154 // test for alignment with width < height
155 SequenceI[] seqs2 = new SequenceI[] { seqa, seqb, seqc, seqd };
156 Alignment al2 = new Alignment(seqs2);
157 props = new ViewportRanges(al2);
159 od = new OverviewDimensionsShowHidden(props, true);
160 int scaledWidth = 300;
161 assertEquals(od.getGraphHeight(), defaultGraphHeight);
162 assertEquals(od.getSequencesHeight(), maxSeqHeight);
163 assertEquals(od.getWidth(), scaledWidth);
164 assertEquals(od.getHeight(), scaledWidth + defaultGraphHeight);
166 // test for alignment with width > height and sequence height scaled below
168 SequenceI[] seqs3 = new SequenceI[] { seqe };
169 Alignment al3 = new Alignment(seqs3);
170 props = new ViewportRanges(al3);
172 od = new OverviewDimensionsShowHidden(props, true);
173 assertEquals(od.getGraphHeight(), defaultGraphHeight);
174 assertEquals(od.getSequencesHeight(), minSeqHeight);
175 assertEquals(od.getWidth(), maxWidth);
176 assertEquals(od.getHeight(), minSeqHeight + defaultGraphHeight);
178 // test for alignment with width < height and width scaled below min value
179 SequenceI[] seqs4 = new SequenceI[] { seqa, seqb, seqc, seqd, seqa,
180 seqb, seqc, seqd, seqa, seqb, seqc, seqd, seqa, seqb, seqc, seqd };
181 Alignment al4 = new Alignment(seqs4);
182 props = new ViewportRanges(al4);
184 od = new OverviewDimensionsShowHidden(props, true);
185 assertEquals(od.getGraphHeight(), defaultGraphHeight);
186 assertEquals(od.getSequencesHeight(), maxSeqHeight);
187 assertEquals(od.getWidth(), minWidth);
188 assertEquals(od.getHeight(), maxSeqHeight + defaultGraphHeight);
190 Alignment al5 = new Alignment(seqs4);
191 props = new ViewportRanges(al5);
193 od = new OverviewDimensionsShowHidden(props, false);
194 assertEquals(od.getGraphHeight(), 0);
195 assertEquals(od.getSequencesHeight(), maxSeqHeight);
196 assertEquals(od.getWidth(), minWidth);
197 assertEquals(od.getHeight(), maxSeqHeight);
201 * Test that validation after mouse adjustments to boxX and boxY sets box
202 * dimensions and scroll values correctly, when there are no hidden rows or
205 @Test(groups = { "Functional" })
206 public void testSetBoxFromMouseClick()
208 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
209 assertEquals(od.getBoxX(), 0);
210 assertEquals(od.getBoxY(), 0);
211 assertEquals(od.getBoxWidth(), boxWidth);
212 assertEquals(vpranges.getStartRes(), 0);
213 assertEquals(vpranges.getStartSeq(), 0);
215 // negative boxX value reset to 0
216 mouseClick(od, -5, 10);
217 assertEquals(od.getBoxX(), 0);
218 assertEquals(od.getBoxWidth(), boxWidth);
219 assertEquals(od.getBoxHeight(), boxHeight);
220 assertEquals(vpranges.getStartSeq() + vpranges.getViewportHeight() / 2,
221 Math.round((float) 10 * alheight / od.getSequencesHeight()));
222 assertEquals(vpranges.getStartRes(), 0);
224 // negative boxY value reset to 0
225 mouseClick(od, 6, -2);
226 assertEquals(od.getBoxY(), 0);
227 assertEquals(od.getBoxWidth(), boxWidth);
228 assertEquals(od.getBoxHeight(), boxHeight);
229 assertEquals(vpranges.getStartRes(), 0);
230 assertEquals(vpranges.getStartSeq(), 0);
232 // overly large boxX value reset to width-boxWidth
233 mouseClick(od, 101, 6);
234 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
235 assertEquals(od.getBoxY(), 1);
236 assertEquals(od.getBoxWidth(), boxWidth);
237 assertEquals(od.getBoxHeight(), boxHeight);
238 assertEquals(vpranges.getStartRes(),
239 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
240 assertEquals(vpranges.getStartSeq(), Math.round(
241 (float) od.getBoxY() * alheight / od.getSequencesHeight()));
243 // overly large boxY value reset to sequenceHeight - boxHeight
244 mouseClick(od, 10, 520);
245 assertEquals(od.getBoxX(), 0);
246 assertEquals(od.getBoxY(), od.getSequencesHeight() - od.getBoxHeight());
247 assertEquals(od.getBoxWidth(), boxWidth);
248 assertEquals(od.getBoxHeight(), boxHeight);
250 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
252 // here (float) od.getBoxY() * alheight / od.getSequencesHeight() = 507.5
253 // and round rounds to 508; however we get 507 working with row values
254 // hence the subtraction of 1
255 assertEquals(vpranges.getStartSeq(), Math.round(
256 (float) od.getBoxY() * alheight / 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()));
265 assertEquals(vpranges.getStartSeq(), Math.round(
266 (float) od.getBoxY() * alheight / od.getSequencesHeight()));
268 // move viewport so startRes non-zero and then mouseclick
271 // click at viewport position
272 int oldboxx = od.getBoxX();
273 int oldboxy = od.getBoxY();
274 mouseClick(od, od.getBoxX() + od.getBoxWidth() / 2 + 6,
275 od.getBoxY() + od.getBoxHeight() / 2 + 3);
276 assertEquals(od.getBoxX(), oldboxx + 6);
277 assertEquals(od.getBoxWidth(), boxWidth);
278 assertEquals(od.getBoxHeight(), boxHeight);
279 assertEquals(vpranges.getStartRes(),
280 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
281 assertEquals(od.getBoxY(), oldboxy + 3);
282 assertEquals(vpranges.getStartSeq(), Math.round(
283 (float) od.getBoxY() * alheight / 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(), Math
316 .round((float) (lastHiddenCol + 1) * od.getWidth() / alwidth));
317 assertEquals(od.getBoxWidth(), boxWidth);
318 assertEquals(od.getBoxHeight(), boxHeight);
320 // try to click in hidden cols, check box does not move
322 mouseClick(od, xpos, 0);
323 assertEquals(od.getBoxX(), Math
324 .round((float) (lastHiddenCol + 1) * od.getWidth() / alwidth));
325 assertEquals(od.getBoxY(), 0);
326 assertEquals(od.getBoxWidth(), boxWidth);
327 assertEquals(od.getBoxHeight(), boxHeight);
328 assertEquals(vpranges.getStartSeq(), 0);
329 assertEquals(vpranges.getStartRes(), 0);
331 // click to right of hidden columns, box moves to click point
332 mouseClick(od, 60 + boxWidth / 2, boxHeight / 2);
333 assertEquals(od.getBoxX(), 60);
334 assertEquals(od.getBoxY(), 0);
335 assertEquals(od.getBoxWidth(), boxWidth);
336 assertEquals(od.getBoxHeight(), boxHeight);
337 assertEquals(vpranges.getStartSeq(), 0);
338 assertEquals(vpranges.getStartRes(),
339 Math.round((float) 60 * alwidth / od.getWidth())
340 - (lastHiddenCol + 1));
342 // click to right of hidden columns such that box runs over right hand side
344 // box position is adjusted away from the edge
345 // overly large boxX value reset to width-boxWidth
347 mouseClick(od, xpos + boxWidth / 2, 5 + boxHeight / 2);
348 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
349 assertEquals(od.getBoxY(), 5);
350 assertEquals(od.getBoxWidth(), boxWidth);
351 assertEquals(od.getBoxHeight(), boxHeight);
352 assertEquals(vpranges.getStartRes(),
353 Math.round((float) od.getBoxX() * alwidth / od.getWidth())
354 - (lastHiddenCol + 1));
355 assertEquals(vpranges.getStartSeq(), Math.round(
356 (float) od.getBoxY() * alheight / od.getSequencesHeight()));
360 * Test setting of the box position, when there are hidden cols in the middle
363 @Test(groups = { "Functional" })
364 public void testFromMouseWithHiddenColsInMiddle()
366 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
367 assertEquals(od.getBoxX(), 0);
368 assertEquals(od.getBoxY(), 0);
369 assertEquals(od.getBoxWidth(), boxWidth);
370 assertEquals(vpranges.getStartRes(), 0);
371 assertEquals(vpranges.getStartSeq(), 0);
373 // hide columns 63-73, no change to box position or dimensions
374 int firstHidden = 63;
376 hiddenCols.hideColumns(firstHidden, lastHidden);
378 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
379 assertEquals(od.getBoxX(), 0);
380 assertEquals(od.getBoxY(), 0);
381 assertEquals(od.getBoxWidth(), boxWidth);
382 assertEquals(vpranges.getStartRes(), 0);
383 assertEquals(vpranges.getStartSeq(), 0);
385 // move box so that it overlaps with hidden cols on one side
386 // box width changes, boxX and scrollCol as for unhidden case
387 int xpos = 54 - boxWidth / 2; // 54 is position in overview approx halfway
388 // between cols 60 and 70
389 mouseClick(od, xpos, boxHeight / 2);
390 assertEquals(od.getBoxX(), xpos - boxWidth / 2);
391 assertEquals(od.getBoxY(), 0);
392 assertEquals(od.getBoxWidth(),
393 Math.round(boxWidth + (float) (lastHidden - firstHidden + 1)
394 * od.getWidth() / alwidth));
395 assertEquals(od.getBoxHeight(), boxHeight);
396 assertEquals(vpranges.getStartRes(),
397 Math.round((xpos - boxWidth / 2) * alwidth / od.getWidth())
398 + 1); // +1 for rounding
399 assertEquals(vpranges.getStartSeq(), 0);
401 // move box so that it completely covers hidden cols
402 // box width changes, boxX and scrollCol as for hidden case
403 xpos = 24 + boxWidth / 2;
404 mouseClick(od, xpos, 0);
405 assertEquals(od.getBoxX(), 24);
406 assertEquals(od.getBoxY(), 0);
407 assertEquals(od.getBoxWidth(),
408 Math.round(boxWidth + (float) (lastHidden - firstHidden + 1)
409 * od.getWidth() / alwidth));
410 assertEquals(od.getBoxHeight(), boxHeight);
411 assertEquals(vpranges.getStartRes(),
412 Math.round((float) 24 * alwidth / od.getWidth()));
413 assertEquals(vpranges.getStartSeq(), 0);
415 // move box so boxX is to right of hidden cols, but does not go beyond full
416 // width of alignment
417 // box width, boxX and scrollCol all as for non-hidden case
418 xpos = Math.round((float) 75 * od.getWidth() / alwidth) + boxWidth / 2;
419 mouseClick(od, xpos, boxHeight / 2);
420 assertEquals(od.getBoxX(), xpos - boxWidth / 2);
421 assertEquals(od.getBoxY(), 0);
422 assertEquals(od.getBoxWidth(), boxWidth);
423 assertEquals(od.getBoxHeight(), boxHeight);
424 assertEquals(vpranges.getStartSeq(), 0);
425 assertEquals(vpranges.getStartRes(),
426 75 - (lastHidden - firstHidden + 1));
428 // move box so it goes beyond full width of alignment
429 // boxX, scrollCol adjusted back, box width normal
431 mouseClick(od, xpos, 5);
432 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
433 assertEquals(od.getBoxY(), 0);
434 assertEquals(od.getBoxWidth(), boxWidth);
435 assertEquals(od.getBoxHeight(), boxHeight);
436 assertEquals(vpranges.getStartRes(),
437 Math.round(((float) od.getBoxX() * alwidth / od.getWidth())
438 - (lastHidden - firstHidden + 1)));
439 assertEquals(vpranges.getStartSeq(), Math.round(
440 (float) od.getBoxY() * alheight / od.getSequencesHeight()));
445 * Test setting of the box position, when there are hidden cols at the end of
448 @Test(groups = { "Functional" })
449 public void testFromMouseWithHiddenColsAtEnd()
451 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
452 assertEquals(od.getBoxX(), 0);
453 assertEquals(od.getBoxY(), 0);
454 assertEquals(od.getBoxWidth(), boxWidth);
455 assertEquals(vpranges.getStartRes(), 0);
456 assertEquals(vpranges.getStartSeq(), 0);
458 // hide columns 140-164, no change to box position or dimensions
459 int firstHidden = 140;
460 int lastHidden = 164;
461 hiddenCols.hideColumns(firstHidden, lastHidden);
462 od.setBoxPosition(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 // click to left of hidden cols, without overlapping
470 // boxX, scrollCol and width as normal
473 testBoxIsAtClickPoint(xpos, ypos);
474 assertEquals(vpranges.getStartSeq(), Math.round(
475 (float) (ypos - boxHeight / 2) * alheight / od.getHeight()));
476 assertEquals(vpranges.getStartRes(), Math.round(
477 (float) (xpos - boxWidth / 2) * alwidth / od.getWidth()));
479 // click to left of hidden cols, with overlap
480 // boxX and scrollCol adjusted for hidden cols, width normal
481 xpos = Math.round((float) 145 * od.getWidth() / alwidth) - boxWidth;
482 mouseClick(od, xpos + boxWidth / 2, boxHeight / 2);
483 assertEquals(od.getBoxX(),
484 Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth)
486 assertEquals(od.getBoxY(), 0);
487 assertEquals(od.getBoxWidth(), boxWidth);
488 assertEquals(od.getBoxHeight(), boxHeight);
489 assertEquals(vpranges.getStartRes(),
490 Math.round((float) (od.getBoxX()) * alwidth / od.getWidth()));
491 assertEquals(vpranges.getStartSeq(), 0);
493 // click in hidden cols
494 // boxX and scrollCol adjusted for hidden cols, width normal
496 assertEquals(od.getBoxX(),
497 Math.round((float) (firstHidden - 1) * 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 / od.getWidth()));
504 assertEquals(vpranges.getStartSeq(), 0);
506 // click off end of alignment
507 // boxX and scrollCol adjusted for hidden cols, width normal
509 assertEquals(od.getBoxX(),
510 Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth)
512 assertEquals(od.getBoxY(), 0);
513 assertEquals(od.getBoxWidth(), boxWidth);
514 assertEquals(od.getBoxHeight(), boxHeight);
515 assertEquals(vpranges.getStartRes(),
516 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
517 assertEquals(vpranges.getStartSeq(), 0);
521 * Test that the box position is set correctly when set from the viewport,
522 * with no hidden rows or columns
524 @Test(groups = { "Functional" })
525 public void testSetBoxFromViewport()
527 // move viewport to start of alignment
529 assertEquals(od.getBoxX(), 0);
530 assertEquals(od.getBoxY(), 0);
531 assertEquals(od.getBoxWidth(), boxWidth);
532 assertEquals(od.getBoxHeight(), boxHeight);
534 // move viewport to right
536 assertEquals(od.getBoxX(),
537 Math.round((float) 70 * od.getWidth() / alwidth));
538 assertEquals(od.getBoxY(), 0);
539 assertEquals(od.getBoxWidth(), boxWidth);
540 assertEquals(od.getBoxHeight(), boxHeight);
542 // move viewport down
544 assertEquals(od.getBoxX(),
545 Math.round((float) 70 * od.getWidth() / alwidth));
546 assertEquals(od.getBoxY(),
547 Math.round(100 * od.getSequencesHeight() / alheight));
548 assertEquals(od.getBoxWidth(), boxWidth);
549 assertEquals(od.getBoxHeight(), boxHeight);
551 // move viewport to bottom right
552 moveViewport(98, 508);
553 assertEquals(od.getBoxX(),
554 Math.round((float) 98 * od.getWidth() / alwidth));
555 assertEquals(od.getBoxY(),
556 Math.round((float) 508 * od.getSequencesHeight() / alheight));
557 assertEquals(od.getBoxWidth(), boxWidth);
558 assertEquals(od.getBoxHeight(), boxHeight);
562 * Test that the box position is set correctly when there are hidden columns
565 @Test(groups = { "Functional" })
566 public void testSetBoxFromViewportHiddenColsAtStart()
570 hiddenCols.hideColumns(firstHidden, lastHidden);
572 // move viewport to start of alignment
574 assertEquals(od.getBoxX(),
575 Math.round((float) (lastHidden + 1) * od.getWidth() / alwidth));
576 assertEquals(od.getBoxY(), 0);
577 assertEquals(od.getBoxWidth(), boxWidth);
578 assertEquals(od.getBoxHeight(), boxHeight);
580 // move viewport to end of alignment - need to make startRes by removing
581 // hidden cols because of how viewport/overview are implemented
582 moveViewport(98 - lastHidden - 1, 0);
583 assertEquals(od.getBoxX(),
584 Math.round((float) 98 * od.getWidth() / alwidth));
585 assertEquals(od.getBoxY(), 0);
586 assertEquals(od.getBoxWidth(), boxWidth);
587 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 testSetBoxFromViewportHiddenColsInMiddle()
597 int firstHidden = 68;
599 hiddenCols.hideColumns(firstHidden, lastHidden);
601 // move viewport before hidden columns
604 assertEquals(od.getBoxX(),
605 Math.round((float) 3 * od.getWidth() / alwidth));
606 assertEquals(od.getBoxY(), 0);
607 assertEquals(od.getBoxWidth(), boxWidth);
608 assertEquals(od.getBoxHeight(), boxHeight);
610 // move viewport to left of hidden columns with overlap
612 assertEquals(od.getBoxX(),
613 Math.round((float) 10 * od.getWidth() / alwidth));
614 assertEquals(od.getBoxY(), 0);
615 assertEquals(od.getBoxWidth(),
616 boxWidth + Math.round((float) (lastHidden - firstHidden + 1)
617 * od.getWidth() / alwidth));
618 assertEquals(od.getBoxHeight(), boxHeight);
620 // move viewport to straddle hidden columns
622 assertEquals(od.getBoxX(),
623 Math.round((float) 63 * od.getWidth() / alwidth));
624 assertEquals(od.getBoxY(), 0);
625 assertEquals(od.getBoxWidth(), boxWidth + Math.round(
626 (lastHidden - firstHidden + 1) * od.getWidth() / alwidth));
627 assertEquals(od.getBoxHeight(), boxHeight);
629 // move viewport to right of hidden columns, no overlap
630 moveViewport(80 - (lastHidden - firstHidden + 1), 0);
631 assertEquals(od.getBoxX(),
632 Math.round((float) 80 * od.getWidth() / alwidth));
633 assertEquals(od.getBoxY(), 0);
634 assertEquals(od.getBoxWidth(), boxWidth);
635 assertEquals(od.getBoxHeight(), boxHeight);
640 * Test that the box position is set correctly when there are hidden columns
643 @Test(groups = { "Functional" })
644 public void testSetBoxFromViewportHiddenColsAtEnd()
646 int firstHidden = 152;
647 int lastHidden = 164;
648 hiddenCols.hideColumns(firstHidden, lastHidden);
650 // move viewport before hidden columns
652 assertEquals(od.getBoxX(),
653 Math.round((float) 3 * od.getWidth() / alwidth));
654 assertEquals(od.getBoxY(), 0);
655 assertEquals(od.getBoxWidth(), boxWidth);
656 assertEquals(od.getBoxHeight(), boxHeight);
658 // move viewport to hidden columns
659 // viewport can't actually extend into hidden cols,
660 // so move to the far right edge of the viewport
661 moveViewport(firstHidden - viewWidth, 0);
662 assertEquals(od.getBoxX(), Math.round(
663 (float) (firstHidden - viewWidth) * od.getWidth() / alwidth));
664 assertEquals(od.getBoxY(), 0);
665 assertEquals(od.getBoxWidth(), boxWidth);
666 assertEquals(od.getBoxHeight(), boxHeight);
670 * Test that the box position is set correctly when there are hidden rows at
673 @Test(groups = { "Functional" })
674 public void testSetBoxFromViewportHiddenRowsAtStart()
678 hideSequences(firstHidden, lastHidden);
680 // move viewport to start of alignment:
681 // box moves to below hidden rows, height remains same
683 assertEquals(od.getBoxX(), 0);
684 assertEquals(od.getBoxY(), Math.round(
685 (float) (lastHidden + 1) * od.getSequencesHeight() / alheight));
686 assertEquals(od.getBoxWidth(), boxWidth);
687 assertEquals(od.getBoxHeight(), boxHeight);
689 // move viewport to end of alignment
690 moveViewport(0, 525 - viewHeight - lastHidden - 1);
691 assertEquals(od.getBoxX(), 0);
692 assertEquals(od.getBoxY(), Math.round((float) (525 - viewHeight)
693 * od.getSequencesHeight() / alheight));
694 assertEquals(od.getBoxWidth(), boxWidth);
695 assertEquals(od.getBoxHeight(), boxHeight);
699 * Test that the box position is set correctly when there are hidden rows in
702 @Test(groups = { "Functional" })
703 public void testSetBoxFromViewportHiddenRowsInMiddle()
705 int firstHidden = 200;
706 int lastHidden = 210;
707 hideSequences(firstHidden, lastHidden);
709 // move viewport to start of alignment:
710 // box, height etc as in non-hidden case
712 assertEquals(od.getBoxX(), 0);
713 assertEquals(od.getBoxY(), 0);
714 assertEquals(od.getBoxWidth(), boxWidth);
715 assertEquals(od.getBoxHeight(), boxHeight);
717 // move viewport to straddle hidden rows
718 moveViewport(0, 198);
719 assertEquals(od.getBoxX(), 0);
720 assertEquals(od.getBoxY(),
721 Math.round((float) 198 * od.getSequencesHeight() / alheight));
722 assertEquals(od.getBoxWidth(), boxWidth);
723 assertEquals(od.getBoxHeight(),
724 Math.round((float) (viewHeight + lastHidden - firstHidden + 1)
725 * od.getSequencesHeight() / alheight));
729 * Test that the box position is set correctly when there are hidden rows at
732 @Test(groups = { "Functional" })
733 public void testSetBoxFromViewportHiddenRowsAtEnd()
735 int firstHidden = 500;
736 int lastHidden = 524;
737 hideSequences(firstHidden, lastHidden);
739 // move viewport to start of alignment:
740 // box, height etc as in non-hidden case
742 assertEquals(od.getBoxX(), 0);
743 assertEquals(od.getBoxY(), 0);
744 assertEquals(od.getBoxWidth(), boxWidth);
745 assertEquals(od.getBoxHeight(), boxHeight);
747 // move viewport to end of alignment
748 // viewport sits above hidden rows and does not include them
749 moveViewport(0, firstHidden - viewHeight - 1);
750 assertEquals(od.getBoxX(), 0);
751 assertEquals(od.getBoxY(),
752 Math.round((float) (firstHidden - viewHeight - 1)
753 * od.getSequencesHeight() / alheight));
754 assertEquals(od.getBoxWidth(), boxWidth);
755 assertEquals(od.getBoxHeight(), boxHeight);
760 * Test setting of the box position, when there are hidden rows at the start
763 @Test(groups = { "Functional" })
764 public void testFromMouseWithHiddenRowsAtStart()
766 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
767 assertEquals(od.getBoxX(), 0);
768 assertEquals(od.getBoxY(), 0);
769 assertEquals(od.getBoxHeight(), boxHeight);
770 assertEquals(od.getBoxWidth(), boxWidth);
771 assertEquals(vpranges.getStartRes(), 0);
772 assertEquals(vpranges.getStartSeq(), 0);
774 // hide rows at start and check updated box position is correct
775 // changes boxY but not boxheight
776 int lastHiddenRow = 30;
777 hideSequences(0, lastHiddenRow);
779 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
780 assertEquals(od.getBoxX(), 0);
781 assertEquals(od.getBoxY(), Math.round((float) (lastHiddenRow + 1)
782 * od.getSequencesHeight() / alheight));
783 assertEquals(od.getBoxWidth(), boxWidth);
784 assertEquals(od.getBoxHeight(), boxHeight);
786 // click in hidden rows - same result
787 mouseClick(od, 0, 0);
788 assertEquals(od.getBoxX(), 0);
789 assertEquals(od.getBoxY(), Math.round((float) (lastHiddenRow + 1)
790 * od.getSequencesHeight() / alheight));
791 assertEquals(od.getBoxWidth(), boxWidth);
792 assertEquals(od.getBoxHeight(), boxHeight);
794 // click below hidden rows
795 mouseClick(od, 0, 150 + boxHeight / 2);
796 assertEquals(od.getBoxX(), 0);
797 assertEquals(od.getBoxY(), 150);
798 assertEquals(od.getBoxWidth(), boxWidth);
799 assertEquals(od.getBoxHeight(), boxHeight);
803 * Test setting of the box position, when there are hidden rows at the middle
806 @Test(groups = { "Functional" })
807 public void testFromMouseWithHiddenRowsInMiddle()
809 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
811 assertEquals(od.getBoxX(), 0);
812 assertEquals(od.getBoxY(), 0);
813 assertEquals(od.getBoxWidth(), boxWidth);
814 assertEquals(od.getBoxHeight(), boxHeight);
815 assertEquals(vpranges.getStartRes(), 0);
816 assertEquals(vpranges.getStartSeq(), 0);
818 // hide rows in middle and check updated box position is correct
820 int firstHiddenRow = 50;
821 int lastHiddenRow = 54;
822 hideSequences(firstHiddenRow, lastHiddenRow);
824 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
826 assertEquals(od.getBoxX(), 0);
827 assertEquals(od.getBoxY(), 0);
828 assertEquals(od.getBoxWidth(), boxWidth);
829 assertEquals(od.getBoxHeight(), boxHeight);
831 // click above hidden rows, so that box overlaps
832 int rowpos = 35; // row value in residues
833 int centrepos = 43; // centre row
834 mouseClick(od, 0, Math
835 .round((float) centrepos * od.getSequencesHeight() / alheight));
836 assertEquals(od.getBoxX(), 0);
837 assertEquals(od.getBoxY(), Math
838 .round((float) rowpos * od.getSequencesHeight() / alheight));
839 assertEquals(od.getBoxWidth(), boxWidth);
840 assertEquals(od.getBoxHeight(),
842 .round((float) (lastHiddenRow - firstHiddenRow + 1)
843 * od.getSequencesHeight() / alheight));
847 * Test setting of the box position, when there are hidden rows at the end of
850 @Test(groups = { "Functional" })
851 public void testFromMouseWithHiddenRowsAtEnd()
853 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
854 assertEquals(od.getBoxX(), 0);
855 assertEquals(od.getBoxY(), 0);
856 assertEquals(od.getBoxWidth(), boxWidth);
857 assertEquals(od.getBoxHeight(), boxHeight);
858 assertEquals(vpranges.getStartRes(), 0);
859 assertEquals(vpranges.getStartSeq(), 0);
861 // hide rows at end and check updated box position is correct
863 int firstHidden = 500;
864 int lastHidden = 524;
865 hideSequences(firstHidden, lastHidden);
867 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
868 assertEquals(od.getBoxX(), 0);
869 assertEquals(od.getBoxY(), 0);
870 assertEquals(od.getBoxWidth(), boxWidth);
871 assertEquals(od.getBoxHeight(), boxHeight);
873 // click above hidden rows, no overlap
874 int ypos = 40 + viewHeight / 2; // top is row 40
876 Math.round((float) ypos * od.getSequencesHeight() / alheight));
877 assertEquals(od.getBoxX(), 0);
878 assertEquals(od.getBoxY(),
879 Math.round((float) 40 * od.getSequencesHeight() / alheight));
880 assertEquals(od.getBoxWidth(), boxWidth);
881 assertEquals(od.getBoxHeight(), boxHeight);
883 // click above hidden rows so box overlaps
884 // boxY moved upwards, boxHeight remains same
885 ypos = 497 + viewHeight / 2; // row 497
887 Math.round((float) ypos * od.getSequencesHeight() / alheight));
888 assertEquals(od.getBoxX(), 0);
889 assertEquals(od.getBoxY(), Math.round((float) (firstHidden - viewHeight)
890 * od.getSequencesHeight() / alheight));
891 assertEquals(od.getBoxWidth(), boxWidth);
892 assertEquals(od.getBoxHeight(), boxHeight);
894 // click within hidden rows
895 ypos = 505 + boxHeight / 2;
897 Math.round((float) ypos * od.getSequencesHeight() / alheight));
898 assertEquals(od.getBoxX(), 0);
899 assertEquals(od.getBoxY(), Math.round((firstHidden - viewHeight)
900 * od.getSequencesHeight() / alheight));
901 assertEquals(od.getBoxWidth(), boxWidth);
902 assertEquals(od.getBoxHeight(), boxHeight);
906 * Test the function to determine if a point is in the overview's box or not
908 @Test(groups = { "Functional" })
909 public void testPositionInBox()
911 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
913 assertFalse(od.isPositionInBox(0, 0));
914 assertTrue(od.isPositionInBox(10, 9));
915 assertFalse(od.isPositionInBox(0, 9));
916 assertFalse(od.isPositionInBox(9, 0));
917 assertFalse(od.isPositionInBox(75, 20));
919 assertTrue(od.isPositionInBox(47, 6));
920 assertFalse(od.isPositionInBox(48, 6));
921 assertTrue(od.isPositionInBox(47, 9));
922 assertFalse(od.isPositionInBox(47, 10));
924 // hide columns in the box area
925 // extends area where a point is considered to be in the box
926 hiddenCols.hideColumns(1, 4);
927 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
928 assertFalse(od.isPositionInBox(0, 0));
929 assertTrue(od.isPositionInBox(10, 9));
930 assertFalse(od.isPositionInBox(0, 9));
931 assertFalse(od.isPositionInBox(9, 0));
932 assertFalse(od.isPositionInBox(75, 20));
934 assertTrue(od.isPositionInBox(47, 6));
935 assertTrue(od.isPositionInBox(48, 6));
936 assertTrue(od.isPositionInBox(47, 9));
937 assertFalse(od.isPositionInBox(47, 10));
939 // hide sequences in box area
940 // extends area where a point is considered to be in the box
942 ColumnSelection cs = new ColumnSelection();
943 hiddenCols.revealAllHiddenColumns(cs);
944 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
945 assertFalse(od.isPositionInBox(0, 0));
946 assertTrue(od.isPositionInBox(10, 9));
947 assertFalse(od.isPositionInBox(0, 9));
948 assertFalse(od.isPositionInBox(9, 0));
949 assertFalse(od.isPositionInBox(75, 20));
951 assertTrue(od.isPositionInBox(47, 6));
952 assertFalse(od.isPositionInBox(48, 6));
953 assertTrue(od.isPositionInBox(47, 9));
954 assertTrue(od.isPositionInBox(47, 10));
958 * Test the dragging functionality
960 @Test(groups = { "Functional" })
961 public void testDragging()
963 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
964 od.setDragPoint(4, 16, al.getHiddenSequences(), hiddenCols);
965 od.adjustViewportFromMouse(20, 22, al.getHiddenSequences(), hiddenCols);
967 // updates require an OverviewPanel to exist which it doesn't here
968 // so call setBoxPosition() as it would be called by the AlignmentPanel
970 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
972 // corner moves 16 (20-4) right and 6 (22-16) up
973 assertEquals(od.getBoxX(), 16);
974 assertEquals(od.getBoxY(), 6);
976 // hide columns - box moves drag distance + hidden cols, vertically makes no
978 hiddenCols.hideColumns(1, 4);
979 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
980 od.setDragPoint(4, 16, al.getHiddenSequences(), hiddenCols);
981 od.adjustViewportFromMouse(20, 22, al.getHiddenSequences(), hiddenCols);
982 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
984 // corner moves 16 (20-4) + hiddenCols right and 6 (22-16) down
985 assertEquals(od.getBoxX(),
986 16 + Math.round((float) 4 * od.getWidth() / alwidth));
987 assertEquals(od.getBoxY(), 6);
989 // hide sequences in box area
990 // makes absolutely no difference
992 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
993 od.setDragPoint(4, 16, al.getHiddenSequences(), hiddenCols);
994 od.adjustViewportFromMouse(20, 22, al.getHiddenSequences(), hiddenCols);
995 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
997 // corner moves 16 (20-4) + hiddenCols right and 6 (22-16) + hiddenRows down
998 assertEquals(od.getBoxX(),
999 16 + Math.round((float) 4 * od.getWidth() / alwidth));
1000 assertEquals(od.getBoxY(),
1001 6 + Math.round((float) 3 * od.getHeight() / alheight));
1005 * Move viewport horizontally: startRes + previous width gives new horizontal extent. Vertical extent stays the same.
1007 private void moveViewportH(int startRes)
1009 vpranges.setViewportStartAndWidth(startRes, viewWidth);
1010 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
1014 * Move viewport vertically: startSeq and endSeq give new vertical extent. Horizontal extent stays the same.
1016 private void moveViewportV(int startSeq)
1018 vpranges.setViewportStartAndHeight(startSeq, viewHeight);
1019 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
1023 * Move viewport horizontally and vertically.
1025 private void moveViewport(int startRes, int startSeq)
1027 vpranges.setViewportStartAndWidth(startRes, viewWidth);
1028 vpranges.setViewportStartAndHeight(startSeq, viewHeight);
1029 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
1033 * Mouse click as position x,y in overview window
1035 private void mouseClick(OverviewDimensions od, int x, int y)
1037 od.updateViewportFromMouse(x, y, al.getHiddenSequences(), hiddenCols);
1039 // updates require an OverviewPanel to exist which it doesn't here
1040 // so call setBoxPosition() as it would be called by the AlignmentPanel
1042 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
1046 * Test that the box is positioned with the centre at xpos, ypos
1047 * and with the original width and height
1049 private void testBoxIsAtClickPoint(int xpos, int ypos)
1051 mouseClick(od, xpos, ypos);
1052 assertEquals(od.getBoxX() + od.getBoxWidth() / 2, xpos);
1053 assertEquals(od.getBoxY() + od.getBoxHeight() / 2, ypos);
1054 assertEquals(od.getBoxWidth(), boxWidth);
1055 assertEquals(od.getBoxHeight(), boxHeight);
1060 * Hide sequences between start and end
1062 private void hideSequences(int start, int end)
1064 SequenceI[] allseqs = al.getSequencesArray();
1065 SequenceGroup theseSeqs = new SequenceGroup();
1067 for (int i = start; i <= end; i++)
1069 theseSeqs.addSequence(allseqs[i], false);
1070 al.getHiddenSequences().hideSequence(allseqs[i]);
1073 hiddenRepSequences.put(allseqs[start], theseSeqs);
1077 * Test setting of the box position, when there are hidden rows at the start
1080 @Test(groups = { "Functional" })
1081 public void testFromMouseWithHiddenRowsAtStartWrapped()
1083 vpranges.setWrappedMode(true);
1084 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
1085 assertEquals(od.getBoxX(), 0);
1086 assertEquals(od.getBoxY(), 0);
1087 assertEquals(od.getBoxHeight(), boxHeight);
1088 assertEquals(od.getBoxWidth(), boxWidth);
1089 assertEquals(vpranges.getStartRes(), 0);
1090 assertEquals(vpranges.getStartSeq(), 0);
1092 // hide rows at start and check updated box position is correct
1093 // changes boxY but not boxheight
1094 int lastHiddenRow = 30;
1095 hideSequences(0, lastHiddenRow);
1097 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
1098 assertEquals(od.getBoxX(), 0);
1099 assertEquals(od.getBoxY(), Math.round((float) (lastHiddenRow + 1)
1100 * od.getSequencesHeight() / alheight));
1101 assertEquals(od.getBoxWidth(), boxWidth);
1102 assertEquals(od.getBoxHeight(), boxHeight);
1104 // click in hidden rows - same result
1105 mouseClick(od, 0, 0);
1106 assertEquals(od.getBoxX(), 0);
1107 int boxY = od.getBoxY();
1108 assertEquals(boxY, Math.round((float) (lastHiddenRow + 1)
1109 * od.getSequencesHeight() / alheight));
1110 assertEquals(od.getBoxWidth(), boxWidth);
1111 assertEquals(od.getBoxHeight(), boxHeight);
1113 // click below hidden rows
1114 // vertical move of overview box is suppressed in wrapped mode
1115 mouseClick(od, 0, 150);
1116 assertEquals(od.getBoxX(), 0);
1117 assertEquals(od.getBoxY(), boxY); // unchanged
1118 assertEquals(od.getBoxWidth(), boxWidth);
1119 assertEquals(od.getBoxHeight(), boxHeight);