2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.appletgui;
23 import jalview.analysis.AnnotationSorter;
24 import jalview.api.AlignViewportI;
25 import jalview.api.AlignmentViewPanel;
26 import jalview.bin.JalviewLite;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.SearchResultsI;
29 import jalview.datamodel.SequenceI;
30 import jalview.structure.StructureSelectionManager;
31 import jalview.viewmodel.ViewportListenerI;
32 import jalview.viewmodel.ViewportRanges;
34 import java.awt.BorderLayout;
35 import java.awt.Color;
36 import java.awt.Dimension;
37 import java.awt.FontMetrics;
38 import java.awt.Frame;
39 import java.awt.Graphics;
40 import java.awt.Panel;
41 import java.awt.Scrollbar;
42 import java.awt.event.AdjustmentEvent;
43 import java.awt.event.AdjustmentListener;
44 import java.awt.event.ComponentAdapter;
45 import java.awt.event.ComponentEvent;
46 import java.beans.PropertyChangeEvent;
47 import java.util.List;
49 public class AlignmentPanel extends Panel implements AdjustmentListener,
50 AlignmentViewPanel, ViewportListenerI
53 public AlignViewport av;
55 OverviewPanel overviewPanel;
61 IdwidthAdjuster idwidthAdjuster;
63 public AlignFrame alignFrame;
65 ScalePanel scalePanel;
67 AnnotationPanel annotationPanel;
69 AnnotationLabels alabels;
71 ViewportRanges vpRanges;
73 // this value is set false when selection area being dragged
74 boolean fastPaint = true;
77 public void finalize() throws Throwable
83 seqPanelHolder = null;
84 sequenceHolderPanel = null;
86 scalePanelHolder = null;
87 annotationPanel = null;
88 annotationPanelHolder = null;
89 annotationSpaceFillerHolder = null;
93 public AlignmentPanel(AlignFrame af, final AlignViewport av)
105 vpRanges = av.getRanges();
106 seqPanel = new SeqPanel(av, this);
107 idPanel = new IdPanel(av, this);
108 scalePanel = new ScalePanel(av, this);
109 idwidthAdjuster = new IdwidthAdjuster(this);
110 annotationPanel = new AnnotationPanel(this);
111 annotationPanelHolder.add(annotationPanel, BorderLayout.CENTER);
113 sequenceHolderPanel.add(annotationPanelHolder, BorderLayout.SOUTH);
114 alabels = new AnnotationLabels(this);
116 setAnnotationVisible(av.isShowAnnotation());
118 idPanelHolder.add(idPanel, BorderLayout.CENTER);
119 idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER);
120 annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER);
121 scalePanelHolder.add(scalePanel, BorderLayout.CENTER);
122 seqPanelHolder.add(seqPanel, BorderLayout.CENTER);
125 setScrollValues(0, 0);
127 apvscroll.addAdjustmentListener(this);
128 hscroll.addAdjustmentListener(this);
129 vscroll.addAdjustmentListener(this);
131 addComponentListener(new ComponentAdapter()
134 public void componentResized(ComponentEvent evt)
136 // reset the viewport ranges when the alignment panel is resized
137 // in particular, this initialises the end residue value when Jalview
139 if (av.getWrapAlignment())
141 int widthInRes = seqPanel.seqCanvas
142 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
143 vpRanges.setViewportWidth(widthInRes);
147 int widthInRes = seqPanel.seqCanvas.getWidth()
149 int heightInSeq = seqPanel.seqCanvas.getHeight()
150 / av.getCharHeight();
152 vpRanges.setViewportWidth(widthInRes);
153 vpRanges.setViewportHeight(heightInSeq);
155 // setScrollValues(vpRanges.getStartRes(), vpRanges.getStartSeq());
156 if (getSize().height > 0
157 && annotationPanelHolder.getSize().height > 0)
159 validateAnnotationDimensions(false);
166 Dimension d = calculateIdWidth();
167 idPanel.idCanvas.setSize(d);
169 hscrollFillerPanel.setSize(d.width, annotationPanel.getSize().height);
171 idPanel.idCanvas.setSize(d.width, seqPanel.seqCanvas.getSize().height);
172 annotationSpaceFillerHolder.setSize(d.width,
173 annotationPanel.getSize().height);
174 alabels.setSize(d.width, annotationPanel.getSize().height);
175 final AlignmentPanel ap = this;
176 av.addPropertyChangeListener(new java.beans.PropertyChangeListener()
179 public void propertyChange(java.beans.PropertyChangeEvent evt)
181 if (evt.getPropertyName().equals("alignment"))
183 PaintRefresher.Refresh(ap, av.getSequenceSetId(), true, true);
188 av.getRanges().addPropertyChangeListener(this);
192 public AlignViewportI getAlignViewport()
197 public SequenceRenderer getSequenceRenderer()
199 return seqPanel.seqCanvas.sr;
203 public jalview.api.FeatureRenderer getFeatureRenderer()
205 return seqPanel.seqCanvas.fr;
209 public jalview.api.FeatureRenderer cloneFeatureRenderer()
211 FeatureRenderer nfr = new FeatureRenderer(av);
212 nfr.transferSettings(seqPanel.seqCanvas.fr);
216 public void alignmentChanged()
218 av.alignmentChanged(this);
220 if (overviewPanel != null)
222 overviewPanel.updateOverviewImage();
225 alignFrame.updateEditMenuBar();
230 public void fontChanged()
232 // set idCanvas bufferedImage to null
233 // to prevent drawing old image
234 idPanel.idCanvas.image = null;
235 FontMetrics fm = getFontMetrics(av.getFont());
237 scalePanel.setSize(new Dimension(10, av.getCharHeight()
239 idwidthAdjuster.setSize(new Dimension(10, av.getCharHeight()
241 av.updateSequenceIdColours();
242 annotationPanel.image = null;
243 int ap = annotationPanel.adjustPanelHeight(false);
244 Dimension d = calculateIdWidth();
245 d.setSize(d.width + 4, seqPanel.seqCanvas.getSize().height);
246 alabels.setSize(d.width + 4, ap);
248 idPanel.idCanvas.setSize(d);
249 hscrollFillerPanel.setSize(d);
251 validateAnnotationDimensions(false);
252 annotationPanel.repaint();
257 public void setIdWidth(int w, int h)
259 idPanel.idCanvas.setSize(w, h);
260 idPanelHolder.setSize(w, idPanelHolder.getSize().height);
261 annotationSpaceFillerHolder.setSize(w,
262 annotationSpaceFillerHolder.getSize().height);
263 alabels.setSize(w, alabels.getSize().height);
267 Dimension calculateIdWidth()
269 if (av.nullFrame == null)
271 av.nullFrame = new Frame();
272 av.nullFrame.addNotify();
275 Graphics g = av.nullFrame.getGraphics();
277 FontMetrics fm = g.getFontMetrics(av.font);
278 AlignmentI al = av.getAlignment();
283 while (i < al.getHeight() && al.getSequenceAt(i) != null)
285 SequenceI s = al.getSequenceAt(i);
286 id = s.getDisplayId(av.getShowJVSuffix());
288 if (fm.stringWidth(id) > idWidth)
290 idWidth = fm.stringWidth(id);
295 // Also check annotation label widths
297 if (al.getAlignmentAnnotation() != null)
299 fm = g.getFontMetrics(av.nullFrame.getFont());
300 while (i < al.getAlignmentAnnotation().length)
302 String label = al.getAlignmentAnnotation()[i].label;
303 if (fm.stringWidth(label) > idWidth)
305 idWidth = fm.stringWidth(label);
311 return new Dimension(idWidth, idPanel.idCanvas.getSize().height);
315 * Highlight the given results on the alignment.
318 public void highlightSearchResults(SearchResultsI results)
320 scrollToPosition(results);
321 seqPanel.seqCanvas.highlightSearchResults(results);
325 * scroll the view to show the position of the highlighted region in results
326 * (if any) and redraw the overview
329 * @return false if results were not found
331 public boolean scrollToPosition(SearchResultsI results)
333 return scrollToPosition(results, true);
337 * scroll the view to show the position of the highlighted region in results
341 * @param redrawOverview
342 * - when set, the overview will be recalculated (takes longer)
343 * @return false if results were not found
345 public boolean scrollToPosition(SearchResultsI results,
346 boolean redrawOverview)
348 return scrollToPosition(results, 0, redrawOverview, false);
352 * scroll the view to show the position of the highlighted region in results
356 * @param redrawOverview
357 * - when set, the overview will be recalculated (takes longer)
358 * @return false if results were not found
360 public boolean scrollToPosition(SearchResultsI results,
362 boolean redrawOverview, boolean centre)
364 // do we need to scroll the panel?
365 if (results != null && results.getSize() > 0)
367 AlignmentI alignment = av.getAlignment();
368 int seqIndex = alignment.findIndex(results);
374 * allow for offset of target sequence (actually scroll to one above it)
377 SequenceI seq = alignment.getSequenceAt(seqIndex);
378 int[] r = results.getResults(seq, 0, alignment.getWidth());
381 if (JalviewLite.debug)
384 .println("DEBUG: scroll didn't happen - results not within alignment : "
385 + seq.getStart() + "," + seq.getEnd());
389 if (JalviewLite.debug)
393 * System.out.println("DEBUG: scroll: start=" + r[0] +
394 * " av.getStartRes()=" + av.getStartRes() + " end=" + r[1] +
395 * " seq.end=" + seq.getEnd() + " av.getEndRes()=" + av.getEndRes() +
396 * " hextent=" + hextent);
403 * To centre results, scroll to positions half the visible width
404 * left/right of the start/end positions
408 int offset = (vpRanges.getEndRes() - vpRanges.getStartRes() + 1) / 2 - 1;
409 start = Math.max(start - offset, 0);
410 end = Math.min(end + offset, seq.getEnd() - 1);
417 if (end == seq.getEnd())
423 * allow for offset of target sequence (actually scroll to one above it)
425 seqIndex = Math.max(0, seqIndex - verticalOffset);
426 return scrollTo(start, end, seqIndex, false, redrawOverview);
431 public boolean scrollTo(int ostart, int end, int seqIndex,
432 boolean scrollToNearest, boolean redrawOverview)
434 int startv, endv, starts, ends, width;
437 if (av.hasHiddenColumns())
439 start = av.getColumnSelection().findColumnPosition(ostart);
440 end = av.getColumnSelection().findColumnPosition(end);
443 if (!scrollToNearest && !av.getColumnSelection().isVisible(ostart))
445 // don't scroll - position isn't visible
455 if (!av.getWrapAlignment())
458 * int spos=av.getStartRes(),sqpos=av.getStartSeq(); if ((startv =
459 * av.getStartRes()) >= start) { spos=start-1; // seqIn //
460 * setScrollValues(start - 1, seqIndex); } else if ((endv =
461 * av.getEndRes()) <= end) { // setScrollValues(spos=startv + 1 + end -
462 * endv, seqIndex); spos=startv + 1 + end - endv; } else if ((starts =
463 * av.getStartSeq()) > seqIndex) { setScrollValues(av.getStartRes(),
464 * seqIndex); } else if ((ends = av.getEndSeq()) <= seqIndex) {
465 * setScrollValues(av.getStartRes(), starts + seqIndex - ends + 1); }
468 // below is scrolling logic up to Jalview 2.8.2
469 // if ((av.getStartRes() > end)
470 // || (av.getEndRes() < start)
471 // || ((av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex)))
473 // if (start > av.getAlignment().getWidth() - hextent)
475 // start = av.getAlignment().getWidth() - hextent;
482 // if (seqIndex > av.getAlignment().getHeight() - vextent)
484 // seqIndex = av.getAlignment().getHeight() - vextent;
490 // setScrollValues(start, seqIndex);
492 // logic copied from jalview.gui.AlignmentPanel:
493 if ((startv = vpRanges.getStartRes()) >= start)
496 * Scroll left to make start of search results visible
498 setScrollValues(start - 1, seqIndex);
500 else if ((endv = vpRanges.getEndRes()) <= end)
503 * Scroll right to make end of search results visible
505 setScrollValues(startv + 1 + end - endv, seqIndex);
507 else if ((starts = vpRanges.getStartSeq()) > seqIndex)
510 * Scroll up to make start of search results visible
512 setScrollValues(vpRanges.getStartRes(), seqIndex);
514 else if ((ends = vpRanges.getEndSeq()) <= seqIndex)
517 * Scroll down to make end of search results visible
519 setScrollValues(vpRanges.getStartRes(), starts + seqIndex - ends
523 * Else results are already visible - no need to scroll
528 vpRanges.scrollToWrappedVisible(start);
531 paintAlignment(redrawOverview);
535 public OverviewPanel getOverviewPanel()
537 return overviewPanel;
540 public void setOverviewPanel(OverviewPanel op)
545 public void setAnnotationVisible(boolean b)
547 if (!av.getWrapAlignment())
549 annotationSpaceFillerHolder.setVisible(b);
550 annotationPanelHolder.setVisible(b);
554 annotationSpaceFillerHolder.setVisible(false);
555 annotationPanelHolder.setVisible(false);
562 * automatically adjust annotation panel height for new annotation whilst
563 * ensuring the alignment is still visible.
566 public void adjustAnnotationHeight()
568 // TODO: display vertical annotation scrollbar if necessary
569 // this is called after loading new annotation onto alignment
570 if (alignFrame.getSize().height == 0)
573 .println("adjustAnnotationHeight frame size zero NEEDS FIXING");
576 validateAnnotationDimensions(true);
577 apvscroll.addNotify();
580 paintAlignment(true);
584 * Calculate the annotation dimensions and refresh slider values accordingly.
585 * Need to do repaints/notifys afterwards.
587 protected void validateAnnotationDimensions(boolean adjustPanelHeight)
589 int rowHeight = av.getCharHeight();
590 int alignmentHeight = rowHeight * av.getAlignment().getHeight();
591 int annotationHeight = av.calcPanelHeight();
593 int mheight = annotationHeight;
594 Dimension d = sequenceHolderPanel.getSize();
596 int availableHeight = d.height - scalePanelHolder.getHeight();
598 if (adjustPanelHeight)
601 * If not enough vertical space, maximize annotation height while keeping
602 * at least two rows of alignment visible
604 if (annotationHeight + alignmentHeight > availableHeight)
606 annotationHeight = Math.min(annotationHeight, availableHeight - 2
612 // maintain same window layout whilst updating sliders
613 annotationHeight = annotationPanelHolder.getSize().height;
616 if (availableHeight - annotationHeight < 5)
618 annotationHeight = availableHeight;
621 annotationPanel.setSize(new Dimension(d.width, annotationHeight));
622 annotationPanelHolder.setSize(new Dimension(d.width, annotationHeight));
623 // seqPanelHolder.setSize(d.width, seqandannot - height);
625 .setSize(d.width, seqPanel.seqCanvas.getSize().height);
627 Dimension e = idPanel.getSize();
628 alabels.setSize(new Dimension(e.width, annotationHeight));
629 annotationSpaceFillerHolder.setSize(new Dimension(e.width,
632 int s = apvscroll.getValue();
633 if (s > mheight - annotationHeight)
637 apvscroll.setValues(s, annotationHeight, 0, mheight);
638 annotationPanel.setScrollOffset(apvscroll.getValue(), false);
639 alabels.setScrollOffset(apvscroll.getValue(), false);
642 public void setWrapAlignment(boolean wrap)
644 vpRanges.setStartSeq(0);
645 vpRanges.setStartRes(0);
646 scalePanelHolder.setVisible(!wrap);
648 hscroll.setVisible(!wrap);
649 idwidthAdjuster.setVisible(!wrap);
653 annotationPanelHolder.setVisible(false);
654 annotationSpaceFillerHolder.setVisible(false);
656 else if (av.isShowAnnotation())
658 annotationPanelHolder.setVisible(true);
659 annotationSpaceFillerHolder.setVisible(true);
662 idSpaceFillerPanel1.setVisible(!wrap);
664 fontChanged(); // This is so that the scalePanel is resized correctly
667 sequenceHolderPanel.validate();
676 public void setScrollValues(int x, int y)
678 if (av.getWrapAlignment())
680 setScrollingForWrappedPanel(x);
685 int width = av.getAlignment().getWidth();
686 int height = av.getAlignment().getHeight();
688 if (av.hasHiddenColumns())
690 width = av.getColumnSelection().findColumnPosition(width);
697 hextent = seqPanel.seqCanvas.getSize().width / av.getCharWidth();
698 vextent = seqPanel.seqCanvas.getSize().height / av.getCharHeight();
705 if (vextent > height)
710 if ((hextent + x) > width)
712 System.err.println("hextent was " + hextent + " and x was " + x);
717 if ((vextent + y) > height)
719 y = height - vextent;
729 System.err.println("x was " + x);
733 hscroll.setValues(x, hextent, 0, width);
734 vscroll.setValues(y, vextent, 0, height);
736 // AWT scrollbar does not fire adjustmentValueChanged for setValues
737 // so also call adjustment code!
746 public void adjustmentValueChanged(AdjustmentEvent evt)
748 if (evt == null || evt.getSource() == apvscroll)
750 annotationPanel.setScrollOffset(apvscroll.getValue(), false);
751 alabels.setScrollOffset(apvscroll.getValue(), false);
753 if (evt == null || evt.getSource() == hscroll)
755 int x = hscroll.getValue();
759 if (evt == null || evt.getSource() == vscroll)
761 int offy = vscroll.getValue();
762 adjustVertical(offy);
767 private void adjustHorizontal(int x)
769 int oldX = vpRanges.getStartRes();
770 int oldwidth = vpRanges.getViewportWidth();
771 int width = seqPanel.seqCanvas.getWidth() / av.getCharWidth();
773 // if we're scrolling to the position we're already at, stop
774 // this prevents infinite recursion of events when the scroll/viewport
775 // ranges values are the same
776 if ((x == oldX) && (width == oldwidth))
780 vpRanges.setViewportStartAndWidth(x, width);
782 if (av.getWrapAlignment() || !fastPaint || av.MAC)
789 private void adjustVertical(int offy)
791 int oldX = vpRanges.getStartRes();
792 int oldwidth = vpRanges.getViewportWidth();
793 int oldY = vpRanges.getStartSeq();
794 int oldheight = vpRanges.getViewportHeight();
796 if (av.getWrapAlignment())
798 int rowSize = seqPanel.seqCanvas
799 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
801 // if we're scrolling to the position we're already at, stop
802 // this prevents infinite recursion of events when the scroll/viewport
803 // ranges values are the same
804 if ((offy * rowSize == oldX) && (oldwidth == rowSize))
810 vpRanges.setViewportStartAndWidth(offy * rowSize, rowSize);
815 int height = seqPanel.seqCanvas.getHeight() / av.getCharHeight();
817 // if we're scrolling to the position we're already at, stop
818 // this prevents infinite recursion of events when the scroll/viewport
819 // ranges values are the same
820 if ((offy == oldY) && (height == oldheight))
824 vpRanges.setViewportStartAndHeight(offy, height);
826 if (av.getWrapAlignment() || !fastPaint || av.MAC)
834 * A helper method to return the AlignmentPanel in the other (complementary)
835 * half of a SplitFrame view. Returns null if not in a SplitFrame.
839 private AlignmentPanel getComplementPanel()
841 AlignmentPanel ap = null;
842 if (alignFrame != null)
844 SplitFrame sf = alignFrame.getSplitFrame();
847 AlignFrame other = sf.getComplement(alignFrame);
850 ap = other.alignPanel;
858 * Follow a scrolling change in the (cDNA/Protein) complementary alignment.
859 * The aim is to keep the two alignments 'lined up' on their centre columns.
862 * holds mapped region(s) of this alignment that we are scrolling
863 * 'to'; may be modified for sequence offset by this method
865 * the number of visible sequences to show above the mapped region
867 protected void scrollToCentre(SearchResultsI sr, int seqOffset)
870 * To avoid jumpy vertical scrolling (if some sequences are gapped or not
871 * mapped), we can make the scroll-to location a sequence above the one
874 SequenceI mappedTo = sr.getResults().get(0).getSequence();
875 List<SequenceI> seqs = av.getAlignment().getSequences();
878 * This is like AlignmentI.findIndex(seq) but here we are matching the
879 * dataset sequence not the aligned sequence
881 boolean matched = false;
882 for (SequenceI seq : seqs)
884 if (mappedTo == seq.getDatasetSequence())
892 return; // failsafe, shouldn't happen
896 * Scroll to position but centring the target residue. Also set a state flag
897 * to prevent adjustmentValueChanged performing this recursively.
899 // setFollowingComplementScroll(true);
900 // this should be scrollToPosition(sr,verticalOffset,
901 scrollToPosition(sr, seqOffset, true, true);
904 private void sendViewPosition()
906 StructureSelectionManager.getStructureSelectionManager(av.applet)
907 .sendViewPosition(this, vpRanges.getStartRes(),
908 vpRanges.getEndRes(), vpRanges.getStartSeq(),
909 vpRanges.getEndSeq());
913 * Repaint the alignment and annotations, and, optionally, any overview window
916 public void paintAlignment(boolean updateOverview)
918 final AnnotationSorter sorter = new AnnotationSorter(getAlignment(),
919 av.isShowAutocalculatedAbove());
920 sorter.sort(getAlignment().getAlignmentAnnotation(),
921 av.getSortAnnotationsBy());
926 // TODO: determine if this paintAlignment changed structure colours
927 jalview.structure.StructureSelectionManager
928 .getStructureSelectionManager(av.applet)
929 .sequenceColoursChanged(this);
931 if (overviewPanel != null)
933 overviewPanel.updateOverviewImage();
939 public void update(Graphics g)
945 public void paint(Graphics g)
948 Dimension d = idPanel.idCanvas.getSize();
949 final int canvasHeight = seqPanel.seqCanvas.getSize().height;
950 if (canvasHeight != d.height)
952 idPanel.idCanvas.setSize(d.width, canvasHeight);
955 setScrollValues(vpRanges.getStartRes(), vpRanges.getStartSeq());
957 seqPanel.seqCanvas.repaint();
958 idPanel.idCanvas.repaint();
959 if (!av.getWrapAlignment())
961 if (av.isShowAnnotation())
964 annotationPanel.repaint();
966 scalePanel.repaint();
972 * Set vertical scroll bar parameters for wrapped panel
974 * the residue to scroll to
976 private void setScrollingForWrappedPanel(int res)
978 // get the width of the alignment in residues
979 int maxwidth = av.getAlignment().getWidth();
980 if (av.hasHiddenColumns())
982 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
985 // get the width of the canvas in residues
986 int canvasWidth = seqPanel.seqCanvas
987 .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width);
990 // position we want to scroll to is number of canvasWidth's to get there
991 int current = res / canvasWidth;
993 // max scroll position: add one because extent is 1 and scrollbar value
994 // can only be set to at most max - extent
995 int max = maxwidth / canvasWidth + 1;
996 vscroll.setUnitIncrement(1);
997 vscroll.setValues(current, 1, 0, max);
1001 protected Panel sequenceHolderPanel = new Panel();
1003 protected Scrollbar vscroll = new Scrollbar();
1005 protected Scrollbar hscroll = new Scrollbar();
1007 protected Panel seqPanelHolder = new Panel();
1009 protected Panel scalePanelHolder = new Panel();
1011 protected Panel idPanelHolder = new Panel();
1013 protected Panel idSpaceFillerPanel1 = new Panel();
1015 public Panel annotationSpaceFillerHolder = new Panel();
1017 protected Panel hscrollFillerPanel = new Panel();
1019 Panel annotationPanelHolder = new Panel();
1021 protected Scrollbar apvscroll = new Scrollbar();
1024 * Flag set while scrolling to follow complementary cDNA/protein scroll. When
1025 * true, suppresses invoking the same method recursively.
1027 private boolean followingComplementScroll = true;
1029 private void jbInit() throws Exception
1031 // idPanelHolder.setPreferredSize(new Dimension(70, 10));
1032 this.setLayout(new BorderLayout());
1034 // sequenceHolderPanel.setPreferredSize(new Dimension(150, 150));
1035 sequenceHolderPanel.setLayout(new BorderLayout());
1036 seqPanelHolder.setLayout(new BorderLayout());
1037 scalePanelHolder.setBackground(Color.white);
1039 // scalePanelHolder.setPreferredSize(new Dimension(10, 30));
1040 scalePanelHolder.setLayout(new BorderLayout());
1041 idPanelHolder.setLayout(new BorderLayout());
1042 idSpaceFillerPanel1.setBackground(Color.white);
1044 // idSpaceFillerPanel1.setPreferredSize(new Dimension(10, 30));
1045 idSpaceFillerPanel1.setLayout(new BorderLayout());
1046 annotationSpaceFillerHolder.setBackground(Color.white);
1048 // annotationSpaceFillerHolder.setPreferredSize(new Dimension(10, 80));
1049 annotationSpaceFillerHolder.setLayout(new BorderLayout());
1050 hscroll.setOrientation(Scrollbar.HORIZONTAL);
1052 Panel hscrollHolder = new Panel();
1053 hscrollHolder.setLayout(new BorderLayout());
1054 hscrollFillerPanel.setBackground(Color.white);
1055 apvscroll.setOrientation(Scrollbar.VERTICAL);
1056 apvscroll.setVisible(true);
1057 apvscroll.addAdjustmentListener(this);
1059 annotationPanelHolder.setBackground(Color.white);
1060 annotationPanelHolder.setLayout(new BorderLayout());
1061 annotationPanelHolder.add(apvscroll, BorderLayout.EAST);
1062 // hscrollFillerPanel.setPreferredSize(new Dimension(70, 10));
1063 hscrollHolder.setBackground(Color.white);
1065 // annotationScroller.setPreferredSize(new Dimension(10, 80));
1066 // this.setPreferredSize(new Dimension(220, 166));
1067 seqPanelHolder.setBackground(Color.white);
1068 idPanelHolder.setBackground(Color.white);
1069 sequenceHolderPanel.add(scalePanelHolder, BorderLayout.NORTH);
1070 sequenceHolderPanel.add(seqPanelHolder, BorderLayout.CENTER);
1071 seqPanelHolder.add(vscroll, BorderLayout.EAST);
1073 // Panel3.add(secondaryPanelHolder, BorderLayout.SOUTH);
1074 this.add(idPanelHolder, BorderLayout.WEST);
1075 idPanelHolder.add(idSpaceFillerPanel1, BorderLayout.NORTH);
1076 idPanelHolder.add(annotationSpaceFillerHolder, BorderLayout.SOUTH);
1077 this.add(hscrollHolder, BorderLayout.SOUTH);
1078 hscrollHolder.add(hscroll, BorderLayout.CENTER);
1079 hscrollHolder.add(hscrollFillerPanel, BorderLayout.WEST);
1080 this.add(sequenceHolderPanel, BorderLayout.CENTER);
1084 * hides or shows dynamic annotation rows based on groups and av state flags
1086 public void updateAnnotation()
1088 updateAnnotation(false);
1091 public void updateAnnotation(boolean applyGlobalSettings)
1093 updateAnnotation(applyGlobalSettings, false);
1096 public void updateAnnotation(boolean applyGlobalSettings,
1097 boolean preserveNewGroupSettings)
1099 av.updateGroupAnnotationSettings(applyGlobalSettings,
1100 preserveNewGroupSettings);
1101 adjustAnnotationHeight();
1105 public AlignmentI getAlignment()
1107 return av.getAlignment();
1111 public String getViewName()
1117 public StructureSelectionManager getStructureSelectionManager()
1119 return StructureSelectionManager
1120 .getStructureSelectionManager(av.applet);
1124 public void raiseOOMWarning(String string, OutOfMemoryError error)
1127 System.err.println("Out of memory whilst '" + string + "'");
1128 error.printStackTrace();
1132 * Set a flag to say we are scrolling to follow a (cDNA/protein) complement.
1136 protected void setFollowingComplementScroll(boolean b)
1138 this.followingComplementScroll = b;
1141 protected boolean isFollowingComplementScroll()
1143 return this.followingComplementScroll;
1148 * Property change event fired when a change is made to the viewport ranges
1149 * object associated with this alignment panel's viewport
1151 public void propertyChange(PropertyChangeEvent evt)
1153 // update this panel's scroll values based on the new viewport ranges values
1154 int x = vpRanges.getStartRes();
1155 int y = vpRanges.getStartSeq();
1156 setScrollValues(x, y);
1158 // now update any complementary alignment (its viewport ranges object
1159 // is different so does not get automatically updated)
1160 if (isFollowingComplementScroll())
1162 setFollowingComplementScroll(false);
1163 av.scrollComplementaryAlignment(getComplementPanel());
1164 setFollowingComplementScroll(true);