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 OverviewResColourFinder extends ResidueColourFinder
32 public static final Color OVERVIEW_DEFAULT_GAP = Color.lightGray;
34 public static final Color OVERVIEW_DEFAULT_LEGACY_GAP = Color.white;
36 public static final Color OVERVIEW_DEFAULT_HIDDEN = Color.darkGray
39 final Color gapColour; // colour to use for gaps
41 final int gapColourInt;
43 final Color residueColour; // colour to use for uncoloured residues
45 final int residueColourInt;
47 final Color hiddenColour; // colour for hidden regions
49 boolean useLegacy = false;
52 * Constructor without colour settings (used by applet)
54 public OverviewResColourFinder()
56 this(false, OVERVIEW_DEFAULT_GAP, OVERVIEW_DEFAULT_HIDDEN);
60 * Constructor with colour settings
62 * @param useLegacyColouring
63 * whether to use legacy gap colouring (white gaps, grey residues)
65 * gap colour if not legacy
67 * hidden region colour (transparency applied by rendering code)
69 public OverviewResColourFinder(boolean useLegacyColouring, Color gapCol,
72 if (useLegacyColouring)
74 gapColour = Color.white;
75 residueColour = Color.lightGray;
80 residueColour = Color.WHITE;
82 gapColourInt = gapColour.getRGB();
83 residueColourInt = residueColour.getRGB();
84 hiddenColour = hiddenCol;
88 public Color getBoxColour(ResidueShaderI shader, SequenceI seq, int i)
90 return new Color(getBoxColourInt(shader, seq, i));
93 public int getBoxColourInt(ResidueShaderI shader, SequenceI seq, int i)
95 char currentChar = seq.getCharAt(i);
96 // In the overview window, gaps are coloured grey, unless the colour scheme
97 // specifies a gap colour, in which case gaps honour the colour scheme
99 boolean isGap = Comparison.isGap(currentChar);
100 if (shader.getColourScheme() == null)
102 return (isGap ? gapColourInt : residueColourInt);
104 return (isGap && !shader.getColourScheme().hasGapColour() ? gapColourInt
105 : shader.findColourInt(currentChar, i, seq));
109 public Color getResidueColour(boolean showBoxes, ResidueShaderI shader,
110 SequenceGroup[] allGroups, final SequenceI seq, int i,
111 FeatureColourFinder finder)
113 Color col = getResidueBoxColour(showBoxes, shader, allGroups, seq, i);
115 // if there's a FeatureColourFinder we might override the residue colour
116 // here with feature colouring
117 col = finder == null || finder.noFeaturesDisplayed() ? col
118 : finder.findFeatureColour(col, seq, i);
123 public int getResidueColourInt(boolean showBoxes, ResidueShaderI shader,
124 SequenceGroup[] allGroups, final SequenceI seq, int i,
125 FeatureColourFinder finder)
128 int c = seq.getColor(i);
134 int col = getResidueBoxColourInt(showBoxes, shader, allGroups, seq, i);
136 // if there's a FeatureColourFinder we might override the residue colour
137 // here with feature colouring
138 col = finder == null || finder.noFeaturesDisplayed() ? col
139 : finder.findFeatureColourInt(col, seq, i);
140 return seq.setColor(i, col);
144 protected Color getResidueBoxColour(boolean showBoxes,
145 ResidueShaderI shader, SequenceGroup[] allGroups, SequenceI seq,
149 getResidueBoxColourInt(showBoxes, shader, allGroups, seq, i));
153 * In the overview, the showBoxes setting is ignored, as the overview displays
154 * the colours regardless.
156 protected int getResidueBoxColourInt(boolean showBoxes,
157 ResidueShaderI shader, SequenceGroup[] allGroups, SequenceI seq,
160 SequenceGroup currentSequenceGroup = getCurrentSequenceGroup(allGroups,
162 ResidueShaderI currentShader = (currentSequenceGroup == null ? shader
163 : currentSequenceGroup.getGroupColourScheme());
164 return getBoxColourInt(currentShader, seq, i);
168 * Supply hidden colour
170 * @return colour of hidden regions
172 protected Color getHiddenColour()