]> WPIA git - gigi.git/blob - src/org/cacert/gigi/output/DataTable.java
47f1fc974c1d4bf769d9d2caca7357f4ee795ff7
[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 int getColoumnCount();
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                 LinkedList<Cell> tableContnet = getTableContent();
18                 for (int i = 0; i < tableContnet.size() / getColoumnCount(); i++) {
19                         out.println("<tr>");
20                         for (int j = 0; j < getColoumnCount(); j++) {
21                                 Cell current = tableContnet.get((i * getColoumnCount()) + j);
22                                 out.println("<td " + current.getHtmlAttribs()
23                                                 + " class=\"DataTD\">");
24                                 out.print(current.shouldTranslate() ? l.getTranslation(current
25                                                 .getText()) : current.getText());
26                                 out.print("</td>");
27                         }
28                         out.println("</tr>");
29                 }
30                 out.println("</table>");
31         }
32
33         /**
34          * <b>Note:</b> All cells have the html attribute class="DataTD"!
35          * 
36          * @author janis
37          * 
38          */
39         public static class Cell {
40                 private String text, htmlAttribs;
41                 private boolean translate;
42
43                 public Cell() {
44                         this("&nbsp;", false);
45                 }
46
47                 public Cell(String text, boolean translate, String htmlAttribs) {
48                         this.text = text;
49                         this.translate = translate;
50                         this.htmlAttribs = htmlAttribs;
51                 }
52
53                 public Cell(String text, boolean translate) {
54                         this(text, translate, "");
55                 }
56
57                 public boolean shouldTranslate() {
58                         return translate;
59                 }
60
61                 public String getText() {
62                         return text;
63                 }
64
65                 public String getHtmlAttribs() {
66                         return htmlAttribs;
67                 }
68
69         }
70
71 }