]> WPIA git - gigi.git/blob - src/org/cacert/gigi/output/DataTable.java
UPD: More advanced cells
[gigi.git] / src / org / cacert / gigi / output / DataTable.java
1 package org.cacert.gigi.output;
2
3 import java.io.PrintWriter;
4 import java.util.LinkedList;
5 import java.util.Map;
6
7 import org.cacert.gigi.Language;
8
9 public abstract class DataTable implements Outputable {
10         protected abstract Cell[] getColumns();
11
12         protected abstract LinkedList<Cell> getTableContent();
13
14         @Override
15         public void output(PrintWriter out, Language l, Map<String, Object> vars) {
16                 out.println("<table align=\"center\" valign=\"middle\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"wrapper\">");
17                 out.println("<tr>");
18                 for (Cell column : getColumns()) {
19                         out.print("<td " + column.getHtmlAttribs() + " class=\"DataTD\">");
20                         out.print(column.shouldTranslate() ? l.getTranslation(column
21                                         .getText()) : column.getText());
22                         out.println("</td>");
23                 }
24                 out.println("</tr>");
25                 LinkedList<Cell> tableContnet = getTableContent();
26                 for (int i = 0; i < tableContnet.size() / getColumns().length; i++) {
27                         out.println("<tr>");
28                         for (int j = 0; j < getColumns().length; j++) {
29                                 Cell current = tableContnet.get((i * getColumns().length) + j);
30                                 out.println("<td " + current.getHtmlAttribs()
31                                                 + " class=\"DataTD\">");
32                                 out.print(current.shouldTranslate() ? l.getTranslation(current
33                                                 .getText()) : current.getText());
34                                 out.print("</td>");
35                         }
36                         out.println("</tr>");
37                 }
38                 out.println("</table>");
39         }
40
41         /**
42          * <b>Note:</b> All cells have the html attribute class="DataTD"!
43          * 
44          * @author janis
45          * 
46          */
47         public static class Cell {
48                 private String text, htmlAttribs;
49                 private boolean translate;
50
51                 public Cell() {
52                         this("&nbsp;", false);
53                 }
54
55                 public Cell(String text, boolean translate, String htmlAttribs) {
56                         this.text = text;
57                         this.translate = translate;
58                         this.htmlAttribs = htmlAttribs;
59                 }
60
61                 public Cell(String text, boolean translate) {
62                         this(text, translate, "");
63                 }
64
65                 public boolean shouldTranslate() {
66                         return translate;
67                 }
68
69                 public String getText() {
70                         return text;
71                 }
72
73                 public String getHtmlAttribs() {
74                         return htmlAttribs;
75                 }
76
77         }
78
79 }