SpanGradientFormatterpublic class SpanGradientFormatter extends GradientFormatter Formats text with different color intensity depending on the score of the
term using the span tag. GradientFormatter uses a bgcolor argument to the font tag which
doesn't work in Mozilla, thus this class. |
Fields Summary |
---|
private static final String | TEMPLATE | private static final int | EXTRA |
Constructors Summary |
---|
public SpanGradientFormatter(float maxScore, String minForegroundColor, String maxForegroundColor, String minBackgroundColor, String maxBackgroundColor)
super( maxScore, minForegroundColor,
maxForegroundColor, minBackgroundColor,
maxBackgroundColor);
|
Methods Summary |
---|
public java.lang.String | highlightTerm(java.lang.String originalText, TokenGroup tokenGroup)
if (tokenGroup.getTotalScore() == 0)
return originalText;
float score = tokenGroup.getTotalScore();
if (score == 0)
{
return originalText;
}
// try to size sb correctly
StringBuffer sb = new StringBuffer( originalText.length() + EXTRA);
sb.append("<span style=\"");
if (highlightForeground)
{
sb.append("color: ");
sb.append(getForegroundColorString(score));
sb.append("; ");
}
if (highlightBackground)
{
sb.append("background: ");
sb.append(getBackgroundColorString(score));
sb.append("; ");
}
sb.append("\">");
sb.append(originalText);
sb.append("</span>");
return sb.toString();
|
|