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.Dimension;
29 import java.awt.Graphics;
30 import java.awt.image.BufferedImage;
32 import javax.swing.JComponent;
34 public class OverviewCanvas extends JComponent
36 private static final Color TRANS_GREY = new Color(100, 100, 100, 25);
38 // This is set true if the alignment view changes whilst
39 // the overview is being calculated
40 private volatile boolean restart = false;
42 private volatile boolean updaterunning = false;
44 private BufferedImage miniMe;
46 private BufferedImage lastMiniMe = null;
48 // Can set different properties in this seqCanvas than
49 // main visible SeqCanvas
50 private SequenceRenderer sr;
52 private jalview.renderer.seqfeatures.FeatureRenderer fr;
54 private OverviewDimensions od;
56 private AlignViewportI av;
58 public OverviewCanvas(OverviewDimensions overviewDims,
59 AlignViewportI alignvp)
64 sr = new SequenceRenderer(av);
65 sr.renderGaps = false;
66 sr.forOverview = true;
67 fr = new jalview.renderer.seqfeatures.FeatureRenderer(av);
71 * Update the overview dimensions object used by the canvas (e.g. if we change
72 * from showing hidden columns to hiding them or vice versa)
76 public void resetOviewDims(OverviewDimensions overviewDims)
82 * Signals to drawing code that the associated alignment viewport has changed
83 * and a redraw will be required
85 public boolean restartDraw()
102 * Draw the overview sequences
104 * @param showSequenceFeatures
105 * true if sequence features are to be shown
106 * @param showAnnotation
107 * true if the annotation is to be shown
108 * @param transferRenderer
109 * the renderer to transfer feature colouring from
111 public void draw(boolean showSequenceFeatures, boolean showAnnotation,
112 FeatureRenderer transferRenderer)
116 if (showSequenceFeatures)
118 fr.transferSettings(transferRenderer);
121 setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
123 OverviewRenderer or = new OverviewRenderer(sr, fr, od);
124 miniMe = or.draw(od.getRows(av.getAlignment()),
125 od.getColumns(av.getAlignment()));
127 Graphics mg = miniMe.getGraphics();
131 mg.translate(0, od.getSequencesHeight());
132 or.drawGraph(mg, av.getAlignmentConservationAnnotation(),
133 av.getCharWidth(), od.getGraphHeight(),
134 od.getColumns(av.getAlignment()));
135 mg.translate(0, -od.getSequencesHeight());
142 draw(showSequenceFeatures, showAnnotation, transferRenderer);
146 updaterunning = false;
152 public void paintComponent(Graphics g)
156 if (lastMiniMe == null)
158 g.setColor(Color.white);
159 g.fillRect(0, 0, getWidth(), getHeight());
163 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
165 g.setColor(TRANS_GREY);
166 g.fillRect(0, 0, getWidth(), getHeight());
168 else if (lastMiniMe != null)
170 g.drawImage(lastMiniMe, 0, 0, this);
171 if (lastMiniMe != miniMe)
173 g.setColor(TRANS_GREY);
174 g.fillRect(0, 0, getWidth(), getHeight());
178 g.setColor(Color.red);