Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.viewmodel

File OverviewDimensionsShowHiddenTest.java

 

Code metrics

4
538
27
1
1,161
809
29
0.05
19.93
27
1.07

Classes

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