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;
29 import java.awt.Color;
30 import java.awt.Dimension;
31 import java.awt.Graphics;
32 import java.awt.image.BufferedImage;
34 import javax.swing.JPanel;
36 public class OverviewCanvas extends JPanel
38 private static final Color TRANS_GREY = new Color(100, 100, 100, 25);
40 // This is set true if the alignment view changes whilst
41 // the overview is being calculated
42 private volatile boolean restart = false;
44 private volatile boolean updaterunning = false;
46 private boolean dispose = false;
48 private BufferedImage miniMe;
50 private BufferedImage lastMiniMe = null;
52 // Can set different properties in this seqCanvas than
53 // main visible SeqCanvas
54 private SequenceRenderer sr;
56 private jalview.renderer.seqfeatures.FeatureRenderer fr;
58 private OverviewDimensions od;
60 private OverviewRenderer or = null;
62 private AlignViewportI av;
64 private OverviewResColourFinder cf;
66 private ProgressPanel progressPanel;
68 public OverviewCanvas(OverviewDimensions overviewDims,
69 AlignViewportI alignvp, ProgressPanel pp)
75 sr = new SequenceRenderer(av);
76 sr.renderGaps = false;
77 fr = new jalview.renderer.seqfeatures.FeatureRenderer(av);
79 boolean useLegacy = Cache.getDefault(Preferences.USE_LEGACY_GAP, false);
80 Color gapCol = Cache.getDefaultColour(Preferences.GAP_COLOUR,
81 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP);
82 Color hiddenCol = Cache.getDefaultColour(Preferences.HIDDEN_COLOUR,
83 jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN);
84 cf = new OverviewResColourFinder(useLegacy, gapCol, hiddenCol);
86 setSize(od.getWidth(), od.getHeight());
90 * Update the overview dimensions object used by the canvas (e.g. if we change
91 * from showing hidden columns to hiding them or vice versa)
95 public void resetOviewDims(OverviewDimensions overviewDims)
101 * Signals to drawing code that the associated alignment viewport has changed
102 * and a redraw will be required
104 public boolean restartDraw()
118 updaterunning = true;
125 * Draw the overview sequences
127 * @param showSequenceFeatures
128 * true if sequence features are to be shown
129 * @param showAnnotation
130 * true if the annotation is to be shown
131 * @param transferRenderer
132 * the renderer to transfer feature colouring from
134 public void draw(boolean showSequenceFeatures, boolean showAnnotation,
135 FeatureRenderer transferRenderer)
139 if (showSequenceFeatures)
141 fr.transferSettings(transferRenderer);
144 setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
146 or = new OverviewRenderer(fr, od, av.getAlignment(),
147 av.getResidueShading(), cf);
149 or.addPropertyChangeListener(progressPanel);
151 miniMe = or.draw(od.getRows(av.getAlignment()),
152 od.getColumns(av.getAlignment()));
154 Graphics mg = miniMe.getGraphics();
158 mg.translate(0, od.getSequencesHeight());
159 or.drawGraph(mg, av.getAlignmentConservationAnnotation(),
160 od.getGraphHeight(), od.getColumns(av.getAlignment()));
161 mg.translate(0, -od.getSequencesHeight());
164 or.removePropertyChangeListener(progressPanel);
171 draw(showSequenceFeatures, showAnnotation, transferRenderer);
176 updaterunning = false;
182 public void paintComponent(Graphics g)
184 //super.paintComponent(g);
188 if (lastMiniMe == null)
190 g.setColor(Color.white);
191 g.fillRect(0, 0, getWidth(), getHeight());
195 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
197 g.setColor(TRANS_GREY);
198 g.fillRect(0, 0, getWidth(), getHeight());
200 else if (lastMiniMe != null)
203 if ((getWidth() > 0) && (getHeight() > 0)
204 && ((getWidth() != od.getWidth())
205 || (getHeight() != od.getHeight())))
207 // if there is annotation, scale the alignment and annotation
209 if (od.getGraphHeight() > 0
210 && od.getSequencesHeight() > 0 // BH 2019
213 BufferedImage topImage = lastMiniMe.getSubimage(0, 0,
214 od.getWidth(), od.getSequencesHeight());
215 BufferedImage bottomImage = lastMiniMe.getSubimage(0,
216 od.getSequencesHeight(), od.getWidth(),
217 od.getGraphHeight());
219 // must be done at this point as we rely on using old width/height
220 // above, and new width/height below
221 od.setWidth(getWidth());
222 od.setHeight(getHeight());
224 // stick the images back together so lastMiniMe is consistent in the
225 // event of a repaint - BUT probably not thread safe
226 lastMiniMe = new BufferedImage(od.getWidth(), od.getHeight(),
227 BufferedImage.TYPE_INT_RGB);
228 Graphics lg = lastMiniMe.getGraphics();
229 lg.drawImage(topImage, 0, 0, od.getWidth(),
230 od.getSequencesHeight(), null);
231 lg.drawImage(bottomImage, 0, od.getSequencesHeight(),
232 od.getWidth(), od.getGraphHeight(), this);
237 od.setWidth(getWidth());
238 od.setHeight(getHeight());
241 // make sure the box is in the right place
242 od.setBoxPosition(av.getAlignment().getHiddenSequences(),
243 av.getAlignment().getHiddenColumns());
245 // fall back to normal behaviour
246 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
250 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
254 g.setColor(Color.red);
259 public void dispose()