8fa0e233f1d6094def9e1185ceb3cd7cf9355a01
[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;
32
33   final Color RESIDUE_COLOUR;
34
35   final Color HIDDEN_COLOUR;
36
37   boolean useLegacy = false;
38
39   public OverviewResColourFinder()
40   {
41     GAP_COLOUR = Color.lightGray; // new Color(240, 240, 240);
42     RESIDUE_COLOUR = Color.white;
43     HIDDEN_COLOUR = Color.DARK_GRAY.darker();
44   }
45
46   public OverviewResColourFinder(boolean useLegacyColouring, Color gapCol,
47           Color hiddenCol)
48   {
49     if (useLegacyColouring)
50     {
51       GAP_COLOUR = Color.white;
52       RESIDUE_COLOUR = Color.lightGray;
53       HIDDEN_COLOUR = hiddenCol;
54     }
55     else
56     {
57       GAP_COLOUR = gapCol;
58       RESIDUE_COLOUR = Color.white;
59       HIDDEN_COLOUR = hiddenCol;
60     }
61   }
62
63   @Override
64   public Color getBoxColour(ResidueShaderI shader, SequenceI seq, int i)
65   {
66     Color resBoxColour = RESIDUE_COLOUR;
67     char currentChar = seq.getCharAt(i);
68
69     // In the overview window, gaps are coloured grey, unless the colour scheme
70     // specifies a gap colour, in which case gaps honour the colour scheme
71     // settings
72     if (shader.getColourScheme() != null)
73     {
74       if (!shader.getColourScheme().hasGapColour()
75               && Comparison.isGap(currentChar))
76       {
77         resBoxColour = GAP_COLOUR;
78       }
79       else
80       {
81         resBoxColour = shader.findColour(currentChar, i, seq);
82       }
83     }
84     else if (Comparison.isGap(currentChar))
85     {
86       resBoxColour = GAP_COLOUR;
87     }
88
89     return resBoxColour;
90   }
91
92   /**
93    * {@inheritDoc} In the overview, the showBoxes setting is ignored, as the
94    * overview displays the colours regardless.
95    */
96   @Override
97   protected Color getResidueBoxColour(boolean showBoxes,
98           ResidueShaderI shader,
99           SequenceGroup[] allGroups, SequenceI seq, int i)
100   {
101     ResidueShaderI currentShader;
102     SequenceGroup currentSequenceGroup = getCurrentSequenceGroup(allGroups,
103             i);
104     if (currentSequenceGroup != null)
105     {
106       currentShader = currentSequenceGroup.getGroupColourScheme();
107     }
108     else
109     {
110       currentShader = shader;
111     }
112
113     return getBoxColour(currentShader, seq, i);
114   }
115
116   protected Color getHiddenColour()
117   {
118     return HIDDEN_COLOUR;
119   }
120 }