2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.renderer;
23 import jalview.datamodel.SequenceGroup;
24 import jalview.datamodel.SequenceI;
25 import jalview.renderer.seqfeatures.FeatureColourFinder;
26 import jalview.util.Comparison;
28 import java.awt.Color;
30 public class ResidueColourFinder
32 private static final Color BACKGROUND_COLOUR = Color.white;
34 protected Color GAP_COLOUR=Color.white; // default colour to use at gaps
36 protected Color RESIDUE_COLOUR=BACKGROUND_COLOUR; // default colour to use at residues
38 public ResidueColourFinder()
41 public ResidueColourFinder(Color gapColour)
43 GAP_COLOUR = gapColour;
47 * Get the colour of a residue in a sequence
50 * true if the viewport's Show Boxes setting is true
52 * the viewport's colour scheme
54 * all the groups which seq participates in
56 * the sequence containing the residue
58 * the position of the residue in the sequence
60 * FeatureColourFinder for the viewport
61 * @return colour of the residue
63 public Color getResidueColour(boolean showBoxes, ResidueShaderI shader,
64 SequenceGroup[] allGroups,
65 final SequenceI seq, int position, FeatureColourFinder finder)
67 Color col = getResidueBoxColour(showBoxes, shader, allGroups, seq,
70 // if there's a FeatureColourFinder we might override the residue colour
71 // here with feature colouring
74 col = finder.findFeatureColour(col, seq, position);
80 * Get the residue colour without accounting for any features
83 * true if the viewport's Show Boxes setting is true
85 * the viewport's colour scheme
87 * all the groups which seq participates in
89 * the sequence containing the residue
91 * the position of the residue in the sequence
94 protected Color getResidueBoxColour(boolean showBoxes,
95 ResidueShaderI shader,
96 SequenceGroup[] allGroups,
99 SequenceGroup currentSequenceGroup = getCurrentSequenceGroup(allGroups,
101 if (currentSequenceGroup != null)
103 if (currentSequenceGroup.getDisplayBoxes())
105 return getBoxColour(currentSequenceGroup.getGroupColourScheme(),
111 return getBoxColour(shader, seq, i);
114 return BACKGROUND_COLOUR;
118 * Search all the groups for a sequence to find the one which a given res
122 * all the groups a sequence participates in
124 * the residue to search for
125 * @return a sequence group for res, or null if no sequence group applies
127 public SequenceGroup getCurrentSequenceGroup(SequenceGroup[] allGroups,
130 if (allGroups == null)
135 for (int i = 0; i < allGroups.length; i++)
137 if ((allGroups[i].getStartRes() <= res)
138 && (allGroups[i].getEndRes() >= res))
140 return (allGroups[i]);
148 * Find the colour for a sequence's position in the alignment
151 * the viewport's colour scheme
153 * the sequence containing the residue
155 * the position of the residue in the sequence
157 public Color getBoxColour(ResidueShaderI shader, SequenceI seq, int i)
159 Color resBoxColour = RESIDUE_COLOUR;
160 char currentChar = seq.getCharAt(i);
162 // In the overview window, gaps are coloured grey, unless the colour scheme
163 // specifies a gap colour, in which case gaps honour the colour scheme
165 if (shader.getColourScheme() != null)
167 if (Comparison.isGap(currentChar)
168 && (!shader.getColourScheme().hasGapColour()))
170 resBoxColour = GAP_COLOUR;
174 resBoxColour = shader.findColour(currentChar, i, seq);
177 else if (Comparison.isGap(currentChar))
179 resBoxColour = GAP_COLOUR;