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 setSize(int width, int height)
160 // TODO Auto-generated method stub
161 super.setSize(width, height);
165 public void paintComponent(Graphics g)
169 if (lastMiniMe == null)
171 g.setColor(Color.white);
172 g.fillRect(0, 0, getWidth(), getHeight());
176 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
178 g.setColor(TRANS_GREY);
179 g.fillRect(0, 0, getWidth(), getHeight());
181 else if (lastMiniMe != null)
183 if ((getWidth() > 0) && (getHeight() > 0)
184 && ((getWidth() != od.getWidth())
185 || (getHeight() != od.getHeight())))
187 // scale the alignment and annotation separately *** if there is
189 if (od.getGraphHeight() > 0)
191 BufferedImage topImage = lastMiniMe.getSubimage(0, 0,
192 od.getWidth(), od.getSequencesHeight());
193 BufferedImage bottomImage = lastMiniMe.getSubimage(0,
194 od.getSequencesHeight(), od.getWidth(),
195 od.getGraphHeight());
197 od.setWidth(getWidth());
198 od.setHeight(getHeight());
200 // stick the images back together so lastMiniMe is consistent in the
203 lastMiniMe = new BufferedImage(od.getWidth(), od.getHeight(),
204 BufferedImage.TYPE_INT_RGB);
205 Graphics lg = lastMiniMe.getGraphics();
206 lg.drawImage(topImage, 0, 0, od.getWidth(),
207 od.getSequencesHeight(), null);
208 lg.drawImage(bottomImage, 0, od.getSequencesHeight(),
209 od.getWidth(), od.getGraphHeight(), this);
213 g.drawImage(lastMiniMe, 0, 0, od.getWidth(), od.getHeight(), null);
217 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
218 if (lastMiniMe != miniMe)
220 g.setColor(TRANS_GREY);
221 g.fillRect(0, 0, getWidth(), getHeight());
227 g.setColor(Color.red);
230 od.setBoxPosition(av.getAlignment().getHiddenSequences(),
231 av.getAlignment().getHiddenColumns());