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.
23 import java.awt.Color;
24 import java.awt.Dimension;
25 import java.awt.Graphics;
26 import java.awt.image.BufferedImage;
27 import java.awt.image.RasterFormatException;
29 import javax.swing.JPanel;
31 import jalview.api.AlignViewportI;
32 import jalview.bin.Cache;
33 import jalview.bin.Console;
34 import jalview.renderer.OverviewRenderer;
35 import jalview.renderer.OverviewResColourFinder;
36 import jalview.viewmodel.OverviewDimensions;
37 import jalview.viewmodel.seqfeatures.FeatureRendererModel;
39 public class OverviewCanvas extends JPanel
41 public static final Color OVERVIEW_DEFAULT_GAP = Color.lightGray;
43 public static final Color OVERVIEW_DEFAULT_LEGACY_GAP = Color.white;
45 public static final Color OVERVIEW_DEFAULT_RESIDUE = Color.white;
47 public static final Color OVERVIEW_DEFAULT_LEGACY_RESIDUE = Color.lightGray;
49 public static final Color OVERVIEW_DEFAULT_HIDDEN = Color.darkGray
52 private static final Color TRANS_GREY = new Color(100, 100, 100, 25);
54 // This is set true if the alignment view changes whilst
55 // the overview is being calculated
56 private volatile boolean restart = false;
58 private volatile boolean updaterunning = false;
60 private boolean dispose = false;
62 private BufferedImage miniMe;
64 private BufferedImage lastMiniMe = null;
66 // Can set different properties in this seqCanvas than
67 // main visible SeqCanvas
68 private SequenceRenderer sr;
70 private jalview.renderer.seqfeatures.FeatureRenderer fr;
72 private OverviewDimensions od;
74 private OverviewRenderer or = null;
76 private AlignViewportI av;
78 private OverviewResColourFinder cf;
80 private ProgressPanel progressPanel;
82 public OverviewCanvas(OverviewDimensions overviewDims,
83 AlignViewportI alignvp, ProgressPanel pp)
89 sr = new SequenceRenderer(av);
90 sr.renderGaps = false;
91 fr = new jalview.renderer.seqfeatures.FeatureRenderer(av);
93 boolean useLegacy = Cache.getDefault(Preferences.USE_LEGACY_GAP, false);
94 Color gapCol = Cache.getDefaultColour(Preferences.GAP_COLOUR,
95 OVERVIEW_DEFAULT_GAP);
96 Color hiddenCol = Cache.getDefaultColour(Preferences.HIDDEN_COLOUR,
97 OVERVIEW_DEFAULT_HIDDEN);
98 Color residueCol = useLegacy ? OVERVIEW_DEFAULT_LEGACY_RESIDUE
99 : OVERVIEW_DEFAULT_RESIDUE;
101 cf = new OverviewResColourFinder(gapCol, residueCol, hiddenCol);
103 setSize(od.getWidth(), od.getHeight());
107 * Update the overview dimensions object used by the canvas (e.g. if we change
108 * from showing hidden columns to hiding them or vice versa)
110 * @param overviewDims
112 public void resetOviewDims(OverviewDimensions overviewDims)
118 * Signals to drawing code that the associated alignment viewport has changed
119 * and a redraw will be required
121 public boolean restartDraw()
135 updaterunning = true;
142 * Draw the overview sequences
144 * @param showSequenceFeatures
145 * true if sequence features are to be shown
146 * @param showAnnotation
147 * true if the annotation is to be shown
148 * @param transferRenderer
149 * the renderer to transfer feature colouring from
151 public void draw(boolean showSequenceFeatures, boolean showAnnotation,
152 FeatureRendererModel transferRenderer)
156 if (showSequenceFeatures)
158 fr.transferSettings(transferRenderer);
161 setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
163 or = new OverviewRenderer(fr, od, av.getAlignment(),
164 av.getResidueShading(), cf);
166 or.addPropertyChangeListener(progressPanel);
168 miniMe = or.draw(od.getRows(av.getAlignment()),
169 od.getColumns(av.getAlignment()));
171 Graphics mg = miniMe.getGraphics();
175 mg.translate(0, od.getSequencesHeight());
176 or.drawGraph(mg, av.getAlignmentConservationAnnotation(),
177 od.getGraphHeight(), od.getColumns(av.getAlignment()));
178 mg.translate(0, -od.getSequencesHeight());
181 or.removePropertyChangeListener(progressPanel);
188 draw(showSequenceFeatures, showAnnotation, transferRenderer);
193 updaterunning = false;
199 public void paintComponent(Graphics g)
201 // super.paintComponent(g);
205 if (lastMiniMe == null)
207 g.setColor(Color.white);
208 g.fillRect(0, 0, getWidth(), getHeight());
212 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
214 g.setColor(TRANS_GREY);
215 g.fillRect(0, 0, getWidth(), getHeight());
217 else if (lastMiniMe != null)
220 if ((getWidth() > 0) && (getHeight() > 0)
221 && ((getWidth() != od.getWidth())
222 || (getHeight() != od.getHeight())))
224 // if there is annotation, scale the alignment and annotation
226 if (od.getGraphHeight() > 0 && od.getSequencesHeight() > 0 // BH 2019
231 BufferedImage topImage = lastMiniMe.getSubimage(0, 0,
232 od.getWidth(), od.getSequencesHeight());
233 BufferedImage bottomImage = lastMiniMe.getSubimage(0,
234 od.getSequencesHeight(), od.getWidth(),
235 od.getGraphHeight());
237 // must be done at this point as we rely on using old width/height
238 // above, and new width/height below
239 od.setWidth(getWidth());
240 od.setHeight(getHeight());
242 // stick the images back together so lastMiniMe is consistent in the
243 // event of a repaint - BUT probably not thread safe
244 lastMiniMe = new BufferedImage(od.getWidth(), od.getHeight(),
245 BufferedImage.TYPE_INT_RGB);
246 Graphics lg = lastMiniMe.getGraphics();
247 lg.drawImage(topImage, 0, 0, od.getWidth(),
248 od.getSequencesHeight(), null);
249 lg.drawImage(bottomImage, 0, od.getSequencesHeight(),
250 od.getWidth(), od.getGraphHeight(), this);
252 } catch (RasterFormatException e)
255 "Scaling miscalculation resizing Overview window");
256 od.setWidth(getWidth());
257 od.setHeight(getHeight());
262 od.setWidth(getWidth());
263 od.setHeight(getHeight());
266 // make sure the box is in the right place
267 od.setBoxPosition(av.getAlignment().getHiddenSequences(),
268 av.getAlignment().getHiddenColumns());
270 // fall back to normal behaviour
271 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
275 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
279 g.setColor(Color.red);
283 public void dispose()
297 public Color getGapColour()
299 return cf.getGapColour();
302 public Color getHiddenColour()
304 return cf.getHiddenColour();
307 public Color getResidueColour()
309 return cf.getResidueColour();
313 * Sets the colours to use for gaps, residues and hidden regions
319 public void setColours(Color gaps, Color residues, Color hidden)
321 cf = new OverviewResColourFinder(gaps, residues, hidden);