JAL-629 Tidy up tests and replaced methods before merge to develop
[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    * @deprecated
52    */
53   @Deprecated
54   public OverviewResColourFinder()
55   {
56     this(Color.lightGray, Color.white, Color.darkGray.darker());
57   }
58
59   /**
60    * Constructor given default colours for gaps, residues and hidden regions
61    * 
62    * @param gaps
63    * @param residues
64    * @param hidden
65    */
66   public OverviewResColourFinder(Color gaps, Color residues, Color hidden)
67   {
68     gapColour = gaps;
69     residueColour = residues;
70     hiddenColour = hidden;
71   }
72
73   @Override
74   public Color getBoxColour(ResidueShaderI shader, SequenceI seq, int i)
75   {
76     Color resBoxColour = residueColour;
77     char currentChar = seq.getCharAt(i);
78
79     // In the overview window, gaps are coloured grey, unless the colour scheme
80     // specifies a gap colour, in which case gaps honour the colour scheme
81     // settings
82     if (shader.getColourScheme() != null)
83     {
84       if (Comparison.isGap(currentChar)
85               && (!shader.getColourScheme().hasGapColour()))
86       {
87         resBoxColour = gapColour;
88       }
89       else
90       {
91         resBoxColour = shader.findColour(currentChar, i, seq);
92       }
93     }
94     else if (Comparison.isGap(currentChar))
95     {
96       resBoxColour = gapColour;
97     }
98
99     return resBoxColour;
100   }
101
102   /**
103    * {@inheritDoc} In the overview, the showBoxes setting is ignored, as the
104    * overview displays the colours regardless.
105    */
106   @Override
107   protected Color getResidueBoxColour(boolean showBoxes,
108           ResidueShaderI shader, SequenceGroup[] allGroups, SequenceI seq,
109           int i)
110   {
111     ResidueShaderI currentShader;
112     SequenceGroup currentSequenceGroup = getCurrentSequenceGroup(allGroups,
113             i);
114     if (currentSequenceGroup != null)
115     {
116       currentShader = currentSequenceGroup.getGroupColourScheme();
117     }
118     else
119     {
120       currentShader = shader;
121     }
122
123     return getBoxColour(currentShader, seq, i);
124   }
125
126   /**
127    * Returns the colour used for hidden regions
128    * 
129    * @return
130    */
131   public Color getHiddenColour()
132   {
133     return hiddenColour;
134   }
135
136   /**
137    * Returns the colour used for gaps, if not overridden by the alignment colour
138    * scheme
139    * 
140    * @return
141    */
142   public Color getGapColour()
143   {
144     return gapColour;
145   }
146
147   /**
148    * Returns the colour used for residues (before applying any feature
149    * colouring) if there is no alignment colour scheme
150    * 
151    * @return
152    */
153   public Color getResidueColour()
154   {
155     return residueColour;
156   }
157 }