a677eff2ece24d8755e0acddd0005337c3e9dcc5
[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     }
439     else
440     {
441       annotationSpaceFillerHolder.setVisible(false);
442       annotationPanelHolder.setVisible(false);
443     }
444     validate();
445     repaint();
446   }
447
448   /**
449    * automatically adjust annotation panel height for new annotation whilst
450    * ensuring the alignment is still visible.
451    */
452   public void adjustAnnotationHeight()
453   {
454     // TODO: display vertical annotation scrollbar if necessary
455     // this is called after loading new annotation onto alignment
456     if (alignFrame.getSize().height == 0)
457     {
458       System.out.println("NEEDS FIXING");
459     }
460     fontChanged();
461     validateAnnotationDimensions(true);
462     apvscroll.addNotify();
463     hscroll.addNotify();
464     validate();
465     paintAlignment(true);
466   }
467
468   /**
469    * calculate the annotation dimensions and refresh slider values accordingly.
470    * need to do repaints/notifys afterwards.
471    */
472   protected void validateAnnotationDimensions(boolean adjustPanelHeight)
473   {
474     boolean modified = false;
475     int height = av.calcPanelHeight();
476     int minsize = 0;
477     if (hscroll.isVisible())
478     {
479       height += (minsize = hscroll.getPreferredSize().height);
480     }
481     if (apvscroll.isVisible())
482     {
483       minsize += apvscroll.getPreferredSize().height;
484     }
485     int mheight = height;
486     Dimension d = sequenceHolderPanel.getSize(), e = idPanel.getSize();
487     int seqandannot = d.height - scalePanelHolder.getSize().height;
488
489     if (adjustPanelHeight)
490     {
491       // NOTE: this logic is different in the application. Need a better
492       // algorithm to define behaviour
493       // sets initial preferred height
494       // try and set height according to alignment
495       float sscaling = (float) ((av.getCharHeight() * av.getAlignment()
496               .getHeight()) / (1.0 * mheight));
497       if (sscaling > 0.5)
498       {
499         // if the alignment is too big then
500         // default is 0.5 split
501         height = seqandannot / 2;
502       }
503       else
504       {
505         // otherwise just set the panel so that one row of sequence is visible
506         height = -av.getCharHeight() * 1
507                 + (int) (seqandannot * (1 - sscaling));
508       }
509     }
510     else
511     {
512       // maintain same window layout whilst updating sliders
513       height = annotationPanelHolder.getSize().height;
514     }
515
516     if (seqandannot - height < 5)
517     {
518       height = seqandannot;
519     }
520     annotationPanel.setSize(new Dimension(d.width, height));
521     alabels.setSize(new Dimension(e.width, height));
522     annotationSpaceFillerHolder.setSize(new Dimension(e.width, height));
523     annotationPanelHolder.setSize(new Dimension(d.width, height));
524     // seqPanelHolder.setSize(d.width, seqandannot - height);
525     seqPanel.seqCanvas
526             .setSize(d.width, seqPanel.seqCanvas.getSize().height);
527     int s = apvscroll.getValue();
528     if (s > mheight - height)
529     {
530       s = 0;
531     }
532     apvscroll.setValues(s, height, 0, mheight);
533     annotationPanel.setScrollOffset(apvscroll.getValue(), false);
534     alabels.setScrollOffset(apvscroll.getValue(), false);
535   }
536
537   public void setWrapAlignment(boolean wrap)
538   {
539     av.startSeq = 0;
540     av.startRes = 0;
541     scalePanelHolder.setVisible(!wrap);
542
543     hscroll.setVisible(!wrap);
544     idwidthAdjuster.setVisible(!wrap);
545
546     if (wrap)
547     {
548       annotationPanelHolder.setVisible(false);
549       annotationSpaceFillerHolder.setVisible(false);
550     }
551     else if (av.showAnnotation)
552     {
553       annotationPanelHolder.setVisible(true);
554       annotationSpaceFillerHolder.setVisible(true);
555     }
556
557     idSpaceFillerPanel1.setVisible(!wrap);
558
559     fontChanged(); // This is so that the scalePanel is resized correctly
560
561     validate();
562     sequenceHolderPanel.revalidate();
563     repaint();
564
565   }
566
567   int hextent = 0;
568
569   int vextent = 0;
570
571   // return value is true if the scroll is valid
572   public boolean scrollUp(boolean up)
573   {
574     if (up)
575     {
576       if (vscroll.getValue() < 1)
577       {
578         return false;
579       }
580       setScrollValues(hscroll.getValue(), vscroll.getValue() - 1);
581     }
582     else
583     {
584       if (vextent + vscroll.getValue() >= av.getAlignment().getHeight())
585       {
586         return false;
587       }
588       setScrollValues(hscroll.getValue(), vscroll.getValue() + 1);
589     }
590
591     repaint();
592     return true;
593   }
594
595   public boolean scrollRight(boolean right)
596   {
597     if (!right)
598     {
599       if (hscroll.getValue() < 1)
600       {
601         return false;
602       }
603       setScrollValues(hscroll.getValue() - 1, vscroll.getValue());
604     }
605     else
606     {
607       if (hextent + hscroll.getValue() >= av.getAlignment().getWidth())
608       {
609         return false;
610       }
611       setScrollValues(hscroll.getValue() + 1, vscroll.getValue());
612     }
613
614     repaint();
615     return true;
616   }
617
618   public void setScrollValues(int x, int y)
619   {
620     int width = av.getAlignment().getWidth();
621     int height = av.getAlignment().getHeight();
622
623     if (av.hasHiddenColumns())
624     {
625       width = av.getColumnSelection().findColumnPosition(width);
626     }
627     if (x < 0)
628     {
629       x = 0;
630     }
631     ;
632
633     hextent = seqPanel.seqCanvas.getSize().width / av.charWidth;
634     vextent = seqPanel.seqCanvas.getSize().height / av.charHeight;
635
636     if (hextent > width)
637     {
638       hextent = width;
639     }
640
641     if (vextent > height)
642     {
643       vextent = height;
644     }
645
646     if ((hextent + x) > width)
647     {
648       System.err.println("hextent was " + hextent + " and x was " + x);
649
650       x = width - hextent;
651     }
652
653     if ((vextent + y) > height)
654     {
655       y = height - vextent;
656     }
657
658     if (y < 0)
659     {
660       y = 0;
661     }
662
663     if (x < 0)
664     {
665       System.err.println("x was " + x);
666       x = 0;
667     }
668
669     av.setStartSeq(y);
670
671     int endSeq = y + vextent;
672     if (endSeq > av.getAlignment().getHeight())
673     {
674       endSeq = av.getAlignment().getHeight();
675     }
676
677     av.setEndSeq(endSeq);
678     av.setStartRes(x);
679     av.setEndRes((x + (seqPanel.seqCanvas.getSize().width / av.charWidth)) - 1);
680
681     hscroll.setValues(x, hextent, 0, width);
682     vscroll.setValues(y, vextent, 0, height);
683
684     if (overviewPanel != null)
685     {
686       overviewPanel.setBoxPosition();
687     }
688     sendViewPosition();
689
690   }
691
692   public void adjustmentValueChanged(AdjustmentEvent evt)
693   {
694     int oldX = av.getStartRes();
695     int oldY = av.getStartSeq();
696
697     if (evt == null || evt.getSource() == apvscroll)
698     {
699       annotationPanel.setScrollOffset(apvscroll.getValue(), false);
700       alabels.setScrollOffset(apvscroll.getValue(), false);
701       // annotationPanel.image=null;
702       // alabels.image=null;
703       // alabels.repaint();
704       // annotationPanel.repaint();
705     }
706     if (evt == null || evt.getSource() == hscroll)
707     {
708       int x = hscroll.getValue();
709       av.setStartRes(x);
710       av.setEndRes(x + seqPanel.seqCanvas.getSize().width
711               / av.getCharWidth() - 1);
712     }
713
714     if (evt == null || evt.getSource() == vscroll)
715     {
716       int offy = vscroll.getValue();
717       if (av.getWrapAlignment())
718       {
719         int rowSize = seqPanel.seqCanvas
720                 .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width);
721         av.setStartRes(vscroll.getValue() * rowSize);
722         av.setEndRes((vscroll.getValue() + 1) * rowSize);
723       }
724       else
725       {
726         av.setStartSeq(offy);
727         av.setEndSeq(offy + seqPanel.seqCanvas.getSize().height
728                 / av.getCharHeight());
729       }
730     }
731
732     if (overviewPanel != null)
733     {
734       overviewPanel.setBoxPosition();
735     }
736
737     int scrollX = av.startRes - oldX;
738     int scrollY = av.startSeq - oldY;
739
740     if (av.getWrapAlignment() || !fastPaint || av.MAC)
741     {
742       repaint();
743     }
744     else
745     {
746       // Make sure we're not trying to draw a panel
747       // larger than the visible window
748       if (scrollX > av.endRes - av.startRes)
749       {
750         scrollX = av.endRes - av.startRes;
751       }
752       else if (scrollX < av.startRes - av.endRes)
753       {
754         scrollX = av.startRes - av.endRes;
755       }
756
757       idPanel.idCanvas.fastPaint(scrollY);
758       seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
759
760       scalePanel.repaint();
761       if (av.getShowAnnotation())
762       {
763         annotationPanel.fastPaint(av.getStartRes() - oldX);
764       }
765     }
766     sendViewPosition();
767
768   }
769
770   private void sendViewPosition()
771   {
772     StructureSelectionManager.getStructureSelectionManager(av.applet)
773             .sendViewPosition(this, av.startRes, av.endRes, av.startSeq,
774                     av.endSeq);
775   }
776
777   public void paintAlignment(boolean updateOverview)
778   {
779     repaint();
780
781     if (updateOverview)
782     {
783       jalview.structure.StructureSelectionManager
784               .getStructureSelectionManager(av.applet)
785               .sequenceColoursChanged(this);
786
787       if (overviewPanel != null)
788       {
789         overviewPanel.updateOverviewImage();
790       }
791     }
792   }
793
794   public void update(Graphics g)
795   {
796     paint(g);
797   }
798
799   public void paint(Graphics g)
800   {
801     invalidate();
802     Dimension d = idPanel.idCanvas.getSize();
803     idPanel.idCanvas.setSize(d.width, seqPanel.seqCanvas.getSize().height);
804
805     if (av.getWrapAlignment())
806     {
807       int maxwidth = av.getAlignment().getWidth();
808
809       if (av.hasHiddenColumns())
810       {
811         maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
812       }
813
814       int canvasWidth = seqPanel.seqCanvas
815               .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width);
816
817       if (canvasWidth > 0)
818       {
819         int max = maxwidth / canvasWidth;
820         vscroll.setMaximum(1 + max);
821         vscroll.setUnitIncrement(1);
822         vscroll.setVisibleAmount(1);
823       }
824     }
825     else
826     {
827       setScrollValues(av.getStartRes(), av.getStartSeq());
828     }
829
830     seqPanel.seqCanvas.repaint();
831     idPanel.idCanvas.repaint();
832     if (!av.wrapAlignment)
833     {
834       if (av.showAnnotation)
835       {
836         alabels.repaint();
837         annotationPanel.repaint();
838       }
839       scalePanel.repaint();
840     }
841
842   }
843
844   protected Panel sequenceHolderPanel = new Panel();
845
846   protected Scrollbar vscroll = new Scrollbar();
847
848   protected Scrollbar hscroll = new Scrollbar();
849
850   protected Panel seqPanelHolder = new Panel();
851
852   BorderLayout borderLayout1 = new BorderLayout();
853
854   BorderLayout borderLayout3 = new BorderLayout();
855
856   protected Panel scalePanelHolder = new Panel();
857
858   protected Panel idPanelHolder = new Panel();
859
860   BorderLayout borderLayout5 = new BorderLayout();
861
862   protected Panel idSpaceFillerPanel1 = new Panel();
863
864   public Panel annotationSpaceFillerHolder = new Panel();
865
866   BorderLayout borderLayout6 = new BorderLayout();
867
868   BorderLayout borderLayout7 = new BorderLayout();
869
870   Panel hscrollHolder = new Panel();
871
872   BorderLayout borderLayout10 = new BorderLayout();
873
874   protected Panel hscrollFillerPanel = new Panel();
875
876   BorderLayout borderLayout11 = new BorderLayout();
877
878   BorderLayout borderLayout4 = new BorderLayout();
879
880   BorderLayout borderLayout2 = new BorderLayout();
881
882   Panel annotationPanelHolder = new Panel();
883
884   protected Scrollbar apvscroll = new Scrollbar();
885
886   BorderLayout borderLayout12 = new BorderLayout();
887
888   private void jbInit() throws Exception
889   {
890     // idPanelHolder.setPreferredSize(new Dimension(70, 10));
891     this.setLayout(borderLayout7);
892
893     // sequenceHolderPanel.setPreferredSize(new Dimension(150, 150));
894     sequenceHolderPanel.setLayout(borderLayout3);
895     seqPanelHolder.setLayout(borderLayout1);
896     scalePanelHolder.setBackground(Color.white);
897
898     // scalePanelHolder.setPreferredSize(new Dimension(10, 30));
899     scalePanelHolder.setLayout(borderLayout6);
900     idPanelHolder.setLayout(borderLayout5);
901     idSpaceFillerPanel1.setBackground(Color.white);
902
903     // idSpaceFillerPanel1.setPreferredSize(new Dimension(10, 30));
904     idSpaceFillerPanel1.setLayout(borderLayout11);
905     annotationSpaceFillerHolder.setBackground(Color.white);
906
907     // annotationSpaceFillerHolder.setPreferredSize(new Dimension(10, 80));
908     annotationSpaceFillerHolder.setLayout(borderLayout4);
909     hscroll.setOrientation(Scrollbar.HORIZONTAL);
910     hscrollHolder.setLayout(borderLayout10);
911     hscrollFillerPanel.setBackground(Color.white);
912     apvscroll.setOrientation(Scrollbar.VERTICAL);
913     apvscroll.setVisible(true);
914     apvscroll.addAdjustmentListener(this);
915
916     annotationPanelHolder.setBackground(Color.white);
917     annotationPanelHolder.setLayout(borderLayout12);
918     annotationPanelHolder.add(apvscroll, BorderLayout.EAST);
919     // hscrollFillerPanel.setPreferredSize(new Dimension(70, 10));
920     hscrollHolder.setBackground(Color.white);
921
922     // annotationScroller.setPreferredSize(new Dimension(10, 80));
923     // this.setPreferredSize(new Dimension(220, 166));
924     seqPanelHolder.setBackground(Color.white);
925     idPanelHolder.setBackground(Color.white);
926     sequenceHolderPanel.add(scalePanelHolder, BorderLayout.NORTH);
927     sequenceHolderPanel.add(seqPanelHolder, BorderLayout.CENTER);
928     seqPanelHolder.add(vscroll, BorderLayout.EAST);
929
930     // Panel3.add(secondaryPanelHolder, BorderLayout.SOUTH);
931     this.add(idPanelHolder, BorderLayout.WEST);
932     idPanelHolder.add(idSpaceFillerPanel1, BorderLayout.NORTH);
933     idPanelHolder.add(annotationSpaceFillerHolder, BorderLayout.SOUTH);
934     this.add(hscrollHolder, BorderLayout.SOUTH);
935     hscrollHolder.add(hscroll, BorderLayout.CENTER);
936     hscrollHolder.add(hscrollFillerPanel, BorderLayout.WEST);
937     this.add(sequenceHolderPanel, BorderLayout.CENTER);
938   }
939
940   /**
941    * hides or shows dynamic annotation rows based on groups and av state flags
942    */
943   public void updateAnnotation()
944   {
945     updateAnnotation(false);
946   }
947
948   public void updateAnnotation(boolean applyGlobalSettings)
949   {
950     updateAnnotation(applyGlobalSettings, false);
951   }
952
953   public void updateAnnotation(boolean applyGlobalSettings,
954           boolean preserveNewGroupSettings)
955   {
956     av.updateGroupAnnotationSettings(applyGlobalSettings,
957             preserveNewGroupSettings);
958     adjustAnnotationHeight();
959   }
960
961   @Override
962   public AlignmentI getAlignment()
963   {
964     return av.getAlignment();
965   }
966
967   @Override
968   public StructureSelectionManager getStructureSelectionManager()
969   {
970     return StructureSelectionManager
971             .getStructureSelectionManager(av.applet);
972   }
973
974   @Override
975   public void raiseOOMWarning(String string, OutOfMemoryError error)
976   {
977     // TODO: JAL-960
978     System.err.println("Out of memory whilst '" + string + "'");
979     error.printStackTrace();
980   }
981
982 }