*/
package jalview.gui;
-import jalview.api.FeatureRenderer;
+import jalview.api.AlignViewportI;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
-import jalview.schemes.ColourSchemeI;
+import jalview.renderer.ResidueColourFinder;
+import jalview.renderer.seqfeatures.FeatureColourFinder;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
-/**
- * DOCUMENT ME!
- *
- * @author $author$
- * @version $Revision$
- */
public class SequenceRenderer implements jalview.api.SequenceRenderer
{
final static int CHAR_TO_UPPER = 'A' - 'a';
- AlignViewport av;
+ AlignViewportI av;
FontMetrics fm;
boolean renderGaps = true;
- SequenceGroup currentSequenceGroup = null;
-
SequenceGroup[] allGroups = null;
- Color resBoxColour;
+ // Color resBoxColour;
Graphics graphics;
boolean monospacedFont;
- boolean forOverview = false;
+ ResidueColourFinder resColourFinder;
/**
- * Creates a new SequenceRenderer object.
+ * Creates a new SequenceRenderer object
*
- * @param av
- * DOCUMENT ME!
+ * @param viewport
*/
- public SequenceRenderer(AlignViewport av)
+ public SequenceRenderer(AlignViewportI viewport)
{
- this.av = av;
+ this.av = viewport;
+ resColourFinder = new ResidueColourFinder();
}
/**
this.renderGaps = renderGaps;
}
- @Override
- public Color getResidueBoxColour(SequenceI seq, int i)
- {
- allGroups = av.getAlignment().findAllGroups(seq);
-
- if (inCurrentSequenceGroup(i))
- {
- if (currentSequenceGroup.getDisplayBoxes())
- {
- getBoxColour(currentSequenceGroup.cs, seq, i);
- }
- }
- else if (av.getShowBoxes())
- {
- getBoxColour(av.getGlobalColourScheme(), seq, i);
- }
-
- return resBoxColour;
- }
-
/**
* Get the residue colour at the given sequence position - as determined by
* the sequence group colour (if any), else the colour scheme, possibly
*
* @param seq
* @param position
- * @param fr
+ * @param finder
* @return
*/
@Override
public Color getResidueColour(final SequenceI seq, int position,
- FeatureRenderer fr)
+ FeatureColourFinder finder)
{
- // TODO replace 8 or so code duplications with calls to this method
- // (refactored as needed)
- Color col = getResidueBoxColour(seq, position);
-
- if (fr != null)
- {
- col = fr.findFeatureColour(col, seq, position);
- }
- return col;
+ return resColourFinder.getResidueColour(av.getShowBoxes(),
+ av.getResidueShading(),
+ allGroups, seq, position,
+ finder);
}
- /**
- * DOCUMENT ME!
- *
- * @param cs
- * DOCUMENT ME!
- * @param seq
- * DOCUMENT ME!
- * @param i
- * DOCUMENT ME!
- */
- void getBoxColour(ColourSchemeI cs, SequenceI seq, int i)
- {
- if (cs != null)
- {
- resBoxColour = cs.findColour(seq.getCharAt(i), i, seq);
- }
- else if (forOverview
- && !jalview.util.Comparison.isGap(seq.getCharAt(i)))
- {
- resBoxColour = Color.lightGray;
- }
- else
- {
- resBoxColour = Color.white;
- }
- }
+
/**
* DOCUMENT ME!
drawBoxes(seq, start, end, y1);
- if (av.validCharWidth)
+ if (av.isValidCharWidth())
{
drawText(seq, start, end, y1);
}
public synchronized void drawBoxes(SequenceI seq, int start, int end,
int y1)
{
+ Color resBoxColour = Color.white;
+
if (seq == null)
- {
+ {
return; // fix for racecondition
}
int i = start;
if (i < length)
{
- if (inCurrentSequenceGroup(i))
+ SequenceGroup currentSequenceGroup = resColourFinder
+ .getCurrentSequenceGroup(
+ allGroups, i);
+ if (currentSequenceGroup != null)
{
if (currentSequenceGroup.getDisplayBoxes())
{
- getBoxColour(currentSequenceGroup.cs, seq, i);
+ resBoxColour = resColourFinder.getBoxColour(
+ currentSequenceGroup.getGroupColourScheme(), seq,
+ i);
}
}
else if (av.getShowBoxes())
{
- getBoxColour(av.getGlobalColourScheme(), seq, i);
+ resBoxColour = resColourFinder
+ .getBoxColour(av.getResidueShading(), seq, i);
}
-
}
if (resBoxColour != tempColour)
boolean srep = av.isDisplayReferenceSeq();
boolean getboxColour = false;
boolean isarep = av.getAlignment().getSeqrep() == seq;
- boolean isgrep = currentSequenceGroup != null ? currentSequenceGroup
- .getSeqrep() == seq : false;
- char sr_c;
+ Color resBoxColour = Color.white;
+
for (int i = start; i <= end; i++)
{
continue;
}
- if (inCurrentSequenceGroup(i))
+ SequenceGroup currentSequenceGroup = resColourFinder
+ .getCurrentSequenceGroup(
+ allGroups, i);
+ if (currentSequenceGroup != null)
{
if (!currentSequenceGroup.getDisplayText())
{
|| currentSequenceGroup.getColourText())
{
getboxColour = true;
- getBoxColour(currentSequenceGroup.cs, seq, i);
+ resBoxColour = resColourFinder.getBoxColour(
+ currentSequenceGroup.getGroupColourScheme(), seq,
+ i);
if (currentSequenceGroup.getColourText())
{
{
graphics.setColor(currentSequenceGroup.textColour);
}
+ boolean isgrep = currentSequenceGroup != null
+ ? currentSequenceGroup.getSeqrep() == seq : false;
if (!isarep && !isgrep
&& currentSequenceGroup.getShowNonconserved()) // todo
// optimize
if (av.getColourText())
{
getboxColour = true;
- getBoxColour(av.getGlobalColourScheme(), seq, i);
+ resBoxColour = resColourFinder
+ .getBoxColour(av.getResidueShading(), seq, i);
if (av.getShowBoxes())
{
{
if (!getboxColour)
{
- getBoxColour(av.getGlobalColourScheme(), seq, i);
+ resBoxColour = resColourFinder
+ .getBoxColour(av.getResidueShading(), seq, i);
}
if (resBoxColour.getRed() + resBoxColour.getBlue()
}
if (!isarep && av.getShowUnconserved())
{
- s = getDisplayChar(srep, i, s, '.', currentSequenceGroup);
+ s = getDisplayChar(srep, i, s, '.', null);
}
charOffset = (av.getCharWidth() - fm.charWidth(s)) / 2;
graphics.drawString(String.valueOf(s),
- charOffset + av.getCharWidth()
- * (i - start), y1);
+ charOffset + av.getCharWidth() * (i - start), y1);
}
}
{
// TODO - use currentSequenceGroup rather than alignment
// currentSequenceGroup.getConsensus()
- char conschar = (usesrep) ? (currentGroup == null ? av.getAlignment()
+ char conschar = (usesrep) ? (currentGroup == null
+ || position < currentGroup.getStartRes()
+ || position > currentGroup.getEndRes() ? av.getAlignment()
.getSeqrep().getCharAt(position)
: (currentGroup.getSeqrep() != null ? currentGroup.getSeqrep()
.getCharAt(position) : av.getAlignment().getSeqrep()
.getCharAt(position)))
- : (currentGroup != null && currentGroup.getConsensus() != null) ? currentGroup
+ : (currentGroup != null && currentGroup.getConsensus() != null
+ && position >= currentGroup.getStartRes()
+ && position <= currentGroup.getEndRes() && currentGroup
+ .getConsensus().annotations.length > position) ? currentGroup
.getConsensus().annotations[position].displayCharacter
.charAt(0)
: av.getAlignmentConsensusAnnotation().annotations[position].displayCharacter
/**
* DOCUMENT ME!
*
- * @param res
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- boolean inCurrentSequenceGroup(int res)
- {
- if (allGroups == null)
- {
- return false;
- }
-
- for (int i = 0; i < allGroups.length; i++)
- {
- if ((allGroups[i].getStartRes() <= res)
- && (allGroups[i].getEndRes() >= res))
- {
- currentSequenceGroup = allGroups[i];
-
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * DOCUMENT ME!
- *
* @param seq
* DOCUMENT ME!
* @param start