]> WPIA git - gigi.git/blob - src/org/cacert/gigi/output/DataTable.java
60893b0446ef0875453168059abbc0a4881c527e
[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 class DataTable implements Outputable {
10         private LinkedList<Cell> cells;
11         private int columnCount;
12
13         public DataTable(int coloumnCount, LinkedList<Cell> content) {
14                 this.columnCount = coloumnCount;
15                 this.cells = content;
16         }
17
18         @Override
19         public void output(PrintWriter out, Language l, Map<String, Object> vars) {
20                 int mesCells = cells.size();
21                 for (Cell c : cells) {
22                         if (c.getColSpan() > 1) {
23                                 mesCells += c.getColSpan();
24                         }
25                 }
26                 out.println("<table align=\"center\" valign=\"middle\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"wrapper\">");
27                 for (int i = 0; i < mesCells / columnCount; i++) {
28                         out.println("<tr>");
29                         for (int j = 0; j < columnCount;) {
30                                 Cell current = cells.get((i * columnCount) + j);
31                                 j += current.getColSpan();
32                                 out.println("<td " + current.getHtmlAttribs()
33                                                 + " class=\"DataTD\">");
34                                 out.print(current.shouldTranslate() ? l.getTranslation(current
35                                                 .getText()) : current.getText());
36                                 out.print("</td>");
37                         }
38                         out.println("</tr>");
39                 }
40                 out.println("</table>");
41         }
42
43         /**
44          * <b>Note:</b> All cells have the html attribute class="DataTD"!
45          * 
46          * @author janis
47          * 
48          */
49         public static class Cell {
50                 private String text, htmlAttribs;
51                 private boolean translate;
52                 private int colSpan;
53
54                 public Cell() {
55                         this("&nbsp;", false);
56                 }
57
58                 public Cell(String text, boolean translate, int colSpan,
59                                 String htmlAttribs) {
60                         this.text = text;
61                         this.translate = translate;
62                         this.htmlAttribs = htmlAttribs;
63                         this.colSpan = colSpan;
64                 }
65
66                 public Cell(String text, boolean translate) {
67                         this(text, translate, 1, "");
68                 }
69
70                 public Cell(String text, boolean translate, int colSpan) {
71                         this(text, translate, colSpan, "");
72                 }
73
74                 public boolean shouldTranslate() {
75                         return translate;
76                 }
77
78                 public String getText() {
79                         return text;
80                 }
81
82                 public int getColSpan() {
83                         return colSpan;
84                 }
85
86                 public String getHtmlAttribs() {
87                         return htmlAttribs;
88                 }
89
90         }
91
92 }