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