Clover icon

Coverage Report

  1. Project Clover database Mon Sep 2 2024 17:57:51 BST
  2. Package jalview.viewmodel

File OverviewDimensionsShowHiddenTest.java

 

Code metrics

4
538
27
1
1,121
763
29
0.05
19.93
27
1.07

Classes

Class Line # Actions
OverviewDimensionsShowHiddenTest 45 538 29
1.0100%
 

Contributing tests

This file is covered by 18 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.viewmodel;
22   
23    import static org.testng.Assert.assertEquals;
24    import static org.testng.Assert.assertFalse;
25    import static org.testng.Assert.assertTrue;
26   
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;
36   
37    import java.util.Hashtable;
38   
39    import org.testng.annotations.AfterClass;
40    import org.testng.annotations.BeforeClass;
41    import org.testng.annotations.BeforeMethod;
42    import org.testng.annotations.Test;
43   
44    @Test(singleThreaded = true)
 
45    public class OverviewDimensionsShowHiddenTest
46    {
47    AlignmentI al;
48   
49    OverviewDimensionsShowHidden od;
50   
51    // cached widths and heights
52    int boxWidth;
53   
54    int boxHeight;
55   
56    int viewHeight;
57   
58    int viewWidth;
59   
60    int alheight;
61   
62    int alwidth;
63   
64    ViewportRanges vpranges;
65   
66    Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences = new Hashtable<>();
67   
68    HiddenColumns hiddenCols = new HiddenColumns();
69   
 
70  1 toggle @BeforeClass(alwaysRun = true)
71    public void setUpAlignment()
72    {
73    // create random alignment
74  1 AlignmentGenerator gen = new AlignmentGenerator(false);
75  1 al = gen.generate(157, 525, 123, 5, 5);
76    }
77   
 
78  18 toggle @BeforeMethod(alwaysRun = true)
79    public void setUp()
80    {
81  18 if (!hiddenRepSequences.isEmpty())
82    {
83  16 al.getHiddenSequences().showAll(hiddenRepSequences);
84    }
85  18 ColumnSelection colsel = new ColumnSelection();
86  18 hiddenCols.revealAllHiddenColumns(colsel);
87   
88  18 vpranges = new ViewportRanges(al);
89  18 vpranges.setViewportStartAndHeight(0, 18);
90  18 vpranges.setViewportStartAndWidth(0, 63);
91   
92  18 viewHeight = vpranges.getEndSeq() - vpranges.getStartSeq() + 1;
93  18 viewWidth = vpranges.getEndRes() - vpranges.getStartRes() + 1;
94   
95  18 HiddenColumns hiddenCols = new HiddenColumns();
96   
97  18 od = new OverviewDimensionsShowHidden(vpranges, true);
98    // Initial box sizing - default path through code
99  18 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
100   
101  18 mouseClick(od, 0, 0);
102  18 moveViewport(0, 0);
103   
104    // calculate before hidden columns so we get absolute values
105  18 alheight = vpranges.getAbsoluteAlignmentHeight();
106  18 alwidth = vpranges.getAbsoluteAlignmentWidth();
107   
108  18 boxWidth = Math.round(
109    (float) (vpranges.getEndRes() - vpranges.getStartRes() + 1)
110    * od.getWidth() / alwidth);
111  18 boxHeight = Math.round(
112    (float) (vpranges.getEndSeq() - vpranges.getStartSeq() + 1)
113    * od.getSequencesHeight() / alheight);
114    }
115   
 
116  1 toggle @AfterClass(alwaysRun = true)
117    public void cleanUp()
118    {
119  1 al = null;
120    }
121   
122    /**
123    * Test that the OverviewDimensions constructor sets width and height
124    * correctly
125    */
 
126  1 toggle @Test(groups = { "Functional" })
127    public void testConstructor()
128    {
129  1 SequenceI seqa = new Sequence("Seq1", "ABC");
130  1 SequenceI seqb = new Sequence("Seq2", "ABC");
131  1 SequenceI seqc = new Sequence("Seq3", "ABC");
132  1 SequenceI seqd = new Sequence("Seq4", "ABC");
133  1 SequenceI seqe = new Sequence("Seq5",
134    "ABCABCABCABCABCABCABCABCBACBACBACBAC");
135   
136  1 int defaultGraphHeight = 20;
137  1 int maxWidth = 400;
138  1 int minWidth = 120;
139  1 int maxSeqHeight = 300;
140  1 int minSeqHeight = 40;
141   
142    // test for alignment with width > height
143  1 SequenceI[] seqs1 = new SequenceI[] { seqa, seqb };
144  1 Alignment al1 = new Alignment(seqs1);
145  1 ViewportRanges props = new ViewportRanges(al1);
146   
147  1 OverviewDimensions od = new OverviewDimensionsShowHidden(props, true);
148  1 int scaledHeight = 267;
149  1 assertEquals(od.getGraphHeight(), defaultGraphHeight);
150  1 assertEquals(od.getSequencesHeight(), scaledHeight);
151  1 assertEquals(od.getWidth(), maxWidth);
152  1 assertEquals(od.getHeight(), scaledHeight + defaultGraphHeight);
153   
154    // test for alignment with width < height
155  1 SequenceI[] seqs2 = new SequenceI[] { seqa, seqb, seqc, seqd };
156  1 Alignment al2 = new Alignment(seqs2);
157  1 props = new ViewportRanges(al2);
158   
159  1 od = new OverviewDimensionsShowHidden(props, true);
160  1 int scaledWidth = 300;
161  1 assertEquals(od.getGraphHeight(), defaultGraphHeight);
162  1 assertEquals(od.getSequencesHeight(), maxSeqHeight);
163  1 assertEquals(od.getWidth(), scaledWidth);
164  1 assertEquals(od.getHeight(), scaledWidth + defaultGraphHeight);
165   
166    // test for alignment with width > height and sequence height scaled below
167    // min value
168  1 SequenceI[] seqs3 = new SequenceI[] { seqe };
169  1 Alignment al3 = new Alignment(seqs3);
170  1 props = new ViewportRanges(al3);
171   
172  1 od = new OverviewDimensionsShowHidden(props, true);
173  1 assertEquals(od.getGraphHeight(), defaultGraphHeight);
174  1 assertEquals(od.getSequencesHeight(), minSeqHeight);
175  1 assertEquals(od.getWidth(), maxWidth);
176  1 assertEquals(od.getHeight(), minSeqHeight + defaultGraphHeight);
177   
178    // test for alignment with width < height and width scaled below min value
179  1 SequenceI[] seqs4 = new SequenceI[] { seqa, seqb, seqc, seqd, seqa,
180    seqb, seqc, seqd, seqa, seqb, seqc, seqd, seqa, seqb, seqc, seqd };
181  1 Alignment al4 = new Alignment(seqs4);
182  1 props = new ViewportRanges(al4);
183   
184  1 od = new OverviewDimensionsShowHidden(props, true);
185  1 assertEquals(od.getGraphHeight(), defaultGraphHeight);
186  1 assertEquals(od.getSequencesHeight(), maxSeqHeight);
187  1 assertEquals(od.getWidth(), minWidth);
188  1 assertEquals(od.getHeight(), maxSeqHeight + defaultGraphHeight);
189   
190  1 Alignment al5 = new Alignment(seqs4);
191  1 props = new ViewportRanges(al5);
192   
193  1 od = new OverviewDimensionsShowHidden(props, false);
194  1 assertEquals(od.getGraphHeight(), 0);
195  1 assertEquals(od.getSequencesHeight(), maxSeqHeight);
196  1 assertEquals(od.getWidth(), minWidth);
197  1 assertEquals(od.getHeight(), maxSeqHeight);
198    }
199   
200    /**
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
203    * columns.
204    */
 
205  1 toggle @Test(groups = { "Functional" })
206    public void testSetBoxFromMouseClick()
207    {
208  1 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
209  1 assertEquals(od.getBoxX(), 0);
210  1 assertEquals(od.getBoxY(), 0);
211  1 assertEquals(od.getBoxWidth(), boxWidth);
212  1 assertEquals(vpranges.getStartRes(), 0);
213  1 assertEquals(vpranges.getStartSeq(), 0);
214   
215    // negative boxX value reset to 0
216  1 mouseClick(od, -5, 10);
217  1 assertEquals(od.getBoxX(), 0);
218  1 assertEquals(od.getBoxWidth(), boxWidth);
219  1 assertEquals(od.getBoxHeight(), boxHeight);
220  1 assertEquals(vpranges.getStartSeq() + vpranges.getViewportHeight() / 2,
221    Math.round((float) 10 * alheight / od.getSequencesHeight()));
222  1 assertEquals(vpranges.getStartRes(), 0);
223   
224    // negative boxY value reset to 0
225  1 mouseClick(od, 6, -2);
226  1 assertEquals(od.getBoxY(), 0);
227  1 assertEquals(od.getBoxWidth(), boxWidth);
228  1 assertEquals(od.getBoxHeight(), boxHeight);
229  1 assertEquals(vpranges.getStartRes(), 0);
230  1 assertEquals(vpranges.getStartSeq(), 0);
231   
232    // overly large boxX value reset to width-boxWidth
233  1 mouseClick(od, 101, 6);
234  1 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
235  1 assertEquals(od.getBoxY(), 1);
236  1 assertEquals(od.getBoxWidth(), boxWidth);
237  1 assertEquals(od.getBoxHeight(), boxHeight);
238  1 assertEquals(vpranges.getStartRes(),
239    Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
240  1 assertEquals(vpranges.getStartSeq(), Math.round(
241    (float) od.getBoxY() * alheight / od.getSequencesHeight()));
242   
243    // overly large boxY value reset to sequenceHeight - boxHeight
244  1 mouseClick(od, 10, 520);
245  1 assertEquals(od.getBoxX(), 0);
246  1 assertEquals(od.getBoxY(), od.getSequencesHeight() - od.getBoxHeight());
247  1 assertEquals(od.getBoxWidth(), boxWidth);
248  1 assertEquals(od.getBoxHeight(), boxHeight);
249  1 assertEquals(0,
250    Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
251   
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  1 assertEquals(vpranges.getStartSeq(), Math.round(
256    (float) od.getBoxY() * alheight / od.getSequencesHeight()) - 1);
257   
258    // click past end of alignment, as above
259  1 mouseClick(od, 3000, 5);
260  1 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
261  1 assertEquals(od.getBoxWidth(), boxWidth);
262  1 assertEquals(od.getBoxHeight(), boxHeight);
263  1 assertEquals(vpranges.getStartRes(),
264    Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
265  1 assertEquals(vpranges.getStartSeq(), Math.round(
266    (float) od.getBoxY() * alheight / od.getSequencesHeight()));
267   
268    // move viewport so startRes non-zero and then mouseclick
269  1 moveViewportH(20);
270   
271    // click at viewport position
272  1 int oldboxx = od.getBoxX();
273  1 int oldboxy = od.getBoxY();
274  1 mouseClick(od, od.getBoxX() + od.getBoxWidth() / 2 + 6,
275    od.getBoxY() + od.getBoxHeight() / 2 + 3);
276  1 assertEquals(od.getBoxX(), oldboxx + 6);
277  1 assertEquals(od.getBoxWidth(), boxWidth);
278  1 assertEquals(od.getBoxHeight(), boxHeight);
279  1 assertEquals(vpranges.getStartRes(),
280    Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
281  1 assertEquals(od.getBoxY(), oldboxy + 3);
282  1 assertEquals(vpranges.getStartSeq(), Math.round(
283    (float) od.getBoxY() * alheight / od.getSequencesHeight()));
284   
285    // click at top corner
286  1 mouseClick(od, 0, 0);
287  1 assertEquals(od.getBoxX(), 0);
288  1 assertEquals(vpranges.getStartRes(), 0);
289  1 assertEquals(od.getBoxY(), 0);
290  1 assertEquals(vpranges.getStartSeq(), 0);
291  1 assertEquals(od.getBoxWidth(), boxWidth);
292  1 assertEquals(od.getBoxHeight(), boxHeight);
293    }
294   
295    /**
296    * Test setting of the box position, when there are hidden cols at the start
297    * of the alignment
298    */
 
299  1 toggle @Test(groups = { "Functional" })
300    public void testFromMouseWithHiddenColsAtStart()
301    {
302  1 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
303  1 assertEquals(od.getBoxX(), 0);
304  1 assertEquals(od.getBoxY(), 0);
305  1 assertEquals(od.getBoxWidth(), boxWidth);
306  1 assertEquals(vpranges.getStartRes(), 0);
307  1 assertEquals(vpranges.getStartSeq(), 0);
308   
309    // hide cols at start and check updated box position is correct
310    // changes boxX but not boxwidth
311  1 int lastHiddenCol = 30;
312  1 hiddenCols.hideColumns(0, lastHiddenCol);
313   
314  1 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
315  1 assertEquals(od.getBoxX(), Math
316    .round((float) (lastHiddenCol + 1) * od.getWidth() / alwidth));
317  1 assertEquals(od.getBoxWidth(), boxWidth);
318  1 assertEquals(od.getBoxHeight(), boxHeight);
319   
320    // try to click in hidden cols, check box does not move
321  1 int xpos = 10;
322  1 mouseClick(od, xpos, 0);
323  1 assertEquals(od.getBoxX(), Math
324    .round((float) (lastHiddenCol + 1) * od.getWidth() / alwidth));
325  1 assertEquals(od.getBoxY(), 0);
326  1 assertEquals(od.getBoxWidth(), boxWidth);
327  1 assertEquals(od.getBoxHeight(), boxHeight);
328  1 assertEquals(vpranges.getStartSeq(), 0);
329  1 assertEquals(vpranges.getStartRes(), 0);
330   
331    // click to right of hidden columns, box moves to click point
332  1 mouseClick(od, 60 + boxWidth / 2, boxHeight / 2);
333  1 assertEquals(od.getBoxX(), 60);
334  1 assertEquals(od.getBoxY(), 0);
335  1 assertEquals(od.getBoxWidth(), boxWidth);
336  1 assertEquals(od.getBoxHeight(), boxHeight);
337  1 assertEquals(vpranges.getStartSeq(), 0);
338  1 assertEquals(vpranges.getStartRes(),
339    Math.round((float) 60 * alwidth / od.getWidth())
340    - (lastHiddenCol + 1));
341   
342    // click to right of hidden columns such that box runs over right hand side
343    // of alignment
344    // box position is adjusted away from the edge
345    // overly large boxX value reset to width-boxWidth
346  1 xpos = 100;
347  1 mouseClick(od, xpos + boxWidth / 2, 5 + boxHeight / 2);
348  1 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
349  1 assertEquals(od.getBoxY(), 5);
350  1 assertEquals(od.getBoxWidth(), boxWidth);
351  1 assertEquals(od.getBoxHeight(), boxHeight);
352  1 assertEquals(vpranges.getStartRes(),
353    Math.round((float) od.getBoxX() * alwidth / od.getWidth())
354    - (lastHiddenCol + 1));
355  1 assertEquals(vpranges.getStartSeq(), Math.round(
356    (float) od.getBoxY() * alheight / od.getSequencesHeight()));
357    }
358   
359    /**
360    * Test setting of the box position, when there are hidden cols in the middle
361    * of the alignment
362    */
 
363  1 toggle @Test(groups = { "Functional" })
364    public void testFromMouseWithHiddenColsInMiddle()
365    {
366  1 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
367  1 assertEquals(od.getBoxX(), 0);
368  1 assertEquals(od.getBoxY(), 0);
369  1 assertEquals(od.getBoxWidth(), boxWidth);
370  1 assertEquals(vpranges.getStartRes(), 0);
371  1 assertEquals(vpranges.getStartSeq(), 0);
372   
373    // hide columns 63-73, no change to box position or dimensions
374  1 int firstHidden = 63;
375  1 int lastHidden = 73;
376  1 hiddenCols.hideColumns(firstHidden, lastHidden);
377   
378  1 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
379  1 assertEquals(od.getBoxX(), 0);
380  1 assertEquals(od.getBoxY(), 0);
381  1 assertEquals(od.getBoxWidth(), boxWidth);
382  1 assertEquals(vpranges.getStartRes(), 0);
383  1 assertEquals(vpranges.getStartSeq(), 0);
384   
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  1 int xpos = 54 - boxWidth / 2; // 54 is position in overview approx halfway
388    // between cols 60 and 70
389  1 mouseClick(od, xpos, boxHeight / 2);
390  1 assertEquals(od.getBoxX(), xpos - boxWidth / 2);
391  1 assertEquals(od.getBoxY(), 0);
392  1 assertEquals(od.getBoxWidth(),
393    Math.round(boxWidth + (float) (lastHidden - firstHidden + 1)
394    * od.getWidth() / alwidth));
395  1 assertEquals(od.getBoxHeight(), boxHeight);
396  1 assertEquals(vpranges.getStartRes(),
397    Math.round((xpos - boxWidth / 2) * alwidth / od.getWidth())
398    + 1); // +1 for rounding
399  1 assertEquals(vpranges.getStartSeq(), 0);
400   
401    // move box so that it completely covers hidden cols
402    // box width changes, boxX and scrollCol as for hidden case
403  1 xpos = 24 + boxWidth / 2;
404  1 mouseClick(od, xpos, 0);
405  1 assertEquals(od.getBoxX(), 24);
406  1 assertEquals(od.getBoxY(), 0);
407  1 assertEquals(od.getBoxWidth(),
408    Math.round(boxWidth + (float) (lastHidden - firstHidden + 1)
409    * od.getWidth() / alwidth));
410  1 assertEquals(od.getBoxHeight(), boxHeight);
411  1 assertEquals(vpranges.getStartRes(),
412    Math.round((float) 24 * alwidth / od.getWidth()));
413  1 assertEquals(vpranges.getStartSeq(), 0);
414   
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  1 xpos = Math.round((float) 75 * od.getWidth() / alwidth) + boxWidth / 2;
419  1 mouseClick(od, xpos, boxHeight / 2);
420  1 assertEquals(od.getBoxX(), xpos - boxWidth / 2);
421  1 assertEquals(od.getBoxY(), 0);
422  1 assertEquals(od.getBoxWidth(), boxWidth);
423  1 assertEquals(od.getBoxHeight(), boxHeight);
424  1 assertEquals(vpranges.getStartSeq(), 0);
425  1 assertEquals(vpranges.getStartRes(),
426    75 - (lastHidden - firstHidden + 1));
427   
428    // move box so it goes beyond full width of alignment
429    // boxX, scrollCol adjusted back, box width normal
430  1 xpos = 3000;
431  1 mouseClick(od, xpos, 5);
432  1 assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
433  1 assertEquals(od.getBoxY(), 0);
434  1 assertEquals(od.getBoxWidth(), boxWidth);
435  1 assertEquals(od.getBoxHeight(), boxHeight);
436  1 assertEquals(vpranges.getStartRes(),
437    Math.round(((float) od.getBoxX() * alwidth / od.getWidth())
438    - (lastHidden - firstHidden + 1)));
439  1 assertEquals(vpranges.getStartSeq(), Math.round(
440    (float) od.getBoxY() * alheight / od.getSequencesHeight()));
441   
442    }
443   
444    /**
445    * Test setting of the box position, when there are hidden cols at the end of
446    * the alignment
447    */
 
448  1 toggle @Test(groups = { "Functional" })
449    public void testFromMouseWithHiddenColsAtEnd()
450    {
451  1 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
452  1 assertEquals(od.getBoxX(), 0);
453  1 assertEquals(od.getBoxY(), 0);
454  1 assertEquals(od.getBoxWidth(), boxWidth);
455  1 assertEquals(vpranges.getStartRes(), 0);
456  1 assertEquals(vpranges.getStartSeq(), 0);
457   
458    // hide columns 140-164, no change to box position or dimensions
459  1 int firstHidden = 140;
460  1 int lastHidden = 164;
461  1 hiddenCols.hideColumns(firstHidden, lastHidden);
462  1 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
463  1 assertEquals(od.getBoxX(), 0);
464  1 assertEquals(od.getBoxY(), 0);
465  1 assertEquals(od.getBoxWidth(), boxWidth);
466  1 assertEquals(vpranges.getStartRes(), 0);
467  1 assertEquals(vpranges.getStartSeq(), 0);
468   
469    // click to left of hidden cols, without overlapping
470    // boxX, scrollCol and width as normal
471  1 int xpos = 30;
472  1 int ypos = 6;
473  1 testBoxIsAtClickPoint(xpos, ypos);
474  1 assertEquals(vpranges.getStartSeq(), Math.round(
475    (float) (ypos - boxHeight / 2) * alheight / od.getHeight()));
476  1 assertEquals(vpranges.getStartRes(), Math.round(
477    (float) (xpos - boxWidth / 2) * alwidth / od.getWidth()));
478   
479    // click to left of hidden cols, with overlap
480    // boxX and scrollCol adjusted for hidden cols, width normal
481  1 xpos = Math.round((float) 145 * od.getWidth() / alwidth) - boxWidth;
482  1 mouseClick(od, xpos + boxWidth / 2, boxHeight / 2);
483  1 assertEquals(od.getBoxX(),
484    Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth)
485    - boxWidth + 1);
486  1 assertEquals(od.getBoxY(), 0);
487  1 assertEquals(od.getBoxWidth(), boxWidth);
488  1 assertEquals(od.getBoxHeight(), boxHeight);
489  1 assertEquals(vpranges.getStartRes(),
490    Math.round((float) (od.getBoxX()) * alwidth / od.getWidth()));
491  1 assertEquals(vpranges.getStartSeq(), 0);
492   
493    // click in hidden cols
494    // boxX and scrollCol adjusted for hidden cols, width normal
495  1 xpos = 115;
496  1 assertEquals(od.getBoxX(),
497    Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth)
498    - boxWidth + 1);
499  1 assertEquals(od.getBoxY(), 0);
500  1 assertEquals(od.getBoxWidth(), boxWidth);
501  1 assertEquals(od.getBoxHeight(), boxHeight);
502  1 assertEquals(vpranges.getStartRes(),
503    Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
504  1 assertEquals(vpranges.getStartSeq(), 0);
505   
506    // click off end of alignment
507    // boxX and scrollCol adjusted for hidden cols, width normal
508  1 xpos = 3000;
509  1 assertEquals(od.getBoxX(),
510    Math.round((float) (firstHidden - 1) * od.getWidth() / alwidth)
511    - boxWidth + 1);
512  1 assertEquals(od.getBoxY(), 0);
513  1 assertEquals(od.getBoxWidth(), boxWidth);
514  1 assertEquals(od.getBoxHeight(), boxHeight);
515  1 assertEquals(vpranges.getStartRes(),
516    Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
517  1 assertEquals(vpranges.getStartSeq(), 0);
518    }
519   
520    /**
521    * Test that the box position is set correctly when set from the viewport,
522    * with no hidden rows or columns
523    */
 
524  1 toggle @Test(groups = { "Functional" })
525    public void testSetBoxFromViewport()
526    {
527    // move viewport to start of alignment
528  1 moveViewport(0, 0);
529  1 assertEquals(od.getBoxX(), 0);
530  1 assertEquals(od.getBoxY(), 0);
531  1 assertEquals(od.getBoxWidth(), boxWidth);
532  1 assertEquals(od.getBoxHeight(), boxHeight);
533   
534    // move viewport to right
535  1 moveViewportH(70);
536  1 assertEquals(od.getBoxX(),
537    Math.round((float) 70 * od.getWidth() / alwidth));
538  1 assertEquals(od.getBoxY(), 0);
539  1 assertEquals(od.getBoxWidth(), boxWidth);
540  1 assertEquals(od.getBoxHeight(), boxHeight);
541   
542    // move viewport down
543  1 moveViewportV(100);
544  1 assertEquals(od.getBoxX(),
545    Math.round((float) 70 * od.getWidth() / alwidth));
546  1 assertEquals(od.getBoxY(),
547    Math.round(100 * od.getSequencesHeight() / alheight));
548  1 assertEquals(od.getBoxWidth(), boxWidth);
549  1 assertEquals(od.getBoxHeight(), boxHeight);
550   
551    // move viewport to bottom right
552  1 moveViewport(98, 508);
553  1 assertEquals(od.getBoxX(),
554    Math.round((float) 98 * od.getWidth() / alwidth));
555  1 assertEquals(od.getBoxY(),
556    Math.round((float) 508 * od.getSequencesHeight() / alheight));
557  1 assertEquals(od.getBoxWidth(), boxWidth);
558  1 assertEquals(od.getBoxHeight(), boxHeight);
559    }
560   
561    /**
562    * Test that the box position is set correctly when there are hidden columns
563    * at the start
564    */
 
565  1 toggle @Test(groups = { "Functional" })
566    public void testSetBoxFromViewportHiddenColsAtStart()
567    {
568  1 int firstHidden = 0;
569  1 int lastHidden = 20;
570  1 hiddenCols.hideColumns(firstHidden, lastHidden);
571   
572    // move viewport to start of alignment
573  1 moveViewport(0, 0);
574  1 assertEquals(od.getBoxX(),
575    Math.round((float) (lastHidden + 1) * od.getWidth() / alwidth));
576  1 assertEquals(od.getBoxY(), 0);
577  1 assertEquals(od.getBoxWidth(), boxWidth);
578  1 assertEquals(od.getBoxHeight(), boxHeight);
579   
580    // move viewport to end of alignment - need to make startRes by removing
581    // hidden cols because of how viewport/overview are implemented
582  1 moveViewport(98 - lastHidden - 1, 0);
583  1 assertEquals(od.getBoxX(),
584    Math.round((float) 98 * od.getWidth() / alwidth));
585  1 assertEquals(od.getBoxY(), 0);
586  1 assertEquals(od.getBoxWidth(), boxWidth);
587  1 assertEquals(od.getBoxHeight(), boxHeight);
588    }
589   
590    /**
591    * Test that the box position is set correctly when there are hidden columns
592    * in the middle
593    */
 
594  1 toggle @Test(groups = { "Functional" })
595    public void testSetBoxFromViewportHiddenColsInMiddle()
596    {
597  1 int firstHidden = 68;
598  1 int lastHidden = 78;
599  1 hiddenCols.hideColumns(firstHidden, lastHidden);
600   
601    // move viewport before hidden columns
602  1 moveViewport(3, 0);
603   
604  1 assertEquals(od.getBoxX(),
605    Math.round((float) 3 * od.getWidth() / alwidth));
606  1 assertEquals(od.getBoxY(), 0);
607  1 assertEquals(od.getBoxWidth(), boxWidth);
608  1 assertEquals(od.getBoxHeight(), boxHeight);
609   
610    // move viewport to left of hidden columns with overlap
611  1 moveViewport(10, 0);
612  1 assertEquals(od.getBoxX(),
613    Math.round((float) 10 * od.getWidth() / alwidth));
614  1 assertEquals(od.getBoxY(), 0);
615  1 assertEquals(od.getBoxWidth(),
616    boxWidth + Math.round((float) (lastHidden - firstHidden + 1)
617    * od.getWidth() / alwidth));
618  1 assertEquals(od.getBoxHeight(), boxHeight);
619   
620    // move viewport to straddle hidden columns
621  1 moveViewport(63, 0);
622  1 assertEquals(od.getBoxX(),
623    Math.round((float) 63 * od.getWidth() / alwidth));
624  1 assertEquals(od.getBoxY(), 0);
625  1 assertEquals(od.getBoxWidth(), boxWidth + Math.round(
626    (lastHidden - firstHidden + 1) * od.getWidth() / alwidth));
627  1 assertEquals(od.getBoxHeight(), boxHeight);
628   
629    // move viewport to right of hidden columns, no overlap
630  1 moveViewport(80 - (lastHidden - firstHidden + 1), 0);
631  1 assertEquals(od.getBoxX(),
632    Math.round((float) 80 * od.getWidth() / alwidth));
633  1 assertEquals(od.getBoxY(), 0);
634  1 assertEquals(od.getBoxWidth(), boxWidth);
635  1 assertEquals(od.getBoxHeight(), boxHeight);
636   
637    }
638   
639    /**
640    * Test that the box position is set correctly when there are hidden columns
641    * at the end
642    */
 
643  1 toggle @Test(groups = { "Functional" })
644    public void testSetBoxFromViewportHiddenColsAtEnd()
645    {
646  1 int firstHidden = 152;
647  1 int lastHidden = 164;
648  1 hiddenCols.hideColumns(firstHidden, lastHidden);
649   
650    // move viewport before hidden columns
651  1 moveViewport(3, 0);
652  1 assertEquals(od.getBoxX(),
653    Math.round((float) 3 * od.getWidth() / alwidth));
654  1 assertEquals(od.getBoxY(), 0);
655  1 assertEquals(od.getBoxWidth(), boxWidth);
656  1 assertEquals(od.getBoxHeight(), boxHeight);
657   
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  1 moveViewport(firstHidden - viewWidth, 0);
662  1 assertEquals(od.getBoxX(), Math.round(
663    (float) (firstHidden - viewWidth) * od.getWidth() / alwidth));
664  1 assertEquals(od.getBoxY(), 0);
665  1 assertEquals(od.getBoxWidth(), boxWidth);
666  1 assertEquals(od.getBoxHeight(), boxHeight);
667    }
668   
669    /**
670    * Test that the box position is set correctly when there are hidden rows at
671    * the start
672    */
 
673  1 toggle @Test(groups = { "Functional" })
674    public void testSetBoxFromViewportHiddenRowsAtStart()
675    {
676  1 int firstHidden = 0;
677  1 int lastHidden = 20;
678  1 hideSequences(firstHidden, lastHidden);
679   
680    // move viewport to start of alignment:
681    // box moves to below hidden rows, height remains same
682  1 moveViewport(0, 0);
683  1 assertEquals(od.getBoxX(), 0);
684  1 assertEquals(od.getBoxY(), Math.round(
685    (float) (lastHidden + 1) * od.getSequencesHeight() / alheight));
686  1 assertEquals(od.getBoxWidth(), boxWidth);
687  1 assertEquals(od.getBoxHeight(), boxHeight);
688   
689    // move viewport to end of alignment
690  1 moveViewport(0, 525 - viewHeight - lastHidden - 1);
691  1 assertEquals(od.getBoxX(), 0);
692  1 assertEquals(od.getBoxY(), Math.round((float) (525 - viewHeight)
693    * od.getSequencesHeight() / alheight));
694  1 assertEquals(od.getBoxWidth(), boxWidth);
695  1 assertEquals(od.getBoxHeight(), boxHeight);
696    }
697   
698    /**
699    * Test that the box position is set correctly when there are hidden rows in
700    * the middle
701    */
 
702  1 toggle @Test(groups = { "Functional" })
703    public void testSetBoxFromViewportHiddenRowsInMiddle()
704    {
705  1 int firstHidden = 200;
706  1 int lastHidden = 210;
707  1 hideSequences(firstHidden, lastHidden);
708   
709    // move viewport to start of alignment:
710    // box, height etc as in non-hidden case
711  1 moveViewport(0, 0);
712  1 assertEquals(od.getBoxX(), 0);
713  1 assertEquals(od.getBoxY(), 0);
714  1 assertEquals(od.getBoxWidth(), boxWidth);
715  1 assertEquals(od.getBoxHeight(), boxHeight);
716   
717    // move viewport to straddle hidden rows
718  1 moveViewport(0, 198);
719  1 assertEquals(od.getBoxX(), 0);
720  1 assertEquals(od.getBoxY(),
721    Math.round((float) 198 * od.getSequencesHeight() / alheight));
722  1 assertEquals(od.getBoxWidth(), boxWidth);
723  1 assertEquals(od.getBoxHeight(),
724    Math.round((float) (viewHeight + lastHidden - firstHidden + 1)
725    * od.getSequencesHeight() / alheight));
726    }
727   
728    /**
729    * Test that the box position is set correctly when there are hidden rows at
730    * the bottom
731    */
 
732  1 toggle @Test(groups = { "Functional" })
733    public void testSetBoxFromViewportHiddenRowsAtEnd()
734    {
735  1 int firstHidden = 500;
736  1 int lastHidden = 524;
737  1 hideSequences(firstHidden, lastHidden);
738   
739    // move viewport to start of alignment:
740    // box, height etc as in non-hidden case
741  1 moveViewport(0, 0);
742  1 assertEquals(od.getBoxX(), 0);
743  1 assertEquals(od.getBoxY(), 0);
744  1 assertEquals(od.getBoxWidth(), boxWidth);
745  1 assertEquals(od.getBoxHeight(), boxHeight);
746   
747    // move viewport to end of alignment
748    // viewport sits above hidden rows and does not include them
749  1 moveViewport(0, firstHidden - viewHeight - 1);
750  1 assertEquals(od.getBoxX(), 0);
751  1 assertEquals(od.getBoxY(),
752    Math.round((float) (firstHidden - viewHeight - 1)
753    * od.getSequencesHeight() / alheight));
754  1 assertEquals(od.getBoxWidth(), boxWidth);
755  1 assertEquals(od.getBoxHeight(), boxHeight);
756   
757    }
758   
759    /**
760    * Test setting of the box position, when there are hidden rows at the start
761    * of the alignment
762    */
 
763  1 toggle @Test(groups = { "Functional" })
764    public void testFromMouseWithHiddenRowsAtStart()
765    {
766  1 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
767  1 assertEquals(od.getBoxX(), 0);
768  1 assertEquals(od.getBoxY(), 0);
769  1 assertEquals(od.getBoxHeight(), boxHeight);
770  1 assertEquals(od.getBoxWidth(), boxWidth);
771  1 assertEquals(vpranges.getStartRes(), 0);
772  1 assertEquals(vpranges.getStartSeq(), 0);
773   
774    // hide rows at start and check updated box position is correct
775    // changes boxY but not boxheight
776  1 int lastHiddenRow = 30;
777  1 hideSequences(0, lastHiddenRow);
778   
779  1 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
780  1 assertEquals(od.getBoxX(), 0);
781  1 assertEquals(od.getBoxY(), Math.round((float) (lastHiddenRow + 1)
782    * od.getSequencesHeight() / alheight));
783  1 assertEquals(od.getBoxWidth(), boxWidth);
784  1 assertEquals(od.getBoxHeight(), boxHeight);
785   
786    // click in hidden rows - same result
787  1 mouseClick(od, 0, 0);
788  1 assertEquals(od.getBoxX(), 0);
789  1 assertEquals(od.getBoxY(), Math.round((float) (lastHiddenRow + 1)
790    * od.getSequencesHeight() / alheight));
791  1 assertEquals(od.getBoxWidth(), boxWidth);
792  1 assertEquals(od.getBoxHeight(), boxHeight);
793   
794    // click below hidden rows
795  1 mouseClick(od, 0, 150 + boxHeight / 2);
796  1 assertEquals(od.getBoxX(), 0);
797  1 assertEquals(od.getBoxY(), 150);
798  1 assertEquals(od.getBoxWidth(), boxWidth);
799  1 assertEquals(od.getBoxHeight(), boxHeight);
800    }
801   
802    /**
803    * Test setting of the box position, when there are hidden rows at the middle
804    * of the alignment
805    */
 
806  1 toggle @Test(groups = { "Functional" })
807    public void testFromMouseWithHiddenRowsInMiddle()
808    {
809  1 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
810   
811  1 assertEquals(od.getBoxX(), 0);
812  1 assertEquals(od.getBoxY(), 0);
813  1 assertEquals(od.getBoxWidth(), boxWidth);
814  1 assertEquals(od.getBoxHeight(), boxHeight);
815  1 assertEquals(vpranges.getStartRes(), 0);
816  1 assertEquals(vpranges.getStartSeq(), 0);
817   
818    // hide rows in middle and check updated box position is correct
819    // no changes
820  1 int firstHiddenRow = 50;
821  1 int lastHiddenRow = 54;
822  1 hideSequences(firstHiddenRow, lastHiddenRow);
823   
824  1 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
825   
826  1 assertEquals(od.getBoxX(), 0);
827  1 assertEquals(od.getBoxY(), 0);
828  1 assertEquals(od.getBoxWidth(), boxWidth);
829  1 assertEquals(od.getBoxHeight(), boxHeight);
830   
831    // click above hidden rows, so that box overlaps
832  1 int rowpos = 35; // row value in residues
833  1 int centrepos = 43; // centre row
834  1 mouseClick(od, 0, Math
835    .round((float) centrepos * od.getSequencesHeight() / alheight));
836  1 assertEquals(od.getBoxX(), 0);
837  1 assertEquals(od.getBoxY(), Math
838    .round((float) rowpos * od.getSequencesHeight() / alheight));
839  1 assertEquals(od.getBoxWidth(), boxWidth);
840  1 assertEquals(od.getBoxHeight(),
841    boxHeight + Math
842    .round((float) (lastHiddenRow - firstHiddenRow + 1)
843    * od.getSequencesHeight() / alheight));
844    }
845   
846    /**
847    * Test setting of the box position, when there are hidden rows at the end of
848    * the alignment
849    */
 
850  1 toggle @Test(groups = { "Functional" })
851    public void testFromMouseWithHiddenRowsAtEnd()
852    {
853  1 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
854  1 assertEquals(od.getBoxX(), 0);
855  1 assertEquals(od.getBoxY(), 0);
856  1 assertEquals(od.getBoxWidth(), boxWidth);
857  1 assertEquals(od.getBoxHeight(), boxHeight);
858  1 assertEquals(vpranges.getStartRes(), 0);
859  1 assertEquals(vpranges.getStartSeq(), 0);
860   
861    // hide rows at end and check updated box position is correct
862    // no changes
863  1 int firstHidden = 500;
864  1 int lastHidden = 524;
865  1 hideSequences(firstHidden, lastHidden);
866   
867  1 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
868  1 assertEquals(od.getBoxX(), 0);
869  1 assertEquals(od.getBoxY(), 0);
870  1 assertEquals(od.getBoxWidth(), boxWidth);
871  1 assertEquals(od.getBoxHeight(), boxHeight);
872   
873    // click above hidden rows, no overlap
874  1 int ypos = 40 + viewHeight / 2; // top is row 40
875  1 mouseClick(od, 0,
876    Math.round((float) ypos * od.getSequencesHeight() / alheight));
877  1 assertEquals(od.getBoxX(), 0);
878  1 assertEquals(od.getBoxY(),
879    Math.round((float) 40 * od.getSequencesHeight() / alheight));
880  1 assertEquals(od.getBoxWidth(), boxWidth);
881  1 assertEquals(od.getBoxHeight(), boxHeight);
882   
883    // click above hidden rows so box overlaps
884    // boxY moved upwards, boxHeight remains same
885  1 ypos = 497 + viewHeight / 2; // row 497
886  1 mouseClick(od, 0,
887    Math.round((float) ypos * od.getSequencesHeight() / alheight));
888  1 assertEquals(od.getBoxX(), 0);
889  1 assertEquals(od.getBoxY(), Math.round((float) (firstHidden - viewHeight)
890    * od.getSequencesHeight() / alheight));
891  1 assertEquals(od.getBoxWidth(), boxWidth);
892  1 assertEquals(od.getBoxHeight(), boxHeight);
893   
894    // click within hidden rows
895  1 ypos = 505 + boxHeight / 2;
896  1 mouseClick(od, 0,
897    Math.round((float) ypos * od.getSequencesHeight() / alheight));
898  1 assertEquals(od.getBoxX(), 0);
899  1 assertEquals(od.getBoxY(), Math.round((firstHidden - viewHeight)
900    * od.getSequencesHeight() / alheight));
901  1 assertEquals(od.getBoxWidth(), boxWidth);
902  1 assertEquals(od.getBoxHeight(), boxHeight);
903    }
904   
905    /**
906    * Test the function to determine if a point is in the overview's box or not
907    */
 
908  1 toggle @Test(groups = { "Functional" })
909    public void testPositionInBox()
910    {
911  1 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
912   
913  1 assertFalse(od.isPositionInBox(0, 0));
914  1 assertTrue(od.isPositionInBox(10, 9));
915  1 assertFalse(od.isPositionInBox(0, 9));
916  1 assertFalse(od.isPositionInBox(9, 0));
917  1 assertFalse(od.isPositionInBox(75, 20));
918   
919  1 assertTrue(od.isPositionInBox(47, 6));
920  1 assertFalse(od.isPositionInBox(48, 6));
921  1 assertTrue(od.isPositionInBox(47, 9));
922  1 assertFalse(od.isPositionInBox(47, 10));
923   
924    // hide columns in the box area
925    // extends area where a point is considered to be in the box
926  1 hiddenCols.hideColumns(1, 4);
927  1 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
928  1 assertFalse(od.isPositionInBox(0, 0));
929  1 assertTrue(od.isPositionInBox(10, 9));
930  1 assertFalse(od.isPositionInBox(0, 9));
931  1 assertFalse(od.isPositionInBox(9, 0));
932  1 assertFalse(od.isPositionInBox(75, 20));
933   
934  1 assertTrue(od.isPositionInBox(47, 6));
935  1 assertTrue(od.isPositionInBox(48, 6));
936  1 assertTrue(od.isPositionInBox(47, 9));
937  1 assertFalse(od.isPositionInBox(47, 10));
938   
939    // hide sequences in box area
940    // extends area where a point is considered to be in the box
941  1 hideSequences(1, 3);
942  1 ColumnSelection cs = new ColumnSelection();
943  1 hiddenCols.revealAllHiddenColumns(cs);
944  1 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
945  1 assertFalse(od.isPositionInBox(0, 0));
946  1 assertTrue(od.isPositionInBox(10, 9));
947  1 assertFalse(od.isPositionInBox(0, 9));
948  1 assertFalse(od.isPositionInBox(9, 0));
949  1 assertFalse(od.isPositionInBox(75, 20));
950   
951  1 assertTrue(od.isPositionInBox(47, 6));
952  1 assertFalse(od.isPositionInBox(48, 6));
953  1 assertTrue(od.isPositionInBox(47, 9));
954  1 assertTrue(od.isPositionInBox(47, 10));
955    }
956   
957    /**
958    * Test the dragging functionality
959    */
 
960  1 toggle @Test(groups = { "Functional" })
961    public void testDragging()
962    {
963  1 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
964  1 od.setDragPoint(4, 16, al.getHiddenSequences(), hiddenCols);
965  1 od.adjustViewportFromMouse(20, 22, al.getHiddenSequences(), hiddenCols);
966   
967    // updates require an OverviewPanel to exist which it doesn't here
968    // so call setBoxPosition() as it would be called by the AlignmentPanel
969    // normally
970  1 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
971   
972    // corner moves 16 (20-4) right and 6 (22-16) up
973  1 assertEquals(od.getBoxX(), 16);
974  1 assertEquals(od.getBoxY(), 6);
975   
976    // hide columns - box moves drag distance + hidden cols, vertically makes no
977    // difference
978  1 hiddenCols.hideColumns(1, 4);
979  1 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
980  1 od.setDragPoint(4, 16, al.getHiddenSequences(), hiddenCols);
981  1 od.adjustViewportFromMouse(20, 22, al.getHiddenSequences(), hiddenCols);
982  1 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
983   
984    // corner moves 16 (20-4) + hiddenCols right and 6 (22-16) down
985  1 assertEquals(od.getBoxX(),
986    16 + Math.round((float) 4 * od.getWidth() / alwidth));
987  1 assertEquals(od.getBoxY(), 6);
988   
989    // hide sequences in box area
990    // makes absolutely no difference
991  1 hideSequences(1, 3);
992  1 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
993  1 od.setDragPoint(4, 16, al.getHiddenSequences(), hiddenCols);
994  1 od.adjustViewportFromMouse(20, 22, al.getHiddenSequences(), hiddenCols);
995  1 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
996   
997    // corner moves 16 (20-4) + hiddenCols right and 6 (22-16) + hiddenRows down
998  1 assertEquals(od.getBoxX(),
999    16 + Math.round((float) 4 * od.getWidth() / alwidth));
1000  1 assertEquals(od.getBoxY(),
1001    6 + Math.round((float) 3 * od.getHeight() / alheight));
1002    }
1003   
1004    /*
1005    * Move viewport horizontally: startRes + previous width gives new horizontal extent. Vertical extent stays the same.
1006    */
 
1007  2 toggle private void moveViewportH(int startRes)
1008    {
1009  2 vpranges.setViewportStartAndWidth(startRes, viewWidth);
1010  2 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
1011    }
1012   
1013    /*
1014    * Move viewport vertically: startSeq and endSeq give new vertical extent. Horizontal extent stays the same.
1015    */
 
1016  1 toggle private void moveViewportV(int startSeq)
1017    {
1018  1 vpranges.setViewportStartAndHeight(startSeq, viewHeight);
1019  1 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
1020    }
1021   
1022    /*
1023    * Move viewport horizontally and vertically.
1024    */
 
1025  34 toggle private void moveViewport(int startRes, int startSeq)
1026    {
1027  34 vpranges.setViewportStartAndWidth(startRes, viewWidth);
1028  34 vpranges.setViewportStartAndHeight(startSeq, viewHeight);
1029  34 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
1030    }
1031   
1032    /*
1033    * Mouse click as position x,y in overview window
1034    */
 
1035  42 toggle private void mouseClick(OverviewDimensions od, int x, int y)
1036    {
1037  42 od.updateViewportFromMouse(x, y, al.getHiddenSequences(), hiddenCols);
1038   
1039    // updates require an OverviewPanel to exist which it doesn't here
1040    // so call setBoxPosition() as it would be called by the AlignmentPanel
1041    // normally
1042  42 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
1043    }
1044   
1045    /*
1046    * Test that the box is positioned with the centre at xpos, ypos
1047    * and with the original width and height
1048    */
 
1049  1 toggle private void testBoxIsAtClickPoint(int xpos, int ypos)
1050    {
1051  1 mouseClick(od, xpos, ypos);
1052  1 assertEquals(od.getBoxX() + od.getBoxWidth() / 2, xpos);
1053  1 assertEquals(od.getBoxY() + od.getBoxHeight() / 2, ypos);
1054  1 assertEquals(od.getBoxWidth(), boxWidth);
1055  1 assertEquals(od.getBoxHeight(), boxHeight);
1056   
1057    }
1058   
1059    /*
1060    * Hide sequences between start and end
1061    */
 
1062  9 toggle private void hideSequences(int start, int end)
1063    {
1064  9 SequenceI[] allseqs = al.getSequencesArray();
1065  9 SequenceGroup theseSeqs = new SequenceGroup();
1066   
1067  164 for (int i = start; i <= end; i++)
1068    {
1069  155 theseSeqs.addSequence(allseqs[i], false);
1070  155 al.getHiddenSequences().hideSequence(allseqs[i]);
1071    }
1072   
1073  9 hiddenRepSequences.put(allseqs[start], theseSeqs);
1074    }
1075   
1076    /**
1077    * Test setting of the box position, when there are hidden rows at the start
1078    * of the alignment
1079    */
 
1080  1 toggle @Test(groups = { "Functional" })
1081    public void testFromMouseWithHiddenRowsAtStartWrapped()
1082    {
1083  1 vpranges.setWrappedMode(true);
1084  1 od.updateViewportFromMouse(0, 0, al.getHiddenSequences(), hiddenCols);
1085  1 assertEquals(od.getBoxX(), 0);
1086  1 assertEquals(od.getBoxY(), 0);
1087  1 assertEquals(od.getBoxHeight(), boxHeight);
1088  1 assertEquals(od.getBoxWidth(), boxWidth);
1089  1 assertEquals(vpranges.getStartRes(), 0);
1090  1 assertEquals(vpranges.getStartSeq(), 0);
1091   
1092    // hide rows at start and check updated box position is correct
1093    // changes boxY but not boxheight
1094  1 int lastHiddenRow = 30;
1095  1 hideSequences(0, lastHiddenRow);
1096   
1097  1 od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
1098  1 assertEquals(od.getBoxX(), 0);
1099  1 assertEquals(od.getBoxY(), Math.round((float) (lastHiddenRow + 1)
1100    * od.getSequencesHeight() / alheight));
1101  1 assertEquals(od.getBoxWidth(), boxWidth);
1102  1 assertEquals(od.getBoxHeight(), boxHeight);
1103   
1104    // click in hidden rows - same result
1105  1 mouseClick(od, 0, 0);
1106  1 assertEquals(od.getBoxX(), 0);
1107  1 int boxY = od.getBoxY();
1108  1 assertEquals(boxY, Math.round((float) (lastHiddenRow + 1)
1109    * od.getSequencesHeight() / alheight));
1110  1 assertEquals(od.getBoxWidth(), boxWidth);
1111  1 assertEquals(od.getBoxHeight(), boxHeight);
1112   
1113    // click below hidden rows
1114    // vertical move of overview box is suppressed in wrapped mode
1115  1 mouseClick(od, 0, 150);
1116  1 assertEquals(od.getBoxX(), 0);
1117  1 assertEquals(od.getBoxY(), boxY); // unchanged
1118  1 assertEquals(od.getBoxWidth(), boxWidth);
1119  1 assertEquals(od.getBoxHeight(), boxHeight);
1120    }
1121    }