prog.utils
Class HTMLTable

java.lang.Object
  |
  +--prog.utils.HTMLTable

public class HTMLTable
extends java.lang.Object

This class enables the creation of an HTML table.

You provide the contents for the cells and specify how many columns the table is to have, which direction to fill the table (by column/VERT or by row/HORIZ) and what table properties you prefer. The makeTable() methods return an String of HTML tags representing the cell contents in an HTML table.

You can supply the cell data via a Vector of Strings or supply the cell data on cell at a time via addCell().

Author:
John E. Darrow (c) 2000

Field Summary
static int BOTTOM
          A variable representing placement.
static int CENTER
          A variable representing placement.
static int HORIZ
          A variable representing placement.
 int indentSize
          How much to indent the table tags in the raw HTML file.
static int LEFT
          A variable representing placement.
static int RIGHT
          A variable representing placement.
 int tableBorder
          The size of the table border.
static int TOP
          A variable representing placement.
static int VERT
          A variable representing placement.
 
Constructor Summary
HTMLTable()
          Prepares for generating a table with 0 indent size.
HTMLTable(int indent)
          Prepares for generating a table with specified indent size.
 
Method Summary
 void addCell(java.lang.String cellContents)
          Adds the cell information to a vector that is used when you call makeTable() with a null value of cellStrs.
static void main(java.lang.String[] args)
           
 java.lang.String makeTable(java.util.Vector cellStrs, int direction, int numCols)
          Returns a String expression representing an HTML table with fixed number of columns whose cells are filled with the String values supplied in cellStrs.
 java.lang.String makeTable(java.util.Vector cellStrs, int direction, int preferredMaxItemsPerCol, int minCols, int maxCols)
          Returns an HTML table (see makeTable(Vector, int, int).
 void setCellPadSpace(int cellPadding, int cellSpacing)
          Changes the default cell padding and spacing of 2 to cellPadding and cellSpacing.
 void setColParams(int column, int horizAlign, int vertAlign, int widthPixels)
          Establishes horizontal and vertical alignment of all cells in a given column.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tableBorder

public int tableBorder
The size of the table border. Default is 0.

indentSize

public int indentSize
How much to indent the table tags in the raw HTML file. Set to a non-0 value only when this table is nested within another table.

LEFT

public static final int LEFT
A variable representing placement.

CENTER

public static final int CENTER
A variable representing placement.

RIGHT

public static final int RIGHT
A variable representing placement.

TOP

public static final int TOP
A variable representing placement.

BOTTOM

public static final int BOTTOM
A variable representing placement.

HORIZ

public static final int HORIZ
A variable representing placement.

VERT

public static final int VERT
A variable representing placement.
Constructor Detail

HTMLTable

public HTMLTable()
Prepares for generating a table with 0 indent size.

HTMLTable

public HTMLTable(int indent)
Prepares for generating a table with specified indent size. Use this constructor if nesting this table within another HTML structure such as another table cell.
Method Detail

setColParams

public void setColParams(int column,
                         int horizAlign,
                         int vertAlign,
                         int widthPixels)
Establishes horizontal and vertical alignment of all cells in a given column.

setCellPadSpace

public void setCellPadSpace(int cellPadding,
                            int cellSpacing)
Changes the default cell padding and spacing of 2 to cellPadding and cellSpacing.

addCell

public void addCell(java.lang.String cellContents)
Adds the cell information to a vector that is used when you call makeTable() with a null value of cellStrs.

makeTable

public java.lang.String makeTable(java.util.Vector cellStrs,
                                  int direction,
                                  int numCols)
Returns a String expression representing an HTML table with fixed number of columns whose cells are filled with the String values supplied in cellStrs. If cellStrs is null, cell contents provided previously via addCell(String) are used. (If no cell values were previously provided, an error message is returned.)

If direction is HORIZ, cell data are inserted into the table row by row. If VERT, column by column. If cellStrs is null, makeTable()uses cell data provided previously via addCell(String). If no cell data were previously provided, the method returns an error message.


makeTable

public java.lang.String makeTable(java.util.Vector cellStrs,
                                  int direction,
                                  int preferredMaxItemsPerCol,
                                  int minCols,
                                  int maxCols)
Returns an HTML table (see makeTable(Vector, int, int). You specify the direction cell data are to be added to the table, the preferred maximum number of cells per column and the maximum and minimum columns you will allow, and this method determines the best number of columns for the available data.
Parameters:
minCols - The minimum number of columns if there are more than one elements. (For only one element, a single-column table is returned.)
preferredMaxItemsPerCol - The maximum number of elements allowed per column before a new column is started. If a new column is needed, elements are balanced over all columns.
maxCols - The maximum number of columns. If preferredMaxItemsPerCol would result in more than maxCols, maxCols takes precedence over preferredMaxItemsPerCol.

main

public static void main(java.lang.String[] args)