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 jalview.api.AlignViewportI;
24 import jalview.bin.Cache;
25 import jalview.renderer.OverviewRenderer;
26 import jalview.renderer.OverviewResColourFinder;
27 import jalview.viewmodel.OverviewDimensions;
28 import jalview.viewmodel.seqfeatures.FeatureRendererModel;
30 import java.awt.Color;
31 import java.awt.Dimension;
32 import java.awt.Graphics;
33 import java.awt.image.BufferedImage;
35 import javax.swing.JPanel;
37 public class OverviewCanvas extends JPanel
39 private static final Color TRANS_GREY = new Color(100, 100, 100, 25);
41 // This is set true if the alignment view changes whilst
42 // the overview is being calculated
43 private volatile boolean restart = false;
45 private volatile boolean updaterunning = false;
47 private boolean dispose = false;
49 private BufferedImage miniMe;
51 private BufferedImage lastMiniMe = null;
53 // Can set different properties in this seqCanvas than
54 // main visible SeqCanvas
55 private SequenceRenderer sr;
57 private jalview.renderer.seqfeatures.FeatureRenderer fr;
59 private OverviewDimensions od;
61 private OverviewRenderer or = null;
63 private AlignViewportI av;
65 private OverviewResColourFinder cf;
67 private ProgressPanel progressPanel;
69 public OverviewCanvas(OverviewDimensions overviewDims,
70 AlignViewportI alignvp, ProgressPanel pp)
76 sr = new SequenceRenderer(av);
77 sr.renderGaps = false;
78 fr = new jalview.renderer.seqfeatures.FeatureRenderer(av);
80 boolean useLegacy = Cache.getDefault(Preferences.USE_LEGACY_GAP, false);
81 Color gapCol = Cache.getDefaultColour(Preferences.GAP_COLOUR,
82 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
83 Color hiddenCol = Cache.getDefaultColour(Preferences.HIDDEN_COLOUR,
84 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
85 cf = new OverviewResColourFinder(useLegacy, gapCol, hiddenCol);
87 setSize(od.getWidth(), od.getHeight());
91 * Update the overview dimensions object used by the canvas (e.g. if we change
92 * from showing hidden columns to hiding them or vice versa)
96 public void resetOviewDims(OverviewDimensions overviewDims)
102 * Signals to drawing code that the associated alignment viewport has changed
103 * and a redraw will be required
105 public boolean restartDraw()
119 updaterunning = true;
126 * Draw the overview sequences
128 * @param showSequenceFeatures
129 * true if sequence features are to be shown
130 * @param showAnnotation
131 * true if the annotation is to be shown
132 * @param transferRenderer
133 * the renderer to transfer feature colouring from
135 public void draw(boolean showSequenceFeatures, boolean showAnnotation,
136 FeatureRendererModel transferRenderer)
140 if (showSequenceFeatures)
142 fr.transferSettings(transferRenderer);
145 setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
147 or = new OverviewRenderer(fr, od, av.getAlignment(),
148 av.getResidueShading(), cf);
150 or.addPropertyChangeListener(progressPanel);
152 miniMe = or.draw(od.getRows(av.getAlignment()),
153 od.getColumns(av.getAlignment()));
155 Graphics mg = miniMe.getGraphics();
159 mg.translate(0, od.getSequencesHeight());
160 or.drawGraph(mg, av.getAlignmentConservationAnnotation(),
161 od.getGraphHeight(), od.getColumns(av.getAlignment()));
162 mg.translate(0, -od.getSequencesHeight());
165 or.removePropertyChangeListener(progressPanel);
172 draw(showSequenceFeatures, showAnnotation, transferRenderer);
177 updaterunning = false;
183 public void paintComponent(Graphics g)
185 //super.paintComponent(g);
189 if (lastMiniMe == null)
191 g.setColor(Color.white);
192 g.fillRect(0, 0, getWidth(), getHeight());
196 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
198 g.setColor(TRANS_GREY);
199 g.fillRect(0, 0, getWidth(), getHeight());
201 else if (lastMiniMe != null)
204 if ((getWidth() > 0) && (getHeight() > 0)
205 && ((getWidth() != od.getWidth())
206 || (getHeight() != od.getHeight())))
208 // if there is annotation, scale the alignment and annotation
210 if (od.getGraphHeight() > 0
211 && od.getSequencesHeight() > 0 // BH 2019
214 BufferedImage topImage = lastMiniMe.getSubimage(0, 0,
215 od.getWidth(), od.getSequencesHeight());
216 BufferedImage bottomImage = lastMiniMe.getSubimage(0,
217 od.getSequencesHeight(), od.getWidth(),
218 od.getGraphHeight());
220 // must be done at this point as we rely on using old width/height
221 // above, and new width/height below
222 od.setWidth(getWidth());
223 od.setHeight(getHeight());
225 // stick the images back together so lastMiniMe is consistent in the
226 // event of a repaint - BUT probably not thread safe
227 lastMiniMe = new BufferedImage(od.getWidth(), od.getHeight(),
228 BufferedImage.TYPE_INT_RGB);
229 Graphics lg = lastMiniMe.getGraphics();
230 lg.drawImage(topImage, 0, 0, od.getWidth(),
231 od.getSequencesHeight(), null);
232 lg.drawImage(bottomImage, 0, od.getSequencesHeight(),
233 od.getWidth(), od.getGraphHeight(), this);
238 od.setWidth(getWidth());
239 od.setHeight(getHeight());
242 // make sure the box is in the right place
243 od.setBoxPosition(av.getAlignment().getHiddenSequences(),
244 av.getAlignment().getHiddenColumns());
246 // fall back to normal behaviour
247 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
251 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
255 g.setColor(Color.red);
260 public void dispose()