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