Clover icon

Coverage Report

  1. Project Clover database Mon Nov 18 2024 09:56:54 GMT
  2. Package jalview.gui

File OverviewCanvas.java

 

Coverage histogram

../../img/srcFileCovDistChart9.png
12% of files have more coverage

Code metrics

28
80
10
1
323
213
29
0.36
8
10
2.9

Classes

Class Line # Actions
OverviewCanvas 39 80 29
0.889830589%
 

Contributing tests

This file is covered by 11 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.gui;
22   
23    import java.awt.Color;
24    import java.awt.Dimension;
25    import java.awt.Graphics;
26    import java.awt.image.BufferedImage;
27    import java.awt.image.RasterFormatException;
28   
29    import javax.swing.JPanel;
30   
31    import jalview.api.AlignViewportI;
32    import jalview.bin.Cache;
33    import jalview.bin.Console;
34    import jalview.renderer.OverviewRenderer;
35    import jalview.renderer.OverviewResColourFinder;
36    import jalview.viewmodel.OverviewDimensions;
37    import jalview.viewmodel.seqfeatures.FeatureRendererModel;
38   
 
39    public class OverviewCanvas extends JPanel
40    {
41    public static final Color OVERVIEW_DEFAULT_GAP = Color.lightGray;
42   
43    public static final Color OVERVIEW_DEFAULT_LEGACY_GAP = Color.white;
44   
45    public static final Color OVERVIEW_DEFAULT_RESIDUE = Color.white;
46   
47    public static final Color OVERVIEW_DEFAULT_LEGACY_RESIDUE = Color.lightGray;
48   
49    public static final Color OVERVIEW_DEFAULT_HIDDEN = Color.darkGray
50    .darker();
51   
52    private static final Color TRANS_GREY = new Color(100, 100, 100, 25);
53   
54    // This is set true if the alignment view changes whilst
55    // the overview is being calculated
56    private volatile boolean restart = false;
57   
58    private volatile boolean updaterunning = false;
59   
60    private boolean dispose = false;
61   
62    private BufferedImage miniMe;
63   
64    private BufferedImage lastMiniMe = null;
65   
66    // Can set different properties in this seqCanvas than
67    // main visible SeqCanvas
68    private SequenceRenderer sr;
69   
70    private jalview.renderer.seqfeatures.FeatureRenderer fr;
71   
72    private OverviewDimensions od;
73   
74    private OverviewRenderer or = null;
75   
76    private AlignViewportI av;
77   
78    private OverviewResColourFinder cf;
79   
80    private ProgressPanel progressPanel;
81   
 
82  38 toggle public OverviewCanvas(OverviewDimensions overviewDims,
83    AlignViewportI alignvp, ProgressPanel pp)
84    {
85  38 od = overviewDims;
86  38 av = alignvp;
87  38 progressPanel = pp;
88   
89  38 sr = new SequenceRenderer(av);
90  38 sr.renderGaps = false;
91  38 fr = new jalview.renderer.seqfeatures.FeatureRenderer(av);
92   
93  38 boolean useLegacy = Cache.getDefault(Preferences.USE_LEGACY_GAP, false);
94  38 Color gapCol = Cache.getDefaultColour(Preferences.GAP_COLOUR,
95    OVERVIEW_DEFAULT_GAP);
96  38 Color hiddenCol = Cache.getDefaultColour(Preferences.HIDDEN_COLOUR,
97    OVERVIEW_DEFAULT_HIDDEN);
98  38 Color residueCol = useLegacy ? OVERVIEW_DEFAULT_LEGACY_RESIDUE
99    : OVERVIEW_DEFAULT_RESIDUE;
100   
101  38 cf = new OverviewResColourFinder(gapCol, residueCol, hiddenCol);
102   
103  38 setSize(od.getWidth(), od.getHeight());
104    }
105   
106    /**
107    * Update the overview dimensions object used by the canvas (e.g. if we change
108    * from showing hidden columns to hiding them or vice versa)
109    *
110    * @param overviewDims
111    */
 
112  0 toggle public void resetOviewDims(OverviewDimensions overviewDims)
113    {
114  0 od = overviewDims;
115    }
116   
117    /**
118    * Signals to drawing code that the associated alignment viewport has changed
119    * and a redraw will be required
120    */
 
121  428 toggle public boolean restartDraw()
122    {
123  428 synchronized (this)
124    {
125  428 if (updaterunning)
126    {
127  332 restart = true;
128  332 if (or != null)
129    {
130  202 or.setRedraw(true);
131    }
132    }
133    else
134    {
135  96 updaterunning = true;
136    }
137  427 return restart;
138    }
139    }
140   
141    /**
142    * Draw the overview sequences
143    *
144    * @param showSequenceFeatures
145    * true if sequence features are to be shown
146    * @param showAnnotation
147    * true if the annotation is to be shown
148    * @param transferRenderer
149    * the renderer to transfer feature colouring from
150    */
 
151  245 toggle public void draw(boolean showSequenceFeatures, boolean showAnnotation,
152    FeatureRendererModel transferRenderer)
153    {
154  245 miniMe = null;
155   
156  245 if (showSequenceFeatures)
157    {
158  35 fr.transferSettings(transferRenderer);
159    }
160   
161  245 setPreferredSize(new Dimension(od.getWidth(), od.getHeight()));
162   
163  245 or = new OverviewRenderer(fr, od, av.getAlignment(),
164    av.getResidueShading(), cf);
165   
166  245 or.addPropertyChangeListener(progressPanel);
167   
168  245 miniMe = or.draw(od.getRows(av.getAlignment()),
169    od.getColumns(av.getAlignment()));
170   
171  245 Graphics mg = miniMe.getGraphics();
172   
173  245 if (showAnnotation)
174    {
175  245 mg.translate(0, od.getSequencesHeight());
176  240 or.drawGraph(mg, av.is3di() ? av.getAlignmentQualityAnnot() : av.getAlignmentConservationAnnotation(),
177    od.getGraphHeight(), od.getColumns(av.getAlignment()));
178  236 mg.translate(0, -od.getSequencesHeight());
179    }
180   
181  236 or.removePropertyChangeListener(progressPanel);
182  236 or = null;
183  236 if (restart)
184    {
185  146 restart = false;
186  146 if (!dispose)
187    {
188  146 draw(showSequenceFeatures, showAnnotation, transferRenderer);
189    }
190    }
191    else
192    {
193  90 updaterunning = false;
194  90 lastMiniMe = miniMe;
195    }
196    }
197   
 
198  21 toggle @Override
199    public void paintComponent(Graphics g)
200    {
201    // super.paintComponent(g);
202   
203  21 if (restart)
204    {
205  1 if (lastMiniMe == null)
206    {
207  1 g.setColor(Color.white);
208  1 g.fillRect(0, 0, getWidth(), getHeight());
209    }
210    else
211    {
212  0 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
213    }
214  1 g.setColor(TRANS_GREY);
215  1 g.fillRect(0, 0, getWidth(), getHeight());
216    }
217  20 else if (lastMiniMe != null)
218    {
219    // is this a resize?
220  17 if ((getWidth() > 0) && (getHeight() > 0)
221    && ((getWidth() != od.getWidth())
222    || (getHeight() != od.getHeight())))
223    {
224    // if there is annotation, scale the alignment and annotation
225    // separately
226  1 if (od.getGraphHeight() > 0 && od.getSequencesHeight() > 0 // BH 2019
227    )
228    {
229  1 try
230    {
231  1 BufferedImage topImage = lastMiniMe.getSubimage(0, 0,
232    od.getWidth(), od.getSequencesHeight());
233  1 BufferedImage bottomImage = lastMiniMe.getSubimage(0,
234    od.getSequencesHeight(), od.getWidth(),
235    od.getGraphHeight());
236   
237    // must be done at this point as we rely on using old width/height
238    // above, and new width/height below
239  1 od.setWidth(getWidth());
240  1 od.setHeight(getHeight());
241   
242    // stick the images back together so lastMiniMe is consistent in the
243    // event of a repaint - BUT probably not thread safe
244  1 lastMiniMe = new BufferedImage(od.getWidth(), od.getHeight(),
245    BufferedImage.TYPE_INT_RGB);
246  1 Graphics lg = lastMiniMe.getGraphics();
247  1 lg.drawImage(topImage, 0, 0, od.getWidth(),
248    od.getSequencesHeight(), null);
249  1 lg.drawImage(bottomImage, 0, od.getSequencesHeight(),
250    od.getWidth(), od.getGraphHeight(), this);
251  1 lg.dispose();
252    } catch (RasterFormatException e)
253    {
254  0 Console.debug(
255    "Scaling miscalculation resizing Overview window");
256  0 od.setWidth(getWidth());
257  0 od.setHeight(getHeight());
258    }
259    }
260    else
261    {
262  0 od.setWidth(getWidth());
263  0 od.setHeight(getHeight());
264    }
265   
266    // make sure the box is in the right place
267  1 od.setBoxPosition(av.getAlignment().getHiddenSequences(),
268    av.getAlignment().getHiddenColumns());
269    }
270    // fall back to normal behaviour
271  17 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
272    }
273    else
274    {
275  3 g.drawImage(lastMiniMe, 0, 0, getWidth(), getHeight(), this);
276    }
277   
278    // draw the box
279  21 g.setColor(Color.red);
280  21 od.drawBox(g);
281    }
282   
 
283  35 toggle public void dispose()
284    {
285  35 dispose = true;
286  35 od = null;
287  35 synchronized (this)
288    {
289  35 restart = true;
290  35 if (or != null)
291    {
292  4 or.setRedraw(true);
293    }
294    }
295    }
296   
 
297  14 toggle public Color getGapColour()
298    {
299  14 return cf.getGapColour();
300    }
301   
 
302  14 toggle public Color getHiddenColour()
303    {
304  14 return cf.getHiddenColour();
305    }
306   
 
307  14 toggle public Color getResidueColour()
308    {
309  14 return cf.getResidueColour();
310    }
311   
312    /**
313    * Sets the colours to use for gaps, residues and hidden regions
314    *
315    * @param gaps
316    * @param residues
317    * @param hidden
318    */
 
319  9 toggle public void setColours(Color gaps, Color residues, Color hidden)
320    {
321  9 cf = new OverviewResColourFinder(gaps, residues, hidden);
322    }
323    }