]> WPIA git - gigi.git/blob - src/org/cacert/gigi/output/DataTable.java
Add smaller output method
[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                 int 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 < mesCells / columnCount; i++) {
28                         out.println("<tr>");
29                         for (int j = 0; j < columnCount;) {
30                                 Cell current = cells.get(cellsRendered);
31                                 cellsRendered++;
32                                 j += current.getColSpan();
33                                 out.println("<td " + current.getHtmlAttribs() + " >");
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         public static class Cell {
44                 private String text, htmlAttribs;
45                 private boolean translate;
46                 private int colSpan;
47
48                 public Cell() {
49                         this("&nbsp;", false);
50                 }
51
52                 public Cell(String text, boolean translate, int colSpan,
53                                 String htmlAttribs) {
54                         this.text = text;
55                         this.translate = translate;
56                         this.htmlAttribs = htmlAttribs;
57                         if (colSpan > 1) {
58                                 this.htmlAttribs += " colspan=\"" + colSpan + "\"";
59                         }
60                         this.colSpan = colSpan;
61                 }
62
63                 public Cell(String text, boolean translate) {
64                         this(text, translate, 1, "class=\"DataTD\"");
65                 }
66
67                 public Cell(String text, boolean translate, int colSpan) {
68                         this(text, translate, colSpan, "class=\"DataTD\"");
69                 }
70
71                 public boolean shouldTranslate() {
72                         return translate;
73                 }
74
75                 public String getText() {
76                         return text;
77                 }
78
79                 public int getColSpan() {
80                         return colSpan;
81                 }
82
83                 public String getHtmlAttribs() {
84                         return htmlAttribs;
85                 }
86
87         }
88
89         @Override
90         public void output(PrintWriter out, Language l, Map<String, Object> vars) {
91                 output(out, l);
92         }
93
94 }