JAL-845 first rough applet SplitFrame (add parameter file2)
[jalview.git] / src / jalview / appletgui / AlignmentPanel.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3  * Copyright (C) 2014 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.appletgui;
22
23 import jalview.api.AlignViewportI;
24 import jalview.api.AlignmentViewPanel;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.SearchResults;
27 import jalview.datamodel.SequenceI;
28 import jalview.structure.StructureSelectionManager;
29
30 import java.awt.BorderLayout;
31 import java.awt.Color;
32 import java.awt.Dimension;
33 import java.awt.FontMetrics;
34 import java.awt.Frame;
35 import java.awt.Graphics;
36 import java.awt.Panel;
37 import java.awt.Scrollbar;
38 import java.awt.event.AdjustmentEvent;
39 import java.awt.event.AdjustmentListener;
40 import java.awt.event.ComponentAdapter;
41 import java.awt.event.ComponentEvent;
42
43 public class AlignmentPanel extends Panel implements AdjustmentListener,
44         AlignmentViewPanel
45 {
46
47   public AlignViewport av;
48
49   OverviewPanel overviewPanel;
50
51   SeqPanel seqPanel;
52
53   IdPanel idPanel;
54
55   IdwidthAdjuster idwidthAdjuster;
56
57   public AlignFrame alignFrame;
58
59   ScalePanel scalePanel;
60
61   AnnotationPanel annotationPanel;
62
63   AnnotationLabels alabels;
64
65   // this value is set false when selection area being dragged
66   boolean fastPaint = true;
67
68   public void finalize()
69   {
70     alignFrame = null;
71     av = null;
72     seqPanel = null;
73     seqPanelHolder = null;
74     sequenceHolderPanel = null;
75     scalePanel = null;
76     scalePanelHolder = null;
77     annotationPanel = null;
78     annotationPanelHolder = null;
79     annotationSpaceFillerHolder = null;
80   }
81
82   public AlignmentPanel(AlignFrame af, final AlignViewport av)
83   {
84     try
85     {
86       jbInit();
87     } catch (Exception e)
88     {
89       e.printStackTrace();
90     }
91
92     alignFrame = af;
93     this.av = av;
94     seqPanel = new SeqPanel(av, this);
95     idPanel = new IdPanel(av, this);
96     scalePanel = new ScalePanel(av, this);
97     idwidthAdjuster = new IdwidthAdjuster(this);
98     annotationPanel = new AnnotationPanel(this);
99     annotationPanelHolder.add(annotationPanel, BorderLayout.CENTER);
100
101     sequenceHolderPanel.add(annotationPanelHolder, BorderLayout.SOUTH);
102     alabels = new AnnotationLabels(this);
103
104     setAnnotationVisible(av.isShowAnnotation());
105
106     idPanelHolder.add(idPanel, BorderLayout.CENTER);
107     idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
108     annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);
109     scalePanelHolder.add(scalePanel, BorderLayout.CENTER);
110     seqPanelHolder.add(seqPanel, BorderLayout.CENTER);
111
112     fontChanged();
113     setScrollValues(0, 0);
114
115     apvscroll.addAdjustmentListener(this);
116     hscroll.addAdjustmentListener(this);
117     vscroll.addAdjustmentListener(this);
118
119     addComponentListener(new ComponentAdapter()
120     {
121       public void componentResized(ComponentEvent evt)
122       {
123         setScrollValues(av.getStartRes(), av.getStartSeq());
124         if (getSize().height > 0
125                 && annotationPanelHolder.getSize().height > 0)
126         {
127           validateAnnotationDimensions(false);
128         }
129         repaint();
130       }
131
132     });
133
134     Dimension d = calculateIdWidth();
135     idPanel.idCanvas.setSize(d);
136
137     hscrollFillerPanel.setSize(d.width, annotationPanel.getSize().height);
138
139     idPanel.idCanvas.setSize(d.width, seqPanel.seqCanvas.getSize().height);
140     annotationSpaceFillerHolder.setSize(d.width,
141             annotationPanel.getSize().height);
142     alabels.setSize(d.width, annotationPanel.getSize().height);
143     final AlignmentPanel ap = this;
144     av.addPropertyChangeListener(new java.beans.PropertyChangeListener()
145     {
146       public void propertyChange(java.beans.PropertyChangeEvent evt)
147       {
148         if (evt.getPropertyName().equals("alignment"))
149         {
150           PaintRefresher.Refresh(ap, av.getSequenceSetId(), true, true);
151           alignmentChanged();
152         }
153       }
154     });
155   }
156
157   @Override
158   public AlignViewportI getAlignViewport()
159   {
160     return av;
161   }
162   public SequenceRenderer getSequenceRenderer()
163   {
164     return seqPanel.seqCanvas.sr;
165   }
166   @Override
167   public jalview.api.FeatureRenderer getFeatureRenderer()
168   {
169     return seqPanel.seqCanvas.fr;
170   }
171   @Override
172   public jalview.api.FeatureRenderer cloneFeatureRenderer()
173   {
174     FeatureRenderer nfr = new FeatureRenderer(av);
175     nfr.transferSettings(seqPanel.seqCanvas.fr);
176     return nfr;
177   }
178   public void alignmentChanged()
179   {
180     av.alignmentChanged(this);
181
182     if (overviewPanel != null)
183     {
184       overviewPanel.updateOverviewImage();
185     }
186
187     alignFrame.updateEditMenuBar();
188
189     repaint();
190   }
191
192   public void fontChanged()
193   {
194     // set idCanvas bufferedImage to null
195     // to prevent drawing old image
196     idPanel.idCanvas.image = null;
197     FontMetrics fm = getFontMetrics(av.getFont());
198
199     scalePanel.setSize(new Dimension(10, av.getCharHeight()
200             + fm.getDescent()));
201     idwidthAdjuster.setSize(new Dimension(10, av.getCharHeight()
202             + fm.getDescent()));
203     av.updateSequenceIdColours();
204     annotationPanel.image = null;
205     int ap = annotationPanel.adjustPanelHeight(false);
206     Dimension d = calculateIdWidth();
207     d.setSize(d.width + 4, seqPanel.seqCanvas.getSize().height);
208     alabels.setSize(d.width + 4, ap);
209
210     idPanel.idCanvas.setSize(d);
211     hscrollFillerPanel.setSize(d);
212
213     validateAnnotationDimensions(false);
214     annotationPanel.repaint();
215     validate();
216     repaint();
217
218     if (overviewPanel != null)
219     {
220       overviewPanel.updateOverviewImage();
221     }
222   }
223
224   public void setIdWidth(int w, int h)
225   {
226     idPanel.idCanvas.setSize(w, h);
227     idPanelHolder.setSize(w, idPanelHolder.getSize().height);
228     annotationSpaceFillerHolder.setSize(w,
229             annotationSpaceFillerHolder.getSize().height);
230     alabels.setSize(w, alabels.getSize().height);
231     validate();
232   }
233
234   Dimension calculateIdWidth()
235   {
236     if (av.nullFrame == null)
237     {
238       av.nullFrame = new Frame();
239       av.nullFrame.addNotify();
240     }
241
242     Graphics g = av.nullFrame.getGraphics();
243
244     FontMetrics fm = g.getFontMetrics(av.font);
245     AlignmentI al = av.getAlignment();
246
247     int i = 0;
248     int idWidth = 0;
249     String id;
250     while (i < al.getHeight() && al.getSequenceAt(i) != null)
251     {
252       SequenceI s = al.getSequenceAt(i);
253       id = s.getDisplayId(av.getShowJVSuffix());
254
255       if (fm.stringWidth(id) > idWidth)
256       {
257         idWidth = fm.stringWidth(id);
258       }
259       i++;
260     }
261
262     // Also check annotation label widths
263     i = 0;
264     if (al.getAlignmentAnnotation() != null)
265     {
266       fm = g.getFontMetrics(av.nullFrame.getFont());
267       while (i < al.getAlignmentAnnotation().length)
268       {
269         String label = al.getAlignmentAnnotation()[i].label;
270         if (fm.stringWidth(label) > idWidth)
271         {
272           idWidth = fm.stringWidth(label);
273         }
274         i++;
275       }
276     }
277
278     return new Dimension(idWidth, idPanel.idCanvas.getSize().height);
279   }
280
281   /**
282    * Highlight the given results on the alignment.
283    * 
284    */
285   public void highlightSearchResults(SearchResults results)
286   {
287     scrollToPosition(results);
288     seqPanel.seqCanvas.highlightSearchResults(results);
289   }
290
291   /**
292    * scroll the view to show the position of the highlighted region in results
293    * (if any) and redraw the overview
294    * 
295    * @param results
296    * @return false if results were not found
297    */
298   public boolean scrollToPosition(SearchResults results)
299   {
300     return scrollToPosition(results, true);
301   }
302
303   /**
304    * scroll the view to show the position of the highlighted region in results
305    * (if any)
306    * 
307    * @param results
308    * @param redrawOverview
309    *          - when set, the overview will be recalculated (takes longer)
310    * @return false if results were not found
311    */
312   public boolean scrollToPosition(SearchResults results,
313           boolean redrawOverview)
314   {
315
316     // do we need to scroll the panel?
317     if (results != null && results.getSize() > 0)
318     {
319       AlignmentI alignment = av.getAlignment();
320       int seqIndex = alignment.findIndex(results);
321       if (seqIndex == -1)
322       {
323         return false;
324       }
325       SequenceI seq = alignment.getSequenceAt(seqIndex);
326       int[] r = results.getResults(seq, 0, alignment.getWidth());
327       if (r == null)
328       {
329         if (av.applet.debug)
330         {// DEBUG
331           System.out
332                   .println("DEBUG: scroll didn't happen - results not within alignment : "
333                           + seq.getStart() + "," + seq.getEnd());
334         }
335         return false;
336       }
337       if (av.applet.debug)
338       {
339         // DEBUG
340         /*
341          * System.out.println("DEBUG: scroll: start=" + r[0] +
342          * " av.getStartRes()=" + av.getStartRes() + " end=" + r[1] +
343          * " seq.end=" + seq.getEnd() + " av.getEndRes()=" + av.getEndRes() +
344          * " hextent=" + hextent);
345          */
346       }
347       int start = r[0];
348       int end = r[1];
349       if (start < 0)
350       {
351         return false;
352       }
353       if (end == seq.getEnd())
354       {
355         return false;
356       }
357       return scrollTo(start, end, seqIndex, false, redrawOverview);
358     }
359     return true;
360   }
361
362   public boolean scrollTo(int ostart, int end, int seqIndex,
363           boolean scrollToNearest, boolean redrawOverview)
364   {
365     int startv, endv, starts, ends, width;
366
367     int start = -1;
368     if (av.hasHiddenColumns())
369     {
370       start = av.getColumnSelection().findColumnPosition(ostart);
371       end = av.getColumnSelection().findColumnPosition(end);
372       if (start == end)
373       {
374         if (!scrollToNearest && !av.getColumnSelection().isVisible(ostart))
375         {
376           // don't scroll - position isn't visible
377           return false;
378         }
379       }
380     }
381     else
382     {
383       start = ostart;
384     }
385     if (!av.getWrapAlignment())
386     {
387       /*
388        * int spos=av.getStartRes(),sqpos=av.getStartSeq(); if ((startv =
389        * av.getStartRes()) >= start) { spos=start-1; // seqIn //
390        * setScrollValues(start - 1, seqIndex); } else if ((endv =
391        * av.getEndRes()) <= end) { // setScrollValues(spos=startv + 1 + end -
392        * endv, seqIndex); spos=startv + 1 + end - endv; } else if ((starts =
393        * av.getStartSeq()) > seqIndex) { setScrollValues(av.getStartRes(),
394        * seqIndex); } else if ((ends = av.getEndSeq()) <= seqIndex) {
395        * setScrollValues(av.getStartRes(), starts + seqIndex - ends + 1); }
396        * 
397        * /*
398        */
399       if ((av.getStartRes() > end)
400               || (av.getEndRes() < start)
401               || ((av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex)))
402       {
403         if (start > av.getAlignment().getWidth() - hextent)
404         {
405           start = av.getAlignment().getWidth() - hextent;
406           if (start < 0)
407           {
408             start = 0;
409           }
410
411         }
412         if (seqIndex > av.getAlignment().getHeight() - vextent)
413         {
414           seqIndex = av.getAlignment().getHeight() - vextent;
415           if (seqIndex < 0)
416           {
417             seqIndex = 0;
418           }
419         }
420         // System.out.println("trying to scroll to: "+start+" "+seqIndex);
421         setScrollValues(start, seqIndex);
422       }/**/
423     }
424     else
425     {
426       scrollToWrappedVisible(start);
427     }
428     if (redrawOverview && overviewPanel != null)
429     {
430       overviewPanel.setBoxPosition();
431     }
432     paintAlignment(redrawOverview);
433     return true;
434   }
435
436   void scrollToWrappedVisible(int res)
437   {
438     int cwidth = seqPanel.seqCanvas
439             .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width);
440     if (res <= av.getStartRes() || res >= (av.getStartRes() + cwidth))
441     {
442       vscroll.setValue(res / cwidth);
443       av.startRes = vscroll.getValue() * cwidth;
444     }
445   }
446
447   public OverviewPanel getOverviewPanel()
448   {
449     return overviewPanel;
450   }
451
452   public void setOverviewPanel(OverviewPanel op)
453   {
454     overviewPanel = op;
455   }
456
457   public void setAnnotationVisible(boolean b)
458   {
459     if (!av.getWrapAlignment())
460     {
461       annotationSpaceFillerHolder.setVisible(b);
462       annotationPanelHolder.setVisible(b);
463     }
464     else
465     {
466       annotationSpaceFillerHolder.setVisible(false);
467       annotationPanelHolder.setVisible(false);
468     }
469     validate();
470     repaint();
471   }
472
473   /**
474    * automatically adjust annotation panel height for new annotation whilst
475    * ensuring the alignment is still visible.
476    */
477   public void adjustAnnotationHeight()
478   {
479     // TODO: display vertical annotation scrollbar if necessary
480     // this is called after loading new annotation onto alignment
481     if (alignFrame.getSize().height == 0)
482     {
483       System.out
484               .println("adjustAnnotationHeight frame size zero NEEDS FIXING");
485     }
486     fontChanged();
487     validateAnnotationDimensions(true);
488     apvscroll.addNotify();
489     hscroll.addNotify();
490     validate();
491     paintAlignment(true);
492   }
493
494   /**
495    * calculate the annotation dimensions and refresh slider values accordingly.
496    * need to do repaints/notifys afterwards.
497    */
498   protected void validateAnnotationDimensions(boolean adjustPanelHeight)
499   {
500     boolean modified = false;
501     int height = av.calcPanelHeight();
502     int minsize = 0;
503     if (hscroll.isVisible())
504     {
505       height += (minsize = hscroll.getPreferredSize().height);
506     }
507     if (apvscroll.isVisible())
508     {
509       minsize += apvscroll.getPreferredSize().height;
510     }
511     int mheight = height;
512     Dimension d = sequenceHolderPanel.getSize(), e = idPanel.getSize();
513     int seqandannot = d.height - scalePanelHolder.getSize().height;
514
515     if (adjustPanelHeight)
516     {
517       // NOTE: this logic is different in the application. Need a better
518       // algorithm to define behaviour
519       // sets initial preferred height
520       // try and set height according to alignment
521       float sscaling = (float) ((av.getCharHeight() * av.getAlignment()
522               .getHeight()) / (1.0 * mheight));
523       if (sscaling > 0.5)
524       {
525         // if the alignment is too big then
526         // default is 0.5 split
527         height = seqandannot / 2;
528       }
529       else
530       {
531         // otherwise just set the panel so that one row of sequence is visible
532         height = -av.getCharHeight() * 1
533                 + (int) (seqandannot * (1 - sscaling));
534       }
535     }
536     else
537     {
538       // maintain same window layout whilst updating sliders
539       height = annotationPanelHolder.getSize().height;
540     }
541
542     if (seqandannot - height < 5)
543     {
544       height = seqandannot;
545     }
546     annotationPanel.setSize(new Dimension(d.width, height));
547     alabels.setSize(new Dimension(e.width, height));
548     annotationSpaceFillerHolder.setSize(new Dimension(e.width, height));
549     annotationPanelHolder.setSize(new Dimension(d.width, height));
550     // seqPanelHolder.setSize(d.width, seqandannot - height);
551     seqPanel.seqCanvas
552             .setSize(d.width, seqPanel.seqCanvas.getSize().height);
553     int s = apvscroll.getValue();
554     if (s > mheight - height)
555     {
556       s = 0;
557     }
558     apvscroll.setValues(s, height, 0, mheight);
559     annotationPanel.setScrollOffset(apvscroll.getValue(), false);
560     alabels.setScrollOffset(apvscroll.getValue(), false);
561   }
562
563   public void setWrapAlignment(boolean wrap)
564   {
565     av.startSeq = 0;
566     av.startRes = 0;
567     scalePanelHolder.setVisible(!wrap);
568
569     hscroll.setVisible(!wrap);
570     idwidthAdjuster.setVisible(!wrap);
571
572     if (wrap)
573     {
574       annotationPanelHolder.setVisible(false);
575       annotationSpaceFillerHolder.setVisible(false);
576     }
577     else if (av.isShowAnnotation())
578     {
579       annotationPanelHolder.setVisible(true);
580       annotationSpaceFillerHolder.setVisible(true);
581     }
582
583     idSpaceFillerPanel1.setVisible(!wrap);
584
585     fontChanged(); // This is so that the scalePanel is resized correctly
586
587     validate();
588     sequenceHolderPanel.validate();
589     repaint();
590
591   }
592
593   int hextent = 0;
594
595   int vextent = 0;
596
597   // return value is true if the scroll is valid
598   public boolean scrollUp(boolean up)
599   {
600     if (up)
601     {
602       if (vscroll.getValue() < 1)
603       {
604         return false;
605       }
606       setScrollValues(hscroll.getValue(), vscroll.getValue() - 1);
607     }
608     else
609     {
610       if (vextent + vscroll.getValue() >= av.getAlignment().getHeight())
611       {
612         return false;
613       }
614       setScrollValues(hscroll.getValue(), vscroll.getValue() + 1);
615     }
616
617     repaint();
618     return true;
619   }
620
621   public boolean scrollRight(boolean right)
622   {
623     if (!right)
624     {
625       if (hscroll.getValue() < 1)
626       {
627         return false;
628       }
629       setScrollValues(hscroll.getValue() - 1, vscroll.getValue());
630     }
631     else
632     {
633       if (hextent + hscroll.getValue() >= av.getAlignment().getWidth())
634       {
635         return false;
636       }
637       setScrollValues(hscroll.getValue() + 1, vscroll.getValue());
638     }
639
640     repaint();
641     return true;
642   }
643
644   public void setScrollValues(int x, int y)
645   {
646     int width = av.getAlignment().getWidth();
647     int height = av.getAlignment().getHeight();
648
649     if (av.hasHiddenColumns())
650     {
651       width = av.getColumnSelection().findColumnPosition(width);
652     }
653     if (x < 0)
654     {
655       x = 0;
656     }
657     ;
658
659     hextent = seqPanel.seqCanvas.getSize().width / av.getCharWidth();
660     vextent = seqPanel.seqCanvas.getSize().height / av.getCharHeight();
661
662     if (hextent > width)
663     {
664       hextent = width;
665     }
666
667     if (vextent > height)
668     {
669       vextent = height;
670     }
671
672     if ((hextent + x) > width)
673     {
674       System.err.println("hextent was " + hextent + " and x was " + x);
675
676       x = width - hextent;
677     }
678
679     if ((vextent + y) > height)
680     {
681       y = height - vextent;
682     }
683
684     if (y < 0)
685     {
686       y = 0;
687     }
688
689     if (x < 0)
690     {
691       System.err.println("x was " + x);
692       x = 0;
693     }
694
695     av.setStartSeq(y);
696
697     int endSeq = y + vextent;
698     if (endSeq > av.getAlignment().getHeight())
699     {
700       endSeq = av.getAlignment().getHeight();
701     }
702
703     av.setEndSeq(endSeq);
704     av.setStartRes(x);
705     av.setEndRes((x + (seqPanel.seqCanvas.getSize().width / av
706             .getCharWidth())) - 1);
707
708     hscroll.setValues(x, hextent, 0, width);
709     vscroll.setValues(y, vextent, 0, height);
710
711     if (overviewPanel != null)
712     {
713       overviewPanel.setBoxPosition();
714     }
715     sendViewPosition();
716
717   }
718
719   public void adjustmentValueChanged(AdjustmentEvent evt)
720   {
721     int oldX = av.getStartRes();
722     int oldY = av.getStartSeq();
723
724     if (evt == null || evt.getSource() == apvscroll)
725     {
726       annotationPanel.setScrollOffset(apvscroll.getValue(), false);
727       alabels.setScrollOffset(apvscroll.getValue(), false);
728       // annotationPanel.image=null;
729       // alabels.image=null;
730       // alabels.repaint();
731       // annotationPanel.repaint();
732     }
733     if (evt == null || evt.getSource() == hscroll)
734     {
735       int x = hscroll.getValue();
736       av.setStartRes(x);
737       av.setEndRes(x + seqPanel.seqCanvas.getSize().width
738               / av.getCharWidth() - 1);
739     }
740
741     if (evt == null || evt.getSource() == vscroll)
742     {
743       int offy = vscroll.getValue();
744       if (av.getWrapAlignment())
745       {
746         int rowSize = seqPanel.seqCanvas
747                 .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width);
748         av.setStartRes(vscroll.getValue() * rowSize);
749         av.setEndRes((vscroll.getValue() + 1) * rowSize);
750       }
751       else
752       {
753         av.setStartSeq(offy);
754         av.setEndSeq(offy + seqPanel.seqCanvas.getSize().height
755                 / av.getCharHeight());
756       }
757     }
758
759     if (overviewPanel != null)
760     {
761       overviewPanel.setBoxPosition();
762     }
763
764     int scrollX = av.startRes - oldX;
765     int scrollY = av.startSeq - oldY;
766
767     if (av.getWrapAlignment() || !fastPaint || av.MAC)
768     {
769       repaint();
770     }
771     else
772     {
773       // Make sure we're not trying to draw a panel
774       // larger than the visible window
775       if (scrollX > av.endRes - av.startRes)
776       {
777         scrollX = av.endRes - av.startRes;
778       }
779       else if (scrollX < av.startRes - av.endRes)
780       {
781         scrollX = av.startRes - av.endRes;
782       }
783
784       idPanel.idCanvas.fastPaint(scrollY);
785       seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
786
787       scalePanel.repaint();
788       if (av.isShowAnnotation())
789       {
790         annotationPanel.fastPaint(av.getStartRes() - oldX);
791       }
792     }
793     sendViewPosition();
794
795   }
796
797   private void sendViewPosition()
798   {
799     StructureSelectionManager.getStructureSelectionManager(av.applet)
800             .sendViewPosition(this, av.startRes, av.endRes, av.startSeq,
801                     av.endSeq);
802   }
803
804   public void paintAlignment(boolean updateOverview)
805   {
806     repaint();
807
808     if (updateOverview)
809     {
810       jalview.structure.StructureSelectionManager
811               .getStructureSelectionManager(av.applet)
812               .sequenceColoursChanged(this);
813
814       if (overviewPanel != null)
815       {
816         overviewPanel.updateOverviewImage();
817       }
818     }
819   }
820
821   public void update(Graphics g)
822   {
823     paint(g);
824   }
825
826   public void paint(Graphics g)
827   {
828     invalidate();
829     Dimension d = idPanel.idCanvas.getSize();
830     idPanel.idCanvas.setSize(d.width, seqPanel.seqCanvas.getSize().height);
831
832     if (av.getWrapAlignment())
833     {
834       int maxwidth = av.getAlignment().getWidth();
835
836       if (av.hasHiddenColumns())
837       {
838         maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
839       }
840
841       int canvasWidth = seqPanel.seqCanvas
842               .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width);
843
844       if (canvasWidth > 0)
845       {
846         int max = maxwidth / canvasWidth;
847         vscroll.setMaximum(1 + max);
848         vscroll.setUnitIncrement(1);
849         vscroll.setVisibleAmount(1);
850       }
851     }
852     else
853     {
854       setScrollValues(av.getStartRes(), av.getStartSeq());
855     }
856
857     seqPanel.seqCanvas.repaint();
858     idPanel.idCanvas.repaint();
859     if (!av.getWrapAlignment())
860     {
861       if (av.isShowAnnotation())
862       {
863         alabels.repaint();
864         annotationPanel.repaint();
865       }
866       scalePanel.repaint();
867     }
868
869   }
870
871   protected Panel sequenceHolderPanel = new Panel();
872
873   protected Scrollbar vscroll = new Scrollbar();
874
875   protected Scrollbar hscroll = new Scrollbar();
876
877   protected Panel seqPanelHolder = new Panel();
878
879   BorderLayout borderLayout1 = new BorderLayout();
880
881   BorderLayout borderLayout3 = new BorderLayout();
882
883   protected Panel scalePanelHolder = new Panel();
884
885   protected Panel idPanelHolder = new Panel();
886
887   BorderLayout borderLayout5 = new BorderLayout();
888
889   protected Panel idSpaceFillerPanel1 = new Panel();
890
891   public Panel annotationSpaceFillerHolder = new Panel();
892
893   BorderLayout borderLayout6 = new BorderLayout();
894
895   BorderLayout borderLayout7 = new BorderLayout();
896
897   Panel hscrollHolder = new Panel();
898
899   BorderLayout borderLayout10 = new BorderLayout();
900
901   protected Panel hscrollFillerPanel = new Panel();
902
903   BorderLayout borderLayout11 = new BorderLayout();
904
905   BorderLayout borderLayout4 = new BorderLayout();
906
907   BorderLayout borderLayout2 = new BorderLayout();
908
909   Panel annotationPanelHolder = new Panel();
910
911   protected Scrollbar apvscroll = new Scrollbar();
912
913   BorderLayout borderLayout12 = new BorderLayout();
914
915   private void jbInit() throws Exception
916   {
917     // idPanelHolder.setPreferredSize(new Dimension(70, 10));
918     this.setLayout(borderLayout7);
919
920     // sequenceHolderPanel.setPreferredSize(new Dimension(150, 150));
921     sequenceHolderPanel.setLayout(borderLayout3);
922     seqPanelHolder.setLayout(borderLayout1);
923     scalePanelHolder.setBackground(Color.white);
924
925     // scalePanelHolder.setPreferredSize(new Dimension(10, 30));
926     scalePanelHolder.setLayout(borderLayout6);
927     idPanelHolder.setLayout(borderLayout5);
928     idSpaceFillerPanel1.setBackground(Color.white);
929
930     // idSpaceFillerPanel1.setPreferredSize(new Dimension(10, 30));
931     idSpaceFillerPanel1.setLayout(borderLayout11);
932     annotationSpaceFillerHolder.setBackground(Color.white);
933
934     // annotationSpaceFillerHolder.setPreferredSize(new Dimension(10, 80));
935     annotationSpaceFillerHolder.setLayout(borderLayout4);
936     hscroll.setOrientation(Scrollbar.HORIZONTAL);
937     hscrollHolder.setLayout(borderLayout10);
938     hscrollFillerPanel.setBackground(Color.white);
939     apvscroll.setOrientation(Scrollbar.VERTICAL);
940     apvscroll.setVisible(true);
941     apvscroll.addAdjustmentListener(this);
942
943     annotationPanelHolder.setBackground(Color.white);
944     annotationPanelHolder.setLayout(borderLayout12);
945     annotationPanelHolder.add(apvscroll, BorderLayout.EAST);
946     // hscrollFillerPanel.setPreferredSize(new Dimension(70, 10));
947     hscrollHolder.setBackground(Color.white);
948
949     // annotationScroller.setPreferredSize(new Dimension(10, 80));
950     // this.setPreferredSize(new Dimension(220, 166));
951     seqPanelHolder.setBackground(Color.white);
952     idPanelHolder.setBackground(Color.white);
953     sequenceHolderPanel.add(scalePanelHolder, BorderLayout.NORTH);
954     sequenceHolderPanel.add(seqPanelHolder, BorderLayout.CENTER);
955     seqPanelHolder.add(vscroll, BorderLayout.EAST);
956
957     // Panel3.add(secondaryPanelHolder, BorderLayout.SOUTH);
958     this.add(idPanelHolder, BorderLayout.WEST);
959     idPanelHolder.add(idSpaceFillerPanel1, BorderLayout.NORTH);
960     idPanelHolder.add(annotationSpaceFillerHolder, BorderLayout.SOUTH);
961     this.add(hscrollHolder, BorderLayout.SOUTH);
962     hscrollHolder.add(hscroll, BorderLayout.CENTER);
963     hscrollHolder.add(hscrollFillerPanel, BorderLayout.WEST);
964     this.add(sequenceHolderPanel, BorderLayout.CENTER);
965   }
966
967   /**
968    * hides or shows dynamic annotation rows based on groups and av state flags
969    */
970   public void updateAnnotation()
971   {
972     updateAnnotation(false);
973   }
974
975   public void updateAnnotation(boolean applyGlobalSettings)
976   {
977     updateAnnotation(applyGlobalSettings, false);
978   }
979
980   public void updateAnnotation(boolean applyGlobalSettings,
981           boolean preserveNewGroupSettings)
982   {
983     av.updateGroupAnnotationSettings(applyGlobalSettings,
984             preserveNewGroupSettings);
985     adjustAnnotationHeight();
986   }
987
988   @Override
989   public AlignmentI getAlignment()
990   {
991     return av.getAlignment();
992   }
993
994   @Override
995   public String getViewName()
996   {
997     return getName();
998   }
999
1000   @Override
1001   public StructureSelectionManager getStructureSelectionManager()
1002   {
1003     return StructureSelectionManager
1004             .getStructureSelectionManager(av.applet);
1005   }
1006
1007   @Override
1008   public void raiseOOMWarning(String string, OutOfMemoryError error)
1009   {
1010     // TODO: JAL-960
1011     System.err.println("Out of memory whilst '" + string + "'");
1012     error.printStackTrace();
1013   }
1014
1015 }