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.datamodel.SequenceI;
24 import jalview.renderer.seqfeatures.FeatureColourFinder;
25 import jalview.viewmodel.OverviewDimensions;
27 import java.awt.Color;
28 import java.awt.Dimension;
29 import java.awt.Frame;
30 import java.awt.Graphics;
31 import java.awt.Image;
33 import javax.swing.JComponent;
35 public class OverviewCanvas extends JComponent
37 // This is set true if the alignment view changes whilst
38 // the overview is being calculated
39 private volatile boolean restart = false;
41 private volatile boolean updaterunning = false;
43 private OverviewDimensions od;
47 private Image offscreen;
49 private AlignViewport av;
51 private AlignmentPanel ap;
53 // Can set different properties in this seqCanvas than
54 // main visible SeqCanvas
55 private SequenceRenderer sr;
57 private FeatureRenderer fr;
59 private Frame nullFrame;
61 public OverviewCanvas(OverviewDimensions overviewDims,
62 AlignViewport alignvp, AlignmentPanel alignp)
68 nullFrame = new Frame();
69 nullFrame.addNotify();
71 sr = new SequenceRenderer(av);
72 sr.graphics = nullFrame.getGraphics();
73 sr.renderGaps = false;
74 sr.forOverview = true;
75 fr = new FeatureRenderer(av);
79 * Signals to drawing code that the associated alignment viewport
80 * has changed and a redraw will be required
82 public boolean restartDraw()
98 public void draw(boolean showSequenceFeatures, boolean showAnnotation)
102 if (av.isShowSequenceFeatures())
104 fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
107 setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
109 miniMe = nullFrame.createImage(od.getWidth(), od.getHeight());
110 offscreen = nullFrame.createImage(od.getWidth(), od.getHeight());
112 Graphics mg = miniMe.getGraphics();
114 int alwidth = av.getAlignment().getWidth();
115 int alheight = av.getAlignment().getAbsoluteHeight();
116 float sampleCol = alwidth / (float) od.getWidth();
117 float sampleRow = alheight / (float) od.getSequencesHeight();
119 buildImage(sampleRow, sampleCol, mg);
121 // check for conservation annotation to make sure overview works for DNA too
124 for (int col = 0; col < od.getWidth() && !restart; col++)
126 mg.translate(col, od.getSequencesHeight());
127 ap.annotationPanel.renderer.drawGraph(mg,
128 av.getAlignmentConservationAnnotation(),
129 av.getAlignmentConservationAnnotation().annotations,
130 (int) (sampleCol) + 1, od.getGraphHeight(),
131 (int) (col * sampleCol), (int) (col * sampleCol) + 1);
132 mg.translate(-col, -od.getSequencesHeight());
140 draw(showSequenceFeatures, showAnnotation);
144 updaterunning = false;
149 * Build the overview panel image
151 private void buildImage(float sampleRow, float sampleCol, Graphics mg)
157 Color color = Color.yellow;
161 SequenceI seq = null;
162 FeatureColourFinder finder = new FeatureColourFinder(fr);
164 final boolean hasHiddenCols = av.hasHiddenColumns();
165 boolean hiddenRow = false;
167 for (int row = 0; row < od.getSequencesHeight() && !restart; row++)
169 if ((int) (row * sampleRow) == lastrow)
175 // get the sequence which would be at alignment index 'lastrow' if no
176 // rows were hidden, and determine whether it is hidden or not
177 hiddenRow = av.getAlignment().isHidden(lastrow);
178 seq = av.getAlignment().getSequenceAtAbsoluteIndex(lastrow);
180 for (int col = 0; col < od.getWidth(); col++)
182 if ((int) (col * sampleCol) == lastcol
183 && (int) (row * sampleRow) == lastrow)
189 lastcol = (int) (col * sampleCol);
191 color = getColumnColourFromSequence(seq, hiddenRow,
192 hasHiddenCols, lastcol, finder);
195 if (sameCol == 1 && sameRow == 1)
197 mg.drawLine(xstart, ystart, xstart, ystart);
201 mg.fillRect(xstart, ystart, sameCol, sameRow);
208 lastrow = (int) (row * sampleRow);
216 * Find the colour of a sequence at a specified column position
218 private Color getColumnColourFromSequence(
219 jalview.datamodel.SequenceI seq, boolean hiddenRow,
220 boolean hasHiddenCols, int lastcol, FeatureColourFinder finder)
222 Color color = Color.white;
223 if (seq.getLength() > lastcol)
225 color = sr.getResidueColour(seq, lastcol, finder);
229 || (hasHiddenCols && !av.getColumnSelection()
230 .isVisible(lastcol)))
232 color = color.darker().darker();
238 public void update(Graphics g)
244 public void paint(Graphics g)
246 Graphics og = offscreen.getGraphics();
249 og.drawImage(miniMe, 0, 0, this);
250 og.setColor(Color.red);
252 g.drawImage(offscreen, 0, 0, this);