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.
21 package jalview.appletgui;
23 import jalview.renderer.OverviewRenderer;
24 import jalview.renderer.OverviewResColourFinder;
25 import jalview.viewmodel.OverviewDimensions;
27 import java.awt.Color;
28 import java.awt.Component;
29 import java.awt.Dimension;
30 import java.awt.Frame;
31 import java.awt.Graphics;
32 import java.awt.Image;
33 import java.awt.image.BufferedImage;
35 @SuppressWarnings("serial")
36 public class OverviewCanvas extends Component
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 OverviewDimensions od;
46 private OverviewRenderer or = null;
50 private Image offscreen;
52 private AlignViewport av;
54 private boolean showSequenceFeatures;
56 private boolean showAnnotation;
58 private jalview.api.FeatureRenderer featureRenderer;
60 private jalview.renderer.seqfeatures.FeatureRenderer fr;
62 private Frame nullFrame;
64 private OverviewPanel panel;
66 public OverviewCanvas(OverviewPanel panel,
67 OverviewDimensions overviewDims,
68 AlignViewport alignvp)
74 nullFrame = new Frame();
75 nullFrame.addNotify();
77 fr = new jalview.renderer.seqfeatures.FeatureRenderer(av);
81 * Update the overview dimensions object used by the canvas (e.g. if we change
82 * from showing hidden columns to hiding them or vice versa)
86 public void resetOviewDims(OverviewDimensions overviewDims)
92 * Signals to drawing code that the associated alignment viewport has changed
93 * and a redraw will be required
95 public boolean restartDraw()
109 updaterunning = true;
115 public void draw(boolean showSequenceFeatures, boolean showAnnotation,
116 jalview.api.FeatureRenderer featureRenderer)
118 this.showSequenceFeatures = showSequenceFeatures;
119 this.showAnnotation = showAnnotation;
120 this.featureRenderer = featureRenderer;
122 if (showSequenceFeatures)
124 fr.transferSettings(featureRenderer);
127 setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
129 or = new OverviewRenderer(panel.ap, fr, od, av.getAlignment(),
130 av.getResidueShading(), new OverviewResColourFinder());
131 offscreen = nullFrame.createImage(od.getWidth(), od.getHeight());
136 public void update(Graphics g)
142 public void paint(Graphics g)
146 Graphics og = offscreen.getGraphics();
147 og.drawImage(miniMe, 0, 0, this);
148 og.setColor(Color.red);
150 g.drawImage(offscreen, 0, 0, this);
156 * Nulls references to protect against potential memory leaks
163 public void finalizeDraw(BufferedImage miniMe)
168 draw(showSequenceFeatures, showAnnotation, featureRenderer);
172 this.miniMe = miniMe;
173 // checks for conservation annotation to make sure overview works for DNA
177 or.drawGraph(av.getAlignmentConservationAnnotation());
179 updaterunning = false;