//
// $Id$

package com.threerings.gwt.ui;

import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Widget;

/**
 * Extends {@link FlexTable} with a number of extremely useful utility methods.
 */
public class SmartTable extends FlexTable
{
    public SmartTable ()
    {
    }

    public SmartTable (int cellPadding, int cellSpacing)
    {
        setCellPadding(cellPadding);
        setCellSpacing(cellSpacing);
    }

    public SmartTable (String styleName, int cellPadding, int cellSpacing)
    {
        setStyleName(styleName);
        setCellPadding(cellPadding);
        setCellSpacing(cellSpacing);
    }

    /**
     * Sets the text in the specified cell, with the specified style and column span.
     *
     * @param text an object whose string value will be displayed.
     */
    public void setText (int row, int column, Object text, int colSpan, String style)
    {
        setText(row, column, String.valueOf(text));
        if (colSpan > 0) {
            getFlexCellFormatter().setColSpan(row, column, colSpan);
        }
        if (style != null) {
            getFlexCellFormatter().setStyleName(row, column, style);
        }
    }

    /**
     * Sets the HTML in the specified cell, with the specified style and column span.
     */
    public void setHTML (int row, int column, String text, int colSpan, String style)
    {
        setHTML(row, column, text);
        if (colSpan > 0) {
            getFlexCellFormatter().setColSpan(row, column, colSpan);
        }
        if (style != null) {
            getFlexCellFormatter().setStyleName(row, column, style);
        }
    }

    /**
     * Sets the widget in the specified cell, with the specified style and column span.
     */
    public void setWidget (int row, int column, Widget widget, int colSpan, String style)
    {
        setWidget(row, column, widget);
        if (colSpan > 0) {
            getFlexCellFormatter().setColSpan(row, column, colSpan);
        }
        if (style != null) {
            getFlexCellFormatter().setStyleName(row, column, style);
        }
    }

    /**
     * Adds text to the bottom row of this table in column zero, with the specified column span and
     * style.
     *
     * @param text an object whose string value will be displayed.
     *
     * @return the row to which the text was added.
     */
    public int addText (Object text, int colSpan, String style)
    {
        int row = getRowCount();
        setText(row, 0, text, colSpan, style);
        return row;
    }

    /**
     * Adds a widget to the bottom row of this table in column zero, with the specified column span
     * and style.
     *
     * @return the row to which the widget was added.
     */
    public int addWidget (Widget widget, int colSpan, String style)
    {
        int row = getRowCount();
        setWidget(row, 0, widget, colSpan, style);
        return row;
    }
}

@@ -886,38 +886,42 @@
  colSpan, String
+...
  style
+s
 )%0A    %7B%0A        
@@ -1078,33 +1078,42 @@
         
-if (style != null
+for (String style : styles
 ) %7B%0A    
@@ -1135,35 +1135,35 @@
 CellFormatter().
-set
+add
 StyleName(row, c
@@ -1366,38 +1366,42 @@
  colSpan, String
+...
  style
+s
 )%0A    %7B%0A        
@@ -1542,33 +1542,42 @@
         
-if (style != null
+for (String style : styles
 ) %7B%0A    
@@ -1599,35 +1599,35 @@
 CellFormatter().
-set
+add
 StyleName(row, c
@@ -1836,38 +1836,42 @@
  colSpan, String
+...
  style
+s
 )%0A    %7B%0A        
@@ -2020,25 +2020,34 @@
     
-if (style != null
+for (String style : styles
 ) %7B%0A
@@ -2081,19 +2081,19 @@
 atter().
-set
+add
 StyleNam
@@ -2443,38 +2443,42 @@
  colSpan, String
+...
  style
+s
 )%0A    %7B%0A        
@@ -2538,32 +2538,33 @@
 , colSpan, style
+s
 );%0A        retur
@@ -2832,22 +2832,26 @@
 , String
+...
  style
+s
 )%0A    %7B%0A
@@ -2923,32 +2923,33 @@
 , colSpan, style
+s
 );%0A        retur

Allow multiple styles to be specified if desired.