Clover icon

Coverage Report

  1. Project Clover database Fri Nov 1 2024 11:46:37 GMT
  2. Package jalview.renderer.seqfeatures

File FeatureColourFinder.java

 

Coverage histogram

../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

20
28
3
1
153
72
14
0.5
9.33
3
4.67

Classes

Class Line # Actions
FeatureColourFinder 39 28 14
0.941176594.1%
 

Contributing tests

This file is covered by 56 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.renderer.seqfeatures;
22   
23    import jalview.api.AlignViewportI;
24    import jalview.api.FeatureRenderer;
25    import jalview.api.FeaturesDisplayedI;
26    import jalview.datamodel.SequenceI;
27    import jalview.viewmodel.seqfeatures.FeatureRendererModel;
28   
29    import java.awt.Color;
30    import java.awt.Graphics;
31    import java.awt.image.BufferedImage;
32   
33    /**
34    * A helper class to find feature colour using an associated FeatureRenderer
35    *
36    * @author gmcarstairs
37    *
38    */
 
39    public class FeatureColourFinder
40    {
41    /*
42    * the class we delegate feature finding to
43    */
44    private FeatureRenderer featureRenderer;
45   
46    /*
47    * a 1-pixel image on which features can be drawn, for the case where
48    * transparency allows 'see-through' of multiple feature colours
49    */
50    private BufferedImage offscreenImage;
51   
52    /**
53    * Constructor
54    *
55    * @param fr
56    */
 
57  558 toggle public FeatureColourFinder(FeatureRenderer fr)
58    {
59  558 featureRenderer = fr;
60  558 offscreenImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
61    }
62   
63    /**
64    * Answers the feature colour to show for the given sequence and column
65    * position. This delegates to the FeatureRenderer to find the colour, which
66    * will depend on feature location, visibility, ordering, colour scheme, and
67    * whether or not transparency is applied. For feature rendering with
68    * transparency, this class provides a dummy 'offscreen' graphics context
69    * where multiple feature colours can be overlaid and the combined colour read
70    * back.
71    * <p>
72    * This method is not thread-safe when transparency is applied, since a shared
73    * BufferedImage would be used by all threads to hold the composite colour at
74    * a position. Each thread should use a separate instance of this class.
75    *
76    * @param defaultColour
77    * @param seq
78    * @param column
79    * alignment column position (0..)
80    * @return
81    */
 
82  366746 toggle public Color findFeatureColour(Color defaultColour, SequenceI seq,
83    int column)
84    {
85  366852 if (noFeaturesDisplayed())
86    {
87  341668 return defaultColour;
88    }
89   
90  25187 Graphics g = null;
91   
92    /*
93    * if transparency applies, provide a notional 1x1 graphics context
94    * that has been primed with the default colour
95    */
96  25187 if (featureRenderer.getTransparency() != 1f)
97    {
98  4 g = offscreenImage.getGraphics();
99  4 if (defaultColour != null)
100    {
101  4 offscreenImage.setRGB(0, 0, defaultColour.getRGB());
102    }
103    }
104   
105  25187 Color c = featureRenderer.findFeatureColour(seq, column + 1, g);
106  25187 if (c == null)
107    {
108  17458 return defaultColour;
109    }
110   
111  7729 if (g != null)
112    {
113  4 c = new Color(offscreenImage.getRGB(0, 0));
114    }
115  7729 return c;
116    }
117   
118    /**
119    * Answers true if feature display is turned off, or there are no features
120    * configured to be visible
121    *
122    * @return
123    */
 
124  366742 toggle boolean noFeaturesDisplayed()
125    {
126  366787 if (featureRenderer == null)
127    {
128  1 return true;
129    }
130  366803 AlignViewportI av = featureRenderer.getViewport();
131  366841 if (av.isShowComplementFeatures())
132    {
133  0 return false;
134    }
135  366860 if (!av.isShowSequenceFeatures())
136    {
137  338184 return true;
138    }
139   
140  28690 if (!((FeatureRendererModel) featureRenderer).hasRenderOrder())
141    {
142  3498 return true;
143    }
144   
145  25192 FeaturesDisplayedI displayed = featureRenderer.getFeaturesDisplayed();
146  25192 if (displayed == null || displayed.getVisibleFeatureCount() == 0)
147    {
148  2 return true;
149    }
150   
151  25190 return false;
152    }
153    }