]> WPIA git - gigi.git/blob - src/org/cacert/gigi/output/DataTable.java
Another calc fix
[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 " + current.getHtmlAttribs() + " >");
33                                 out.print(current.shouldTranslate() ? l.getTranslation(current
34                                                 .getText()) : current.getText());
35                                 out.print("</td>");
36                         }
37                         out.println("</tr>");
38                 }
39                 out.println("</table>");
40         }
41
42         public static class Cell {
43                 private String text, htmlAttribs;
44                 private boolean translate;
45                 private int colSpan;
46
47                 public Cell() {
48                         this("&nbsp;", false);
49                 }
50
51                 public Cell(String text, boolean translate, int colSpan,
52                                 String htmlAttribs) {
53                         this.text = text;
54                         this.translate = translate;
55                         this.htmlAttribs = htmlAttribs;
56                         if (colSpan > 1) {
57                                 this.htmlAttribs += " colspan=\"" + colSpan + "\"";
58                         }
59                         this.colSpan = colSpan;
60                 }
61
62                 public Cell(String text, boolean translate) {
63                         this(text, translate, 1, "class=\"DataTD\"");
64                 }
65
66                 public Cell(String text, boolean translate, int colSpan) {
67                         this(text, translate, colSpan, "class=\"DataTD\"");
68                 }
69
70                 public boolean shouldTranslate() {
71                         return translate;
72                 }
73
74                 public String getText() {
75                         return text;
76                 }
77
78                 public int getColSpan() {
79                         return colSpan;
80                 }
81
82                 public String getHtmlAttribs() {
83                         return htmlAttribs;
84                 }
85
86         }
87
88         @Override
89         public void output(PrintWriter out, Language l, Map<String, Object> vars) {
90                 output(out, l);
91         }
92
93 }