import java.io.*;

/**
 * Writes formatted tables (i.e., 2-dimensional arrays of
 * String objects) to a PrintWriter
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class TableWriterOrig
{
    private int               fieldWidth;
    private PrintWriter       out;

    /**
     * Explicit Value Constructor
     *
     * @param out   The PrintWriter to write to
     */
    public TableWriter(PrintWriter out)
    {
	this.out   = out;
	fieldWidth = 12;
    }


    /**
     * Print a table
     *
     * @param table   The table to print
     */
    public void printTable(String[][] table)
    {
	FieldFormat        formatter;
	int                i, j;

	formatter = new FieldFormat();
	formatter.setFieldWidth(fieldWidth);

	for (i=0; i < table.length; i++)
	{
	    for (j=0; j < table[0].length; j++)
	    {
		if (table[i][j] == null)
		{
		    out.print(formatter.fitStringToField(" "));
		}
		else
		{
		    out.print(formatter.fitStringToField(table[i][j]));
		}
	    }
	    out.println();
	}
    }



    /**
     * Set the field width to use for each 
     * entry in the table
     *
     * @param width
     */
    public void setFieldWidth(int width)
    {
	fieldWidth = width;
    }
			   
}
