JAL-2527 Updates following code review
[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.gui.Preferences;
26 import jalview.util.Comparison;
27
28 import java.awt.Color;
29
30 public class OverviewResColourFinder extends ResidueColourFinder
31 {
32   final Color GAP_COLOUR; // default colour to use at gaps
33
34   final Color RESIDUE_COLOUR; // default colour to use at residues
35
36   final Color HIDDEN_COLOUR; // colour for hidden regions
37
38   boolean useLegacy = false;
39
40   /**
41    * Constructor without colour settings (used by applet)
42    */
43   public OverviewResColourFinder()
44   {
45     this(false, Preferences.OVERVIEW_DEFAULT_GAP,
46             Preferences.OVERVIEW_DEFAULT_HIDDEN);
47   }
48
49   /**
50    * Constructor with colour settings
51    * 
52    * @param useLegacyColouring
53    *          whether to use legacy gap colouring (white gaps, grey residues)
54    * @param gapCol
55    *          gap colour if not legacy
56    * @param hiddenCol
57    *          hidden region colour (transparency applied by rendering code)
58    */
59   public OverviewResColourFinder(boolean useLegacyColouring, Color gapCol,
60           Color hiddenCol)
61   {
62     if (useLegacyColouring)
63     {
64       GAP_COLOUR = Color.white;
65       RESIDUE_COLOUR = Color.lightGray;
66       HIDDEN_COLOUR = hiddenCol;
67     }
68     else
69     {
70       GAP_COLOUR = gapCol;
71       RESIDUE_COLOUR = Color.white;
72       HIDDEN_COLOUR = hiddenCol;
73     }
74   }
75
76   @Override
77   public Color getBoxColour(ResidueShaderI shader, SequenceI seq, int i)
78   {
79     Color resBoxColour = RESIDUE_COLOUR;
80     char currentChar = seq.getCharAt(i);
81
82     // In the overview window, gaps are coloured grey, unless the colour scheme
83     // specifies a gap colour, in which case gaps honour the colour scheme
84     // settings
85     if (shader.getColourScheme() != null)
86     {
87       if (Comparison.isGap(currentChar)
88               && (!shader.getColourScheme().hasGapColour()))
89       {
90         resBoxColour = GAP_COLOUR;
91       }
92       else
93       {
94         resBoxColour = shader.findColour(currentChar, i, seq);
95       }
96     }
97     else if (Comparison.isGap(currentChar))
98     {
99       resBoxColour = GAP_COLOUR;
100     }
101
102     return resBoxColour;
103   }
104
105   /**
106    * {@inheritDoc} In the overview, the showBoxes setting is ignored, as the
107    * overview displays the colours regardless.
108    */
109   @Override
110   protected Color getResidueBoxColour(boolean showBoxes,
111           ResidueShaderI shader,
112           SequenceGroup[] allGroups, SequenceI seq, int i)
113   {
114     ResidueShaderI currentShader;
115     SequenceGroup currentSequenceGroup = getCurrentSequenceGroup(allGroups,
116             i);
117     if (currentSequenceGroup != null)
118     {
119       currentShader = currentSequenceGroup.getGroupColourScheme();
120     }
121     else
122     {
123       currentShader = shader;
124     }
125
126     return getBoxColour(currentShader, seq, i);
127   }
128
129   /**
130    * Supply hidden colour
131    * 
132    * @return colour of hidden regions
133    */
134   protected Color getHiddenColour()
135   {
136     return HIDDEN_COLOUR;
137   }
138 }