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 // Can set different properties in this seqCanvas than
52 // main visible SeqCanvas
53 private SequenceRenderer sr;
55 private FeatureRenderer fr;
57 private Frame nullFrame;
59 public OverviewCanvas(OverviewDimensions overviewDims,
60 AlignViewport alignvp)
65 nullFrame = new Frame();
66 nullFrame.addNotify();
68 sr = new SequenceRenderer(av);
69 sr.graphics = nullFrame.getGraphics();
70 sr.renderGaps = false;
71 sr.forOverview = true;
72 fr = new FeatureRenderer(av);
76 * Signals to drawing code that the associated alignment viewport
77 * has changed and a redraw will be required
79 public boolean restartDraw()
95 public void draw(boolean showSequenceFeatures, boolean showAnnotation,
100 if (av.isShowSequenceFeatures())
102 fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());
105 setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
107 miniMe = nullFrame.createImage(od.getWidth(), od.getHeight());
108 offscreen = nullFrame.createImage(od.getWidth(), od.getHeight());
110 Graphics mg = miniMe.getGraphics();
112 int alwidth = av.getAlignment().getWidth();
113 int alheight = av.getAlignment().getAbsoluteHeight();
114 float sampleCol = alwidth / (float) od.getWidth();
115 float sampleRow = alheight / (float) od.getSequencesHeight();
117 buildImage(sampleRow, sampleCol, mg);
119 // check for conservation annotation to make sure overview works for DNA too
122 for (int col = 0; col < od.getWidth() && !restart; col++)
124 mg.translate(col, od.getSequencesHeight());
125 ap.annotationPanel.renderer.drawGraph(mg,
126 av.getAlignmentConservationAnnotation(),
127 av.getAlignmentConservationAnnotation().annotations,
128 (int) (sampleCol) + 1, od.getGraphHeight(),
129 (int) (col * sampleCol), (int) (col * sampleCol) + 1);
130 mg.translate(-col, -od.getSequencesHeight());
138 draw(showSequenceFeatures, showAnnotation, ap);
142 updaterunning = false;
147 * Build the overview panel image
149 private void buildImage(float sampleRow, float sampleCol, Graphics mg)
155 Color color = Color.yellow;
159 SequenceI seq = null;
160 FeatureColourFinder finder = new FeatureColourFinder(fr);
162 final boolean hasHiddenCols = av.hasHiddenColumns();
163 boolean hiddenRow = false;
165 for (int row = 0; row < od.getSequencesHeight() && !restart; row++)
167 if ((int) (row * sampleRow) == lastrow)
173 // get the sequence which would be at alignment index 'lastrow' if no
174 // rows were hidden, and determine whether it is hidden or not
175 hiddenRow = av.getAlignment().isHidden(lastrow);
176 seq = av.getAlignment().getSequenceAtAbsoluteIndex(lastrow);
178 for (int col = 0; col < od.getWidth(); col++)
180 if ((int) (col * sampleCol) == lastcol
181 && (int) (row * sampleRow) == lastrow)
187 lastcol = (int) (col * sampleCol);
189 color = getColumnColourFromSequence(seq, hiddenRow,
190 hasHiddenCols, lastcol, finder);
193 if (sameCol == 1 && sameRow == 1)
195 mg.drawLine(xstart, ystart, xstart, ystart);
199 mg.fillRect(xstart, ystart, sameCol, sameRow);
206 lastrow = (int) (row * sampleRow);
214 * Find the colour of a sequence at a specified column position
216 private Color getColumnColourFromSequence(
217 jalview.datamodel.SequenceI seq, boolean hiddenRow,
218 boolean hasHiddenCols, int lastcol, FeatureColourFinder finder)
220 Color color = Color.white;
221 if (seq.getLength() > lastcol)
223 color = sr.getResidueColour(seq, lastcol, finder);
227 || (hasHiddenCols && !av.getAlignment().getHiddenColumns()
228 .isVisible(lastcol)))
230 color = color.darker().darker();
236 public void update(Graphics g)
242 public void paint(Graphics g)
244 Graphics og = offscreen.getGraphics();
247 og.drawImage(miniMe, 0, 0, this);
248 og.setColor(Color.red);
250 g.drawImage(offscreen, 0, 0, this);