2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import static org.testng.Assert.assertEquals;
25 import jalview.analysis.AlignmentGenerator;
26 import jalview.datamodel.Alignment;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.ColumnSelection;
29 import jalview.datamodel.HiddenColumns;
30 import jalview.datamodel.Sequence;
31 import jalview.datamodel.SequenceCollectionI;
32 import jalview.datamodel.SequenceGroup;
33 import jalview.datamodel.SequenceI;
35 import java.util.Hashtable;
37 import org.testng.annotations.AfterClass;
38 import org.testng.annotations.BeforeClass;
39 import org.testng.annotations.BeforeMethod;
40 import org.testng.annotations.Test;
42 @Test(singleThreaded = true)
43 public class OverviewDimensionsTest
46 OverviewDimensions od;
48 // cached widths and heights
56 ViewportRanges vpranges;
58 Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
60 HiddenColumns hiddenCols = new HiddenColumns();
62 @BeforeClass(alwaysRun = true)
63 public void setUpJvOptionPane()
65 // create random alignment
66 AlignmentGenerator gen = new AlignmentGenerator(false);
67 al = gen.generate(157, 525, 123, 5, 5);
70 @BeforeMethod(alwaysRun = true)
73 if (!hiddenRepSequences.isEmpty())
75 al.getHiddenSequences().showAll(hiddenRepSequences);
77 ColumnSelection colsel = new ColumnSelection();
78 hiddenCols.revealAllHiddenColumns(colsel);
80 vpranges = new ViewportRanges(al);
81 vpranges.setStartRes(0);
82 vpranges.setEndRes(62);
83 vpranges.setStartSeq(0);
84 vpranges.setEndSeq(17);
86 viewHeight = vpranges.getEndSeq() - vpranges.getStartSeq() + 1;
87 viewWidth = vpranges.getEndRes() - vpranges.getStartRes() + 1;
89 HiddenColumns hiddenCols = new HiddenColumns();
91 od = new OverviewDimensions(vpranges, true);
92 // Initial box sizing - default path through code
93 od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges);
98 // calculate before hidden columns so we get absolute values
99 alheight = vpranges.getAbsoluteAlignmentHeight();
100 alwidth = vpranges.getAbsoluteAlignmentWidth();
102 boxWidth = Math.round((float) (vpranges.getEndRes()
103 - vpranges.getStartRes() + 1)
104 * od.getWidth() / alwidth);
105 boxHeight = Math.round((float) (vpranges.getEndSeq()
106 - vpranges.getStartSeq() + 1)
107 * od.getSequencesHeight() / alheight);
110 @AfterClass(alwaysRun = true)
111 public void cleanUp()
117 * Test that the OverviewDimensions constructor sets width and height
120 @Test(groups = { "Functional" })
121 public void testConstructor()
123 SequenceI seqa = new Sequence("Seq1", "ABC");
124 SequenceI seqb = new Sequence("Seq2", "ABC");
125 SequenceI seqc = new Sequence("Seq3", "ABC");
126 SequenceI seqd = new Sequence("Seq4", "ABC");
127 SequenceI seqe = new Sequence("Seq5",
128 "ABCABCABCABCABCABCABCABCBACBACBACBAC");
130 int defaultGraphHeight = 20;
133 int maxSeqHeight = 300;
134 int minSeqHeight = 40;
136 // test for alignment with width > height
137 SequenceI[] seqs1 = new SequenceI[] { seqa, seqb };
138 Alignment al1 = new Alignment(seqs1);
139 ViewportRanges props = new ViewportRanges(al1);
141 OverviewDimensions od = new OverviewDimensions(props, true);
142 int scaledHeight = 267;
143 assertEquals(od.getGraphHeight(), defaultGraphHeight);
144 assertEquals(od.getSequencesHeight(), scaledHeight);
145 assertEquals(od.getWidth(), maxWidth);
146 assertEquals(od.getHeight(), scaledHeight + defaultGraphHeight);
148 // test for alignment with width < height
149 SequenceI[] seqs2 = new SequenceI[] { seqa, seqb, seqc, seqd };
150 Alignment al2 = new Alignment(seqs2);
151 props = new ViewportRanges(al2);
153 od = new OverviewDimensions(props, true);
154 int scaledWidth = 300;
155 assertEquals(od.getGraphHeight(), defaultGraphHeight);
156 assertEquals(od.getSequencesHeight(), maxSeqHeight);
157 assertEquals(od.getWidth(), scaledWidth);
158 assertEquals(od.getHeight(), scaledWidth + defaultGraphHeight);
160 // test for alignment with width > height and sequence height scaled below
162 SequenceI[] seqs3 = new SequenceI[] { seqe };
163 Alignment al3 = new Alignment(seqs3);
164 props = new ViewportRanges(al3);
166 od = new OverviewDimensions(props, true);
167 assertEquals(od.getGraphHeight(), defaultGraphHeight);
168 assertEquals(od.getSequencesHeight(), minSeqHeight);
169 assertEquals(od.getWidth(), maxWidth);
170 assertEquals(od.getHeight(), minSeqHeight + defaultGraphHeight);
172 // test for alignment with width < height and width scaled below min value
173 SequenceI[] seqs4 = new SequenceI[] { seqa, seqb, seqc, seqd, seqa,
174 seqb, seqc, seqd, seqa, seqb, seqc, seqd, seqa, seqb, seqc, seqd };
175 Alignment al4 = new Alignment(seqs4);
176 props = new ViewportRanges(al4);
178 od = new OverviewDimensions(props, true);
179 assertEquals(od.getGraphHeight(), defaultGraphHeight);
180 assertEquals(od.getSequencesHeight(), maxSeqHeight);
181 assertEquals(od.getWidth(), minWidth);
182 assertEquals(od.getHeight(), maxSeqHeight + defaultGraphHeight);
184 Alignment al5 = new Alignment(seqs4);
185 props = new ViewportRanges(al5);
187 od = new OverviewDimensions(props, false);
188 assertEquals(od.getGraphHeight(), 0);
189 assertEquals(od.getSequencesHeight(), maxSeqHeight);
190 assertEquals(od.getWidth(), minWidth);
191 assertEquals(od.getHeight(), maxSeqHeight);
195 * Test that validation after mouse adjustments to boxX and boxY sets box
196 * dimensions and scroll values correctly, when there are no hidden rows or
199 @Test(groups = { "Functional" })
200 public void testSetBoxFromMouseClick()
202 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols,
204 assertEquals(od.getBoxX(), 0);
205 assertEquals(od.getBoxY(), 0);
206 assertEquals(od.getBoxWidth(), boxWidth);
207 assertEquals(od.getScrollCol(), 0);
208 assertEquals(od.getScrollRow(), 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(od.getScrollRow(),
216 Math.round((float) 10 * alheight / od.getSequencesHeight()));
217 assertEquals(od.getScrollCol(), 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(od.getScrollCol(),
225 Math.round((float) 6 * alwidth / od.getWidth()));
226 assertEquals(od.getScrollRow(), 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(od.getScrollCol(),
235 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
236 assertEquals(od.getScrollRow(),
237 Math.round((float) od.getBoxY() * alheight
238 / od.getSequencesHeight()));
240 // overly large boxY value reset to sequenceHeight - boxHeight
241 mouseClick(od, 10, 520);
242 assertEquals(od.getBoxX(), 10);
243 assertEquals(od.getBoxY(), od.getSequencesHeight() - od.getBoxHeight());
244 assertEquals(od.getBoxWidth(), boxWidth);
245 assertEquals(od.getBoxHeight(), boxHeight);
246 assertEquals(od.getScrollCol(),
247 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
249 // here (float) od.getBoxY() * alheight / od.getSequencesHeight() = 507.5
250 // and round rounds to 508; however we get 507 working with row values
251 // hence the subtraction of 1
252 assertEquals(od.getScrollRow(),
253 Math.round((float) od.getBoxY() * alheight
254 / od.getSequencesHeight()) - 1);
256 // click past end of alignment, as above
257 mouseClick(od, 3000, 5);
258 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
259 assertEquals(od.getBoxWidth(), boxWidth);
260 assertEquals(od.getBoxHeight(), boxHeight);
261 assertEquals(od.getScrollCol(),
262 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
263 assertEquals(od.getScrollRow(),
264 Math.round((float) od.getBoxY() * alheight
265 / od.getSequencesHeight()));
267 // move viewport so startRes non-zero and then mouseclick
270 // click at viewport position
271 int oldboxx = od.getBoxX();
272 int oldboxy = od.getBoxY();
273 mouseClick(od, od.getBoxX() + 5, od.getBoxY() + 2);
274 assertEquals(od.getBoxX(), oldboxx + 5);
275 assertEquals(od.getBoxWidth(), boxWidth);
276 assertEquals(od.getBoxHeight(), boxHeight);
277 assertEquals(od.getScrollCol(),
278 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
279 assertEquals(od.getBoxY(), oldboxy + 2);
280 assertEquals(od.getScrollRow(),
281 Math.round((float) od.getBoxY() * alheight
282 / od.getSequencesHeight()));
284 // click at top corner
285 mouseClick(od, 0, 0);
286 assertEquals(od.getBoxX(), 0);
287 assertEquals(od.getScrollCol(), 0);
288 assertEquals(od.getBoxY(), 0);
289 assertEquals(od.getScrollRow(), 0);
290 assertEquals(od.getBoxWidth(), boxWidth);
291 assertEquals(od.getBoxHeight(), boxHeight);
295 * Test setting of the box position, when there are hidden cols at the start
298 @Test(groups = { "Functional" })
299 public void testFromMouseWithHiddenColsAtStart()
301 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols,
303 assertEquals(od.getBoxX(), 0);
304 assertEquals(od.getBoxY(), 0);
305 assertEquals(od.getBoxWidth(), boxWidth);
306 assertEquals(od.getScrollCol(), 0);
307 assertEquals(od.getScrollRow(), 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, vpranges);
315 assertEquals(od.getBoxX(),
316 Math.round((float) (lastHiddenCol + 1) * od.getWidth()
318 assertEquals(od.getBoxWidth(), boxWidth);
319 assertEquals(od.getBoxHeight(), boxHeight);
321 // try to click in hidden cols, check box does not move
323 mouseClick(od, xpos, 0);
326 Math.round((float) (lastHiddenCol + 1) * od.getWidth()
328 assertEquals(od.getBoxY(), 0);
329 assertEquals(od.getBoxWidth(), boxWidth);
330 assertEquals(od.getBoxHeight(), boxHeight);
331 assertEquals(od.getScrollRow(), 0);
332 assertEquals(od.getScrollCol(), 0);
334 // click to right of hidden columns, box moves to click point
335 testBoxIsAtClickPoint(40, 0);
336 assertEquals(od.getScrollRow(), 0);
337 assertEquals(od.getScrollCol(),
338 Math.round((float) 40 * alwidth / od.getWidth())
339 - (lastHiddenCol + 1));
341 // click to right of hidden columns such that box runs over right hand side
343 // box position is adjusted away from the edge
344 // overly large boxX value reset to width-boxWidth
346 mouseClick(od, xpos, 5);
347 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
348 assertEquals(od.getBoxY(), 5);
349 assertEquals(od.getBoxWidth(), boxWidth);
350 assertEquals(od.getBoxHeight(), boxHeight);
351 assertEquals(od.getScrollCol(),
352 Math.round((float) od.getBoxX() * alwidth / od.getWidth())
353 - (lastHiddenCol + 1));
354 assertEquals(od.getScrollRow(),
355 Math.round((float) od.getBoxY() * alheight
356 / 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,
368 assertEquals(od.getBoxX(), 0);
369 assertEquals(od.getBoxY(), 0);
370 assertEquals(od.getBoxWidth(), boxWidth);
371 assertEquals(od.getScrollCol(), 0);
372 assertEquals(od.getScrollRow(), 0);
374 // hide columns 63-73, no change to box position or dimensions
375 int firstHidden = 63;
377 hiddenCols.hideColumns(firstHidden, lastHidden);
379 od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges);
380 assertEquals(od.getBoxX(), 0);
381 assertEquals(od.getBoxY(), 0);
382 assertEquals(od.getBoxWidth(), boxWidth);
383 assertEquals(od.getScrollCol(), 0);
384 assertEquals(od.getScrollRow(), 0);
386 // move box so that it overlaps with hidden cols on one side
387 // box width changes, boxX and scrollCol as for unhidden case
388 int xpos = 55 - boxWidth; // 55 is position in overview approx halfway
389 // between cols 60 and 70
390 mouseClick(od, xpos, 0);
391 assertEquals(od.getBoxX(), xpos);
392 assertEquals(od.getBoxY(), 0);
395 Math.round(boxWidth + (float) (lastHidden - firstHidden + 1)
396 * od.getWidth() / alwidth));
397 assertEquals(od.getBoxHeight(), boxHeight);
398 assertEquals(od.getScrollCol(),
399 Math.round(xpos * alwidth / od.getWidth()));
400 assertEquals(od.getScrollRow(), 0);
402 // move box so that it completely covers hidden cols
403 // box width changes, boxX and scrollCol as for hidden case
405 mouseClick(od, xpos, 0);
406 assertEquals(od.getBoxX(), xpos);
407 assertEquals(od.getBoxY(), 0);
410 Math.round(boxWidth + (float) (lastHidden - firstHidden + 1)
411 * od.getWidth() / alwidth));
412 assertEquals(od.getBoxHeight(), boxHeight);
413 assertEquals(od.getScrollCol(),
414 Math.round((float) xpos * alwidth / od.getWidth()));
415 assertEquals(od.getScrollRow(), 0);
417 // move box so boxX is in hidden cols, box overhangs at right
418 // boxX and scrollCol at left of hidden area, box width extends across
421 mouseClick(od, xpos, 0);
422 assertEquals(od.getBoxX(),
423 Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth));
424 assertEquals(od.getBoxY(), 0);
428 + Math.round((float) (lastHidden - firstHidden + 1)
429 * od.getWidth() / alwidth));
430 assertEquals(od.getBoxHeight(), boxHeight);
431 assertEquals(od.getScrollCol(), firstHidden - 1);
432 assertEquals(od.getScrollRow(), 0);
434 // move box so boxX is to right of hidden cols, but does not go beyond full
435 // width of alignment
436 // box width, boxX and scrollCol all as for non-hidden case
438 testBoxIsAtClickPoint(xpos, 0);
439 assertEquals(od.getScrollRow(), 0);
440 assertEquals(od.getScrollCol(),
441 Math.round(xpos * alwidth / od.getWidth())
442 - (lastHidden - firstHidden + 1));
444 // move box so it goes beyond full width of alignment
445 // boxX, scrollCol adjusted back, box width normal
447 mouseClick(od, xpos, 5);
448 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
449 assertEquals(od.getBoxY(), 5);
450 assertEquals(od.getBoxWidth(), boxWidth);
451 assertEquals(od.getBoxHeight(), boxHeight);
452 assertEquals(od.getScrollCol(),
453 Math.round(((float) od.getBoxX() * alwidth / od.getWidth())
454 - (lastHidden - firstHidden + 1)));
455 assertEquals(od.getScrollRow(),
456 Math.round((float) od.getBoxY() * alheight
457 / od.getSequencesHeight()));
462 * Test setting of the box position, when there are hidden cols at the end of
465 @Test(groups = { "Functional" })
466 public void testFromMouseWithHiddenColsAtEnd()
468 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols,
470 assertEquals(od.getBoxX(), 0);
471 assertEquals(od.getBoxY(), 0);
472 assertEquals(od.getBoxWidth(), boxWidth);
473 assertEquals(od.getScrollCol(), 0);
474 assertEquals(od.getScrollRow(), 0);
476 // hide columns 140-164, no change to box position or dimensions
477 int firstHidden = 140;
478 int lastHidden = 164;
479 hiddenCols.hideColumns(firstHidden, lastHidden);
480 od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges);
481 assertEquals(od.getBoxX(), 0);
482 assertEquals(od.getBoxY(), 0);
483 assertEquals(od.getBoxWidth(), boxWidth);
484 assertEquals(od.getScrollCol(), 0);
485 assertEquals(od.getScrollRow(), 0);
487 // click to left of hidden cols, without overlapping
488 // boxX, scrollCol and width as normal
490 testBoxIsAtClickPoint(xpos, 0);
491 assertEquals(od.getScrollRow(), 0);
492 assertEquals(od.getScrollCol(),
493 Math.round((float) xpos * alwidth / od.getWidth()));
495 // click to left of hidden cols, with overlap
496 // boxX and scrollCol adjusted for hidden cols, width normal
497 xpos = Math.round((float) 145 * od.getWidth() / alwidth) - boxWidth;
498 mouseClick(od, xpos, 0);
499 assertEquals(od.getBoxX(),
500 Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth)
502 assertEquals(od.getBoxY(), 0);
503 assertEquals(od.getBoxWidth(), boxWidth);
504 assertEquals(od.getBoxHeight(), boxHeight);
505 assertEquals(od.getScrollCol(),
506 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
507 assertEquals(od.getScrollRow(), 0);
509 // click in hidden cols
510 // boxX and scrollCol adjusted for hidden cols, width normal
512 assertEquals(od.getBoxX(),
513 Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth)
515 assertEquals(od.getBoxY(), 0);
516 assertEquals(od.getBoxWidth(), boxWidth);
517 assertEquals(od.getBoxHeight(), boxHeight);
518 assertEquals(od.getScrollCol(),
519 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
520 assertEquals(od.getScrollRow(), 0);
522 // click off end of alignment
523 // boxX and scrollCol adjusted for hidden cols, width normal
525 assertEquals(od.getBoxX(),
526 Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth)
528 assertEquals(od.getBoxY(), 0);
529 assertEquals(od.getBoxWidth(), boxWidth);
530 assertEquals(od.getBoxHeight(), boxHeight);
531 assertEquals(od.getScrollCol(),
532 Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
533 assertEquals(od.getScrollRow(), 0);
537 * Test that the box position is set correctly when set from the viewport,
538 * with no hidden rows or columns
540 @Test(groups = { "Functional" })
541 public void testSetBoxFromViewport()
543 // move viewport to start of alignment
545 assertEquals(od.getBoxX(), 0);
546 assertEquals(od.getBoxY(), 0);
547 assertEquals(od.getBoxWidth(), boxWidth);
548 assertEquals(od.getBoxHeight(), boxHeight);
550 // move viewport to right
552 assertEquals(od.getBoxX(),
553 Math.round((float) 70 * od.getWidth() / alwidth));
554 assertEquals(od.getBoxY(), 0);
555 assertEquals(od.getBoxWidth(), boxWidth);
556 assertEquals(od.getBoxHeight(), boxHeight);
558 // move viewport down
560 assertEquals(od.getBoxX(),
561 Math.round((float) 70 * od.getWidth() / alwidth));
562 assertEquals(od.getBoxY(),
563 Math.round(100 * od.getSequencesHeight() / alheight));
564 assertEquals(od.getBoxWidth(), boxWidth);
565 assertEquals(od.getBoxHeight(), boxHeight);
567 // move viewport to bottom right
568 moveViewport(98, 508);
569 assertEquals(od.getBoxX(),
570 Math.round((float) 98 * od.getWidth() / alwidth));
571 assertEquals(od.getBoxY(),
572 Math.round((float) 508 * od.getSequencesHeight() / alheight));
573 assertEquals(od.getBoxWidth(), boxWidth);
574 assertEquals(od.getBoxHeight(), boxHeight);
578 * Test that the box position is set correctly when there are hidden columns
581 @Test(groups = { "Functional" })
582 public void testSetBoxFromViewportHiddenColsAtStart()
586 hiddenCols.hideColumns(firstHidden, lastHidden);
588 // move viewport to start of alignment
590 assertEquals(od.getBoxX(),
591 Math.round((float) (lastHidden + 1) * od.getWidth() / alwidth));
592 assertEquals(od.getBoxY(), 0);
593 assertEquals(od.getBoxWidth(), boxWidth);
594 assertEquals(od.getBoxHeight(), boxHeight);
596 // move viewport to end of alignment - need to make startRes by removing
597 // hidden cols because of how viewport/overview are implemented
598 moveViewport(98 - lastHidden - 1, 0);
599 assertEquals(od.getBoxX(),
600 Math.round((float) 98 * od.getWidth() / alwidth));
601 assertEquals(od.getBoxY(), 0);
602 assertEquals(od.getBoxWidth(), boxWidth);
603 assertEquals(od.getBoxHeight(), boxHeight);
607 * Test that the box position is set correctly when there are hidden columns
610 @Test(groups = { "Functional" })
611 public void testSetBoxFromViewportHiddenColsInMiddle()
613 int firstHidden = 68;
615 hiddenCols.hideColumns(firstHidden, lastHidden);
617 // move viewport before hidden columns
620 assertEquals(od.getBoxX(),
621 Math.round((float) 3 * od.getWidth() / alwidth));
622 assertEquals(od.getBoxY(), 0);
623 System.out.println(od.getBoxWidth());
624 assertEquals(od.getBoxWidth(), boxWidth);
625 System.out.println(od.getBoxWidth());
626 assertEquals(od.getBoxHeight(), boxHeight);
628 // move viewport to left of hidden columns with overlap
630 assertEquals(od.getBoxX(),
631 Math.round((float) 10 * od.getWidth() / alwidth));
632 assertEquals(od.getBoxY(), 0);
636 + Math.round((float) (lastHidden - firstHidden + 1)
637 * od.getWidth() / alwidth));
638 assertEquals(od.getBoxHeight(), boxHeight);
640 // move viewport to straddle hidden columns
642 assertEquals(od.getBoxX(),
643 Math.round((float) 63 * od.getWidth() / alwidth));
644 assertEquals(od.getBoxY(), 0);
648 + Math.round((lastHidden - firstHidden + 1)
649 * od.getWidth() / alwidth));
650 assertEquals(od.getBoxHeight(), boxHeight);
652 // move viewport to right of hidden columns, no overlap
653 moveViewport(80 - (lastHidden - firstHidden + 1), 0);
654 assertEquals(od.getBoxX(),
655 Math.round((float) 80 * od.getWidth() / alwidth));
656 assertEquals(od.getBoxY(), 0);
657 assertEquals(od.getBoxWidth(), boxWidth);
658 assertEquals(od.getBoxHeight(), boxHeight);
663 * Test that the box position is set correctly when there are hidden columns
666 @Test(groups = { "Functional" })
667 public void testSetBoxFromViewportHiddenColsAtEnd()
669 int firstHidden = 152;
670 int lastHidden = 164;
671 hiddenCols.hideColumns(firstHidden, lastHidden);
673 // move viewport before hidden columns
675 assertEquals(od.getBoxX(),
676 Math.round((float) 3 * od.getWidth() / alwidth));
677 assertEquals(od.getBoxY(), 0);
678 assertEquals(od.getBoxWidth(), boxWidth);
679 assertEquals(od.getBoxHeight(), boxHeight);
681 // move viewport to hidden columns
682 // viewport can't actually extend into hidden cols,
683 // so move to the far right edge of the viewport
684 moveViewport(firstHidden - viewWidth, 0);
685 assertEquals(od.getBoxX(),
686 Math.round((float) (firstHidden - viewWidth)
687 * od.getWidth() / alwidth));
688 assertEquals(od.getBoxY(), 0);
689 assertEquals(od.getBoxWidth(), boxWidth);
690 assertEquals(od.getBoxHeight(), boxHeight);
694 * Test that the box position is set correctly when there are hidden rows at
697 @Test(groups = { "Functional" })
698 public void testSetBoxFromViewportHiddenRowsAtStart()
702 hideSequences(firstHidden, lastHidden);
704 // move viewport to start of alignment:
705 // box moves to below hidden rows, height remains same
707 assertEquals(od.getBoxX(), 0);
708 assertEquals(od.getBoxY(),
709 Math.round((float) (lastHidden + 1) * od.getSequencesHeight()
711 assertEquals(od.getBoxWidth(), boxWidth);
712 assertEquals(od.getBoxHeight(), boxHeight);
714 // move viewport to end of alignment
715 moveViewport(0, 525 - viewHeight - lastHidden - 1);
716 assertEquals(od.getBoxX(), 0);
719 Math.round((float) (525 - viewHeight) * od.getSequencesHeight()
721 assertEquals(od.getBoxWidth(), boxWidth);
722 assertEquals(od.getBoxHeight(), boxHeight);
726 * Test that the box position is set correctly when there are hidden rows in
729 @Test(groups = { "Functional" })
730 public void testSetBoxFromViewportHiddenRowsInMiddle()
732 int firstHidden = 200;
733 int lastHidden = 210;
734 hideSequences(firstHidden, lastHidden);
736 // move viewport to start of alignment:
737 // box, height etc as in non-hidden case
739 assertEquals(od.getBoxX(), 0);
740 assertEquals(od.getBoxY(), 0);
741 assertEquals(od.getBoxWidth(), boxWidth);
742 assertEquals(od.getBoxHeight(), boxHeight);
744 // move viewport to straddle hidden rows
745 moveViewport(0, 198);
746 assertEquals(od.getBoxX(), 0);
747 assertEquals(od.getBoxY(), Math.round ((float)198 * od.getSequencesHeight()
749 assertEquals(od.getBoxWidth(), boxWidth);
752 Math.round((float) (viewHeight + lastHidden - firstHidden + 1)
753 * od.getSequencesHeight() / alheight));
757 * Test that the box position is set correctly when there are hidden rows at
760 @Test(groups = { "Functional" })
761 public void testSetBoxFromViewportHiddenRowsAtEnd()
763 int firstHidden = 500;
764 int lastHidden = 524;
765 hideSequences(firstHidden, lastHidden);
767 // move viewport to start of alignment:
768 // box, height etc as in non-hidden case
770 assertEquals(od.getBoxX(), 0);
771 assertEquals(od.getBoxY(), 0);
772 assertEquals(od.getBoxWidth(), boxWidth);
773 assertEquals(od.getBoxHeight(), boxHeight);
775 // move viewport to end of alignment
776 // viewport sits above hidden rows and does not include them
777 moveViewport(0, firstHidden - viewHeight - 1);
778 assertEquals(od.getBoxX(), 0);
781 Math.round((float) (firstHidden - viewHeight - 1)
782 * od.getSequencesHeight() / alheight));
783 assertEquals(od.getBoxWidth(), boxWidth);
784 assertEquals(od.getBoxHeight(), boxHeight);
789 * Test setting of the box position, when there are hidden rows at the start
792 @Test(groups = { "Functional" })
793 public void testFromMouseWithHiddenRowsAtStart()
795 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols,
797 assertEquals(od.getBoxX(), 0);
798 assertEquals(od.getBoxY(), 0);
799 assertEquals(od.getBoxHeight(), boxHeight);
800 assertEquals(od.getBoxWidth(), boxWidth);
801 assertEquals(od.getScrollCol(), 0);
802 assertEquals(od.getScrollRow(), 0);
804 // hide rows at start and check updated box position is correct
805 // changes boxY but not boxheight
806 int lastHiddenRow = 30;
807 hideSequences(0, lastHiddenRow);
809 od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges);
810 assertEquals(od.getBoxX(), 0);
811 assertEquals(od.getBoxY(),
812 Math.round((float) (lastHiddenRow + 1)
813 * od.getSequencesHeight() / alheight));
814 assertEquals(od.getBoxWidth(), boxWidth);
815 assertEquals(od.getBoxHeight(), boxHeight);
817 // click in hidden rows - same result
818 mouseClick(od, 0, 0);
819 assertEquals(od.getBoxX(), 0);
822 Math.round((float) (lastHiddenRow + 1)
823 * od.getSequencesHeight() / alheight));
824 assertEquals(od.getBoxWidth(), boxWidth);
825 assertEquals(od.getBoxHeight(), boxHeight);
827 // click below hidden rows
828 mouseClick(od, 0, 150);
829 assertEquals(od.getBoxX(), 0);
830 assertEquals(od.getBoxY(), 150);
831 assertEquals(od.getBoxWidth(), boxWidth);
832 assertEquals(od.getBoxHeight(), boxHeight);
836 * Test setting of the box position, when there are hidden rows at the middle
839 @Test(groups = { "Functional" })
840 public void testFromMouseWithHiddenRowsInMiddle()
842 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols,
845 assertEquals(od.getBoxX(), 0);
846 assertEquals(od.getBoxY(), 0);
847 assertEquals(od.getBoxWidth(), boxWidth);
848 assertEquals(od.getBoxHeight(), boxHeight);
849 assertEquals(od.getScrollCol(), 0);
850 assertEquals(od.getScrollRow(), 0);
852 // hide rows in middle and check updated box position is correct
854 int firstHiddenRow = 50;
855 int lastHiddenRow = 54;
856 hideSequences(firstHiddenRow, lastHiddenRow);
858 od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges);
860 assertEquals(od.getBoxX(), 0);
861 assertEquals(od.getBoxY(), 0);
862 assertEquals(od.getBoxWidth(), boxWidth);
863 assertEquals(od.getBoxHeight(), boxHeight);
865 // click above hidden rows, so that box overlaps
866 int ypos = 35; // column value in residues
868 Math.round((float) ypos * od.getSequencesHeight() / alheight));
869 assertEquals(od.getBoxX(), 0);
870 assertEquals(od.getBoxY(),
871 Math.round((float) ypos * od.getSequencesHeight() / alheight));
872 assertEquals(od.getBoxWidth(), boxWidth);
876 + Math.round((float) (lastHiddenRow - firstHiddenRow + 1)
877 * od.getSequencesHeight() / alheight));
879 // click so that box straddles hidden rows
880 ypos = 44; // column value in residues
882 Math.round((float) ypos * od.getSequencesHeight() / alheight));
883 assertEquals(od.getBoxX(), 0);
884 assertEquals(od.getBoxY(),
885 Math.round((float) ypos * od.getSequencesHeight() / alheight));
886 assertEquals(od.getBoxWidth(), boxWidth);
890 + Math.round((float) (lastHiddenRow - firstHiddenRow + 1)
891 * od.getSequencesHeight() / alheight));
895 * Test setting of the box position, when there are hidden rows at the end of
898 @Test(groups = { "Functional" })
899 public void testFromMouseWithHiddenRowsAtEnd()
901 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols,
903 assertEquals(od.getBoxX(), 0);
904 assertEquals(od.getBoxY(), 0);
905 assertEquals(od.getBoxWidth(), boxWidth);
906 assertEquals(od.getBoxHeight(), boxHeight);
907 assertEquals(od.getScrollCol(), 0);
908 assertEquals(od.getScrollRow(), 0);
910 // hide rows at end and check updated box position is correct
912 int firstHidden = 500;
913 int lastHidden = 524;
914 hideSequences(firstHidden, lastHidden);
916 od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges);
917 assertEquals(od.getBoxX(), 0);
918 assertEquals(od.getBoxY(), 0);
919 assertEquals(od.getBoxWidth(), boxWidth);
920 assertEquals(od.getBoxHeight(), boxHeight);
922 // click above hidden rows
923 int ypos = 40; // row 40
925 Math.round((float) ypos * od.getSequencesHeight() / alheight));
926 assertEquals(od.getBoxX(), 0);
927 assertEquals(od.getBoxY(),
928 Math.round((float) ypos * od.getSequencesHeight() / alheight));
929 assertEquals(od.getBoxWidth(), boxWidth);
930 assertEquals(od.getBoxHeight(), boxHeight);
932 // click above hidden rows so box overlaps
933 // boxY moved upwards, boxHeight remains same
934 ypos = 497; // row 497
936 Math.round((float) ypos * od.getSequencesHeight() / alheight));
937 assertEquals(od.getBoxX(), 0);
940 Math.round((float) (firstHidden - viewHeight)
941 * od.getSequencesHeight() / alheight));
942 assertEquals(od.getBoxWidth(), boxWidth);
943 assertEquals(od.getBoxHeight(), boxHeight);
945 // click within hidden rows
948 Math.round((float) ypos * od.getSequencesHeight() / alheight));
949 assertEquals(od.getBoxX(), 0);
952 Math.round((firstHidden - viewHeight) * od.getSequencesHeight()
954 assertEquals(od.getBoxWidth(), boxWidth);
955 assertEquals(od.getBoxHeight(), boxHeight);
959 * Move viewport horizontally: startRes + previous width gives new horizontal extent. Vertical extent stays the same.
961 private void moveViewportH(int startRes)
963 vpranges.setStartRes(startRes);
964 vpranges.setEndRes(startRes + viewWidth - 1);
965 od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges);
969 * Move viewport vertically: startSeq and endSeq give new vertical extent. Horizontal extent stays the same.
971 private void moveViewportV(int startSeq)
973 vpranges.setStartSeq(startSeq);
974 vpranges.setEndSeq(startSeq + viewHeight - 1);
975 od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges);
979 * Move viewport horizontally and vertically.
981 private void moveViewport(int startRes, int startSeq)
983 vpranges.setStartRes(startRes);
984 vpranges.setEndRes(startRes + viewWidth - 1);
985 vpranges.setStartSeq(startSeq);
986 vpranges.setEndSeq(startSeq + viewHeight - 1);
987 od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges);
991 * Mouse click as position x,y in overview window
993 private void mouseClick(OverviewDimensions od, int x, int y)
995 od.updateViewportFromMouse(x, y, al.getHiddenSequences(), hiddenCols,
998 // updates require an OverviewPanel to exist which it doesn't here
999 // so call setBoxPosition() as it would be called by the AlignmentPanel
1002 vpranges.setStartRes(od.getScrollCol());
1003 vpranges.setEndRes(od.getScrollCol() + viewWidth - 1);
1004 vpranges.setStartSeq(od.getScrollRow());
1005 vpranges.setEndSeq(od.getScrollRow() + viewHeight - 1);
1006 od.setBoxPosition(al.getHiddenSequences(), hiddenCols, vpranges);
1010 * Test that the box is positioned with the top left corner at xpos, ypos
1011 * and with the original width and height
1013 private void testBoxIsAtClickPoint(int xpos, int ypos)
1015 mouseClick(od, xpos, ypos);
1016 assertEquals(od.getBoxX(), xpos);
1017 assertEquals(od.getBoxY(), ypos);
1018 assertEquals(od.getBoxWidth(), boxWidth);
1019 assertEquals(od.getBoxHeight(), boxHeight);
1024 * Hide sequences between start and end
1026 private void hideSequences(int start, int end)
1028 SequenceI[] allseqs = al.getSequencesArray();
1029 SequenceGroup theseSeqs = new SequenceGroup();
1031 for (int i = start; i <= end; i++)
1033 theseSeqs.addSequence(allseqs[i], false);
1034 al.getHiddenSequences().hideSequence(allseqs[i]);
1037 hiddenRepSequences.put(allseqs[start], theseSeqs);