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.bin.Cache;
25 import jalview.renderer.OverviewRenderer;
26 import jalview.renderer.OverviewResColourFinder;
27 import jalview.viewmodel.OverviewDimensions;
29 import java.awt.Color;
30 import java.awt.Dimension;
31 import java.awt.Graphics;
32 import java.awt.image.BufferedImage;
34 import javax.swing.JComponent;
36 public class OverviewCanvas extends JComponent
38 private static final Color TRANS_GREY = new Color(100, 100, 100, 25);
40 // This is set true if the alignment view changes whilst
41 // the overview is being calculated
42 private volatile boolean restart = false;
44 private volatile boolean updaterunning = false;
46 private BufferedImage miniMe;
48 private BufferedImage lastMiniMe = null;
50 // Can set different properties in this seqCanvas than
51 // main visible SeqCanvas
52 private SequenceRenderer sr;
54 private jalview.renderer.seqfeatures.FeatureRenderer fr;
56 private OverviewDimensions od;
58 private OverviewRenderer or = null;
60 private AlignViewportI av;
62 private OverviewResColourFinder cf;
64 public OverviewCanvas(OverviewDimensions overviewDims,
65 AlignViewportI alignvp)
70 sr = new SequenceRenderer(av);
71 sr.renderGaps = false;
72 fr = new jalview.renderer.seqfeatures.FeatureRenderer(av);
74 boolean useLegacy = Cache.getDefault("USE_LEGACY_GAP", false);
75 Color gapCol = Cache.getDefaultColour("GAP_COLOUR", Color.lightGray);
76 Color hiddenCol = Cache.getDefaultColour("HIDDEN_COLOUR",
77 Color.DARK_GRAY.darker());
78 cf = new OverviewResColourFinder(useLegacy, gapCol, hiddenCol);
82 * Update the overview dimensions object used by the canvas (e.g. if we change
83 * from showing hidden columns to hiding them or vice versa)
87 public void resetOviewDims(OverviewDimensions overviewDims)
93 * Signals to drawing code that the associated alignment viewport has changed
94 * and a redraw will be required
96 public boolean restartDraw()
110 updaterunning = true;
117 * Draw the overview sequences
119 * @param showSequenceFeatures
120 * true if sequence features are to be shown
121 * @param showAnnotation
122 * true if the annotation is to be shown
123 * @param transferRenderer
124 * the renderer to transfer feature colouring from
126 public void draw(boolean showSequenceFeatures, boolean showAnnotation,
127 FeatureRenderer transferRenderer)
131 if (showSequenceFeatures)
133 fr.transferSettings(transferRenderer);
136 setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
138 or = new OverviewRenderer(fr, od, av.getAlignment(),
139 av.getResidueShading(), cf);
140 miniMe = or.draw(od.getRows(av.getAlignment()),
141 od.getColumns(av.getAlignment()));
143 Graphics mg = miniMe.getGraphics();
147 mg.translate(0, od.getSequencesHeight());
148 or.drawGraph(mg, av.getAlignmentConservationAnnotation(),
149 av.getCharWidth(), od.getGraphHeight(),
150 od.getColumns(av.getAlignment()));
151 mg.translate(0, -od.getSequencesHeight());
158 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)
186 g.drawImage(lastMiniMe, 0, 0, this);
187 if (lastMiniMe != miniMe)
189 g.setColor(TRANS_GREY);
190 g.fillRect(0, 0, getWidth(), getHeight());
194 g.setColor(Color.red);