JAL-2388 Remove OverviewDimensions dependency on gui classes
[jalview.git] / test / jalview / viewmodel / OverviewDimensionsTest.java
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
25 import jalview.analysis.AlignmentGenerator;
26 import jalview.bin.Cache;
27 import jalview.bin.Jalview;
28 import jalview.datamodel.Alignment;
29 import jalview.datamodel.AlignmentI;
30 import jalview.datamodel.Sequence;
31 import jalview.datamodel.SequenceGroup;
32 import jalview.datamodel.SequenceI;
33 import jalview.gui.AlignFrame;
34 import jalview.gui.AlignViewport;
35 import jalview.gui.Desktop;
36 import jalview.gui.JvOptionPane;
37 import jalview.io.DataSourceType;
38 import jalview.io.FileLoader;
39
40 import java.util.List;
41
42 import org.testng.annotations.AfterClass;
43 import org.testng.annotations.AfterMethod;
44 import org.testng.annotations.BeforeClass;
45 import org.testng.annotations.BeforeMethod;
46 import org.testng.annotations.Test;
47
48 @Test(singleThreaded = true)
49 public class OverviewDimensionsTest {
50
51   SequenceI seq1 = new Sequence(
52           "Seq1",
53           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
54
55   SequenceI seq2 = new Sequence(
56           "Seq2",
57           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
58
59   SequenceI seq3 = new Sequence(
60           "Seq3",
61           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
62
63   SequenceI seq4 = new Sequence(
64           "Seq4",
65           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
66
67   SequenceI seq5 = new Sequence(
68           "Seq5",
69           "ABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBACABCABCABCABCABCABCABCABCBACBACBACBAC");
70
71   AlignFrame af;
72   AlignViewport av;
73
74   AlignmentI al;
75   OverviewDimensions od;
76
77   int boxWidth;
78   int boxHeight;
79   int viewHeight;
80   int viewWidth;
81   int alheight;
82   int alwidth;
83
84   @BeforeClass(alwaysRun = true)
85   public void setUpJvOptionPane()
86   {
87     JvOptionPane.setInteractiveMode(false);
88     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
89
90     // create random alignment
91     AlignmentGenerator gen = new AlignmentGenerator(false);
92     al = gen.generate(157, 525, 123, 5, 5);
93   }
94
95   @BeforeMethod(alwaysRun = true)
96   public void setUp()
97   {
98     Jalview.main(new String[] { "-nonews", "-props",
99         "test/jalview/testProps.jvprops" });
100
101     Cache.applicationProperties.setProperty("SHOW_IDENTITY",
102             Boolean.TRUE.toString());
103     af = new FileLoader().LoadFileWaitTillLoaded(al.toString(),
104             DataSourceType.PASTE);
105
106     /*
107      * wait for Consensus thread to complete
108      */
109     synchronized (this)
110     {
111       while (af.getViewport().getConsensusSeq() == null)
112       {
113         try
114         {
115           wait(50);
116         } catch (InterruptedException e)
117         {
118         }
119       }
120     }
121     
122     av = af.getViewport();
123
124     od = new OverviewDimensions(av.getPosProps(), true);
125
126     while (av.isCalcInProgress())
127     {
128       try
129       {
130         Thread.sleep(50);
131       } catch (InterruptedException e)
132       {
133
134       }
135     }
136
137     // Initial box sizing - default path through code
138     od.setBoxPosition(av.getAlignment()
139             .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
140
141     init();
142   }
143
144   private void init()
145   {
146     av.showAllHiddenColumns();
147     av.showAllHiddenSeqs();
148     av.setSelectionGroup(null);
149     // o/w hidden seqs retain selection group, causes problems later when hiding
150     // sequences
151
152     // wait for conservation calc to complete again
153     while (av.isCalcInProgress())
154     {
155       try
156       {
157         Thread.sleep(50);
158       } catch (InterruptedException e)
159       {
160
161       }
162     }
163
164     mouseClick(od, 0, 0);
165     moveViewport(0, 0);
166
167     viewHeight = av.getEndSeq() - av.getStartSeq();
168     viewWidth = av.getEndRes() - av.getStartRes();
169
170     // wait for gui to get set up
171     // this does actually appear to be necessary
172     while (viewHeight != 17 || viewWidth != 62)
173     {
174       try
175       {
176         Thread.sleep(50);
177         viewHeight = av.getEndSeq() - av.getStartSeq();
178         viewWidth = av.getEndRes() - av.getStartRes();
179       } catch (InterruptedException e)
180       {
181
182       }
183     }
184
185     // calculate before hidden columns so we get absolute values
186     alheight = av.getAlignment().getHeight();
187     alwidth = av.getAlignment().getWidth();
188
189     boxWidth = Math.round((float) (av.getEndRes() - av.getStartRes() + 1)
190             / alwidth * od.getWidth());
191     boxHeight = Math.round((float) (av.getEndSeq() - av.getStartSeq())
192             / alheight * od.getHeight());
193     System.out.println(boxHeight);
194
195   }
196
197   @AfterMethod(alwaysRun = true)
198   public void tearDown()
199   {
200     af = null;
201     av = null;
202     Desktop.instance.closeAll_actionPerformed(null);
203   }
204
205   @AfterClass(alwaysRun = true)
206   public void cleanUp()
207   {
208     al = null;
209   }
210
211   /**
212    * Test that the OverviewDimensions constructor sets width and height
213    * correctly
214    */
215   @Test(groups = { "Functional" })
216   public void testConstructor()
217   {
218     SequenceI seqa = new Sequence("Seq1", "ABC");
219     SequenceI seqb = new Sequence("Seq2", "ABC");
220     SequenceI seqc = new Sequence("Seq3", "ABC");
221     SequenceI seqd = new Sequence("Seq4", "ABC");
222     SequenceI seqe = new Sequence("Seq5",
223             "ABCABCABCABCABCABCABCABCBACBACBACBAC");
224
225     int defaultGraphHeight = 20;
226     int maxWidth = 400;
227     int minWidth = 120;
228     int maxSeqHeight = 300;
229     int minSeqHeight = 40;
230
231     // test for alignment with width > height
232     SequenceI[] seqs1 = new SequenceI[] { seqa, seqb };
233     Alignment al1 = new Alignment(seqs1);
234     al1.setDataset(null);
235     AlignViewport av1 = new AlignViewport(al1);
236
237     OverviewDimensions od = new OverviewDimensions(av1.getPosProps(), true);
238     int scaledHeight = 266;
239     assertEquals(od.getGraphHeight(), defaultGraphHeight);
240     assertEquals(od.getSequencesHeight(), scaledHeight);
241     assertEquals(od.getWidth(), maxWidth);
242     assertEquals(od.getHeight(), scaledHeight + defaultGraphHeight);
243
244     // test for alignment with width < height
245     SequenceI[] seqs2 = new SequenceI[] { seqa, seqb, seqc, seqd };
246     Alignment al2 = new Alignment(seqs2);
247     al2.setDataset(null);
248     AlignViewport av2 = new AlignViewport(al2);
249
250     od = new OverviewDimensions(av2.getPosProps(), true);
251     int scaledWidth = 300;
252     assertEquals(od.getGraphHeight(), defaultGraphHeight);
253     assertEquals(od.getSequencesHeight(), maxSeqHeight);
254     assertEquals(od.getWidth(), scaledWidth);
255     assertEquals(od.getHeight(), scaledWidth + defaultGraphHeight);
256
257     // test for alignment with width > height and sequence height scaled below
258     // min value
259     SequenceI[] seqs3 = new SequenceI[] { seqe };
260     Alignment al3 = new Alignment(seqs3);
261     al3.setDataset(null);
262     AlignViewport av3 = new AlignViewport(al3);
263
264     od = new OverviewDimensions(av3.getPosProps(), true);
265     assertEquals(od.getGraphHeight(), defaultGraphHeight);
266     assertEquals(od.getSequencesHeight(), minSeqHeight);
267     assertEquals(od.getWidth(), maxWidth);
268     assertEquals(od.getHeight(), minSeqHeight + defaultGraphHeight);
269
270     // test for alignment with width < height and width scaled below min value
271     SequenceI[] seqs4 = new SequenceI[] { seqa, seqb, seqc, seqd, seqa,
272         seqb, seqc, seqd, seqa, seqb, seqc, seqd, seqa, seqb, seqc, seqd };
273     Alignment al4 = new Alignment(seqs4);
274     al4.setDataset(null);
275     AlignViewport av4 = new AlignViewport(al4);
276
277     od = new OverviewDimensions(av4.getPosProps(), true);
278     assertEquals(od.getGraphHeight(), defaultGraphHeight);
279     assertEquals(od.getSequencesHeight(), maxSeqHeight);
280     assertEquals(od.getWidth(), minWidth);
281     assertEquals(od.getHeight(), maxSeqHeight + defaultGraphHeight);
282
283     Alignment al5 = new Alignment(seqs4);
284     al5.setDataset(null);
285     AlignViewport av5 = new AlignViewport(al5);
286
287     od = new OverviewDimensions(av5.getPosProps(), false);
288     assertEquals(od.getGraphHeight(), 0);
289     assertEquals(od.getSequencesHeight(), maxSeqHeight);
290     assertEquals(od.getWidth(), minWidth);
291     assertEquals(od.getHeight(), maxSeqHeight);
292   }
293
294   /**
295    * Test that validation after mouse adjustments to boxX and boxY sets box
296    * dimensions and scroll values correctly, when there are no hidden rows or
297    * columns.
298    * 
299    * The current implementation uses multiple transformations between coordinate
300    * systems which often involve casting to int, which causes values to be
301    * truncated. As a result we can lose accuracy. The tests below use
302    * approximate test values where appropriate.
303    */
304   @Test(groups = { "Functional" })
305   public void testSetBoxFromMouseClick()
306   {
307     od.updateViewportFromMouse(0, 0,
308             av.getAlignment().getHiddenSequences(),
309             av.getColumnSelection(), av.getPosProps());
310     assertEquals(od.getBoxX(), 0);
311     assertEquals(od.getBoxY(), 0);
312     assertEquals(od.getBoxWidth(), boxWidth);
313     assertEquals(od.getScrollCol(), 0);
314     assertEquals(od.getScrollRow(), 0);
315
316     // negative boxX value reset to 0
317     mouseClick(od, -5, 10);
318     assertEquals(od.getBoxX(), 0);
319     assertEquals(od.getBoxWidth(), boxWidth);
320     assertEquals(od.getBoxHeight(), boxHeight);
321     assertEquals(od.getScrollRow(),
322             Math.round((float) 10 * alheight / od.getSequencesHeight()));
323     assertEquals(od.getScrollCol(), 0);
324
325     // negative boxY value reset to 0
326     mouseClick(od, 6, -2);
327     assertEquals(od.getBoxY(), 0);
328     assertEquals(od.getBoxWidth(), boxWidth);
329     assertEquals(od.getBoxHeight(), boxHeight);
330     assertEquals(od.getScrollCol(),
331             Math.round((float) 6 * alwidth / od.getWidth()));
332     assertEquals(od.getScrollRow(), 0);
333
334     // overly large boxX value reset to width-boxWidth
335     mouseClick(od, 100, 6);
336     assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
337     assertEquals(od.getBoxY(), 6);
338     assertEquals(od.getBoxWidth(), boxWidth);
339     assertEquals(od.getBoxHeight(), boxHeight);
340     assertEquals(od.getScrollCol(),
341             Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
342     assertEquals(od.getScrollRow(),
343             Math.round((float) od.getBoxY() * alheight
344                     / od.getSequencesHeight()));
345
346     // overly large boxY value reset to sequenceHeight - boxHeight
347     mouseClick(od, 10, 520);
348     assertEquals(od.getBoxX(), 10);
349     assertEquals(od.getBoxY(), od.getSequencesHeight() - od.getBoxHeight());
350     assertEquals(od.getBoxWidth(), boxWidth);
351     assertEquals(od.getBoxHeight(), boxHeight);
352     assertEquals(od.getScrollCol(),
353             Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
354     assertEquals(od.getScrollRow(),
355             Math.round((float) od.getBoxY() * alheight
356                     / od.getSequencesHeight()));
357
358     // click past end of alignment, as above
359     mouseClick(od, 3000, 5);
360     assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
361     assertEquals(od.getBoxWidth(), boxWidth);
362     assertEquals(od.getBoxHeight(), boxHeight);
363     assertEquals(od.getScrollCol(),
364             Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
365     assertEquals(od.getScrollRow(),
366             Math.round((float) od.getBoxY() * alheight
367                     / od.getSequencesHeight()));
368
369     // move viewport so startRes non-zero and then mouseclick
370     moveViewportH(50);
371
372     // click at viewport position
373     int oldboxx = od.getBoxX();
374     int oldboxy = od.getBoxY();
375     mouseClick(od, od.getBoxX() + 5, od.getBoxY() + 2);
376     assertEquals(od.getBoxX(), oldboxx + 5);
377     assertEquals(od.getBoxWidth(), boxWidth);
378     assertEquals(od.getBoxHeight(), boxHeight);
379     assertEquals(od.getScrollCol(),
380             Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
381     assertEquals(od.getBoxY(), oldboxy + 2);
382     assertEquals(od.getScrollRow(),
383             Math.round((float) od.getBoxY() * alheight
384                     / od.getSequencesHeight()));
385
386     // click at top corner
387     mouseClick(od, 0, 0);
388     assertEquals(od.getBoxX(), 0);
389     assertEquals(od.getScrollCol(), 0);
390     assertEquals(od.getBoxY(), 0);
391     assertEquals(od.getScrollRow(), 0);
392     assertEquals(od.getBoxWidth(), boxWidth);
393     assertEquals(od.getBoxHeight(), boxHeight);
394   }
395
396   /**
397    * Test setting of the box position, when there are hidden cols at the start
398    * of the alignment
399    */
400   @Test(groups = { "Functional" })
401   public void testFromMouseWithHiddenColsAtStart()
402   {
403     od.updateViewportFromMouse(0, 0,
404             av.getAlignment().getHiddenSequences(),
405             av.getColumnSelection(), av.getPosProps());
406     assertEquals(od.getBoxX(), 0);
407     assertEquals(od.getBoxY(), 0);
408     assertEquals(od.getBoxWidth(), boxWidth);
409     assertEquals(od.getScrollCol(), 0);
410     assertEquals(od.getScrollRow(), 0);
411
412     // hide cols at start and check updated box position is correct
413     // changes boxX but not boxwidth
414     int lastHiddenCol = 30;
415     hideColumns(0, lastHiddenCol);
416
417     od.setBoxPosition(av.getAlignment()
418             .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
419     assertEquals(od.getBoxX(),
420             Math.round((float) (lastHiddenCol + 1) * od.getWidth()
421                     / alwidth));
422     assertEquals(od.getBoxWidth(), boxWidth);
423     assertEquals(od.getBoxHeight(), boxHeight);
424
425     // try to click in hidden cols, check box does not move
426     // this test currently fails as the overview box does not behave like this!
427     /*    int xpos = 10;
428         mouseClick(od, xpos, 0);
429         assertEquals(od.getBoxX(),
430                 Math.round ((lastHiddenCol + 1) * od.getWidth() / alwidth));
431         assertEquals(od.getBoxY(), 0);
432         assertEquals(od.getBoxWidth(), boxWidth);
433         assertEquals(od.getBoxHeight(), boxHeight);
434         assertEquals(od.getScrollRow(), 0);
435         assertEquals(od.getScrollCol(),
436                 Math.round (xpos * alwidth / od.getWidth()));
437     */
438     // click to right of hidden columns, box moves to click point
439     testBoxIsAtClickPoint(40, 0);
440     assertEquals(od.getScrollRow(), 0);
441     assertEquals(od.getScrollCol(),
442             Math.round((float) 40 * alwidth / od.getWidth())
443                     - (lastHiddenCol + 1));
444
445     // click to right of hidden columns such that box runs over right hand side
446     // of alignment
447     // box position is adjusted away from the edge
448     // overly large boxX value reset to width-boxWidth
449     int xpos = 100;
450     mouseClick(od, xpos, 5);
451     assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
452     assertEquals(od.getBoxY(), 5);
453     assertEquals(od.getBoxWidth(), boxWidth);
454     assertEquals(od.getBoxHeight(), boxHeight);
455     assertEquals(od.getScrollCol(),
456             Math.round((float) od.getBoxX() * alwidth / od.getWidth())
457                     - (lastHiddenCol + 1));
458     assertEquals(od.getScrollRow(),
459             Math.round((float) od.getBoxY() * alheight
460                     / od.getSequencesHeight()));
461   }
462
463   /**
464    * Test setting of the box position, when there are hidden cols in the middle
465    * of the alignment
466    */
467   @Test(groups = { "Functional" })
468   public void testFromMouseWithHiddenColsInMiddle()
469   {
470     od.updateViewportFromMouse(0, 0,
471             av.getAlignment().getHiddenSequences(),
472             av.getColumnSelection(), av.getPosProps());
473     assertEquals(od.getBoxX(), 0);
474     assertEquals(od.getBoxY(), 0);
475     assertEquals(od.getBoxWidth(), boxWidth);
476     assertEquals(od.getScrollCol(), 0);
477     assertEquals(od.getScrollRow(), 0);
478     
479     // hide columns 60-68, no change to box position or dimensions
480     int firstHidden = 63;
481     int lastHidden = 73;
482     hideColumns(firstHidden, lastHidden);
483
484     od.setBoxPosition(av.getAlignment()
485             .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
486     assertEquals(od.getBoxX(), 0);
487     assertEquals(od.getBoxY(), 0);
488     assertEquals(od.getBoxWidth(), boxWidth);
489     assertEquals(od.getScrollCol(), 0);
490     assertEquals(od.getScrollRow(), 0);
491
492     // move box so that it overlaps with hidden cols on one side
493     // box width changes, boxX and scrollCol as for unhidden case
494     int xpos = 55 - boxWidth; // 55 is position in overview approx halfway
495                               // between cols 60 and 70
496     mouseClick(od, xpos, 0);
497     assertEquals(od.getBoxX(), xpos);
498     assertEquals(od.getBoxY(), 0);
499     assertEquals(
500             od.getBoxWidth(),
501             Math.round(boxWidth + (float) (lastHidden - firstHidden + 1)
502                     * od.getWidth() / alwidth));
503     assertEquals(od.getBoxHeight(), boxHeight);
504     assertEquals(od.getScrollCol(),
505             Math.round(xpos * alwidth / od.getWidth()));
506     assertEquals(od.getScrollRow(), 0);
507
508     // move box so that it completely covers hidden cols
509     // box width changes, boxX and scrollCol as for hidden case
510     xpos = 33;
511     mouseClick(od, xpos, 0);
512     assertEquals(od.getBoxX(), xpos);
513     assertEquals(od.getBoxY(), 0);
514     assertEquals(
515             od.getBoxWidth(),
516             Math.round(boxWidth + (float) (lastHidden - firstHidden + 1)
517                     * od.getWidth() / alwidth));
518     assertEquals(od.getBoxHeight(), boxHeight);
519     assertEquals(od.getScrollCol(),
520             Math.round((float) xpos * alwidth / od.getWidth()));
521     assertEquals(od.getScrollRow(), 0);
522
523     // move box so boxX is in hidden cols, box overhangs at right
524     // box width back to normal, boxX and scrollCol move to right of hidden area
525     // TODO currently this test fails in the Jalview GUI, there is a gap between
526     // the rhs of the hidden area and the box
527     /*    xpos = 50;
528         mouseClick(od, xpos, 0);
529         assertEquals(od.getBoxX(),
530                 (lastHidden + 1) * scalew * av.getCharWidth());
531         assertEquals(od.getBoxY(), 0);
532         assertEquals(od.getBoxWidth(), boxWidth);
533         assertEquals(od.getBoxHeight(), boxHeight);
534         assertEquals(od.getScrollCol(),
535                 Math.round(xpos * alwidth / od.getWidth()));
536         assertEquals(od.getScrollRow(), 0);*/
537
538     // move box so boxX is to right of hidden cols, but does not go beyond full
539     // width of alignment
540     // box width, boxX and scrollCol all as for non-hidden case
541     // TODO currently this test fails in the Jalview GUI because boxX is
542     // calculated
543     // based on the current boxWidth, which includes hidden columns, thereby
544     // pushing
545     // the box off the end of the alignment. So boxX is adjusted backwards
546     // unnecessarily.
547     /*   xpos = 72;
548        testBoxIsAtClickPoint(xpos, 0);
549        assertEquals(od.getScrollRow(), 0);
550        assertEquals(od.getScrollCol(),
551                Math.round(xpos * alwidth / od.getWidth())
552                - lastHidden);*/
553     
554     // move box so it goes beyond full width of alignment
555     // boxX, scrollCol adjusted back, box width normal
556     xpos = 3000;
557     mouseClick(od, xpos, 5);
558     assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
559     assertEquals(od.getBoxY(), 5);
560     assertEquals(od.getBoxWidth(), boxWidth);
561     assertEquals(od.getBoxHeight(), boxHeight);
562     assertEquals(od.getScrollCol(),
563             Math.round(((float) od.getBoxX() * alwidth / od.getWidth())
564                     - (lastHidden - firstHidden + 1)));
565     assertEquals(od.getScrollRow(),
566             Math.round((float) od.getBoxY() * alheight
567                     / od.getSequencesHeight()));
568
569   }
570
571   /**
572    * Test setting of the box position, when there are hidden cols at the end of
573    * the alignment
574    */
575   @Test(groups = { "Functional" })
576   public void testFromMouseWithHiddenColsAtEnd()
577   {
578     od.updateViewportFromMouse(0, 0,
579             av.getAlignment().getHiddenSequences(),
580             av.getColumnSelection(), av.getPosProps());
581     assertEquals(od.getBoxX(), 0);
582     assertEquals(od.getBoxY(), 0);
583     assertEquals(od.getBoxWidth(), boxWidth);
584     assertEquals(od.getScrollCol(), 0);
585     assertEquals(od.getScrollRow(), 0);
586
587     // hide columns 140-157, no change to box position or dimensions
588     int firstHidden = 140;
589     int lastHidden = 157;
590     hideColumns(firstHidden, lastHidden);
591     od.setBoxPosition(av.getAlignment()
592             .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
593     assertEquals(od.getBoxX(), 0);
594     assertEquals(od.getBoxY(), 0);
595     assertEquals(od.getBoxWidth(), boxWidth);
596     assertEquals(od.getScrollCol(), 0);
597     assertEquals(od.getScrollRow(), 0);
598
599     // click to left of hidden cols, without overlapping
600     // boxX, scrollCol and width as normal
601     int xpos = 5;
602     testBoxIsAtClickPoint(xpos, 0);
603     assertEquals(od.getScrollRow(), 0);
604     assertEquals(od.getScrollCol(),
605             Math.round((float) xpos * alwidth / od.getWidth()));
606
607     // click to left of hidden cols, with overlap
608     // boxX and scrollCol adjusted for hidden cols, width normal
609     // TODO this fails because setBoxPosition screws up the hidden cols calc
610     // only works in GUI because of AlignmentPanel::setScrollValues
611     /*xpos = 115 - boxWidth;
612     mouseClick(od, xpos, 0);
613     assertEquals(
614             od.getBoxX(),
615             Math.round((firstHidden - 1) * scalew * av.getCharWidth())
616                     - od.getBoxWidth());
617     assertEquals(od.getBoxY(), 0);
618     assertEquals(od.getBoxWidth(), boxWidth);
619     assertEquals(od.getBoxHeight(), boxHeight);
620     assertEquals(od.getScrollCol(),
621             Math.round(od.getBoxX() * alwidth / od.getWidth()));
622     assertEquals(od.getScrollRow(), 0);*/
623
624     // click in hidden cols
625     // boxX and scrollCol adjusted for hidden cols, width normal
626     // TODO breaks as above test
627     /*xpos = 115;
628     assertEquals(
629             od.getBoxX(),
630             Math.round((firstHidden - 1) * scalew * av.getCharWidth())
631                     - od.getBoxWidth());
632     assertEquals(od.getBoxY(), 0);
633     assertEquals(od.getBoxWidth(), boxWidth);
634     assertEquals(od.getBoxHeight(), boxHeight);
635     assertEquals(od.getScrollCol(),
636             Math.round(od.getBoxX() * alwidth / od.getWidth()));
637     assertEquals(od.getScrollRow(), 0);*/
638
639     // click off end of alignment
640     // boxX and scrollCol adjusted for hidden cols, width normal
641     // TODO breaks as above test
642     /*    xpos = 3000;
643         assertEquals(
644                 od.getBoxX(),
645                 Math.round((firstHidden - 1) * scalew * av.getCharWidth())
646                         - od.getBoxWidth());
647         assertEquals(od.getBoxY(), 0);
648         assertEquals(od.getBoxWidth(), boxWidth);
649         assertEquals(od.getBoxHeight(), boxHeight);
650         assertEquals(od.getScrollCol(),
651                 Math.round(od.getBoxX() * alwidth / od.getWidth()));
652         assertEquals(od.getScrollRow(), 0);*/
653   }
654
655   /**
656    * Test that the box position is set correctly when set from the viewport,
657    * with no hidden rows or columns
658    */
659   @Test(groups = { "Functional" })
660   public void testSetBoxFromViewport()
661   {
662     // move viewport to start of alignment
663     moveViewport(0, 0);
664     assertEquals(od.getBoxX(), 0);
665     assertEquals(od.getBoxY(), 0);
666     assertEquals(od.getBoxWidth(), boxWidth);
667     assertEquals(od.getBoxHeight(), boxHeight);
668
669     // move viewport to right
670     moveViewportH(70);
671     assertEquals(od.getBoxX(),
672             Math.round((float) 70 * od.getWidth() / alwidth));
673     assertEquals(od.getBoxY(), 0);
674     assertEquals(od.getBoxWidth(), boxWidth);
675     assertEquals(od.getBoxHeight(), boxHeight);
676
677     // move viewport down
678     moveViewportV(100);
679     assertEquals(od.getBoxX(),
680             Math.round((float) 70 * od.getWidth() / alwidth));
681     assertEquals(od.getBoxY(),
682             Math.round(100 * od.getSequencesHeight() / alheight));
683     assertEquals(od.getBoxWidth(), boxWidth);
684     assertEquals(od.getBoxHeight(), boxHeight);
685
686     // move viewport to bottom right
687     moveViewport(98, 508);
688     assertEquals(od.getBoxX(),
689             Math.round((float) 98 * od.getWidth() / alwidth));
690     assertEquals(od.getBoxY(),
691             Math.round((float) 508 * od.getSequencesHeight() / alheight));
692     assertEquals(od.getBoxWidth(), boxWidth);
693     assertEquals(od.getBoxHeight(), boxHeight);
694   }
695
696   /**
697    * Test that the box position is set correctly when there are hidden columns
698    * at the start
699    */
700   @Test(groups = { "Functional" })
701   public void testSetBoxFromViewportHiddenColsAtStart()
702   {
703     int firstHidden = 0;
704     int lastHidden = 20;
705     hideColumns(firstHidden, lastHidden);
706
707     // move viewport to start of alignment
708     moveViewport(0, 0);
709     assertEquals(od.getBoxX(),
710             Math.round((float) (lastHidden + 1) * od.getWidth() / alwidth));
711     assertEquals(od.getBoxY(), 0);
712     assertEquals(od.getBoxWidth(), boxWidth);
713     assertEquals(od.getBoxHeight(), boxHeight);
714
715     // move viewport to end of alignment - need to make startRes by removing
716     // hidden cols because of how viewport/overview are implemented
717     moveViewport(98 - lastHidden - 1, 0);
718     assertEquals(od.getBoxX(),
719             Math.round((float) 98 * od.getWidth() / alwidth));
720     assertEquals(od.getBoxY(), 0);
721     assertEquals(od.getBoxWidth(), boxWidth);
722     assertEquals(od.getBoxHeight(), boxHeight);
723   }
724
725   /**
726    * Test that the box position is set correctly when there are hidden columns
727    * in the middle
728    */
729   @Test(groups = { "Functional" })
730   public void testSetBoxFromViewportHiddenColsInMiddle()
731   {
732     int firstHidden = 68;
733     int lastHidden = 78;
734     hideColumns(firstHidden, lastHidden);
735
736     // move viewport before hidden columns
737     moveViewport(3, 0);
738
739     assertEquals(od.getBoxX(),
740             Math.round((float) 3 * od.getWidth() / alwidth));
741     assertEquals(od.getBoxY(), 0);
742     System.out.println(od.getBoxWidth());
743     assertEquals(od.getBoxWidth(), boxWidth);
744     System.out.println(od.getBoxWidth());
745     assertEquals(od.getBoxHeight(), boxHeight);
746
747     // move viewport to left of hidden columns with overlap
748     moveViewport(10, 0);
749     assertEquals(od.getBoxX(),
750             Math.round((float) 10 * od.getWidth() / alwidth));
751     assertEquals(od.getBoxY(), 0);
752     assertEquals(
753             od.getBoxWidth(),
754             boxWidth
755                     + Math.round((float) (lastHidden - firstHidden + 1)
756                             * od.getWidth() / alwidth));
757     assertEquals(od.getBoxHeight(), boxHeight);
758
759     // move viewport to straddle hidden columns
760     moveViewport(63, 0);
761     assertEquals(od.getBoxX(),
762             Math.round((float) 63 * od.getWidth() / alwidth));
763     assertEquals(od.getBoxY(), 0);
764     assertEquals(
765             od.getBoxWidth(),
766             boxWidth
767                     + Math.round((lastHidden - firstHidden + 1)
768                             * od.getWidth() / alwidth));
769     assertEquals(od.getBoxHeight(), boxHeight);
770
771     // move viewport to right of hidden columns, no overlap
772     moveViewport(80 - (lastHidden - firstHidden + 1), 0);
773     assertEquals(od.getBoxX(),
774             Math.round((float) 80 * od.getWidth() / alwidth));
775     assertEquals(od.getBoxY(), 0);
776     assertEquals(od.getBoxWidth(), boxWidth);
777     assertEquals(od.getBoxHeight(), boxHeight);
778
779   }
780
781   /**
782    * Test that the box position is set correctly when there are hidden columns
783    * at the end
784    */
785   @Test(groups = { "Functional" })
786   public void testSetBoxFromViewportHiddenColsAtEnd()
787   {
788     int firstHidden = 152;
789     int lastHidden = 164;
790     hideColumns(firstHidden, lastHidden);
791
792     // move viewport before hidden columns
793     moveViewport(3, 0);
794     assertEquals(od.getBoxX(),
795             Math.round((float) 3 * od.getWidth() / alwidth));
796     assertEquals(od.getBoxY(), 0);
797     assertEquals(od.getBoxWidth(), boxWidth);
798     assertEquals(od.getBoxHeight(), boxHeight);
799
800     // move viewport to hidden columns
801     // TODO boxwidth includes hidden in overview panel (why?)
802     moveViewport(102, 0);
803     assertEquals(od.getBoxX(),
804             Math.round((float) 102 * od.getWidth() / alwidth));
805     assertEquals(od.getBoxY(), 0);
806     assertEquals(od.getBoxWidth(), boxWidth
807                     + Math.round((float) (lastHidden - firstHidden)
808                             * od.getWidth() / alwidth));
809     assertEquals(od.getBoxHeight(), boxHeight);
810   }
811
812   /**
813    * Test that the box position is set correctly when there are hidden rows at
814    * the start
815    */
816   @Test(groups = { "Functional" })
817   public void testSetBoxFromViewportHiddenRowsAtStart()
818   {
819     int firstHidden = 0;
820     int lastHidden = 20;
821     hideSequences(firstHidden, lastHidden + 1, lastHidden + 1);
822
823     // move viewport to start of alignment:
824     // box moves to below hidden rows, height remains same
825     moveViewport(0, 0);
826     assertEquals(od.getBoxX(), 0);
827     assertEquals(od.getBoxY(),
828             Math.round((float) (lastHidden + 1) * od.getSequencesHeight()
829                     / alheight));
830     assertEquals(od.getBoxWidth(), boxWidth);
831     assertEquals(od.getBoxHeight(), boxHeight);
832
833     // move viewport to end of alignment, need to account for hidden rows
834     // because of how alignment panel/overview panel are implemented
835
836     // AlignViewport adjusts endSeq using Alignment height which excludes hidden
837     // rows if we happen to be at the bottom of the alignment
838     // od.setBoxPosition adjusts endSeq to include hidden rows
839     // od.checkValid adjusts scroll position to exclude hidden rows
840     // TODO this test fails because of the above!
841
842     /*    moveViewport(0, 525 - viewHeight - lastHidden - 1);
843         assertEquals(od.getBoxX(), 0);
844         assertEquals(od.getBoxY(),
845                 (525 - viewHeight) * scaleh
846                 * av.getCharHeight());
847         assertEquals(od.getBoxWidth(), boxWidth);
848         assertEquals(od.getBoxHeight(), boxHeight);*/
849   }
850
851   /**
852    * Test that the box position is set correctly when there are hidden rows in
853    * the middle
854    */
855   @Test(groups = { "Functional" })
856   public void testSetBoxFromViewportHiddenRowsInMiddle()
857   {
858     int firstHidden = 200;
859     int lastHidden = 210;
860     hideSequences(firstHidden, lastHidden + 1, lastHidden + 1);
861
862     // move viewport to start of alignment:
863     // box, height etc as in non-hidden case
864     // TODO fails with boxy=12 because that's what setBoxPosition sets it to!
865     /*moveViewport(0, 0);
866     assertEquals(od.getBoxX(), 0);
867     assertEquals(od.getBoxY(), 0);
868     assertEquals(od.getBoxWidth(), boxWidth);
869     assertEquals(od.getBoxHeight(), boxHeight);*/
870
871     // move viewport to straddle hidden rows
872     // TODO also fails with boxY out by 12
873     /*moveViewport(0, 198);
874     assertEquals(od.getBoxX(), 0);
875     assertEquals(od.getBoxY(), Math.round (198 * scaleh * av.getCharHeight()),
876             1.5);
877     assertEquals(od.getBoxWidth(), boxWidth);
878     assertEquals(od.getBoxHeight(), boxHeight
879             + ((lastHidden - firstHidden) * scaleh * av.getCharHeight()),
880             1.5);*/
881   }
882
883   /**
884    * Test that the box position is set correctly when there are hidden rows at
885    * the bottom
886    */
887   @Test(groups = { "Functional" })
888   public void testSetBoxFromViewportHiddenRowsAtEnd()
889   {
890     int firstHidden = 500;
891     int lastHidden = 524;
892     hideSequences(firstHidden - 1, lastHidden, firstHidden - 1);
893
894     // move viewport to start of alignment:
895     // box, height etc as in non-hidden case
896     moveViewport(0, 0);
897     assertEquals(od.getBoxX(), 0);
898     assertEquals(od.getBoxY(), 0);
899     assertEquals(od.getBoxWidth(), boxWidth);
900     assertEquals(od.getBoxHeight(), boxHeight);
901
902     // move viewport to end of alignment
903     // TODO fails with wrong boxHeight who knows why
904     /*moveViewport(0, firstHidden - viewHeight - 1);
905         assertEquals(od.getBoxX(), 0);
906         assertEquals(od.getBoxY(),
907      Math.round ((firstHidden - viewHeight - 1)
908                 * scaleh * av.getCharHeight()));
909         assertEquals(od.getBoxWidth(), boxWidth);
910         assertEquals(
911                 od.getBoxHeight(),
912                 boxHeight
913                         + Math.round ((lastHidden - firstHidden + 1) * scaleh * av
914                                 .getCharHeight()));*/
915
916   }
917
918   /**
919    * Test setting of the box position, when there are hidden rows at the start
920    * of the alignment
921    */
922   @Test(groups = { "Functional" })
923   public void testFromMouseWithHiddenRowsAtStart()
924   {
925     od.updateViewportFromMouse(0, 0,
926             av.getAlignment().getHiddenSequences(),
927             av.getColumnSelection(), av.getPosProps());
928     assertEquals(od.getBoxX(), 0);
929     assertEquals(od.getBoxY(), 0);
930     assertEquals(od.getBoxHeight(), boxHeight);
931     assertEquals(od.getBoxWidth(), boxWidth);
932     assertEquals(od.getScrollCol(), 0);
933     assertEquals(od.getScrollRow(), 0);
934
935     // hide rows at start and check updated box position is correct
936     // changes boxY but not boxheight
937     int lastHiddenRow = 30;
938     hideSequences(0, lastHiddenRow + 1, lastHiddenRow + 1);
939
940     od.setBoxPosition(av.getAlignment()
941             .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
942     assertEquals(od.getBoxX(), 0);
943     assertEquals(od.getBoxY(),
944             Math.round((float) (lastHiddenRow + 1)
945                     * od.getSequencesHeight() / alheight));
946     assertEquals(od.getBoxWidth(), boxWidth);
947     assertEquals(od.getBoxHeight(), boxHeight);
948
949     // click in hidden rows
950     // TODO fails because boxHeight is 27 not 25 (possible rounding issue)
951     /*    mouseClick(od, 0, 0);
952         assertEquals(od.getBoxX(), 0);
953         assertEquals(od.getBoxY(), 0);
954         assertEquals(od.getBoxWidth(), boxWidth);
955         assertEquals(od.getBoxHeight(), boxHeight
956                 + Math.round ((lastHiddenRow + 1) * scaleh * av.getCharHeight()),
957                 1.5);*/
958
959     // click below hidden rows
960     mouseClick(od, 0, 150);
961     assertEquals(od.getBoxX(), 0);
962     assertEquals(od.getBoxY(), 150);
963     assertEquals(od.getBoxWidth(), boxWidth);
964     assertEquals(od.getBoxHeight(), boxHeight);
965   }
966
967   /**
968    * Test setting of the box position, when there are hidden rows at the middle
969    * of the alignment
970    */
971   @Test(groups = { "Functional" })
972   public void testFromMouseWithHiddenRowsInMiddle()
973   {
974     od.updateViewportFromMouse(0, 0,
975             av.getAlignment().getHiddenSequences(),
976             av.getColumnSelection(), av.getPosProps());
977
978     assertEquals(od.getBoxX(), 0);
979     assertEquals(od.getBoxY(), 0);
980     assertEquals(od.getBoxWidth(), boxWidth);
981     assertEquals(od.getBoxHeight(), boxHeight);
982     assertEquals(od.getScrollCol(), 0);
983     assertEquals(od.getScrollRow(), 0);
984
985     // hide rows in middle and check updated box position is correct
986     // no changes
987     int firstHiddenRow = 50;
988     int lastHiddenRow = 60;
989     hideSequences(firstHiddenRow, lastHiddenRow + 1, lastHiddenRow + 1);
990
991     od.setBoxPosition(av.getAlignment()
992             .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
993
994     assertEquals(od.getBoxX(), 0);
995     assertEquals(od.getBoxY(), 0);
996     assertEquals(od.getBoxWidth(), boxWidth);
997     assertEquals(od.getBoxHeight(), boxHeight);
998
999     // click above hidden rows, so that box overlaps
1000     int ypos = 40;
1001     // TODO test fails because box does not change height - dealt with by scroll
1002     // values
1003     /*    mouseClick(od, 0, Math.round (ypos * alheight / od.getSequencesHeight()));
1004         assertEquals(od.getBoxX(), 0);
1005         assertEquals(od.getBoxY(), Math.round (ypos * alheight / od.getSequencesHeight()),
1006                 1.5);
1007         assertEquals(od.getBoxWidth(), boxWidth);
1008         assertEquals(
1009                 od.getBoxHeight(),
1010                 boxHeight
1011                         + Math.round ((lastHiddenRow - firstHiddenRow + 1) / scaleh / av
1012                                 .getCharHeight()));
1013     */
1014     // click so that box straddles hidden rows
1015     ypos = 48;
1016     // TODO test fails because box does not change height - dealt with by scroll
1017     // values
1018     /*mouseClick(od, 0, Math.round (ypos * alheight / od.getSequencesHeight()));
1019     assertEquals(od.getBoxX(), 0);
1020     assertEquals(od.getBoxY(), Math.round (ypos * alheight / od.getSequencesHeight()),
1021             1.5);
1022     assertEquals(od.getBoxWidth(), boxWidth);
1023     assertEquals(
1024             od.getBoxHeight(),
1025             boxHeight
1026                     + Math.round ((lastHiddenRow - firstHiddenRow + 1) / scaleh / av
1027                             .getCharHeight()));*/
1028   }
1029
1030   /**
1031    * Test setting of the box position, when there are hidden rows at the end of
1032    * the alignment
1033    */
1034   @Test(groups = { "Functional" })
1035   public void testFromMouseWithHiddenRowsAtEnd()
1036   {
1037     od.updateViewportFromMouse(0, 0,
1038             av.getAlignment().getHiddenSequences(),
1039             av.getColumnSelection(), av.getPosProps());
1040     assertEquals(od.getBoxX(), 0);
1041     assertEquals(od.getBoxY(), 0);
1042     assertEquals(od.getBoxWidth(), boxWidth);
1043     assertEquals(od.getBoxHeight(), boxHeight);
1044     assertEquals(od.getScrollCol(), 0);
1045     assertEquals(od.getScrollRow(), 0);
1046
1047     // hide rows at end and check updated box position is correct
1048     // no changes
1049     int firstHidden = 500;
1050     int lastHidden = 524;
1051     hideSequences(firstHidden - 1, lastHidden, firstHidden - 1);
1052
1053     od.setBoxPosition(av.getAlignment()
1054             .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
1055     assertEquals(od.getBoxX(), 0);
1056     assertEquals(od.getBoxY(), 0);
1057     assertEquals(od.getBoxWidth(), boxWidth);
1058     assertEquals(od.getBoxHeight(), boxHeight);
1059
1060     // click above hidden rows
1061     int ypos = 40; // row 40
1062     mouseClick(od, 0,
1063             Math.round((float) ypos * od.getSequencesHeight() / alheight));
1064     assertEquals(od.getBoxX(), 0);
1065     assertEquals(od.getBoxY(),
1066             Math.round((float) ypos * od.getSequencesHeight() / alheight));
1067     assertEquals(od.getBoxWidth(), boxWidth);
1068     assertEquals(od.getBoxHeight(), boxHeight);
1069
1070     // click above hidden rows so box overlaps
1071     // boxY moved upwards, boxHeight remains same
1072     // TODO fails with boxY located at row 497 - correction done by
1073     // setScrollValues
1074     /*   ypos = 497; // row 497
1075        mouseClick(od, 0, Math.round (ypos * scaleh * av.getCharHeight()));
1076        assertEquals(od.getBoxX(), 0);
1077        assertEquals(
1078                od.getBoxY(),
1079                Math.round ((firstHidden - viewHeight) * scaleh * av.getCharHeight()),
1080                1.5);
1081        assertEquals(od.getBoxWidth(), boxWidth);
1082        assertEquals(od.getBoxHeight(), boxHeight);*/
1083
1084     // click within hidden rows
1085     ypos = 505;
1086     // TODO: fails with wrong boxHeight - correction done by setScrollValues(?)
1087     /*mouseClick(od, 0, Math.round (ypos * scaleh * av.getCharHeight()));
1088     assertEquals(od.getBoxX(), 0);
1089     assertEquals(
1090             od.getBoxY(),
1091             Math.round ((firstHidden - viewHeight) * scaleh * av.getCharHeight()),
1092             1.5);
1093     assertEquals(od.getBoxWidth(), boxWidth);
1094     assertEquals(od.getBoxHeight(), boxHeight);*/
1095   }
1096
1097   /*
1098    * Move viewport horizontally: startRes + previous width gives new horizontal extent. Vertical extent stays the same.
1099    */
1100   private void moveViewportH(int startRes)
1101   {
1102     av.setStartRes(startRes);
1103     av.setEndRes(startRes + viewWidth);
1104     od.setBoxPosition(av.getAlignment()
1105             .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
1106   }
1107
1108   /*
1109    * Move viewport vertically: startSeq and endSeq give new vertical extent. Horizontal extent stays the same.
1110    */
1111   private void moveViewportV(int startSeq)
1112   {
1113     av.setStartSeq(startSeq);
1114     av.setEndSeq(startSeq + viewHeight);
1115     od.setBoxPosition(av.getAlignment()
1116             .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
1117   }
1118
1119   /*
1120    * Move viewport horizontally and vertically.
1121    */
1122   private void moveViewport(int startRes, int startSeq)
1123   {
1124     av.setStartRes(startRes);
1125     av.setEndRes(startRes + viewWidth);
1126     av.setStartSeq(startSeq);
1127     av.setEndSeq(startSeq + viewHeight);
1128     od.setBoxPosition(av.getAlignment()
1129             .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
1130   }
1131
1132   /*
1133    * Mouse click as position x,y in overview window
1134    */
1135   private void mouseClick(OverviewDimensions od, int x, int y)
1136   {
1137     od.updateViewportFromMouse(x, y,
1138             av.getAlignment().getHiddenSequences(),
1139             av.getColumnSelection(), av.getPosProps());
1140     // updates require an OverviewPanel to exist which it doesn't here
1141     // so call setBoxPosition() as it would be called by the AlignmentPanel
1142     // normally
1143     // int width = av.getEndRes() - av.getStartRes();
1144     // int height = av.getEndSeq() - av.getStartSeq();
1145     av.setStartRes(od.getScrollCol());
1146     av.setEndRes(od.getScrollCol() + viewWidth);
1147     av.setStartSeq(od.getScrollRow());
1148     av.setEndSeq(od.getScrollRow() + viewHeight);
1149     od.setBoxPosition(av.getAlignment()
1150             .getHiddenSequences(), av.getColumnSelection(), av.getPosProps());
1151   }
1152   
1153   private void testBoxIsAtClickPoint(int xpos, int ypos)
1154   {
1155     mouseClick(od, xpos, ypos);
1156     assertEquals(od.getBoxX(), xpos);
1157     assertEquals(od.getBoxY(), ypos);
1158     assertEquals(od.getBoxWidth(), boxWidth);
1159     assertEquals(od.getBoxHeight(), boxHeight);
1160
1161   }
1162
1163   /*
1164    * Hide sequences between start and end, using hideseq to do the hiding
1165    * (start <= hideseq <= end. Sequence hideseq is not hidden but the others are
1166    */
1167   private void hideSequences(int start, int end, int hideseq)
1168   {
1169     SequenceGroup sg = new SequenceGroup();
1170     List<SequenceI> allseqs = av.getAlignment().getSequences();
1171     for (int i = start; i <= end; ++i)
1172     {
1173       sg.addSequence(allseqs.get(i), false);
1174     }
1175     av.setSelectionGroup(sg);
1176
1177     /*
1178      * hide group
1179      */
1180     av.hideSequences(allseqs.get(hideseq), true);
1181
1182     while (av.isCalcInProgress())
1183     {
1184       try
1185       {
1186         Thread.sleep(50);
1187       } catch (InterruptedException e)
1188       {
1189         System.out.println("Hiding seqs interruption");
1190       }
1191     }
1192   }
1193
1194   private void hideColumns(int firstHidden, int lastHidden)
1195   {
1196     av.hideColumns(firstHidden, lastHidden);
1197
1198     while (av.isCalcInProgress())
1199     {
1200       try
1201       {
1202         Thread.sleep(50);
1203       } catch (InterruptedException e)
1204       {
1205         System.out.println("Hiding cols interruption");
1206       }
1207     }
1208   }
1209 }