Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.gui

File OverviewCanvas.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
56% of files have more coverage

Code metrics

24
71
6
1
273
179
22
0.31
11.83
6
3.67

Classes

Class Line # Actions
OverviewCanvas 37 71 22
0.00%
 

Contributing tests

No tests hitting this source file were found.

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