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.renderer;
23 import jalview.api.AlignmentColsCollectionI;
24 import jalview.api.AlignmentRowsCollectionI;
25 import jalview.datamodel.AlignmentAnnotation;
26 import jalview.datamodel.Annotation;
27 import jalview.datamodel.SequenceI;
28 import jalview.renderer.seqfeatures.FeatureColourFinder;
29 import jalview.renderer.seqfeatures.FeatureRenderer;
30 import jalview.viewmodel.OverviewDimensions;
32 import java.awt.Color;
33 import java.awt.Graphics;
34 import java.awt.image.BufferedImage;
36 public class OverviewRenderer
38 private FeatureColourFinder finder;
40 private jalview.api.SequenceRenderer sr;
43 private BufferedImage miniMe;
45 // raw number of pixels to allocate to each column
46 private float pixelsPerCol;
48 // raw number of pixels to allocate to each row
49 private float pixelsPerSeq;
51 // flag to indicate whether to halt drawing
52 private volatile boolean redraw = false;
54 public OverviewRenderer(jalview.api.SequenceRenderer seqRenderer,
55 FeatureRenderer fr, OverviewDimensions od)
58 finder = new FeatureColourFinder(fr);
60 pixelsPerCol = od.getPixelsPerCol();
61 pixelsPerSeq = od.getPixelsPerSeq();
62 miniMe = new BufferedImage(od.getWidth(), od.getHeight(),
63 BufferedImage.TYPE_INT_RGB);
67 * Draw alignment rows and columns onto an image
70 * Iterator over rows to be drawn
72 * Iterator over columns to be drawn
73 * @return image containing the drawing
75 public BufferedImage draw(AlignmentRowsCollectionI rows,
76 AlignmentColsCollectionI cols)
78 int rgbcolor = Color.white.getRGB();
82 for (int alignmentRow : rows)
89 // get details of this alignment row
90 boolean hidden = rows.isHidden(alignmentRow);
91 SequenceI seq = rows.getSequence(alignmentRow);
93 // calculate where this row extends to in pixels
94 int endRow = Math.min(Math.round((seqIndex + 1) * pixelsPerSeq) - 1,
95 miniMe.getHeight() - 1);
99 for (int alignmentCol : cols)
106 // calculate where this column extends to in pixels
107 int endCol = Math.min(
108 Math.round((colIndex + 1) * pixelsPerCol) - 1,
109 miniMe.getWidth() - 1);
111 // don't do expensive colour determination if we're not going to use it
112 // NB this is important to avoid performance issues in the overview
114 if (pixelCol <= endCol)
116 // determine the colour based on the sequence and column position
117 rgbcolor = getColumnColourFromSequence(seq,
118 hidden || cols.isHidden(alignmentCol), alignmentCol,
121 // fill in the appropriate number of pixels
122 for (int row = pixelRow; row <= endRow; ++row)
124 for (int col = pixelCol; col <= endCol; ++col)
126 miniMe.setRGB(col, row, rgbcolor);
130 pixelCol = endCol + 1;
134 pixelRow = endRow + 1;
141 * Find the colour of a sequence at a specified column position
143 private int getColumnColourFromSequence(jalview.datamodel.SequenceI seq,
144 boolean isHidden, int lastcol, FeatureColourFinder fcfinder)
146 Color color = Color.white;
148 if ((seq != null) && (seq.getLength() > lastcol))
150 color = sr.getResidueColour(seq, lastcol, fcfinder);
155 color = color.darker().darker();
158 return color.getRGB();
162 * Draw the alignment annotation in the overview panel
165 * the graphics object to draw on
167 * alignment annotation information
169 * alignment character width value
171 * y-position for the annotation graph
173 * the collection of columns used in the overview panel
175 public void drawGraph(Graphics g, AlignmentAnnotation anno, int charWidth,
176 int y, AlignmentColsCollectionI cols)
178 Annotation[] annotations = anno.annotations;
179 g.setColor(Color.white);
180 g.fillRect(0, 0, miniMe.getWidth(), y);
185 for (int alignmentCol : cols)
191 if (alignmentCol >= annotations.length)
193 break; // no more annotations to draw here
197 int endCol = Math.min(
198 Math.round((colIndex + 1) * pixelsPerCol) - 1,
199 miniMe.getWidth() - 1);
201 if (annotations[alignmentCol] != null)
203 if (annotations[alignmentCol].colour == null)
205 g.setColor(Color.black);
209 g.setColor(annotations[alignmentCol].colour);
212 height = (int) ((annotations[alignmentCol].value / anno.graphMax) * y);
218 g.fillRect(pixelCol, y - height, endCol - pixelCol + 1, height);
220 pixelCol = endCol + 1;
226 public void setRedraw(boolean b)