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);
741 public void adjustmentValueChanged(AdjustmentEvent evt)
743 int oldX = vpRanges.getStartRes();
744 int oldwidth = vpRanges.getViewportWidth();
745 int oldY = vpRanges.getStartSeq();
746 int oldheight = vpRanges.getViewportHeight();
748 if (evt == null || evt.getSource() == apvscroll)
750 annotationPanel.setScrollOffset(apvscroll.getValue(), false);
751 alabels.setScrollOffset(apvscroll.getValue(), false);
752 // annotationPanel.image=null;
753 // alabels.image=null;
754 // alabels.repaint();
755 // annotationPanel.repaint();
757 if (evt == null || evt.getSource() == hscroll)
759 int x = hscroll.getValue();
760 int width = seqPanel.seqCanvas.getWidth() / av.getCharWidth();
762 // if we're scrolling to the position we're already at, stop
763 // this prevents infinite recursion of events when the scroll/viewport
764 // ranges values are the same
765 if ((x == oldX) && (width == oldwidth))
769 vpRanges.setViewportStartAndWidth(x, width);
772 if (evt == null || evt.getSource() == vscroll)
774 int offy = vscroll.getValue();
775 if (av.getWrapAlignment())
777 int rowSize = seqPanel.seqCanvas
778 .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
780 // if we're scrolling to the position we're already at, stop
781 // this prevents infinite recursion of events when the scroll/viewport
782 // ranges values are the same
783 if ((offy * rowSize == oldX) && (oldwidth == rowSize))
789 vpRanges.setViewportStartAndWidth(offy * rowSize, rowSize);
794 int height = seqPanel.seqCanvas.getHeight() / av.getCharHeight();
796 // if we're scrolling to the position we're already at, stop
797 // this prevents infinite recursion of events when the scroll/viewport
798 // ranges values are the same
799 if ((offy == oldY) && (height == oldheight))
803 vpRanges.setViewportStartAndHeight(offy, height);
807 /* if (overviewPanel != null)
809 overviewPanel.setBoxPosition();
812 int scrollX = vpRanges.getStartRes() - oldX;
813 int scrollY = vpRanges.getStartSeq() - oldY;
815 if (av.getWrapAlignment() || !fastPaint || av.MAC)
821 // Make sure we're not trying to draw a panel
822 // larger than the visible window
823 if (scrollX > vpRanges.getEndRes() - vpRanges.getStartRes())
825 scrollX = vpRanges.getEndRes() - vpRanges.getStartRes();
827 else if (scrollX < vpRanges.getStartRes() - vpRanges.getEndRes())
829 scrollX = vpRanges.getStartRes() - vpRanges.getEndRes();
832 idPanel.idCanvas.fastPaint(scrollY);
833 seqPanel.seqCanvas.fastPaint(scrollX, scrollY);
835 scalePanel.repaint();
836 if (av.isShowAnnotation())
838 annotationPanel.fastPaint(vpRanges.getStartRes() - oldX);
844 * If there is one, scroll the (Protein/cDNA) complementary alignment to
845 * match, unless we are ourselves doing that.
847 /* if (isFollowingComplementScroll())
849 setFollowingComplementScroll(false);
853 AlignmentPanel ap = getComplementPanel();
854 av.scrollComplementaryAlignment(ap);
860 * A helper method to return the AlignmentPanel in the other (complementary)
861 * half of a SplitFrame view. Returns null if not in a SplitFrame.
865 private AlignmentPanel getComplementPanel()
867 AlignmentPanel ap = null;
868 if (alignFrame != null)
870 SplitFrame sf = alignFrame.getSplitFrame();
873 AlignFrame other = sf.getComplement(alignFrame);
876 ap = other.alignPanel;
884 * Follow a scrolling change in the (cDNA/Protein) complementary alignment.
885 * The aim is to keep the two alignments 'lined up' on their centre columns.
888 * holds mapped region(s) of this alignment that we are scrolling
889 * 'to'; may be modified for sequence offset by this method
891 * the number of visible sequences to show above the mapped region
893 protected void scrollToCentre(SearchResultsI sr, int seqOffset)
896 * To avoid jumpy vertical scrolling (if some sequences are gapped or not
897 * mapped), we can make the scroll-to location a sequence above the one
900 SequenceI mappedTo = sr.getResults().get(0).getSequence();
901 List<SequenceI> seqs = av.getAlignment().getSequences();
904 * This is like AlignmentI.findIndex(seq) but here we are matching the
905 * dataset sequence not the aligned sequence
907 boolean matched = false;
908 for (SequenceI seq : seqs)
910 if (mappedTo == seq.getDatasetSequence())
918 return; // failsafe, shouldn't happen
922 * Scroll to position but centring the target residue. Also set a state flag
923 * to prevent adjustmentValueChanged performing this recursively.
925 setFollowingComplementScroll(true);
926 // this should be scrollToPosition(sr,verticalOffset,
927 scrollToPosition(sr, seqOffset, true, true);
930 private void sendViewPosition()
932 StructureSelectionManager.getStructureSelectionManager(av.applet)
933 .sendViewPosition(this, vpRanges.getStartRes(),
934 vpRanges.getEndRes(), vpRanges.getStartSeq(),
935 vpRanges.getEndSeq());
939 * Repaint the alignment and annotations, and, optionally, any overview window
942 public void paintAlignment(boolean updateOverview)
944 final AnnotationSorter sorter = new AnnotationSorter(getAlignment(),
945 av.isShowAutocalculatedAbove());
946 sorter.sort(getAlignment().getAlignmentAnnotation(),
947 av.getSortAnnotationsBy());
952 // TODO: determine if this paintAlignment changed structure colours
953 jalview.structure.StructureSelectionManager
954 .getStructureSelectionManager(av.applet)
955 .sequenceColoursChanged(this);
957 if (overviewPanel != null)
959 overviewPanel.updateOverviewImage();
965 public void update(Graphics g)
971 public void paint(Graphics g)
974 Dimension d = idPanel.idCanvas.getSize();
975 final int canvasHeight = seqPanel.seqCanvas.getSize().height;
976 if (canvasHeight != d.height)
978 idPanel.idCanvas.setSize(d.width, canvasHeight);
981 setScrollValues(vpRanges.getStartRes(), vpRanges.getStartSeq());
983 seqPanel.seqCanvas.repaint();
984 idPanel.idCanvas.repaint();
985 if (!av.getWrapAlignment())
987 if (av.isShowAnnotation())
990 annotationPanel.repaint();
992 scalePanel.repaint();
998 * Set vertical scroll bar parameters for wrapped panel
1000 * the residue to scroll to
1002 private void setScrollingForWrappedPanel(int res)
1004 // get the width of the alignment in residues
1005 int maxwidth = av.getAlignment().getWidth();
1006 if (av.hasHiddenColumns())
1008 maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;
1011 // get the width of the canvas in residues
1012 int canvasWidth = seqPanel.seqCanvas
1013 .getWrappedCanvasWidth(seqPanel.seqCanvas.getSize().width);
1014 if (canvasWidth > 0)
1016 // position we want to scroll to is number of canvasWidth's to get there
1017 int current = res / canvasWidth;
1019 // max scroll position: add one because extent is 1 and scrollbar value
1020 // can only be set to at most max - extent
1021 int max = maxwidth / canvasWidth + 1;
1022 vscroll.setUnitIncrement(1);
1023 vscroll.setValues(current, 1, 0, max);
1027 protected Panel sequenceHolderPanel = new Panel();
1029 protected Scrollbar vscroll = new Scrollbar();
1031 protected Scrollbar hscroll = new Scrollbar();
1033 protected Panel seqPanelHolder = new Panel();
1035 protected Panel scalePanelHolder = new Panel();
1037 protected Panel idPanelHolder = new Panel();
1039 protected Panel idSpaceFillerPanel1 = new Panel();
1041 public Panel annotationSpaceFillerHolder = new Panel();
1043 protected Panel hscrollFillerPanel = new Panel();
1045 Panel annotationPanelHolder = new Panel();
1047 protected Scrollbar apvscroll = new Scrollbar();
1050 * Flag set while scrolling to follow complementary cDNA/protein scroll. When
1051 * true, suppresses invoking the same method recursively.
1053 private boolean followingComplementScroll;
1055 private void jbInit() throws Exception
1057 // idPanelHolder.setPreferredSize(new Dimension(70, 10));
1058 this.setLayout(new BorderLayout());
1060 // sequenceHolderPanel.setPreferredSize(new Dimension(150, 150));
1061 sequenceHolderPanel.setLayout(new BorderLayout());
1062 seqPanelHolder.setLayout(new BorderLayout());
1063 scalePanelHolder.setBackground(Color.white);
1065 // scalePanelHolder.setPreferredSize(new Dimension(10, 30));
1066 scalePanelHolder.setLayout(new BorderLayout());
1067 idPanelHolder.setLayout(new BorderLayout());
1068 idSpaceFillerPanel1.setBackground(Color.white);
1070 // idSpaceFillerPanel1.setPreferredSize(new Dimension(10, 30));
1071 idSpaceFillerPanel1.setLayout(new BorderLayout());
1072 annotationSpaceFillerHolder.setBackground(Color.white);
1074 // annotationSpaceFillerHolder.setPreferredSize(new Dimension(10, 80));
1075 annotationSpaceFillerHolder.setLayout(new BorderLayout());
1076 hscroll.setOrientation(Scrollbar.HORIZONTAL);
1078 Panel hscrollHolder = new Panel();
1079 hscrollHolder.setLayout(new BorderLayout());
1080 hscrollFillerPanel.setBackground(Color.white);
1081 apvscroll.setOrientation(Scrollbar.VERTICAL);
1082 apvscroll.setVisible(true);
1083 apvscroll.addAdjustmentListener(this);
1085 annotationPanelHolder.setBackground(Color.white);
1086 annotationPanelHolder.setLayout(new BorderLayout());
1087 annotationPanelHolder.add(apvscroll, BorderLayout.EAST);
1088 // hscrollFillerPanel.setPreferredSize(new Dimension(70, 10));
1089 hscrollHolder.setBackground(Color.white);
1091 // annotationScroller.setPreferredSize(new Dimension(10, 80));
1092 // this.setPreferredSize(new Dimension(220, 166));
1093 seqPanelHolder.setBackground(Color.white);
1094 idPanelHolder.setBackground(Color.white);
1095 sequenceHolderPanel.add(scalePanelHolder, BorderLayout.NORTH);
1096 sequenceHolderPanel.add(seqPanelHolder, BorderLayout.CENTER);
1097 seqPanelHolder.add(vscroll, BorderLayout.EAST);
1099 // Panel3.add(secondaryPanelHolder, BorderLayout.SOUTH);
1100 this.add(idPanelHolder, BorderLayout.WEST);
1101 idPanelHolder.add(idSpaceFillerPanel1, BorderLayout.NORTH);
1102 idPanelHolder.add(annotationSpaceFillerHolder, BorderLayout.SOUTH);
1103 this.add(hscrollHolder, BorderLayout.SOUTH);
1104 hscrollHolder.add(hscroll, BorderLayout.CENTER);
1105 hscrollHolder.add(hscrollFillerPanel, BorderLayout.WEST);
1106 this.add(sequenceHolderPanel, BorderLayout.CENTER);
1110 * hides or shows dynamic annotation rows based on groups and av state flags
1112 public void updateAnnotation()
1114 updateAnnotation(false);
1117 public void updateAnnotation(boolean applyGlobalSettings)
1119 updateAnnotation(applyGlobalSettings, false);
1122 public void updateAnnotation(boolean applyGlobalSettings,
1123 boolean preserveNewGroupSettings)
1125 av.updateGroupAnnotationSettings(applyGlobalSettings,
1126 preserveNewGroupSettings);
1127 adjustAnnotationHeight();
1131 public AlignmentI getAlignment()
1133 return av.getAlignment();
1137 public String getViewName()
1143 public StructureSelectionManager getStructureSelectionManager()
1145 return StructureSelectionManager
1146 .getStructureSelectionManager(av.applet);
1150 public void raiseOOMWarning(String string, OutOfMemoryError error)
1153 System.err.println("Out of memory whilst '" + string + "'");
1154 error.printStackTrace();
1158 * Set a flag to say we are scrolling to follow a (cDNA/protein) complement.
1162 protected void setFollowingComplementScroll(boolean b)
1164 this.followingComplementScroll = b;
1167 protected boolean isFollowingComplementScroll()
1169 return this.followingComplementScroll;
1174 * Property change event fired when a change is made to the viewport ranges
1175 * object associated with this alignment panel's viewport
1177 public void propertyChange(PropertyChangeEvent evt)
1179 // update this panel's scroll values based on the new viewport ranges values
1180 int x = vpRanges.getStartRes();
1181 int y = vpRanges.getStartSeq();
1182 setScrollValues(x, y);
1184 // now update any complementary alignment (its viewport ranges object
1185 // is different so does not get automatically updated)
1186 if (isFollowingComplementScroll())
1188 setFollowingComplementScroll(false);
1189 av.scrollComplementaryAlignment(getComplementPanel());
1190 setFollowingComplementScroll(true);