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.datamodel.AlignmentI;
26 import jalview.renderer.OverviewRenderer;
27 import jalview.renderer.OverviewResColourFinder;
28 import jalview.viewmodel.OverviewDimensions;
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 @SuppressWarnings("serial")
38 public class OverviewCanvas extends JPanel
40 private static final Color TRANS_GREY = new Color(100, 100, 100, 25);
42 // This is set true if the alignment view changes whilst
43 // the overview is being calculated
44 private volatile boolean restart = false;
46 private volatile boolean updaterunning = false;
48 private boolean disposed = false;
50 BufferedImage lastMiniMe = null;
52 // Can set different properties in this seqCanvas than
53 // main visible SeqCanvas
54 private final SequenceRenderer sr;
56 private final jalview.renderer.seqfeatures.FeatureRenderer fr;
58 private OverviewDimensions od;
60 private OverviewRenderer or = null;
62 private final AlignViewportI av;
64 private final OverviewResColourFinder cf;
66 private final ProgressPanel progressPanel;
68 private boolean showSequenceFeatures;
70 private boolean showAnnotation;
72 private jalview.api.FeatureRenderer featureRenderer;
74 private final OverviewPanel panel;
76 private final boolean showProgress;
78 public OverviewCanvas(OverviewPanel panel,
79 OverviewDimensions overviewDims,
80 AlignViewportI alignvp, ProgressPanel pp)
87 showProgress = (pp != null);
88 sr = new SequenceRenderer(av);
89 sr.renderGaps = false;
90 fr = new jalview.renderer.seqfeatures.FeatureRenderer(av);
92 boolean useLegacy = Cache.getDefault(Preferences.USE_LEGACY_GAP, false);
93 Color gapCol = Cache.getDefaultColour(Preferences.GAP_COLOUR,
94 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
95 Color hiddenCol = Cache.getDefaultColour(Preferences.HIDDEN_COLOUR,
96 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
97 cf = new OverviewResColourFinder(useLegacy, gapCol, hiddenCol);
99 setSize(od.getWidth(), od.getHeight());
100 setPreferredSize(getSize()); // BH 2019.07.29 added
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)
116 * Signals to drawing code that the associated alignment viewport has changed
117 * and a redraw will be required
119 public boolean restartDraw()
125 setRestart("restartDraw");
129 updaterunning = true;
136 private void setRestart(String why)
138 // System.out.println("OC restart true " + why);
147 * Draw the overview sequences
149 * @param showSequenceFeatures
150 * true if sequence features are to be shown
151 * @param showAnnotation
152 * true if the annotation is to be shown
153 * @param featureRenderer
154 * the renderer to transfer feature colouring from
156 public void draw(boolean showSequenceFeatures, boolean showAnnotation,
157 jalview.api.FeatureRenderer featureRenderer)
159 this.showSequenceFeatures = showSequenceFeatures;
160 this.showAnnotation = showAnnotation;
161 this.featureRenderer = featureRenderer;
162 if (showSequenceFeatures)
164 fr.transferSettings(featureRenderer);
166 setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
167 AlignmentI al = av.getAlignment();
168 or = new OverviewRenderer(panel.ap, fr, od, al, av.getResidueShading(),
172 or.addPropertyChangeListener(progressPanel);
177 synchronized void finalizeDraw(BufferedImage miniMe)
179 if (showProgress && or != null)
181 or.removePropertyChangeListener(progressPanel);
189 draw(showSequenceFeatures, showAnnotation, featureRenderer);
194 if (showAnnotation && or != null)
196 or.drawGraph(av.getAlignmentConservationAnnotation());
199 updaterunning = false;
206 public void paintComponent(Graphics g)
211 if (w == 0 || od.getBoxWidth() <= 0)
213 // BH 2019.07.27 removes two unnecessary paints, since boxwidth can be -1
214 // or 0 during early-stage painting
218 boolean drawMe = (lastMiniMe != null);
223 g.drawImage(lastMiniMe, 0, 0, w, h, this);
227 g.setColor(Color.white);
228 g.fillRect(0, 0, w, h);
230 g.setColor(TRANS_GREY);
231 g.fillRect(0, 0, w, h);
237 if (w != od.getWidth() || h != od.getHeight())
242 // // if there is annotation, scale the alignment and annotation
244 // if (od.getGraphHeight() <= 0 && od.getSequencesHeight() <= 0)
252 // BufferedImage topImage = lastMiniMe.getSubimage(0, 0,
253 // od.getWidth(), od.getSequencesHeight());
255 // BufferedImage bottomImage = lastMiniMe.getSubimage(0,
256 // od.getSequencesHeight(), od.getWidth(),
257 // od.getGraphHeight());
259 // // must be done at this point as we rely on using old width/height
260 // // above, and new width/height below
264 // // stick the images back together so lastMiniMe is consistent in the
265 // // event of a repaint - BUT probably not thread safe
267 // // right -- this fails with fast user action.
269 // lastMiniMe = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
270 // Graphics lg = lastMiniMe.getGraphics();
271 // lg.drawImage(topImage, 0, 0, w, od.getSequencesHeight(), null);
272 // lg.drawImage(bottomImage, 0, od.getSequencesHeight(), w,
273 // od.getGraphHeight(), this);
276 // } catch (RasterFormatException e)
278 // System.out.println("OC Raster Exception " + lastMiniMe.getWidth()
279 // + "/" + w + "," + lastMiniMe.getHeight() + "/" + h + " "
280 // + od.getSequencesHeight() + " " + od.getGraphHeight());
282 // BH 2019: removed -- this is now taken care of using vpbox in
284 // // make sure the box is in the right place
285 // od.setBoxPosition(av.getAlignment().getHiddenSequences(),
286 // av.getAlignment().getHiddenColumns());
292 g.drawImage(lastMiniMe, 0, 0, w, h, this);
295 g.setColor(Color.red);
296 // System.out.println("OC paintComponent nd=" + ndraw + " nr=" + nrepaint
297 // + " np=" + ++npaint);
301 // private int ndraw, npaint, nrepaint;
304 // public void repaint()
306 // System.out.println("OC repaint " + (++nrepaint));
310 public void dispose()
317 setRestart("dispose");