Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.gui

File OverviewCanvas.java

 

Coverage histogram

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

Code metrics

24
71
6
1
269
176
21
0.3
11.83
6
3.5

Classes

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