JAL-3383 get color as int options removed (to separate branch 3443)
[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   public static final Color OVERVIEW_DEFAULT_GAP = Color.lightGray;
32
33   public static final Color OVERVIEW_DEFAULT_LEGACY_GAP = Color.white;
34
35   public static final Color OVERVIEW_DEFAULT_HIDDEN = Color.darkGray
36           .darker();
37
38   final Color gapColour; // colour to use for gaps
39
40   final int gapColourInt; // RGB value of gapColour
41
42   final Color residueColour; // colour to use for uncoloured residues
43
44   final Color hiddenColour; // colour for hidden regions
45
46   boolean useLegacy = false;
47
48   /**
49    * Constructor without colour settings (used by applet)
50    */
51   public OverviewResColourFinder()
52   {
53     this(false, OVERVIEW_DEFAULT_GAP, OVERVIEW_DEFAULT_HIDDEN);
54   }
55
56   /**
57    * Constructor with colour settings
58    * 
59    * @param useLegacyColouring
60    *          whether to use legacy gap colouring (white gaps, grey residues)
61    * @param gapCol
62    *          gap colour if not legacy
63    * @param hiddenCol
64    *          hidden region colour (transparency applied by rendering code)
65    */
66   public OverviewResColourFinder(boolean useLegacyColouring, Color gapCol,
67           Color hiddenCol)
68   {
69     if (useLegacyColouring)
70     {
71       gapColour = Color.white;
72       residueColour = Color.lightGray;
73     }
74     else
75     {
76       gapColour = gapCol;
77       residueColour = Color.WHITE;
78     }
79     gapColourInt = gapColour.getRGB();
80     hiddenColour = hiddenCol;
81   }
82
83   /**
84    * Overrides the method to return the currently configured Overview colours
85    * for gaps, or residues with no colour scheme set. A custom colour scheme
86    * which specifies a colour for gaps overrides the normal gap colour.
87    */
88   @Override
89   public Color getBoxColour(ResidueShaderI shader, SequenceI seq, int i)
90   {
91     char currentChar = seq.getCharAt(i);
92     boolean isGap = Comparison.isGap(currentChar);
93     if (shader.getColourScheme() == null)
94     {
95       return (isGap ? gapColour : residueColour);
96     }
97     return (isGap && !shader.getColourScheme().hasGapColour() ? gapColour
98             : shader.findColour(currentChar, i, seq));
99   }
100
101   /**
102    * In the overview, the showBoxes setting is ignored, as the overview displays
103    * the colours regardless
104    */
105   @Override
106   protected Color getResidueBoxColour(boolean showBoxes,
107           ResidueShaderI shader, SequenceGroup[] allGroups, SequenceI seq,
108           int i)
109   {
110     SequenceGroup currentSequenceGroup = getCurrentSequenceGroup(allGroups,
111             i);
112     ResidueShaderI currentShader = (currentSequenceGroup == null ? shader
113             : currentSequenceGroup.getGroupColourScheme());
114     return getBoxColour(currentShader, seq, i);
115   }
116
117   /**
118    * Returns the coloured configured for hidden regions in the Overview
119    * 
120    * @return
121    */
122   protected Color getHiddenColour()
123   {
124     return hiddenColour;
125   }
126 }