forked from duke-compsci308-spring2016/lab_wordcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTMLPage.java
More file actions
43 lines (38 loc) · 1.23 KB
/
HTMLPage.java
File metadata and controls
43 lines (38 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.util.Map.Entry;
/**
* A simple module to encapsulate using HTML tags.
*
* Note, makes use of CSS styling in an effort ease changing the style later.
*
* @author Robert C. Duvall
*/
public class HTMLPage {
/**
* @return tags to be included at top of HTML page
*/
public static String startPage (int numSizes, int startSize, int increment) {
StringBuilder style = new StringBuilder();
for (int k = 0; k < numSizes; k++) {
style.append(" .size-" + k + " { font-size: " + (startSize + increment * k) + "px; }");
}
return "<html><head><style>" + style + "</style></head><body><p>\n";
}
/**
* @return tags to be included at bottom of HTML page
*/
public static String endPage () {
return "</p></body></html>";
}
/**
* @return tags to display a single styled word
*/
public static String formatWord (String word, long cssSize) {
return " <span class=\"size-" + cssSize + "\">" + word + "</span>\n";
}
/**
* @return tags to display a single styled word
*/
public static String formatWord (Entry<String, Long> wordCount) {
return formatWord(wordCount.getKey(), wordCount.getValue());
}
}