All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class net.strandberg.html.HTMLTable

java.lang.Object
   |
   +----net.strandberg.html.HTMLTable

public class HTMLTable
extends Object
implements HTMLItem
The class HTMLTable is used to create an HTML table. An instance of class HTMLTable can be created from a matrix of strings or be created empty and later filled with contents by calling methods in the class. The main method of the class can be used to have the HTMLTable get its contents from a file, using the net.strandberg.file.TableInFile to read a matrix of strings from a file.

Version:
$Revision: 0.2 $
Author:
Mats Strandberg
See Also:
TableInFile

Constructor Index

 o HTMLTable()
Constructs a new HTMLTable, initially empty.
 o HTMLTable(boolean)
Constructs a new HTMLTable, initially empty.
 o HTMLTable(String)
Constructs a new HTMLTable, initially empty.
 o HTMLTable(String, int, int, boolean)
Constructs a new HTMLTable, initially empty.
 o HTMLTable(String[][])
Constructs a new HTMLTable which will get its contents from the String[][] argument.
 o HTMLTable(String[][], String)
Constructs a new HTMLTable which will get its contents from the String[][] argument.
 o HTMLTable(String[][], String, int, int, boolean)
Constructs a new HTMLTable which will get its contents from the String[][] argument.

Method Index

 o addContent(HTMLItem)
Adds contents for the next cell in turn.
 o addContent(String)
Adds contents for the next cell in turn.
 o addContentAndProp(String, String)
Adds contents for the next cell in turn with certain properties.
 o addContentWithSpan(String, int)
Adds contents for the next cell in turn with a certain COLSPAN.
 o addProp(int, int, String)
Adds a property for a given table cell.
 o centerCol(int)
Makes alignment centered for a given column.
 o endRow()
Ends the current row.
 o main(String[])
The main method of HTMLTable is used to transform the contents of a file containing a matrix of strings into a HTML Table.
 o setBufferSize(int)
Sets the buffer size used when generating the HTML in the toHTML() method.
 o toHTML()
Returns HTML code representing this HTMLTable.

Constructors

 o HTMLTable
 public HTMLTable()
Constructs a new HTMLTable, initially empty. The table will have no caption & no headers for the columns. There will be no borders between cells.

 o HTMLTable
 public HTMLTable(boolean hasHeader)
Constructs a new HTMLTable, initially empty. The table will have no caption & there will be no borders between cells.

Parameters:
hasHeader - if true the first row of the table will be generated as a header when toHTML() is called.
 o HTMLTable
 public HTMLTable(String caption)
Constructs a new HTMLTable, initially empty. The table will have no headers for the columns & no borders between cells.

Parameters:
caption - the caption that will be generated when toHTML() is called.
 o HTMLTable
 public HTMLTable(String matrix[][])
Constructs a new HTMLTable which will get its contents from the String[][] argument. The table will have no caption & no headers for the columns. There will be no borders between cells.

Parameters:
matrix - an N x M matrix containing the string to be table cell contents
 o HTMLTable
 public HTMLTable(String matrix[][],
                  String caption)
Constructs a new HTMLTable which will get its contents from the String[][] argument. The table will have no headers for the columns. There will be no borders between cells.

Parameters:
matrix - an N x M matrix containing the string to be table cell contents
caption - the string put between <CAPTION> and </CAPTION>
 o HTMLTable
 public HTMLTable(String caption,
                  int tableBorder,
                  int cellSpacing,
                  boolean hasHeader)
Constructs a new HTMLTable, initially empty.

Parameters:
caption - the string put between <CAPTION> and </CAPTION>
tableBorder - thickness of borders between cells in pixels
cellSpacing - thickness of area between cells in pixels
hasHeader - true if the first row of the table shall be headers
 o HTMLTable
 public HTMLTable(String matrix[][],
                  String caption,
                  int tableBorder,
                  int cellSpacing,
                  boolean hasHeader)
Constructs a new HTMLTable which will get its contents from the String[][] argument.

Parameters:
matrix - an N x M matrix containing the string to be table cell contents
caption - the string put between <CAPTION> and </CAPTION>
tableBorder - thickness of borders between cells in pixels
cellSpacing - thickness of area between cells in pixels
hasHeader - true if the first row of the table shall be headers

Methods

 o main
 public static void main(String args[])
The main method of HTMLTable is used to transform the contents of a file containing a matrix of strings into a HTML Table. The usage is:
java HTMLTable -m matrixFile
where matrixFile is a file containing the table cells to be transformed into an HTML table. The matrixFile should follow the syntax described in net.strandberg.file.TableInFile.

Parameters:
args - command line arguments as described above.
See Also:
TableInFile
 o centerCol
 public void centerCol(int column)
Makes alignment centered for a given column.

Parameters:
column - the column for which the contents should be centered.
 o addProp
 public void addProp(int row,
                     int column,
                     String property)
Adds a property for a given table cell.

Parameters:
row - the row of the table cell for which the property should be set
column - the column of the table cell for which the property should be set
the - property to be set for this table cell e.g. ALIGN=RIGHT.
 o addContent
 public void addContent(String content)
Adds contents for the next cell in turn.

Parameters:
content - the contents to go in the next cell in turn.
 o addContent
 public void addContent(HTMLItem content)
Adds contents for the next cell in turn.

Parameters:
content - the contents to go in the next cell in turn.
 o addContentWithSpan
 public void addContentWithSpan(String content,
                                int colspan)
Adds contents for the next cell in turn with a certain COLSPAN.

Parameters:
content - the contents to go in the next cell in turn.
colspan - the value of the COLSPAN property for this cell.
 o addContentAndProp
 public void addContentAndProp(String content,
                               String properties)
Adds contents for the next cell in turn with certain properties.

Parameters:
content - the contents to go in the next cell in turn.
properties - the properties to with this table cell
 o endRow
 public void endRow()
Ends the current row. To be used in conjunction with the addXXX methods.

 o toHTML
 public String toHTML()
Returns HTML code representing this HTMLTable.

 o setBufferSize
 public void setBufferSize(int bufferSize)
Sets the buffer size used when generating the HTML in the toHTML() method. If the table is very large, setting a buffer size other than the default (4 Kbytes) can boost performance. This as we can avoid the array copy that would otherwise be needed when the internal string, used to represent the HTML code, dynamically grows.

Parameters:
bufferSize - the size of the internal string buffer used when generating HTML code. The size should be given in bytes. (For an extremely large table the default buffer size of 4 Kbytes will not be used. Instead a size somewhere close to the number of cells in the table times 16 will be used).

All Packages  Class Hierarchy  This Package  Previous  Next  Index