/*
* SPDXVersion: SPDX-1.1
* Creator: Person: Nuno Brito (nuno.brito@triplecheck.de)
* Creator: Organization: TripleCheck (contact@triplecheck.de)
* Created: 2013-11-17T00:00:00Z
* LicenseName: NOASSERTION
* FileName: Table.java
* FileType: SOURCE
* FileCopyrightText: <text> Copyright 2013 Nuno Brito, TripleCheck </text>
* FileComment: <text> Eases the creation of HTML tables </text>
*/
package www;
import java.util.ArrayList;
/**
*
* @author Nuno Brito, 17th of November 2013 in Darmstadt, Germany.
* nuno.brito@triplecheck.de | http://nunobrito.eu
*/
public class Table {
String
headerOutput,
footerOutput;
int size = 0;
String
color1 = "<td style=\"font-family: Arial;\">",
color2 = "<td style=\"font-family: Arial; background-color: rgb(219, 229, 241);\">";
Boolean alternate = true;
//ArrayList<String[]> items = new ArrayList();
String
itemData = "",
headerData = "";
/**
* Public constructor, important to define the array
* @param header
*/
public Table(String[] header){
size = header.length;
String result = "";
for(String item : header){
result += //"<th>"
"<th style=\"text-align: left; color: rgb(31, 73, 125); "
+ "font-weight: bold; font-family: Arial;\">"
+ item
+ "</th>";
}
// do the header
headerData = "<tr>"
+ result
+ "</tr>";
}
/**
* Add this item to our table list
* @param item the data that we want to fill our list with
*/
public void add(String[] item){
// we need items with the same size as available columns
if(item.length != size){
System.err.println("TB001 - Column sizes don't match: ["
+ utils.text.arrayToString(item, "], [")+ "]");
return;
}
// all good, add up this item
//items.add(item);
itemData += "<tr>";
String color;// = color1;
// do the color switching
if(alternate){
color = color2;
alternate = false;
}else{
color = color1;
alternate = true;
}
// go through each column
for(String text : item){
itemData += color
//+ "<small>"
+ text
//+ "</small>"
+ "</td>";
}
itemData += "</tr>";
}
/**
* Provides the output of this table along with its data
* @return
*/
public String output(){
String result;
// do the header
result = "<table style=\"text-align: left; width: 5px;\" border=\"0\""
+ "cellpadding=\"2\" cellspacing=\"2\">"
+ "<tbody>";
result +=
headerData
+ itemData;
// // now add up our items
// for(String[] item : items){
// result += "<tr>";
// // go through each column
// for(String text : item){
// result += "<td align=\"undefined\" valign=\"undefined\">"
// + text
// + "</td>";
// }
// result += "</tr>";
// }
// add the closing part of the code
result += "</tbody></table>";
// all done
return result;
}
}