Merge branch 'releases/Release_2_11_3_Branch'
[jalview.git] / src / jalview / renderer / OverviewResColourFinder.java
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;
22
23 import java.awt.Color;
24
25 import jalview.datamodel.SequenceGroup;
26 import jalview.datamodel.SequenceI;
27 import jalview.util.Comparison;
28
29 public class OverviewResColourFinder extends ResidueColourFinder
30 {
31   /*
32    * colour for gaps (unless overridden by colour scheme)
33    * - as set in Preferences, _or_ read from a project file
34    */
35   Color gapColour;
36
37   /*
38    * colour for residues if no colour scheme set (before feature colouring)
39    * - as set in Preferences, _or_ read from a project file
40    */
41   Color residueColour;
42
43   /*
44    * colour for hidden regions
45    * - as set in Preferences, _or_ read from a project file
46    */
47   Color hiddenColour;
48
49   /**
50    * Constructor without colour settings (used by applet)
51    * 
52    * @deprecated
53    */
54   @Deprecated
55   public OverviewResColourFinder()
56   {
57     this(Color.lightGray, Color.white, Color.darkGray.darker());
58   }
59
60   /**
61    * Constructor given default colours for gaps, residues and hidden regions
62    * 
63    * @param gaps
64    * @param residues
65    * @param hidden
66    */
67   public OverviewResColourFinder(Color gaps, Color residues, Color hidden)
68   {
69     gapColour = gaps;
70     residueColour = residues;
71     hiddenColour = hidden;
72   }
73
74   @Override
75   public Color getBoxColour(ResidueShaderI shader, SequenceI seq, int i)
76   {
77     Color resBoxColour = residueColour;
78     char currentChar = seq.getCharAt(i);
79
80     // In the overview window, gaps are coloured grey, unless the colour scheme
81     // specifies a gap colour, in which case gaps honour the colour scheme
82     // settings
83     if (shader.getColourScheme() != null)
84     {
85       if (Comparison.isGap(currentChar)
86               && (!shader.getColourScheme().hasGapColour()))
87       {
88         resBoxColour = gapColour;
89       }
90       else
91       {
92         resBoxColour = shader.findColour(currentChar, i, seq);
93       }
94     }
95     else if (Comparison.isGap(currentChar))
96     {
97       resBoxColour = gapColour;
98     }
99
100     return resBoxColour;
101   }
102
103   /**
104    * {@inheritDoc} In the overview, the showBoxes setting is ignored, as the
105    * overview displays the colours regardless.
106    */
107   @Override
108   protected Color getResidueBoxColour(boolean showBoxes,
109           ResidueShaderI shader, SequenceGroup[] allGroups, SequenceI seq,
110           int i)
111   {
112     ResidueShaderI currentShader;
113     SequenceGroup currentSequenceGroup = getCurrentSequenceGroup(allGroups,
114             i);
115     if (currentSequenceGroup != null)
116     {
117       currentShader = currentSequenceGroup.getGroupColourScheme();
118     }
119     else
120     {
121       currentShader = shader;
122     }
123
124     return getBoxColour(currentShader, seq, i);
125   }
126
127   /**
128    * Returns the colour used for hidden regions
129    * 
130    * @return
131    */
132   public Color getHiddenColour()
133   {
134     return hiddenColour;
135   }
136
137   /**
138    * Returns the colour used for gaps, if not overridden by the alignment colour
139    * scheme
140    * 
141    * @return
142    */
143   public Color getGapColour()
144   {
145     return gapColour;
146   }
147
148   /**
149    * Returns the colour used for residues (before applying any feature
150    * colouring) if there is no alignment colour scheme
151    * 
152    * @return
153    */
154   public Color getResidueColour()
155   {
156     return residueColour;
157   }
158 }