edu.northwestern.at.utils.tagcloud
Class TagCloud

java.lang.Object
  extended by edu.northwestern.at.utils.tagcloud.TagCloud

public class TagCloud
extends java.lang.Object

Generates HTML for a tag cloud.

A tag cloud accepts a series of (string , score, color) triples and creates HTML to display the strings in descending order by score. The font size for each string is based upon the relative value of that string's score. The colors are standard HTML colors, e.g., blue, green, black, etc. The styles are defined by TagCloudTextStyle and can be plain, bold, italicized, or bold and italicized.

To create a tag cloud:

TagCloud tagCloud = new TagCloud();

To add an entry to the cloud:

tagCloud.addTag( "my tag" , 10.234 , "black" , new TagCloudTextStyle( false , false ) );

To get the HTML for displaying the cloud after all the tags have been added:

String html = tagCloud.getHTML();

The generated HTML only contains style settings and a div wrapping a sequence of lines for displaying the tags. This allows the tag cloud html to be embedded within a larger html context.

To set the font size for the largest score (default 100):

tagCloud.setMaximumFontSize( 150 );

To set the minimum font size for display (default 3):

tagCloud.setMinimumFontSize( 150 );

Tags whose font sizes are smaller than minFontSize are not displayed in the cloud.

To deactivate a tag once it has been added, so that the tag will not display in the cloud:

tagCloud.deactivateTag( "my tag" , 10.234 );

Both the tag and score must match an existing tag or the deactivation request is ignored. To reactivate a tag for display:

tagCloud.activateTag( "my tag" , 10.234 );


Field Summary
protected  java.lang.StringBuffer cloudHTML
          Holds HTML text for tag cloud.
protected  double maxFontSize
          Maximum font point size for display.
protected  double minFontSize
          Minimum font point size for display.
protected  SortedArrayList tagScoreList
          Tags sorted by score.
 
Constructor Summary
TagCloud()
          Create empty tag cloud.
 
Method Summary
 void activateTag(java.lang.String tag, double score)
          Activate tag in cloud.
protected  void addFooter()
          Add footer.
protected  void addHeader()
          Add header.
protected  void addHTML(java.lang.String html)
          Add HTML line to cloud.
 void addTag(java.lang.String tag, double score)
          Add tag to cloud.
 void addTag(java.lang.String tag, double score, java.lang.String color)
          Add tag to cloud.
 void addTag(java.lang.String tag, double score, java.lang.String color, TagCloudTextStyle style)
          Add tag to cloud.
 void deactivateTag(java.lang.String tag, double score)
          Deactivate tag in cloud.
 java.lang.String getHTML()
          Return tag cloud HTML.
 void setMaximumFontSize(double maxFontSize)
          Set the maximum font size.
 void setMinimumFontSize(double minFontSize)
          Set the minimum font size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cloudHTML

protected java.lang.StringBuffer cloudHTML
Holds HTML text for tag cloud.


tagScoreList

protected SortedArrayList tagScoreList
Tags sorted by score.


maxFontSize

protected double maxFontSize
Maximum font point size for display.


minFontSize

protected double minFontSize
Minimum font point size for display.

Constructor Detail

TagCloud

public TagCloud()
Create empty tag cloud.

Method Detail

addTag

public void addTag(java.lang.String tag,
                   double score,
                   java.lang.String color,
                   TagCloudTextStyle style)
Add tag to cloud.

Parameters:
tag - The tag string.
score - The tag score.
color - The color for the string. Should be specified using standard HTML color names, e.g., "black" , "blue", etc.
style - The style for the string.

addTag

public void addTag(java.lang.String tag,
                   double score,
                   java.lang.String color)
Add tag to cloud.

Parameters:
tag - The tag string.
score - The tag score.
color - The color for the string. Should be specified using standard HTML color names, e.g., "black" , "blue", etc.

Uses plain normal as the text style.


addTag

public void addTag(java.lang.String tag,
                   double score)
Add tag to cloud.

Parameters:
tag - The tag string.
score - The tag score.

Uses plain normal as the text style and black as the text color.


deactivateTag

public void deactivateTag(java.lang.String tag,
                          double score)
Deactivate tag in cloud.

Parameters:
tag - The tag string.
score - The tag score.

activateTag

public void activateTag(java.lang.String tag,
                        double score)
Activate tag in cloud.

Parameters:
tag - The tag string.
score - The tag score.

getHTML

public java.lang.String getHTML()
Return tag cloud HTML.


setMaximumFontSize

public void setMaximumFontSize(double maxFontSize)
Set the maximum font size.

Parameters:
maxFontSize - Maximum font size for display.

setMinimumFontSize

public void setMinimumFontSize(double minFontSize)
Set the minimum font size.

Parameters:
minFontSize - Minimum font size for display.

Tags whose font sizes are smaller than minFontSize are not displayed in the cloud.


addHTML

protected void addHTML(java.lang.String html)
Add HTML line to cloud.


addHeader

protected void addHeader()
Add header.


addFooter

protected void addFooter()
Add footer.