import java.util.*;

import THtmlFont;
import THtmlTableCell;

/*-------------------------------------------------- 
* CLASS: THtmlTableRow
* DESCRIPTION: Is used to produce a formatted Html
   Table Row tag ("<tr>...</tr>") with a number of 
   attributes
* STATUS: 
* HISTORY: 
    25th Jan 2001- written
* DOCUMENTED AT: ? 
* CODE LOCATION: 
    \LibraryCode\Java\Classes\SourceCode1\ 
* TO DO: 
------------------------------------------------------*/ 

public class THtmlTableRow
{
  private StringBuffer sbBackgroundColour;
  private List llTableCells;     

  //-----------------------------------
  // Constructors
  //-----------------------------------
  public THtmlTableRow(List llTableCells, String sBackgroundColour)
  {
    this.sbBackgroundColour = new StringBuffer(sBackgroundColour);
    this.llTableCells = llTableCells;
  } /* Constructor: (L, S) */

  public THtmlTableRow(List llTableCells)
    { this(llTableCells, "white"); }

  public THtmlTableRow()
    { this(new ArrayList(), "white"); }

  //-----------------------------------
  // Accessor methods
  //-----------------------------------

  public void setBackgroundColour(String sBackgroundColour)
    { this.sbBackgroundColour = new StringBuffer(sBackgroundColour); }

  public void setTableCells(List llTableCells)
    { this.llTableCells = llTableCells; }

  public String getBackgroundColour()
    { return this.sbBackgroundColour.toString(); }

  public List getTableCells()
    { return this.llTableCells; }

  public THtmlTableCell getTableCell(int iCellIndex)
    { return (THtmlTableCell)this.llTableCells.get(iCellIndex); }

  //-----------------------------------
  // Append method
  //-----------------------------------

  public void appendTableCell(THtmlTableCell htcTableCell)
    { this.llTableCells.add(htcTableCell); }

  //-----------------------------------
  // toString method
  //-----------------------------------
  public String toString()
  {
    String sReturn;
    sReturn = "";
    sReturn = 
      "<tr   bgcolor = \"" + this.sbBackgroundColour + "\"> \n";
    for (ListIterator ii = this.llTableCells.listIterator(); ii.hasNext();)
    {
      sReturn += (THtmlTableCell)ii.next();
    } /* for */

    sReturn += "</tr> \n";
    return sReturn;
  } /* method: toString */
  
  //-- Test script
  public static void main(String[] args)
  {
    String sDisplay;
    List llCells;
    THtmlTableCell htcTableCell;
    THtmlFont hfFont;
    THtmlTableRow htrTestRow;

    sDisplay = 
      "+----------------------------------------------------------+ \n" +
      "|  The THtmlTableRow class:                                | \n" +
      "|                                                          | \n" +
      "|  This purpose of this class is to produce an Html        | \n" +
      "|  'td' tag with a (small) number of attributes and        | \n" +
      "|  containing some text.                                   | \n" +
      "|  The toString() method produces the formatted Html text. | \n" +
      "|  The THtmlTableRow class has a dependency on the         | \n" +
      "|  THtmlFont class, and the THtmlTableCell class           | \n" +
      "|                                                          | \n" +
      "+----------------------------------------------------------+ \n" +
      "|  Testing the toString() method with a                    | \n" +
      "|  constructor ()...                                       | \n" +
      "+----------------------------------------------------------+ \n\n";       

    htrTestRow = new THtmlTableRow();
    sDisplay += htrTestRow;

    sDisplay +=
      "+----------------------------------------------------------+ \n" +
      "|  Testing the toString() method, appendTableCell() method | \n" +
      "|  with constructor()...                                   | \n" +
      "+----------------------------------------------------------+ \n\n";       

    htcTableCell = new THtmlTableCell("cell contents");
    htrTestRow = new THtmlTableRow();
    htrTestRow.appendTableCell(htcTableCell);
    htrTestRow.appendTableCell(htcTableCell);

    sDisplay += htrTestRow;

    sDisplay +=
      "+----------------------------------------------------------+ \n" +
      "|  Testing the toString() method, with a 2 argument        | \n" +
      "|  constructor (List, String)...                           | \n" +
      "+----------------------------------------------------------+ \n\n";       

    htcTableCell = new THtmlTableCell("cell one");
    llCells = new ArrayList();
    llCells.add(htcTableCell);
    htcTableCell = new THtmlTableCell("cell two");
    llCells.add(htcTableCell);

    htrTestRow = new THtmlTableRow(llCells, "blue");
    sDisplay += htrTestRow;

    System.out.println(sDisplay);
  } //-- main
} //--class: THtmlTableRow