JAL-3719 Format->Colour Gaps option uses Overview gap colour logic pulled up to align...
[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
32   final Color HIDDEN_COLOUR; // colour for hidden regions
33
34   boolean useLegacy = false;
35
36   public static final Color OVERVIEW_DEFAULT_GAP = Color.lightGray;
37
38   public static final Color OVERVIEW_DEFAULT_LEGACY_GAP = Color.white;
39
40   public static final Color OVERVIEW_DEFAULT_HIDDEN = Color.darkGray
41           .darker();
42
43   /**
44    * Constructor without colour settings (used by applet)
45    */
46   public OverviewResColourFinder()
47   {
48     this(false, OVERVIEW_DEFAULT_GAP, OVERVIEW_DEFAULT_HIDDEN);
49   }
50
51   /**
52    * Constructor with colour settings
53    * 
54    * @param useLegacyColouring
55    *          whether to use legacy gap colouring (white gaps, grey residues)
56    * @param gapCol
57    *          gap colour if not legacy
58    * @param hiddenCol
59    *          hidden region colour (transparency applied by rendering code)
60    */
61   public OverviewResColourFinder(boolean useLegacyColouring, Color gapCol,
62           Color hiddenCol)
63   {
64     if (useLegacyColouring)
65     {
66       GAP_COLOUR = Color.white;
67       RESIDUE_COLOUR = Color.lightGray;
68       HIDDEN_COLOUR = hiddenCol;
69     }
70     else
71     {
72       GAP_COLOUR = gapCol;
73       RESIDUE_COLOUR = Color.white;
74       HIDDEN_COLOUR = hiddenCol;
75     }
76   }
77
78   /**
79    * {@inheritDoc} In the overview, the showBoxes setting is ignored, as the
80    * overview displays the colours regardless.
81    */
82   @Override
83   protected Color getResidueBoxColour(boolean showBoxes,
84           ResidueShaderI shader,
85           SequenceGroup[] allGroups, SequenceI seq, int i)
86   {
87     ResidueShaderI currentShader;
88     SequenceGroup currentSequenceGroup = getCurrentSequenceGroup(allGroups,
89             i);
90     if (currentSequenceGroup != null)
91     {
92       currentShader = currentSequenceGroup.getGroupColourScheme();
93     }
94     else
95     {
96       currentShader = shader;
97     }
98
99     return getBoxColour(currentShader, seq, i);
100   }
101
102   /**
103    * Supply hidden colour
104    * 
105    * @return colour of hidden regions
106    */
107   protected Color getHiddenColour()
108   {
109     return HIDDEN_COLOUR;
110   }
111 }