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.renderer.OverviewRenderer;
25 import jalview.viewmodel.OverviewDimensions;
27 import java.awt.Color;
28 import java.awt.Graphics;
29 import java.awt.image.BufferedImage;
31 import javax.swing.JComponent;
33 public class OverviewCanvas extends JComponent
35 private static final Color TRANS_GREY = new Color(100, 100, 100, 25);
37 // This is set true if the alignment view changes whilst
38 // the overview is being calculated
39 private volatile boolean restart = false;
41 private volatile boolean updaterunning = false;
43 private boolean dispose = false;
45 private BufferedImage miniMe;
47 private BufferedImage lastMiniMe = null;
49 // Can set different properties in this seqCanvas than
50 // main visible SeqCanvas
51 private SequenceRenderer sr;
53 private jalview.renderer.seqfeatures.FeatureRenderer fr;
55 private OverviewDimensions od;
57 private OverviewRenderer or = null;
59 private AlignViewportI av;
61 private ProgressPanel progressPanel;
63 public OverviewCanvas(OverviewDimensions overviewDims,
64 AlignViewportI alignvp, ProgressPanel pp)
70 sr = new SequenceRenderer(av);
71 sr.renderGaps = false;
72 sr.forOverview = true;
73 fr = new jalview.renderer.seqfeatures.FeatureRenderer(av);
75 setSize(od.getWidth(), od.getHeight());
79 * Update the overview dimensions object used by the canvas (e.g. if we change
80 * from showing hidden columns to hiding them or vice versa)
84 public void resetOviewDims(OverviewDimensions overviewDims)
90 * Signals to drawing code that the associated alignment viewport has changed
91 * and a redraw will be required
93 public boolean restartDraw()
107 updaterunning = true;
114 * Draw the overview sequences
116 * @param showSequenceFeatures
117 * true if sequence features are to be shown
118 * @param showAnnotation
119 * true if the annotation is to be shown
120 * @param transferRenderer
121 * the renderer to transfer feature colouring from
123 public void draw(boolean showSequenceFeatures, boolean showAnnotation,
124 FeatureRenderer transferRenderer)
128 if (showSequenceFeatures)
130 fr.transferSettings(transferRenderer);
133 or = new OverviewRenderer(sr, fr, od);
134 or.addPropertyChangeListener(progressPanel);
135 miniMe = or.draw(od.getRows(av.getAlignment()),
136 od.getColumns(av.getAlignment()));
138 Graphics mg = miniMe.getGraphics();
142 mg.translate(0, od.getSequencesHeight());
143 or.drawGraph(mg, av.getAlignmentConservationAnnotation(),
144 av.getCharWidth(), od.getGraphHeight(),
145 od.getColumns(av.getAlignment()));
146 mg.translate(0, -od.getSequencesHeight());
150 or.removePropertyChangeListener(progressPanel);
157 draw(showSequenceFeatures, showAnnotation, transferRenderer);
162 updaterunning = false;
168 public void paintComponent(Graphics g)
172 if (lastMiniMe == null)
174 g.setColor(Color.white);
175 g.fillRect(0, 0, getWidth(), getHeight());
179 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
181 g.setColor(TRANS_GREY);
182 g.fillRect(0, 0, getWidth(), getHeight());
184 else if (lastMiniMe != null)
187 if ((getWidth() > 0) && (getHeight() > 0)
188 && ((getWidth() != od.getWidth())
189 || (getHeight() != od.getHeight())))
191 // if there is annotation, scale the alignment and annotation separately
192 if (od.getGraphHeight() > 0)
194 BufferedImage topImage = lastMiniMe.getSubimage(0, 0,
195 od.getWidth(), od.getSequencesHeight());
196 BufferedImage bottomImage = lastMiniMe.getSubimage(0,
197 od.getSequencesHeight(), od.getWidth(),
198 od.getGraphHeight());
200 // must be done at this point as we rely on using old width/height
201 // above, and new width/height below
202 od.setWidth(getWidth());
203 od.setHeight(getHeight());
205 // stick the images back together so lastMiniMe is consistent in the
206 // event of a repaint - BUT probably not thread safe
207 lastMiniMe = new BufferedImage(od.getWidth(), od.getHeight(),
208 BufferedImage.TYPE_INT_RGB);
209 Graphics lg = lastMiniMe.getGraphics();
210 lg.drawImage(topImage, 0, 0, od.getWidth(),
211 od.getSequencesHeight(), null);
212 lg.drawImage(bottomImage, 0, od.getSequencesHeight(),
213 od.getWidth(), od.getGraphHeight(), this);
218 od.setWidth(getWidth());
219 od.setHeight(getHeight());
222 // scale lastMiniMe to the new size
223 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
225 // make sure the box is in the right place
226 od.setBoxPosition(av.getAlignment().getHiddenSequences(),
227 av.getAlignment().getHiddenColumns());
231 // fall back to normal behaviour
232 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
237 g.setColor(Color.red);
241 public void dispose()