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
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 OverviewDimensionsHideHidden(vpranges, true);
98 // Initial box sizing - default path through code
99 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
101 mouseClick(od, 0, 0);
104 // calculate with visible values
105 alheight = vpranges.getVisibleAlignmentHeight();
106 alwidth = vpranges.getVisibleAlignmentWidth();
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 OverviewDimensionsHideHidden(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 OverviewDimensionsHideHidden(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 OverviewDimensionsHideHidden(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 OverviewDimensionsHideHidden(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 OverviewDimensionsHideHidden(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);
249 assertEquals(vpranges.getStartRes(),
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 int lastHiddenCol = 30;
311 hiddenCols.hideColumns(0, lastHiddenCol);
313 testBoxIsAtClickPoint(boxWidth / 2, boxHeight / 2);
315 // click to right of hidden columns, box moves to click point
316 testBoxIsAtClickPoint(41 + boxWidth / 2, boxHeight / 2);
317 assertEquals(vpranges.getStartSeq(), 0);
318 assertEquals(vpranges.getStartRes(),
319 Math.round((float) 41 * alwidth / od.getWidth()));
321 // click to right of hidden columns such that box runs over right hand side
323 // box position is adjusted away from the edge
324 // overly large boxX value reset to width-boxWidth
325 int xpos = 100 + boxWidth / 2;
326 mouseClick(od, xpos, boxHeight / 2);
327 assertEquals(od.getBoxX(), Math.round(od.getWidth()) - boxWidth);
328 assertEquals(od.getBoxY(), 0);
329 assertEquals(od.getBoxWidth(), boxWidth);
330 assertEquals(od.getBoxHeight(), boxHeight);
331 assertEquals(vpranges.getStartRes(),
332 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
333 assertEquals(vpranges.getStartSeq(), 0);
337 * Test setting of the box position, when there are hidden cols in the middle
340 @Test(groups = { "Functional" })
341 public void testFromMouseWithHiddenColsInMiddle()
343 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
344 testBoxIsAtClickPoint(boxWidth / 2, boxHeight / 2);
345 assertEquals(od.getBoxX(), 0);
346 assertEquals(od.getBoxY(), 0);
347 assertEquals(od.getBoxWidth(), boxWidth);
348 assertEquals(vpranges.getStartRes(), 0);
349 assertEquals(vpranges.getStartSeq(), 0);
351 // hide columns 63-73, no change to box position or dimensions
352 int firstHidden = 63;
354 hiddenCols.hideColumns(firstHidden, lastHidden);
356 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
357 testBoxIsAtClickPoint(boxWidth / 2, boxHeight / 2);
358 assertEquals(od.getBoxX(), 0);
359 assertEquals(od.getBoxY(), 0);
360 assertEquals(od.getBoxWidth(), boxWidth);
361 assertEquals(vpranges.getStartRes(), 0);
362 assertEquals(vpranges.getStartSeq(), 0);
364 // move box so that it overlaps with hidden cols on one side
365 // box width, boxX and scrollCol as for unhidden case
366 int xpos = 54 - boxWidth / 2; // 54 is position in overview approx halfway
367 // between cols 60 and 70
368 mouseClick(od, xpos, boxHeight / 2);
369 testBoxIsAtClickPoint(xpos, boxHeight / 2);
370 assertEquals(vpranges.getStartRes(), 1 + // rounding
371 Math.round((xpos - boxWidth / 2) * alwidth / od.getWidth()));
372 assertEquals(vpranges.getStartSeq(), 0);
374 // move box so that it completely covers hidden cols
375 // box width, boxX and scrollCol as for unhidden case
377 mouseClick(od, xpos, boxHeight / 2);
378 testBoxIsAtClickPoint(xpos, boxHeight / 2);
379 assertEquals(vpranges.getStartRes(), Math.round(
380 (float) (xpos - boxWidth / 2) * alwidth / od.getWidth()));
381 assertEquals(vpranges.getStartSeq(), 0);
383 // move box so boxX is in hidden cols, box overhangs at right
384 // boxX and scrollCol at left of hidden area, box width unchanged
385 xpos = Math.round((float) 50 * od.getWidth() / alwidth) + boxWidth / 2;
386 mouseClick(od, xpos, boxHeight / 2);
387 assertEquals(od.getBoxX() + od.getBoxWidth() / 2, xpos);
388 assertEquals(od.getBoxY(), 0);
389 assertEquals(od.getBoxWidth(), boxWidth);
390 assertEquals(od.getBoxHeight(), boxHeight);
391 assertEquals(vpranges.getStartRes(), 50);
392 assertEquals(vpranges.getStartSeq(), 0);
394 // move box so boxX is to right of hidden cols, but does not go beyond full
395 // width of alignment
396 // box width, boxX and scrollCol all as for non-hidden case
397 xpos = Math.round((float) 75 * od.getWidth() / alwidth) + boxWidth / 2;
398 mouseClick(od, xpos, boxHeight / 2);
399 assertEquals(od.getBoxX() + od.getBoxWidth() / 2, xpos);
400 assertEquals(od.getBoxY(), 0);
401 assertEquals(od.getBoxWidth(), boxWidth);
402 assertEquals(od.getBoxHeight(), boxHeight);
403 assertEquals(vpranges.getStartSeq(), 0);
404 assertEquals(vpranges.getStartRes(), 75);
406 // move box so it goes beyond full width of alignment
407 // boxX, scrollCol adjusted back, box width normal
409 mouseClick(od, xpos, boxHeight / 2);
410 assertEquals(od.getBoxX(), Math.round(od.getWidth()) - boxWidth);
411 assertEquals(od.getBoxY(), 0);
412 assertEquals(od.getBoxWidth(), boxWidth);
413 assertEquals(od.getBoxHeight(), boxHeight);
414 assertEquals(vpranges.getStartRes(),
415 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
416 assertEquals(vpranges.getStartSeq(), 0);
421 * Test setting of the box position, when there are hidden cols at the end of
424 @Test(groups = { "Functional" })
425 public void testFromMouseWithHiddenColsAtEnd()
427 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
428 assertEquals(od.getBoxX(), 0);
429 assertEquals(od.getBoxY(), 0);
430 assertEquals(od.getBoxWidth(), boxWidth);
431 assertEquals(vpranges.getStartRes(), 0);
432 assertEquals(vpranges.getStartSeq(), 0);
434 // hide columns 140-164, no change to box position or dimensions
435 int firstHidden = 140;
436 int lastHidden = 164;
437 hiddenCols.hideColumns(firstHidden, lastHidden);
438 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
439 assertEquals(od.getBoxX(), 0);
440 assertEquals(od.getBoxY(), 0);
441 assertEquals(od.getBoxWidth(), boxWidth);
442 assertEquals(vpranges.getStartRes(), 0);
443 assertEquals(vpranges.getStartSeq(), 0);
445 // click to left of hidden cols, without overlapping
446 // boxX, scrollCol and width as normal
449 testBoxIsAtClickPoint(xpos, ypos);
450 assertEquals(vpranges.getStartSeq(), Math.round(
451 (float) (ypos - boxHeight / 2) * alheight / od.getHeight()));
452 assertEquals(vpranges.getStartRes(), Math.round(
453 (float) (xpos - boxWidth / 2) * alwidth / od.getWidth()));
455 // click to left of hidden cols, with overlap
456 // boxX and scrollCol adjusted for hidden cols, width normal
457 xpos = Math.round((float) 144 * od.getWidth() / alwidth) - boxWidth;
458 mouseClick(od, xpos, boxHeight / 2);
459 testBoxIsAtClickPoint(xpos, boxHeight / 2);
460 assertEquals(vpranges.getStartRes(), Math.round(
461 (float) (xpos - boxWidth / 2) * alwidth / od.getWidth()));
462 assertEquals(vpranges.getStartSeq(), 0);
464 // click off end of alignment
465 // boxX and scrollCol adjusted backwards, width normal
467 mouseClick(od, xpos, 0);
468 assertEquals(od.getBoxX(), Math.round(od.getWidth()) - boxWidth);
469 assertEquals(od.getBoxY(), 0);
470 assertEquals(od.getBoxWidth(), boxWidth);
471 assertEquals(od.getBoxHeight(), boxHeight);
472 assertEquals(vpranges.getStartRes(),
473 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
474 assertEquals(vpranges.getStartSeq(), 0);
478 * Test that the box position is set correctly when set from the viewport,
479 * with no hidden rows or columns
481 @Test(groups = { "Functional" })
482 public void testSetBoxFromViewport()
484 // move viewport to start of alignment
486 assertEquals(od.getBoxX(), 0);
487 assertEquals(od.getBoxY(), 0);
488 assertEquals(od.getBoxWidth(), boxWidth);
489 assertEquals(od.getBoxHeight(), boxHeight);
491 // move viewport to right
493 assertEquals(od.getBoxX(),
494 Math.round((float) 70 * od.getWidth() / alwidth));
495 assertEquals(od.getBoxY(), 0);
496 assertEquals(od.getBoxWidth(), boxWidth);
497 assertEquals(od.getBoxHeight(), boxHeight);
499 // move viewport down
501 assertEquals(od.getBoxX(),
502 Math.round((float) 70 * od.getWidth() / alwidth));
503 assertEquals(od.getBoxY(),
504 Math.round(100 * od.getSequencesHeight() / alheight));
505 assertEquals(od.getBoxWidth(), boxWidth);
506 assertEquals(od.getBoxHeight(), boxHeight);
508 // move viewport to bottom right
509 moveViewport(98, 508);
510 assertEquals(od.getBoxX(),
511 Math.round((float) 98 * od.getWidth() / alwidth));
512 assertEquals(od.getBoxY(),
513 Math.round((float) 508 * od.getSequencesHeight() / alheight));
514 assertEquals(od.getBoxWidth(), boxWidth);
515 assertEquals(od.getBoxHeight(), boxHeight);
519 * Test that the box position is set correctly when there are hidden columns
522 @Test(groups = { "Functional" })
523 public void testSetBoxFromViewportHiddenColsAtStart()
527 hiddenCols.hideColumns(firstHidden, lastHidden);
529 // move viewport to start of alignment
531 assertEquals(od.getBoxX(), 0);
532 assertEquals(od.getBoxY(), 0);
533 assertEquals(od.getBoxWidth(), boxWidth);
534 assertEquals(od.getBoxHeight(), boxHeight);
536 // move viewport to end of alignment - need to make startRes by removing
537 // hidden cols because of how viewport/overview are implemented
538 moveViewport(98 - lastHidden - 1, 0);
539 assertEquals(od.getBoxX(), Math.round(
540 (float) (98 - lastHidden - 1) * od.getWidth() / alwidth));
541 assertEquals(od.getBoxY(), 0);
542 assertEquals(od.getBoxWidth(), boxWidth);
543 assertEquals(od.getBoxHeight(), boxHeight);
547 * Test that the box position is set correctly when there are hidden columns
550 @Test(groups = { "Functional" })
551 public void testSetBoxFromViewportHiddenColsInMiddle()
553 int firstHidden = 68;
555 hiddenCols.hideColumns(firstHidden, lastHidden);
557 // move viewport before hidden columns
560 assertEquals(od.getBoxX(),
561 Math.round((float) 3 * od.getWidth() / alwidth));
562 assertEquals(od.getBoxY(), 0);
563 assertEquals(od.getBoxWidth(), boxWidth);
564 assertEquals(od.getBoxHeight(), boxHeight);
566 // move viewport to left of hidden columns with overlap
568 assertEquals(od.getBoxX(),
569 Math.round((float) 10 * od.getWidth() / alwidth));
570 assertEquals(od.getBoxY(), 0);
571 assertEquals(od.getBoxWidth(), boxWidth);
572 assertEquals(od.getBoxHeight(), boxHeight);
574 // move viewport to straddle hidden columns
576 assertEquals(od.getBoxX(),
577 Math.round((float) 63 * od.getWidth() / alwidth));
578 assertEquals(od.getBoxY(), 0);
579 assertEquals(od.getBoxWidth(), boxWidth);
580 assertEquals(od.getBoxHeight(), boxHeight);
582 // move viewport to right of hidden columns, no overlap
583 moveViewport(80 - (lastHidden - firstHidden + 1), 0);
584 assertEquals(od.getBoxX(),
585 Math.round((float) (80 - (lastHidden - firstHidden + 1))
586 * od.getWidth() / alwidth));
587 assertEquals(od.getBoxY(), 0);
588 assertEquals(od.getBoxWidth(), boxWidth);
589 assertEquals(od.getBoxHeight(), boxHeight);
594 * Test that the box position is set correctly when there are hidden columns
597 @Test(groups = { "Functional" })
598 public void testSetBoxFromViewportHiddenColsAtEnd()
600 int firstHidden = 152;
601 int lastHidden = 164;
602 hiddenCols.hideColumns(firstHidden, lastHidden);
604 // move viewport before hidden columns
606 assertEquals(od.getBoxX(),
607 Math.round((float) 3 * od.getWidth() / alwidth));
608 assertEquals(od.getBoxY(), 0);
609 assertEquals(od.getBoxWidth(), boxWidth);
610 assertEquals(od.getBoxHeight(), boxHeight);
612 // move viewport to hidden columns
613 // viewport can't actually extend into hidden cols,
614 // so move to the far right edge of the viewport
615 moveViewport(firstHidden - viewWidth, 0);
616 assertEquals(od.getBoxX(), Math.round(
617 (float) (firstHidden - viewWidth) * od.getWidth() / alwidth));
618 assertEquals(od.getBoxY(), 0);
619 assertEquals(od.getBoxWidth(), boxWidth);
620 assertEquals(od.getBoxHeight(), boxHeight);
624 * Test that the box position is set correctly when there are hidden rows at
627 @Test(groups = { "Functional" })
628 public void testSetBoxFromViewportHiddenRowsAtStart()
632 hideSequences(firstHidden, lastHidden);
634 // calculate with visible values
635 alheight = vpranges.getVisibleAlignmentHeight();
636 alwidth = vpranges.getVisibleAlignmentWidth();
638 boxWidth = Math.round(
639 (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
640 * od.getWidth() / alwidth);
641 boxHeight = Math.round(
642 (float) (vpranges.getEndSeq() - vpranges.getStartSeq() + 1)
643 * od.getSequencesHeight() / alheight);
645 // move viewport to start of alignment:
646 // box moves to below hidden rows, height remains same
648 assertEquals(od.getBoxX(), 0);
649 assertEquals(od.getBoxY(), 0);
650 assertEquals(od.getBoxWidth(), boxWidth);
651 assertEquals(od.getBoxHeight(), boxHeight);
653 // move viewport to end of alignment
654 moveViewport(0, 525 - viewHeight - lastHidden - 1);
655 assertEquals(od.getBoxX(), 0);
656 assertEquals(od.getBoxY(),
657 Math.round((float) (525 - viewHeight - lastHidden - 1)
658 * od.getSequencesHeight() / alheight));
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(
679 (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
680 * od.getWidth() / alwidth);
681 boxHeight = Math.round(
682 (float) (vpranges.getEndSeq() - 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(),
697 Math.round((float) 198 * od.getSequencesHeight() / alheight));
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(
718 (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
719 * od.getWidth() / alwidth);
720 boxHeight = Math.round(
721 (float) (vpranges.getEndSeq() - 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);
736 assertEquals(od.getBoxY(),
737 Math.round((float) (firstHidden - viewHeight - 1)
738 * od.getSequencesHeight() / alheight));
739 assertEquals(od.getBoxWidth(), boxWidth);
740 assertEquals(od.getBoxHeight(), boxHeight);
745 * Test setting of the box position, when there are hidden rows at the start
748 @Test(groups = { "Functional" })
749 public void testFromMouseWithHiddenRowsAtStart()
751 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
752 assertEquals(od.getBoxX(), 0);
753 assertEquals(od.getBoxY(), 0);
754 assertEquals(od.getBoxHeight(), boxHeight);
755 assertEquals(od.getBoxWidth(), boxWidth);
756 assertEquals(vpranges.getStartRes(), 0);
757 assertEquals(vpranges.getStartSeq(), 0);
759 // hide rows at start and check updated box position is correct
760 int lastHiddenRow = 30;
761 hideSequences(0, lastHiddenRow);
763 // calculate with visible values
764 alheight = vpranges.getVisibleAlignmentHeight();
765 alwidth = vpranges.getVisibleAlignmentWidth();
767 boxWidth = Math.round(
768 (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
769 * od.getWidth() / alwidth);
770 boxHeight = Math.round(
771 (float) (vpranges.getEndSeq() - vpranges.getStartSeq() + 1)
772 * od.getSequencesHeight() / alheight);
774 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
775 assertEquals(od.getBoxX(), 0);
776 assertEquals(od.getBoxY(), 0);
777 assertEquals(od.getBoxWidth(), boxWidth);
778 assertEquals(od.getBoxHeight(), boxHeight);
780 // click below hidden rows
781 mouseClick(od, 0, 151 + boxHeight / 2);
782 assertEquals(od.getBoxX(), 0);
783 assertEquals(od.getBoxY(), 151);
784 assertEquals(od.getBoxWidth(), boxWidth);
785 assertEquals(od.getBoxHeight(), boxHeight);
789 * Test setting of the box position, when there are hidden rows at the middle
792 @Test(groups = { "Functional" })
793 public void testFromMouseWithHiddenRowsInMiddle()
795 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
797 assertEquals(od.getBoxX(), 0);
798 assertEquals(od.getBoxY(), 0);
799 assertEquals(od.getBoxWidth(), boxWidth);
800 assertEquals(od.getBoxHeight(), boxHeight);
801 assertEquals(vpranges.getStartRes(), 0);
802 assertEquals(vpranges.getStartSeq(), 0);
804 // hide rows in middle and check updated box position is correct
806 int firstHiddenRow = 50;
807 int lastHiddenRow = 54;
808 hideSequences(firstHiddenRow, lastHiddenRow);
810 // calculate with visible values
811 alheight = vpranges.getVisibleAlignmentHeight();
812 alwidth = vpranges.getVisibleAlignmentWidth();
814 boxWidth = Math.round(
815 (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
816 * od.getWidth() / alwidth);
817 boxHeight = Math.round(
818 (float) (vpranges.getEndSeq() - vpranges.getStartSeq() + 1)
819 * od.getSequencesHeight() / alheight);
821 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
823 assertEquals(od.getBoxX(), 0);
824 assertEquals(od.getBoxY(), 0);
825 assertEquals(od.getBoxWidth(), boxWidth);
826 assertEquals(od.getBoxHeight(), boxHeight);
828 // click above hidden rows, so that box overlaps
829 int ypos = 35 + viewHeight / 2; // row value in residues
831 Math.round((float) ypos * od.getSequencesHeight() / alheight));
832 assertEquals(od.getBoxX(), 0);
833 assertEquals(od.getBoxY(),
834 Math.round((float) 35 * od.getSequencesHeight() / alheight));
835 assertEquals(od.getBoxWidth(), boxWidth);
836 assertEquals(od.getBoxHeight(), boxHeight);
838 // click so that box straddles hidden rows
839 ypos = 45 + viewHeight / 2; // row value in residues
841 Math.round((float) ypos * od.getSequencesHeight() / alheight));
842 assertEquals(od.getBoxX(), 0);
843 assertEquals(od.getBoxY(),
844 Math.round((float) 45 * od.getSequencesHeight() / alheight));
845 assertEquals(od.getBoxWidth(), boxWidth);
846 assertEquals(od.getBoxHeight(), boxHeight);
850 * Test setting of the box position, when there are hidden rows at the end of
853 @Test(groups = { "Functional" })
854 public void testFromMouseWithHiddenRowsAtEnd()
856 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
857 assertEquals(od.getBoxX(), 0);
858 assertEquals(od.getBoxY(), 0);
859 assertEquals(od.getBoxWidth(), boxWidth);
860 assertEquals(od.getBoxHeight(), boxHeight);
861 assertEquals(vpranges.getStartRes(), 0);
862 assertEquals(vpranges.getStartSeq(), 0);
864 // hide rows at end and check updated box position is correct
866 int firstHidden = 500;
867 int lastHidden = 524;
868 hideSequences(firstHidden, lastHidden);
870 // calculate with visible values
871 alheight = vpranges.getVisibleAlignmentHeight();
872 alwidth = vpranges.getVisibleAlignmentWidth();
874 boxWidth = Math.round(
875 (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
876 * od.getWidth() / alwidth);
877 boxHeight = Math.round(
878 (float) (vpranges.getEndSeq() - vpranges.getStartSeq() + 1)
879 * od.getSequencesHeight() / alheight);
881 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
882 assertEquals(od.getBoxX(), 0);
883 assertEquals(od.getBoxY(), 0);
884 assertEquals(od.getBoxWidth(), boxWidth);
885 assertEquals(od.getBoxHeight(), boxHeight);
887 // click above hidden rows
888 int ypos = 41 + viewHeight / 2; // row 41
890 Math.round((float) ypos * od.getSequencesHeight() / alheight));
891 assertEquals(od.getBoxX(), 0);
892 assertEquals(od.getBoxY(),
893 Math.round((float) 41 * od.getSequencesHeight() / alheight));
894 assertEquals(od.getBoxWidth(), boxWidth);
895 assertEquals(od.getBoxHeight(), boxHeight);
897 // click above hidden rows so box overlaps
898 // boxY, boxHeight remains same
899 ypos = 497 + viewHeight / 2; // row 497
901 Math.round((float) ypos * od.getSequencesHeight() / alheight));
902 assertEquals(od.getBoxX(), 0);
903 assertEquals(od.getBoxY(), Math
904 .round((float) firstHidden * od.getSequencesHeight() / alheight)
906 assertEquals(od.getBoxWidth(), boxWidth);
907 assertEquals(od.getBoxHeight(), boxHeight);
911 * Test the function to determine if a point is in the overview's box or not
913 @Test(groups = { "Functional" })
914 public void testPositionInBox()
916 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
918 assertFalse(od.isPositionInBox(0, 0));
919 assertTrue(od.isPositionInBox(10, 9));
920 assertFalse(od.isPositionInBox(0, 9));
921 assertFalse(od.isPositionInBox(9, 0));
922 assertFalse(od.isPositionInBox(75, 20));
924 // hide columns in the box area
925 // makes absolutely no difference
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 // hide sequences in box area
935 // makes absolutely no difference
937 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
938 assertFalse(od.isPositionInBox(0, 0));
939 assertTrue(od.isPositionInBox(10, 9));
940 assertFalse(od.isPositionInBox(0, 9));
941 assertFalse(od.isPositionInBox(9, 0));
942 assertFalse(od.isPositionInBox(75, 20));
946 * Test the dragging functionality
948 @Test(groups = { "Functional" })
949 public void testDragging()
951 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
952 od.setDragPoint(4, 16, al.getHiddenSequences(), hiddenCols);
953 od.adjustViewportFromMouse(20, 22, al.getHiddenSequences(), hiddenCols);
955 // updates require an OverviewPanel to exist which it doesn't here
956 // so call setBoxPosition() as it would be called by the AlignmentPanel
958 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
960 // corner moves 16 (20-4) right and 6 (22-16) up
961 assertEquals(od.getBoxX(), 16);
962 assertEquals(od.getBoxY(), 6);
964 // hide columns - makes no difference
965 hiddenCols.hideColumns(1, 4);
966 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
967 od.setDragPoint(4, 16, al.getHiddenSequences(), hiddenCols);
968 od.adjustViewportFromMouse(20, 22, al.getHiddenSequences(), hiddenCols);
969 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
971 // corner moves 16 (20-4) right and 6 (22-16) up
972 assertEquals(od.getBoxX(), 16);
973 assertEquals(od.getBoxY(), 6);
975 // hide sequences in box area
976 // makes absolutely no difference
978 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
979 od.setDragPoint(4, 16, al.getHiddenSequences(), hiddenCols);
980 od.adjustViewportFromMouse(20, 22, al.getHiddenSequences(), hiddenCols);
981 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
983 // corner moves 16 (20-4) right and 6 (22-16) up
984 assertEquals(od.getBoxX(), 16);
985 assertEquals(od.getBoxY(), 6);
989 * Move viewport horizontally: startRes + previous width gives new horizontal extent. Vertical extent stays the same.
991 private void moveViewportH(int startRes)
993 vpranges.setViewportStartAndWidth(startRes, viewWidth);
994 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
998 * Move viewport vertically: startSeq and endSeq give new vertical extent. Horizontal extent stays the same.
1000 private void moveViewportV(int startSeq)
1002 vpranges.setViewportStartAndHeight(startSeq, viewHeight);
1003 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
1007 * Move viewport horizontally and vertically.
1009 private void moveViewport(int startRes, int startSeq)
1011 vpranges.setViewportStartAndWidth(startRes, viewWidth);
1012 vpranges.setViewportStartAndHeight(startSeq, viewHeight);
1013 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
1017 * Mouse click as position x,y in overview window
1019 private void mouseClick(OverviewDimensions od, int x, int y)
1021 od.updateViewportFromMouse(x, y, al.getHiddenSequences(), hiddenCols);
1023 // updates require an OverviewPanel to exist which it doesn't here
1024 // so call setBoxPosition() as it would be called by the AlignmentPanel
1026 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
1030 * Test that the box is positioned with the top left corner at xpos, ypos
1031 * and with the original width and height
1033 private void testBoxIsAtClickPoint(int xpos, int ypos)
1035 mouseClick(od, xpos, ypos);
1036 assertEquals(od.getBoxX() + od.getBoxWidth() / 2, xpos);
1037 assertEquals(od.getBoxY() + od.getBoxHeight() / 2, ypos);
1038 assertEquals(od.getBoxWidth(), boxWidth);
1039 assertEquals(od.getBoxHeight(), boxHeight);
1044 * Hide sequences between start and end
1046 private void hideSequences(int start, int end)
1048 SequenceI[] allseqs = al.getSequencesArray();
1049 SequenceGroup theseSeqs = new SequenceGroup();
1051 for (int i = start; i <= end; i++)
1053 theseSeqs.addSequence(allseqs[i], false);
1054 al.getHiddenSequences().hideSequence(allseqs[i]);
1057 hiddenRepSequences.put(allseqs[start], theseSeqs);