ec638a7a0ac11ac2dc6bcc7df8aad13078f3616c
[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 jalview.datamodel.SequenceGroup;
24 import jalview.datamodel.SequenceI;
25 import jalview.util.Comparison;
26
27 import java.awt.Color;
28
29 public class OverviewResColourFinder extends ResidueColourFinder
30 {
31   final Color GAP_COLOUR = new Color(240, 240, 240);
32
33   @Override
34   public Color getBoxColour(ResidueShaderI shader, SequenceI seq, int i)
35   {
36     Color resBoxColour = Color.white;
37     char currentChar = seq.getCharAt(i);
38
39     // In the overview window, gaps are coloured grey, unless the colour scheme
40     // specifies a gap colour, in which case gaps honour the colour scheme
41     // settings
42     if (shader.getColourScheme() != null)
43     {
44       if (Comparison.isGap(currentChar)
45               && !shader.getColourScheme().hasGapColour())
46       {
47         resBoxColour = GAP_COLOUR;
48       }
49       else
50       {
51         resBoxColour = shader.findColour(currentChar, i, seq);
52       }
53     }
54     else if (Comparison.isGap(currentChar))
55     {
56       resBoxColour = GAP_COLOUR;
57     }
58
59     return resBoxColour;
60   }
61
62   /**
63    * {@inheritDoc} In the overview, the showBoxes setting is ignored, as the
64    * overview displays the colours regardless.
65    */
66   @Override
67   protected Color getResidueBoxColour(boolean showBoxes,
68           ResidueShaderI shader,
69           SequenceGroup[] allGroups, SequenceI seq, int i)
70   {
71     ResidueShaderI currentShader;
72     SequenceGroup currentSequenceGroup = getCurrentSequenceGroup(allGroups,
73             i);
74     if (currentSequenceGroup != null)
75     {
76       currentShader = currentSequenceGroup.getGroupColourScheme();
77     }
78     else
79     {
80       currentShader = shader;
81     }
82
83     return getBoxColour(currentShader, seq, i);
84   }
85 }