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;
28 import javax.swing.JPanel;
30 import jalview.api.AlignViewportI;
31 import jalview.bin.Cache;
32 import jalview.renderer.OverviewRenderer;
33 import jalview.renderer.OverviewResColourFinder;
34 import jalview.viewmodel.OverviewDimensions;
35 import jalview.viewmodel.seqfeatures.FeatureRendererModel;
37 public class OverviewCanvas extends JPanel
39 public static final Color OVERVIEW_DEFAULT_GAP = Color.lightGray;
41 public static final Color OVERVIEW_DEFAULT_LEGACY_GAP = Color.white;
43 public static final Color OVERVIEW_DEFAULT_RESIDUE = Color.white;
45 public static final Color OVERVIEW_DEFAULT_LEGACY_RESIDUE = Color.lightGray;
47 public static final Color OVERVIEW_DEFAULT_HIDDEN = Color.darkGray
50 private static final Color TRANS_GREY = new Color(100, 100, 100, 25);
52 // This is set true if the alignment view changes whilst
53 // the overview is being calculated
54 private volatile boolean restart = false;
56 private volatile boolean updaterunning = false;
58 private boolean dispose = false;
60 private BufferedImage miniMe;
62 private BufferedImage lastMiniMe = null;
64 // Can set different properties in this seqCanvas than
65 // main visible SeqCanvas
66 private SequenceRenderer sr;
68 private jalview.renderer.seqfeatures.FeatureRenderer fr;
70 private OverviewDimensions od;
72 private OverviewRenderer or = null;
74 private AlignViewportI av;
76 private OverviewResColourFinder cf;
78 private ProgressPanel progressPanel;
80 public OverviewCanvas(OverviewDimensions overviewDims,
81 AlignViewportI alignvp, ProgressPanel pp)
87 sr = new SequenceRenderer(av);
88 sr.renderGaps = false;
89 fr = new jalview.renderer.seqfeatures.FeatureRenderer(av);
91 boolean useLegacy = Cache.getDefault(Preferences.USE_LEGACY_GAP, false);
92 Color gapCol = Cache.getDefaultColour(Preferences.GAP_COLOUR,
93 OVERVIEW_DEFAULT_GAP);
94 Color hiddenCol = Cache.getDefaultColour(Preferences.HIDDEN_COLOUR,
95 OVERVIEW_DEFAULT_HIDDEN);
96 Color residueCol = useLegacy ? OVERVIEW_DEFAULT_LEGACY_RESIDUE : OVERVIEW_DEFAULT_RESIDUE;
98 cf = new OverviewResColourFinder(gapCol, residueCol, hiddenCol);
100 setSize(od.getWidth(), od.getHeight());
104 * Update the overview dimensions object used by the canvas (e.g. if we change
105 * from showing hidden columns to hiding them or vice versa)
107 * @param overviewDims
109 public void resetOviewDims(OverviewDimensions overviewDims)
115 * Signals to drawing code that the associated alignment viewport has changed
116 * and a redraw will be required
118 public boolean restartDraw()
132 updaterunning = true;
139 * Draw the overview sequences
141 * @param showSequenceFeatures
142 * true if sequence features are to be shown
143 * @param showAnnotation
144 * true if the annotation is to be shown
145 * @param transferRenderer
146 * the renderer to transfer feature colouring from
148 public void draw(boolean showSequenceFeatures, boolean showAnnotation,
149 FeatureRendererModel transferRenderer)
153 if (showSequenceFeatures)
155 fr.transferSettings(transferRenderer);
158 setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
160 or = new OverviewRenderer(fr, od, av.getAlignment(),
161 av.getResidueShading(), cf);
163 or.addPropertyChangeListener(progressPanel);
165 miniMe = or.draw(od.getRows(av.getAlignment()),
166 od.getColumns(av.getAlignment()));
168 Graphics mg = miniMe.getGraphics();
172 mg.translate(0, od.getSequencesHeight());
173 or.drawGraph(mg, av.getAlignmentConservationAnnotation(),
174 od.getGraphHeight(), od.getColumns(av.getAlignment()));
175 mg.translate(0, -od.getSequencesHeight());
178 or.removePropertyChangeListener(progressPanel);
185 draw(showSequenceFeatures, showAnnotation, transferRenderer);
190 updaterunning = false;
196 public void paintComponent(Graphics g)
198 // super.paintComponent(g);
202 if (lastMiniMe == null)
204 g.setColor(Color.white);
205 g.fillRect(0, 0, getWidth(), getHeight());
209 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
211 g.setColor(TRANS_GREY);
212 g.fillRect(0, 0, getWidth(), getHeight());
214 else if (lastMiniMe != null)
217 if ((getWidth() > 0) && (getHeight() > 0)
218 && ((getWidth() != od.getWidth())
219 || (getHeight() != od.getHeight())))
221 // if there is annotation, scale the alignment and annotation
223 if (od.getGraphHeight() > 0 && od.getSequencesHeight() > 0 // BH 2019
226 BufferedImage topImage = lastMiniMe.getSubimage(0, 0,
227 od.getWidth(), od.getSequencesHeight());
228 BufferedImage bottomImage = lastMiniMe.getSubimage(0,
229 od.getSequencesHeight(), od.getWidth(),
230 od.getGraphHeight());
232 // must be done at this point as we rely on using old width/height
233 // above, and new width/height below
234 od.setWidth(getWidth());
235 od.setHeight(getHeight());
237 // stick the images back together so lastMiniMe is consistent in the
238 // event of a repaint - BUT probably not thread safe
239 lastMiniMe = new BufferedImage(od.getWidth(), od.getHeight(),
240 BufferedImage.TYPE_INT_RGB);
241 Graphics lg = lastMiniMe.getGraphics();
242 lg.drawImage(topImage, 0, 0, od.getWidth(),
243 od.getSequencesHeight(), null);
244 lg.drawImage(bottomImage, 0, od.getSequencesHeight(),
245 od.getWidth(), od.getGraphHeight(), this);
250 od.setWidth(getWidth());
251 od.setHeight(getHeight());
254 // make sure the box is in the right place
255 od.setBoxPosition(av.getAlignment().getHiddenSequences(),
256 av.getAlignment().getHiddenColumns());
258 // fall back to normal behaviour
259 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
263 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
267 g.setColor(Color.red);
271 public void dispose()
285 public Color getGapColour()
287 return cf.getGapColour();
290 public Color getHiddenColour()
292 return cf.getHiddenColour();
295 public Color getResidueColour()
297 return cf.getResidueColour();
301 * Sets the colours to use for gaps, residues and hidden regions
307 public void setColours(Color gaps, Color residues, Color hidden)
309 cf = new OverviewResColourFinder(gaps, residues, hidden);