1.2ish awt methods
[jalview.git] / src / jalview / appletgui / AlignmentPanel.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3  * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
10  * 
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.appletgui;
19
20 import java.awt.*;
21 import java.awt.event.*;
22 import java.util.Hashtable;
23 import java.util.Vector;
24
25 import jalview.datamodel.*;
26
27 public class AlignmentPanel extends Panel implements AdjustmentListener
28 {
29
30   public AlignViewport av;
31
32   OverviewPanel overviewPanel;
33
34   SeqPanel seqPanel;
35
36   IdPanel idPanel;
37
38   IdwidthAdjuster idwidthAdjuster;
39
40   public AlignFrame alignFrame;
41
42   ScalePanel scalePanel;
43
44   AnnotationPanel annotationPanel;
45
46   AnnotationLabels alabels;
47
48   // this value is set false when selection area being dragged
49   boolean fastPaint = true;
50
51   public AlignmentPanel(AlignFrame af, final AlignViewport av)
52   {
53     try
54     {
55       jbInit();
56     } catch (Exception e)
57     {
58       e.printStackTrace();
59     }
60
61     alignFrame = af;
62     this.av = av;
63     seqPanel = new SeqPanel(av, this);
64     idPanel = new IdPanel(av, this);
65     scalePanel = new ScalePanel(av, this);
66     idwidthAdjuster = new IdwidthAdjuster(this);
67 //    annotationScroller = new ScrollPane();
68  //   annotationScroller.setBackground(Color.white);
69     annotationPanel = new AnnotationPanel(this);
70     annotationPanelHolder.add(annotationPanel, BorderLayout.CENTER);
71     // annotationScroller.setPreferredSize(new Dimension(10,80));
72 //    annotationScroller.add(annotationPanel);
73 //    annotationScroller.getInsets().set(0,0,0,0);
74     
75     sequenceHolderPanel.add(annotationPanelHolder, BorderLayout.SOUTH);
76
77     alabels = new AnnotationLabels(this);
78
79     setAnnotationVisible(av.showAnnotation);
80
81     idPanelHolder.add(idPanel, BorderLayout.CENTER);
82     idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
83     annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);
84     scalePanelHolder.add(scalePanel, BorderLayout.CENTER);
85     seqPanelHolder.add(seqPanel, BorderLayout.CENTER);
86     
87     fontChanged();
88     setScrollValues(0, 0);
89
90     apvscroll.addAdjustmentListener(this);
91     hscroll.addAdjustmentListener(this);
92     vscroll.addAdjustmentListener(this);
93
94     addComponentListener(new ComponentAdapter()
95     {
96       public void componentResized(ComponentEvent evt)
97       {
98         setScrollValues(av.getStartRes(), av.getStartSeq());
99         repaint();
100       }
101     });
102
103     Dimension d = calculateIdWidth();
104     idPanel.idCanvas.setSize(d);
105
106     hscrollFillerPanel.setSize(d.width, annotationPanel.getSize().height);
107
108     idPanel.idCanvas.setSize(d.width, seqPanel.seqCanvas.getSize().height);
109     annotationSpaceFillerHolder.setSize(d.width,
110             annotationPanel.getSize().height);
111     alabels.setSize(d.width, annotationPanel.getSize().height);
112     final AlignmentPanel ap = this;
113     av.addPropertyChangeListener(new java.beans.PropertyChangeListener()
114     {
115       public void propertyChange(java.beans.PropertyChangeEvent evt)
116       {
117         if (evt.getPropertyName().equals("alignment"))
118         {
119           PaintRefresher.Refresh(ap, av.getSequenceSetId(), true, true);
120           alignmentChanged();
121         }
122       }
123     });
124
125   }
126
127   public SequenceRenderer getSequenceRenderer()
128   {
129     return seqPanel.seqCanvas.sr;
130   }
131
132   public FeatureRenderer getFeatureRenderer()
133   {
134     return seqPanel.seqCanvas.fr;
135   }
136
137   public void alignmentChanged()
138   {
139     av.alignmentChanged(this);
140
141     if (overviewPanel != null)
142     {
143       overviewPanel.updateOverviewImage();
144     }
145
146     alignFrame.updateEditMenuBar();
147
148     repaint();
149   }
150
151   public void fontChanged()
152   {
153     // set idCanvas bufferedImage to null
154     // to prevent drawing old image
155     idPanel.idCanvas.image = null;
156     FontMetrics fm = getFontMetrics(av.getFont());
157
158     scalePanel.setSize(new Dimension(10, av.charHeight + fm.getDescent()));
159     idwidthAdjuster.setSize(new Dimension(10, av.charHeight
160             + fm.getDescent()));
161     av.updateSequenceIdColours();
162     annotationPanel.image = null;
163     int ap = annotationPanel.adjustPanelHeight(false);
164     annotationPanel.repaint();
165     Dimension d = calculateIdWidth();
166     d.setSize(d.width + 4, seqPanel.seqCanvas.getSize().height);
167     alabels.setSize(d.width + 4, ap);
168     idPanel.idCanvas.setSize(d);
169     hscrollFillerPanel.setSize(d);
170
171     validate();
172     repaint();
173
174     if (overviewPanel != null)
175     {
176       overviewPanel.updateOverviewImage();
177     }
178   }
179
180   public void setIdWidth(int w, int h)
181   {
182     idPanel.idCanvas.setSize(w, h);
183     idPanelHolder.setSize(w, idPanelHolder.getSize().height);
184     alabels.setSize(w, alabels.getSize().height);
185     validate();
186   }
187
188   Dimension calculateIdWidth()
189   {
190     if (av.nullFrame == null)
191     {
192       av.nullFrame = new Frame();
193       av.nullFrame.addNotify();
194     }
195
196     Graphics g = av.nullFrame.getGraphics();
197
198     FontMetrics fm = g.getFontMetrics(av.font);
199     AlignmentI al = av.getAlignment();
200
201     int i = 0;
202     int idWidth = 0;
203     String id;
204     while (i < al.getHeight() && al.getSequenceAt(i) != null)
205     {
206       SequenceI s = al.getSequenceAt(i);
207       id = s.getDisplayId(av.getShowJVSuffix());
208
209       if (fm.stringWidth(id) > idWidth)
210       {
211         idWidth = fm.stringWidth(id);
212       }
213       i++;
214     }
215
216     // Also check annotation label widths
217     i = 0;
218     if (al.getAlignmentAnnotation() != null)
219     {
220       fm = g.getFontMetrics(av.nullFrame.getFont());
221       while (i < al.getAlignmentAnnotation().length)
222       {
223         String label = al.getAlignmentAnnotation()[i].label;
224         if (fm.stringWidth(label) > idWidth)
225         {
226           idWidth = fm.stringWidth(label);
227         }
228         i++;
229       }
230     }
231
232     return new Dimension(idWidth, idPanel.idCanvas.getSize().height);
233   }
234
235   /**
236    * Highlight the given results on the alignment.
237    * 
238    */
239   public void highlightSearchResults(SearchResults results)
240   {
241     scrollToPosition(results);
242     seqPanel.seqCanvas.highlightSearchResults(results);
243   }
244
245   /**
246    * scroll the view to show the position of the highlighted region in results
247    * (if any) and redraw the overview
248    * 
249    * @param results
250    * @return false if results were not found
251    */
252   public boolean scrollToPosition(SearchResults results)
253   {
254     return scrollToPosition(results, true);
255   }
256
257   /**
258    * scroll the view to show the position of the highlighted region in results
259    * (if any)
260    * 
261    * @param results
262    * @param redrawOverview
263    *          - when set, the overview will be recalculated (takes longer)
264    * @return false if results were not found
265    */
266   public boolean scrollToPosition(SearchResults results,
267           boolean redrawOverview)
268   {
269     // do we need to scroll the panel?
270     if (results != null && results.getSize() > 0)
271     {
272       int seqIndex = av.alignment.findIndex(results);
273       if (seqIndex == -1)
274       {
275         return false;
276       }
277       SequenceI seq = av.alignment.getSequenceAt(seqIndex);
278       int[] r = results.getResults(seq, seq.getStart(), seq.getEnd());
279       if (r == null)
280       {
281         return false;
282       }
283       int start = r[0];
284       int end = r[1];
285       if (start < 0)
286       {
287         return false;
288       }
289       if (end == seq.getEnd())
290       {
291         return false;
292       }
293       if (av.hasHiddenColumns)
294       {
295         start = av.getColumnSelection().findColumnPosition(start);
296         end = av.getColumnSelection().findColumnPosition(end);
297         if (start == end)
298         {
299           if (!av.colSel.isVisible(r[0]))
300           {
301             // don't scroll - position isn't visible
302             return false;
303           }
304         }
305       }
306       if (!av.wrapAlignment)
307       {
308         if ((av.getStartRes() > end)
309                 || (av.getEndRes() < start)
310                 || ((av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex)))
311         {
312           if (start > av.alignment.getWidth() - hextent)
313           {
314             start = av.alignment.getWidth() - hextent;
315             if (start < 0)
316             {
317               start = 0;
318             }
319           }
320           if (seqIndex > av.alignment.getHeight() - vextent)
321           {
322             seqIndex = av.alignment.getHeight() - vextent;
323             if (seqIndex < 0)
324             {
325               seqIndex = 0;
326             }
327           }
328           setScrollValues(start, seqIndex);
329         }
330       }
331       else
332       {
333         scrollToWrappedVisible(start);
334       }
335     }
336     if (redrawOverview && overviewPanel != null)
337     {
338       overviewPanel.setBoxPosition();
339     }
340     paintAlignment(redrawOverview);
341     return true;
342   }
343
344   void scrollToWrappedVisible(int res)
345   {
346     int cwidth = seqPanel.seqCanvas
347             .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width);
348     if (res <= av.getStartRes() || res >= (av.getStartRes() + cwidth))
349     {
350       vscroll.setValue(res / cwidth);
351       av.startRes = vscroll.getValue() * cwidth;
352     }
353   }
354
355   public OverviewPanel getOverviewPanel()
356   {
357     return overviewPanel;
358   }
359
360   public void setOverviewPanel(OverviewPanel op)
361   {
362     overviewPanel = op;
363   }
364
365   public void setAnnotationVisible(boolean b)
366   {
367     if (!av.wrapAlignment)
368     {
369       annotationSpaceFillerHolder.setVisible(b);
370       annotationPanel.setVisible(b);
371     }
372     validate();
373     repaint();
374   }
375
376   public void setWrapAlignment(boolean wrap)
377   {
378     av.startSeq = 0;
379     av.startRes = 0;
380     scalePanelHolder.setVisible(!wrap);
381
382     hscroll.setVisible(!wrap);
383     idwidthAdjuster.setVisible(!wrap);
384
385     if (wrap)
386     {
387       annotationPanel.setVisible(false);
388       annotationSpaceFillerHolder.setVisible(false);
389     }
390     else if (av.showAnnotation)
391     {
392       annotationPanel.setVisible(true);
393       annotationSpaceFillerHolder.setVisible(true);
394     }
395
396     idSpaceFillerPanel1.setVisible(!wrap);
397
398     fontChanged(); // This is so that the scalePanel is resized correctly
399
400     validate();
401     repaint();
402
403   }
404
405   int hextent = 0;
406
407   int vextent = 0;
408
409   // return value is true if the scroll is valid
410   public boolean scrollUp(boolean up)
411   {
412     if (up)
413     {
414       if (vscroll.getValue() < 1)
415       {
416         return false;
417       }
418       setScrollValues(hscroll.getValue(), vscroll.getValue() - 1);
419     }
420     else
421     {
422       if (vextent + vscroll.getValue() >= av.getAlignment().getHeight())
423       {
424         return false;
425       }
426       setScrollValues(hscroll.getValue(), vscroll.getValue() + 1);
427     }
428
429     repaint();
430     return true;
431   }
432
433   public boolean scrollRight(boolean right)
434   {
435     if (!right)
436     {
437       if (hscroll.getValue() < 1)
438       {
439         return false;
440       }
441       setScrollValues(hscroll.getValue() - 1, vscroll.getValue());
442     }
443     else
444     {
445       if (hextent + hscroll.getValue() >= av.getAlignment().getWidth())
446       {
447         return false;
448       }
449       setScrollValues(hscroll.getValue() + 1, vscroll.getValue());
450     }
451
452     repaint();
453     return true;
454   }
455
456   public void setScrollValues(int x, int y)
457   {
458     int width = av.alignment.getWidth();
459     int height = av.alignment.getHeight();
460
461     if (av.hasHiddenColumns)
462     {
463       width = av.getColumnSelection().findColumnPosition(width);
464     }
465
466     av.setStartRes(x);
467     av.setEndRes((x + (seqPanel.seqCanvas.getSize().width / av.charWidth)) - 1);
468
469     hextent = seqPanel.seqCanvas.getSize().width / av.charWidth;
470     vextent = seqPanel.seqCanvas.getSize().height / av.charHeight;
471
472     if (hextent > width)
473     {
474       hextent = width;
475     }
476
477     if (vextent > height)
478     {
479       vextent = height;
480     }
481
482     if ((hextent + x) > width)
483     {
484       x = width - hextent;
485     }
486
487     if ((vextent + y) > height)
488     {
489       y = height - vextent;
490     }
491
492     if (y < 0)
493     {
494       y = 0;
495     }
496
497     if (x < 0)
498     {
499       x = 0;
500     }
501
502     av.setStartSeq(y);
503
504     int endSeq = y + vextent;
505     if (endSeq > av.alignment.getHeight())
506     {
507       endSeq = av.alignment.getHeight();
508     }
509
510     av.setEndSeq(endSeq);
511     hscroll.setValues(x, hextent, 0, width);
512     vscroll.setValues(y, vextent, 0, height);
513
514     if (overviewPanel != null)
515     {
516       overviewPanel.setBoxPosition();
517     }
518
519   }
520
521   public void adjustmentValueChanged(AdjustmentEvent evt)
522   {
523     int oldX = av.getStartRes();
524     int oldY = av.getStartSeq();
525
526     if (evt == null || evt.getSource()==apvscroll)
527     {
528       annotationPanel.setScrollOffset(apvscroll.getValue());
529       alabels.setScrollOffset(apvscroll.getValue());
530       //annotationPanel.image=null;
531       //alabels.image=null;
532       //alabels.repaint();
533       //annotationPanel.repaint();
534     }
535     if (evt == null || evt.getSource() == hscroll)
536     {
537       int x = hscroll.getValue();
538       av.setStartRes(x);
539       av.setEndRes(x + seqPanel.seqCanvas.getSize().width
540               / av.getCharWidth() - 1);
541     }
542
543     if (evt == null || evt.getSource() == vscroll)
544     {
545       int offy = vscroll.getValue();
546       if (av.getWrapAlignment())
547       {
548         int rowSize = seqPanel.seqCanvas
549                 .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width);
550         av.setStartRes(vscroll.getValue() * rowSize);
551         av.setEndRes((vscroll.getValue() + 1) * rowSize);
552       }
553       else
554       {
555         av.setStartSeq(offy);
556         av.setEndSeq(offy + seqPanel.seqCanvas.getSize().height
557                 / av.getCharHeight());
558       }
559     }
560
561     if (overviewPanel != null)
562     {
563       overviewPanel.setBoxPosition();
564     }
565
566     int scrollX = av.startRes - oldX;
567     int scrollY = av.startSeq - oldY;
568
569     if (av.getWrapAlignment() || !fastPaint || av.MAC)
570     {
571       repaint();
572     }
573     else
574     {
575       // Make sure we're not trying to draw a panel
576       // larger than the visible window
577       if (scrollX > av.endRes - av.startRes)
578       {
579         scrollX = av.endRes - av.startRes;
580       }
581       else if (scrollX < av.startRes - av.endRes)
582       {
583         scrollX = av.startRes - av.endRes;
584       }
585
586       idPanel.idCanvas.fastPaint(scrollY);
587       seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
588
589       scalePanel.repaint();
590       if (av.getShowAnnotation())
591       {
592         annotationPanel.fastPaint(av.getStartRes() - oldX);
593       }
594     }
595
596   }
597
598   public void paintAlignment(boolean updateOverview)
599   {
600     repaint();
601
602     if (updateOverview)
603     {
604       jalview.structure.StructureSelectionManager
605               .getStructureSelectionManager().sequenceColoursChanged(this);
606
607       if (overviewPanel != null)
608       {
609         overviewPanel.updateOverviewImage();
610       }
611     }
612   }
613
614   public void update(Graphics g)
615   {
616     paint(g);
617   }
618
619   public void paint(Graphics g)
620   {
621     invalidate();
622     Dimension d = idPanel.idCanvas.getSize();
623     idPanel.idCanvas.setSize(d.width, seqPanel.seqCanvas.getSize().height);
624     annotationPanelHolder.setSize(seqPanel.getSize().width, annotationPanel.getSize().height);
625     annotationSpaceFillerHolder.setSize(d.width,
626             annotationPanel.getSize().height);
627
628     alabels.setSize(d.width, annotationPanelHolder.getSize().height);
629
630     if (av.getWrapAlignment())
631     {
632       int maxwidth = av.alignment.getWidth();
633
634       if (av.hasHiddenColumns)
635       {
636         maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
637       }
638
639       int canvasWidth = seqPanel.seqCanvas
640               .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width);
641
642       if (canvasWidth > 0)
643       {
644         int max = maxwidth / canvasWidth;
645         vscroll.setMaximum(1+max);
646         vscroll.setUnitIncrement(1);
647         vscroll.setVisibleAmount(1);
648       }
649     }
650     else
651     {
652       setScrollValues(av.getStartRes(), av.getStartSeq());
653     }
654
655     alabels.repaint();
656
657     seqPanel.seqCanvas.repaint();
658     scalePanel.repaint();
659     annotationPanel.repaint();
660     idPanel.idCanvas.repaint();
661   }
662
663   protected Panel sequenceHolderPanel = new Panel();
664
665   protected Scrollbar vscroll = new Scrollbar();
666
667   protected Scrollbar hscroll = new Scrollbar();
668
669   protected Panel seqPanelHolder = new Panel();
670
671   BorderLayout borderLayout1 = new BorderLayout();
672
673   BorderLayout borderLayout3 = new BorderLayout();
674
675   protected Panel scalePanelHolder = new Panel();
676
677   protected Panel idPanelHolder = new Panel();
678
679   BorderLayout borderLayout5 = new BorderLayout();
680
681   protected Panel idSpaceFillerPanel1 = new Panel();
682
683   public Panel annotationSpaceFillerHolder = new Panel();
684
685   BorderLayout borderLayout6 = new BorderLayout();
686
687   BorderLayout borderLayout7 = new BorderLayout();
688
689   Panel hscrollHolder = new Panel();
690
691   BorderLayout borderLayout10 = new BorderLayout();
692
693   protected Panel hscrollFillerPanel = new Panel();
694
695   BorderLayout borderLayout11 = new BorderLayout();
696
697   BorderLayout borderLayout4 = new BorderLayout();
698
699   BorderLayout borderLayout2 = new BorderLayout();
700
701   Panel annotationPanelHolder = new Panel();
702   protected Scrollbar apvscroll=new Scrollbar();
703
704   BorderLayout borderLayout12 = new BorderLayout();
705
706   private void jbInit() throws Exception
707   {
708     // idPanelHolder.setPreferredSize(new Dimension(70, 10));
709     this.setLayout(borderLayout7);
710
711     // sequenceHolderPanel.setPreferredSize(new Dimension(150, 150));
712     sequenceHolderPanel.setLayout(borderLayout3);
713     seqPanelHolder.setLayout(borderLayout1);
714     scalePanelHolder.setBackground(Color.white);
715
716     // scalePanelHolder.setPreferredSize(new Dimension(10, 30));
717     scalePanelHolder.setLayout(borderLayout6);
718     idPanelHolder.setLayout(borderLayout5);
719     idSpaceFillerPanel1.setBackground(Color.white);
720
721     // idSpaceFillerPanel1.setPreferredSize(new Dimension(10, 30));
722     idSpaceFillerPanel1.setLayout(borderLayout11);
723     annotationSpaceFillerHolder.setBackground(Color.white);
724
725     // annotationSpaceFillerHolder.setPreferredSize(new Dimension(10, 80));
726     annotationSpaceFillerHolder.setLayout(borderLayout4);
727     hscroll.setOrientation(Scrollbar.HORIZONTAL);
728     hscrollHolder.setLayout(borderLayout10);
729     hscrollFillerPanel.setBackground(Color.white);
730     apvscroll.setOrientation(Scrollbar.VERTICAL);
731     apvscroll.setVisible(true);
732     apvscroll.addAdjustmentListener(this);
733
734     annotationPanelHolder.setBackground(Color.white);
735     annotationPanelHolder.setLayout(borderLayout12);
736     annotationPanelHolder.add(apvscroll, BorderLayout.EAST);
737     // hscrollFillerPanel.setPreferredSize(new Dimension(70, 10));
738     hscrollHolder.setBackground(Color.white);
739
740     // annotationScroller.setPreferredSize(new Dimension(10, 80));
741     // this.setPreferredSize(new Dimension(220, 166));
742     seqPanelHolder.setBackground(Color.white);
743     idPanelHolder.setBackground(Color.white);
744     sequenceHolderPanel.add(scalePanelHolder, BorderLayout.NORTH);
745     sequenceHolderPanel.add(seqPanelHolder, BorderLayout.CENTER);
746     seqPanelHolder.add(vscroll, BorderLayout.EAST);
747
748     // Panel3.add(secondaryPanelHolder, BorderLayout.SOUTH);
749     this.add(idPanelHolder, BorderLayout.WEST);
750     idPanelHolder.add(idSpaceFillerPanel1, BorderLayout.NORTH);
751     idPanelHolder.add(annotationSpaceFillerHolder, BorderLayout.SOUTH);
752     this.add(hscrollHolder, BorderLayout.SOUTH);
753     hscrollHolder.add(hscroll, BorderLayout.CENTER);
754     hscrollHolder.add(hscrollFillerPanel, BorderLayout.WEST);
755     this.add(sequenceHolderPanel, BorderLayout.CENTER);
756   }
757
758   /**
759    * hides or shows dynamic annotation rows based on groups and av state flags
760    */
761   public void updateAnnotation()
762   {
763     updateAnnotation(false);
764   }
765
766   public void updateAnnotation(boolean applyGlobalSettings)
767   {
768     // TODO: this should be merged with other annotation update stuff - that
769     // sits on AlignViewport
770     boolean updateCalcs = false;
771     boolean conv = av.isShowGroupConservation();
772     boolean cons = av.isShowGroupConsensus();
773     boolean showprf = av.isShowSequenceLogo();
774     boolean showConsHist = av.isShowConsensusHistogram();
775
776     boolean sortg = true;
777
778     // remove old automatic annotation
779     // add any new annotation
780
781     Vector gr = av.alignment.getGroups(); // OrderedBy(av.alignment.getSequencesArray());
782     // intersect alignment annotation with alignment groups
783
784     AlignmentAnnotation[] aan = av.alignment.getAlignmentAnnotation();
785     Hashtable oldrfs = new Hashtable();
786     if (aan != null)
787     {
788       for (int an = 0; an < aan.length; an++)
789       {
790         if (aan[an].autoCalculated && aan[an].groupRef != null)
791         {
792           oldrfs.put(aan[an].groupRef, aan[an].groupRef);
793           av.alignment.deleteAnnotation(aan[an]);
794           aan[an] = null;
795         }
796       }
797     }
798     SequenceGroup sg;
799     if (gr != null)
800     {
801       for (int g = 0; g < gr.size(); g++)
802       {
803         updateCalcs = false;
804         sg = (SequenceGroup) gr.elementAt(g);
805         if (applyGlobalSettings || !oldrfs.containsKey(sg))
806         {
807           // set defaults for this group's conservation/consensus
808           sg.setshowSequenceLogo(showprf);
809           sg.setShowConsensusHistogram(showConsHist);
810         }
811         if (conv)
812         {
813           updateCalcs = true;
814           av.alignment.addAnnotation(sg.getConservationRow(), 0);
815         }
816         if (cons)
817         {
818           updateCalcs = true;
819           av.alignment.addAnnotation(sg.getConsensus(), 0);
820         }
821         // refresh the annotation rows
822         if (updateCalcs)
823         {
824           sg.recalcConservation();
825         }
826       }
827     }
828     oldrfs.clear();
829     adjustAnnotationHeight();
830   }
831   /**
832    * automatically adjust annotation panel height for new annotation
833    * whilst ensuring the alignment is still visible.
834    */
835   public void adjustAnnotationHeight()
836   {
837     // TODO: display vertical annotation scrollbar if necessary
838     // this is called after loading new annotation onto alignment
839     if (alignFrame.getSize().height == 0)
840     {
841       System.out.println("NEEDS FIXING");
842     }
843     fontChanged();
844     int height = annotationPanel.adjustPanelHeight();
845     if (hscroll.isVisible())
846     {
847       height += hscroll.getPreferredSize().height;
848     }
849     int mheight=height;
850     // sets initial preferred height
851     if (height > alignFrame.getSize().height/ 2)
852     {
853       height = alignFrame.getSize().height / 2;
854     }
855     apvscroll.setValues(apvscroll.getValue(), height, 0, mheight);
856     annotationPanel.setScrollOffset(apvscroll.getValue());
857     alabels.setScrollOffset(apvscroll.getValue());
858     apvscroll.addNotify();
859     hscroll.addNotify();
860
861     annotationPanelHolder.setSize(new Dimension(annotationPanel
862             .getSize().width, height));
863
864     annotationSpaceFillerHolder.setSize(new Dimension(
865             annotationSpaceFillerHolder.getSize().width
866             , height));
867     
868     //annotationScroller.validate();// repaint();
869     validate();
870     addNotify();
871     repaint();
872   }
873
874 }