import jalview.datamodel.SequenceI;
import jalview.renderer.ResidueColourFinder;
import jalview.renderer.seqfeatures.FeatureColourFinder;
+import jalview.schemes.ColourSchemeI;
+import jalview.util.Comparison;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
-public class SequenceRenderer implements jalview.api.SequenceRenderer
+public class SequenceRenderer implements jalview.api.SequenceRendererI
{
final static int CHAR_TO_UPPER = 'A' - 'a';
- AlignViewportI av;
+ private AlignViewportI av;
- FontMetrics fm;
+ private FontMetrics fm;
- boolean renderGaps = true;
+ private SequenceGroup[] allGroups = null;
- SequenceGroup[] allGroups = null;
+ private Graphics graphics;
- // Color resBoxColour;
+ private boolean monospacedFont;
- Graphics graphics;
-
- boolean monospacedFont;
-
- ResidueColourFinder resColourFinder;
+ private ResidueColourFinder resColourFinder;
/**
* Creates a new SequenceRenderer object
}
/**
- * DOCUMENT ME!
+ * Constructor given a choice of colour scheme. May be used to find colours
+ * for a structure that has a viewport colour scheme other than 'by sequence'
*
- * @param b
- * DOCUMENT ME!
+ * @param cs
+ */
+ public SequenceRenderer(AlignViewportI viewport, ColourSchemeI cs)
+ {
+ this.av = viewport;
+ resColourFinder = new ResidueColourFinder(viewport, cs);
+ }
+
+/**
+ * Sets the Graphics context to draw on, and also guesses whether we are using a monospaced font
+ *
+ * @param g
*/
- public void prepare(Graphics g, boolean renderGaps)
+ public void setGraphics(Graphics g)
{
graphics = g;
fm = g.getFontMetrics();
monospacedFont = (dwidth == fm.getStringBounds("|", g).getWidth()
&& av.getCharWidth() == dwidth);
-
- this.renderGaps = renderGaps;
}
/**
}
/**
- * DOCUMENT ME!
+ * Draws the sequence (box colour and residues) over the given range, at the
+ * specified y-offset on the Graphics context
*
- * @param g
- * DOCUMENT ME!
* @param seq
- * DOCUMENT ME!
- * @param sg
- * DOCUMENT ME!
+ * @param sg groups (if any) that the sequence is a member of (may have
+ * distinct group colouring)
* @param start
- * DOCUMENT ME!
* @param end
- * DOCUMENT ME!
- * @param x1
- * DOCUMENT ME!
* @param y1
- * DOCUMENT ME!
- * @param width
- * DOCUMENT ME!
- * @param height
- * DOCUMENT ME!
+ * @param drawGaps
*/
public void drawSequence(SequenceI seq, SequenceGroup[] sg, int start,
- int end, int y1)
+ int end, int y1, boolean drawGaps)
{
allGroups = sg;
if (av.isValidCharWidth())
{
- drawText(seq, start, end, y1);
+ drawText(seq, start, end, y1, drawGaps);
}
}
/**
- * DOCUMENT ME!
+ * Draws box colours on the given sequence residue range, at the specified
+ * y-offset on the Graphics context
*
* @param seq
- * DOCUMENT ME!
* @param start
- * DOCUMENT ME!
* @param end
- * DOCUMENT ME!
- * @param x1
- * DOCUMENT ME!
* @param y1
- * DOCUMENT ME!
- * @param width
- * DOCUMENT ME!
- * @param height
- * DOCUMENT ME!
*/
public synchronized void drawBoxes(SequenceI seq, int start, int end,
int y1)
}
/**
- * DOCUMENT ME!
+ * Draws residue letters on the given sequence residue range, at the specified
+ * y-offset on the Graphics context
*
* @param seq
- * DOCUMENT ME!
* @param start
- * DOCUMENT ME!
* @param end
- * DOCUMENT ME!
- * @param x1
- * DOCUMENT ME!
* @param y1
- * DOCUMENT ME!
- * @param width
- * DOCUMENT ME!
- * @param height
- * DOCUMENT ME!
+ * @param drawGaps
*/
- public void drawText(SequenceI seq, int start, int end, int y1)
+ public void drawText(SequenceI seq, int start, int end, int y1, boolean drawGaps)
{
y1 += av.getCharHeight() - av.getCharHeight() / 5; // height/5 replaces pady
int charOffset = 0;
getboxColour = false;
s = seq.getCharAt(i);
- if (!renderGaps && jalview.util.Comparison.isGap(s))
+ if (!drawGaps && Comparison.isGap(s))
{
continue;
}
{
// todo - use sequence group consensus
s = getDisplayChar(srep, i, s, '.', currentSequenceGroup);
-
}
-
}
else
{
if (!isarep && av.getShowUnconserved())
{
s = getDisplayChar(srep, i, s, '.', null);
-
}
-
}
charOffset = (av.getCharWidth() - fm.charWidth(s)) / 2;
graphics.drawString(String.valueOf(s),
charOffset + av.getCharWidth() * (i - start), y1);
-
}
}
}
}
}
- public void drawCursor(SequenceI seq, int res, int x1, int y1)
+ /**
+ * Draw a sequence canvas cursor
+ *
+ * @param g
+ * graphics context to draw on
+ * @param s
+ * character to draw at cursor
+ * @param x1
+ * x position of cursor in graphics context
+ * @param y1
+ * y position of cursor in graphics context
+ */
+ public void drawCursor(Graphics g, char s, int x1, int y1)
{
int pady = av.getCharHeight() / 5;
int charOffset = 0;
- graphics.setColor(Color.black);
- graphics.fillRect(x1, y1, av.getCharWidth(), av.getCharHeight());
+ g.setColor(Color.black);
+ g.fillRect(x1, y1, av.getCharWidth(), av.getCharHeight());
if (av.isValidCharWidth())
{
- graphics.setColor(Color.white);
-
- char s = seq.getCharAt(res);
-
+ g.setColor(Color.white);
charOffset = (av.getCharWidth() - fm.charWidth(s)) / 2;
- graphics.drawString(String.valueOf(s), charOffset + x1,
+ g.drawString(String.valueOf(s), charOffset + x1,
(y1 + av.getCharHeight()) - pady);
}