1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sf.statcvs.renderer;
24
25 import net.sf.statcvs.Messages;
26 import net.sf.statcvs.model.Author;
27 import net.sf.statcvs.model.Directory;
28 import net.sf.statcvs.model.VersionedFile;
29 import net.sf.statcvs.output.WebRepositoryIntegration;
30 import net.sf.statcvs.pages.HTML;
31 import net.sf.statcvs.pages.MarkupSyntax;
32 import net.sf.statcvs.pages.ReportSuiteMaker;
33
34
35
36
37
38
39
40
41 public class HTMLTableCellRenderer implements TableCellRenderer {
42 private String html = null;
43 private MarkupSyntax output = null;
44
45
46
47
48
49 public void renderCell(final String content) {
50 html = content;
51 }
52
53
54
55
56 public void renderEmptyCell() {
57 html = null;
58 }
59
60
61
62
63
64 public void renderIntegerCell(final int value) {
65 html = Integer.toString(value);
66 }
67
68
69
70
71
72
73
74 public void renderIntegerCell(final int value, final int total) {
75 html = Integer.toString(value) + " (" + getPercentage((double) value / (double) total) + ")";
76 }
77
78
79
80
81
82 public void renderPercentageCell(final double ratio) {
83 html = getPercentage(ratio);
84 }
85
86
87
88
89
90 public void renderAuthorCell(final Author author) {
91 html = HTML.getAuthorLink(author);
92 }
93
94
95
96
97
98 public void renderAuthorIdCell(final Author author) {
99 html = HTML.getAuthorIdLink(author);
100 }
101
102
103
104
105
106 public void renderDirectoryCell(final Directory directory) {
107 html = HTML.getDirectoryLink(directory);
108 }
109
110
111
112
113
114
115
116 public void renderFileCell(final VersionedFile file, final boolean withIcon, final WebRepositoryIntegration webRepository) {
117 if (webRepository == null) {
118 html = file.getFilenameWithPath();
119 } else {
120 html = HTML.getLink(webRepository.getFileViewUrl(file), file.getFilenameWithPath());
121 }
122 if (withIcon) {
123 if (file.isDead()) {
124 html = HTML.getIcon(ReportSuiteMaker.DELETED_FILE_ICON, Messages.getString("DELETED_FILE_ICON")) + " " + html;
125 } else {
126 html = HTML.getIcon(ReportSuiteMaker.FILE_ICON, Messages.getString("FILE_ICON")) + " " + html;
127 }
128 }
129 }
130
131
132
133
134 public void renderLinkCell(final String url, final String label) {
135 this.html = HTML.getLink(url, label);
136 }
137
138
139
140
141
142 public String getColumnHead() {
143 return getHtml("th");
144 }
145
146
147
148
149
150
151 public String getRowHead() {
152 return getHtml("th");
153 }
154
155
156
157
158
159
160 public String getTableCell() {
161 return getHtml("td");
162 }
163
164 private String getPercentage(final double ratio) {
165 if (Double.isNaN(ratio)) {
166 return "-";
167 }
168 final int percentTimes10 = (int) Math.round(ratio * 1000);
169 final double percent = percentTimes10 / 10.0;
170 return Double.toString(percent) + "%";
171 }
172
173 private String getHtml(final String tag) {
174 if (html == null) {
175 return "<" + tag + "></" + tag + ">";
176 }
177 return "<" + tag + ">" + html + "</" + tag + ">";
178 }
179
180
181
182
183 public MarkupSyntax getOutput() {
184 return output;
185 }
186
187
188
189
190 public void setOutput(final MarkupSyntax output) {
191 this.output = output;
192 }
193
194 public String getOddRowFormat() {
195 return " class=\"even\"";
196 }
197
198 public String getEvenRowFormat() {
199 return " class=\"odd\"";
200 }
201 }