import org.cacert.gigi.Language;
-public abstract class DataTable implements Outputable {
- protected abstract String[] getColumns();
+public class DataTable implements Outputable {
+ private LinkedList<Cell> cells;
+ private int columnCount;
- protected abstract LinkedList<Cell> getTableContent();
+ public DataTable(int coloumnCount, LinkedList<Cell> content) {
+ this.columnCount = coloumnCount;
+ this.cells = content;
+ }
- @Override
- public void output(PrintWriter out, Language l, Map<String, Object> vars) {
- out.println("<table align=\"center\" valign=\"middle\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"wrapper\">");
- out.println("<tr>");
- for (String column : getColumns()) {
- out.print("<td class=\"DataTD\">");
- out.print(l.getTranslation(column));
- out.println("</td>");
+ public void output(PrintWriter out, Language l) {
+ float mesCells = cells.size();
+ for (Cell c : cells) {
+ if (c.getColSpan() > 1) {
+ mesCells += c.getColSpan();
+ }
}
- out.println("</tr>");
- LinkedList<Cell> tableContnet = getTableContent();
- for (int i = 0; i < tableContnet.size() / getColumns().length; i++) {
+ out.println("<table align=\"center\" valign=\"middle\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"wrapper\">");
+ int cellsRendered = 0;
+ for (int i = 0; i < Math.ceil(mesCells / columnCount) - 1; i++) {
out.println("<tr>");
- for (int j = 0; j < getColumns().length; j++) {
- out.println("<td class=\"DataTD\">");
- Cell current = tableContnet.get((i * getColumns().length) + j);
+ for (int j = 0; j < columnCount;) {
+ Cell current = cells.get(cellsRendered++);
+ j += current.getColSpan();
+ out.println("<td ");
+ out.print(current.getHtmlAttribs());
+ out.print(" >");
out.print(current.shouldTranslate() ? l.getTranslation(current
.getText()) : current.getText());
out.print("</td>");
}
public static class Cell {
- private String text;
+ private String text, htmlAttribs;
private boolean translate;
+ private int colSpan;
- public Cell(String text, boolean translate) {
+ public Cell() {
+ this(" ", false);
+ }
+
+ public Cell(String text, boolean translate, int colSpan,
+ String htmlAttribs) {
this.text = text;
this.translate = translate;
+ this.htmlAttribs = htmlAttribs;
+ if (colSpan > 1) {
+ this.htmlAttribs += " colspan=\"" + colSpan + "\"";
+ }
+ this.colSpan = colSpan;
+ }
+
+ public Cell(String text, boolean translate) {
+ this(text, translate, 1, "class=\"DataTD\"");
+ }
+
+ public Cell(String text, boolean translate, int colSpan) {
+ this(text, translate, colSpan, "class=\"DataTD\"");
}
public boolean shouldTranslate() {
return text;
}
- }
-
- public static class EmptyCell extends Cell {
+ public int getColSpan() {
+ return colSpan;
+ }
- public EmptyCell() {
- super(" ", false);
+ public String getHtmlAttribs() {
+ return htmlAttribs;
}
}
+ @Override
+ public void output(PrintWriter out, Language l, Map<String, Object> vars) {
+ output(out, l);
+ }
+
}