Clover icon

jalviewX

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

File FeatureColourFinder.java

 

Coverage histogram

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

Code metrics

16
23
3
1
144
63
13
0.57
7.67
3
4.33

Classes

Class Line # Actions
FeatureColourFinder 38 23 13 1
0.9761904597.6%
 

Contributing tests

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