1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.gwe.utils.web;
18
19
20
21
22
23
24 public class HtmlTableCell {
25
26 private CellAlignment alignment = CellAlignment.LEFT;
27 private String tooltip = "";
28 private boolean header = false;
29 private HtmlContent[] content;
30
31 public HtmlTableCell(String caption, String tooltip, HtmlLink link) {
32 this(caption, tooltip, link, null);
33 }
34
35 public HtmlTableCell(String caption, String tooltip, HtmlLink link, WebIcon image) {
36 this(tooltip, new HtmlContent(caption, link, image));
37 if (link != null || image != null) this.alignment = CellAlignment.CENTER;
38 }
39
40 public HtmlTableCell(String caption, String tooltip) {
41 this(tooltip, new HtmlContent(caption));
42 this.alignment = CellAlignment.LEFT;
43 }
44
45 public HtmlTableCell(String tooltip, HtmlContent... content) {
46 this.tooltip = tooltip;
47 this.content = content;
48 this.alignment = CellAlignment.CENTER;
49 }
50
51 public void setHeader(boolean value) {
52 this.header = value;
53 }
54
55 public void setAlignment(CellAlignment alignment) {
56 this.alignment = alignment;
57 }
58
59 public StringBuffer getHTML() {
60 String htmlTag = header ? "th" : "td";
61 StringBuffer result = new StringBuffer();
62
63
64 result.append("\t\t<").append(htmlTag).append(" align=\"").append(alignment).append("\"");
65 if (tooltip != null && !tooltip.equals(""))
66 result.append(" title=\"").append(tooltip).append("\" ");
67 result.append(">");
68
69
70 result.append(getContent());
71
72
73 return result.append("</").append(htmlTag).append(">\n");
74 }
75
76 private String getContent() {
77 if (content == null || content.length == 0) return "";
78 StringBuffer result = new StringBuffer();
79 for (HtmlContent cont : content) result.append(cont.getHTML());
80 return result.toString();
81 }
82 }