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 OverviewRenderer or = null;
58 private AlignViewportI av;
60 public OverviewCanvas(OverviewDimensions overviewDims,
61 AlignViewportI alignvp)
66 sr = new SequenceRenderer(av);
67 sr.renderGaps = false;
68 sr.forOverview = true;
69 fr = new jalview.renderer.seqfeatures.FeatureRenderer(av);
73 * Update the overview dimensions object used by the canvas (e.g. if we change
74 * from showing hidden columns to hiding them or vice versa)
78 public void resetOviewDims(OverviewDimensions overviewDims)
84 * Signals to drawing code that the associated alignment viewport has changed
85 * and a redraw will be required
87 public boolean restartDraw()
101 updaterunning = true;
108 * Draw the overview sequences
110 * @param showSequenceFeatures
111 * true if sequence features are to be shown
112 * @param showAnnotation
113 * true if the annotation is to be shown
114 * @param transferRenderer
115 * the renderer to transfer feature colouring from
117 public void draw(boolean showSequenceFeatures, boolean showAnnotation,
118 FeatureRenderer transferRenderer)
122 if (showSequenceFeatures)
124 fr.transferSettings(transferRenderer);
127 setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
129 or = new OverviewRenderer(sr, fr, od);
130 miniMe = or.draw(od.getRows(av.getAlignment()),
131 od.getColumns(av.getAlignment()));
133 Graphics mg = miniMe.getGraphics();
137 mg.translate(0, od.getSequencesHeight());
138 or.drawGraph(mg, av.getAlignmentConservationAnnotation(),
139 av.getCharWidth(), od.getGraphHeight(),
140 od.getColumns(av.getAlignment()));
141 mg.translate(0, -od.getSequencesHeight());
148 draw(showSequenceFeatures, showAnnotation, transferRenderer);
152 updaterunning = false;
158 public void paintComponent(Graphics g)
162 if (lastMiniMe == null)
164 g.setColor(Color.white);
165 g.fillRect(0, 0, getWidth(), getHeight());
169 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
171 g.setColor(TRANS_GREY);
172 g.fillRect(0, 0, getWidth(), getHeight());
174 else if (lastMiniMe != null)
176 g.drawImage(lastMiniMe, 0, 0, this);
177 if (lastMiniMe != miniMe)
179 g.setColor(TRANS_GREY);
180 g.fillRect(0, 0, getWidth(), getHeight());
184 g.setColor(Color.red);