Class HTMLTable

public class HTMLTable
extends Panel
implements SourcesTableEvents

// Superclass of Grid, FlexTable
HTMLTable contains the common table algorithms for Grid and FlexTable.

Nested Classes

HTMLTable.CellFormatterThis class contains methods used to format a table's cells.
HTMLTable.RowFormatterThis class contains methods used to format a table's rows.

Constructors

HTMLTable()

Methods

add(Widget)This method is not implemented, as widgets must be added to specific cells in the table.
addTableListener(TableListener)Adds a listener interface to receive click events.
clear()Removes all widgets from this table, but does not remove other HTML or text contents of cells.
clearCell(int, int)Clears the given row and column.
createCell()Creates a new cell.
getBodyElement()
getCellCount(int)Gets the number of cells in a given row.
getCellFormatter()Gets the CellFormatter associated with this table.
getCellPadding()Gets the amount of padding that is added around all cells.
getCellSpacing()Gets the amount of spacing that is added around all cells.
getHTML(int, int)Gets the HTML contents of the specified cell.
getRowCount()Gets the number of rows present in this table.
getRowFormatter()Gets the RowFormatter associated with this table.
getText(int, int)Gets the text within the specified cell.
getWidget(int, int)Gets the widget in the specified cell.
insertCell(int, int)Inserts a new cell into the specified row.
insertCells(int, int, int)Inserts a number of cells before the specified cell.
insertRow(int)Inserts a new row into the table.
iterator()Gets an iterator for the contained widgets.
onBrowserEvent(Event)
prepareCell(int, int)Subclasses must implement this method.
remove(Widget)Removes a widget from the panel.
removeCell(int, int)Removes the specified cell from the table.
removeRow(int)Removes the specified row from the table.
removeTableListener(TableListener)Removes a previously added listener interface.
setBorderWidth(int)Sets the width of the table's border.
setCellFormatter(HTMLTable.CellFormatter)Sets the table's CellFormatter.
setCellPadding(int)Sets the amount of padding to be added around all cells.
setCellSpacing(int)Sets the amount of spacing to be added around all cells.
setHTML(int, int, String)Sets the HTML contents of the specified cell.
setRowFormatter(HTMLTable.RowFormatter)Sets the table's RowFormatter.
setText(int, int, String)Sets the text within the specified cell.
setWidget(int, int, Widget)Sets the widget within the specified cell.

Constructor Detail

HTMLTable

public HTMLTable()

Method Detail

add

public boolean add(Widget w)
This method is not implemented, as widgets must be added to specific cells in the table.

Parameters

w

addTableListener

public void addTableListener(TableListener listener)
Adds a listener interface to receive click events.

Parameters

listener
the listener interface to add

clear

public void clear()
Removes all widgets from this table, but does not remove other HTML or text contents of cells.

clearCell

public boolean clearCell(int row, int column)
Clears the given row and column. If it contains a Widget, it will be removed from the table. If not, its contents will simply be cleared.

Parameters

row
the widget's column
column
the widget's column

Return Value

true if a widget was removed

createCell

protected Element createCell()
Creates a new cell. Override this method if the cell should have initial contents

Return Value

the newly created TD

getBodyElement

protected Element getBodyElement()

getCellCount

public int getCellCount(int row)
Gets the number of cells in a given row.

Parameters

row
the row whose cells are to be counted

Return Value

the number of cells present in the row

getCellFormatter

public HTMLTable.CellFormatter getCellFormatter()
Gets the CellFormatter associated with this table.

Return Value

this table's cell formatter

getCellPadding

public int getCellPadding()
Gets the amount of padding that is added around all cells.

Return Value

the cell padding, in pixels

getCellSpacing

public int getCellSpacing()
Gets the amount of spacing that is added around all cells.

Return Value

the cell spacing, in pixels

getHTML

public String getHTML(int row, int column)
Gets the HTML contents of the specified cell.

Parameters

row
the cell's row
column
the cell's column

Return Value

the cell's HTML contents

getRowCount

public int getRowCount()
Gets the number of rows present in this table.

Return Value

the table's row count

getRowFormatter

public HTMLTable.RowFormatter getRowFormatter()
Gets the RowFormatter associated with this table.

Return Value

the table's row formatter

getText

public String getText(int row, int column)
Gets the text within the specified cell.

Parameters

row
the cell's row
column
the cell's column

Return Value

the cell's text contents

getWidget

public Widget getWidget(int row, int column)
Gets the widget in the specified cell.

Parameters

row
the cell's row
column
the cell's column

Return Value

the widget in the specified cell, or null if none is present

insertCell

protected void insertCell(int row, int column)
Inserts a new cell into the specified row.

Parameters

row
the row into which the new cell will be inserted
column
the column before which the cell will be inserted

insertCells

protected void insertCells(int row, int column, int count)
Inserts a number of cells before the specified cell.

Parameters

row
the row into which the new cells will be inserted
column
the column before which the new cells will be inserted
count
number of cells to be inserted

insertRow

protected int insertRow(int beforeRow)
Inserts a new row into the table.

Parameters

beforeRow
the index before which the new row will be inserted

Return Value

the index of the newly-created row

iterator

public Iterator iterator()
Gets an iterator for the contained widgets.

onBrowserEvent

public void onBrowserEvent(Event event)

Parameters

event

prepareCell

protected abstract void prepareCell(int row, int column)
Subclasses must implement this method. It allows them to decide what to do just before a cell is accessed. If the cell already exists, this method must do nothing. Otherwise, a subclass must either ensure that the cell exists or throw an IndexOutOfBoundsException.

Parameters

row
the cell's row
column
the cell's column

remove

public abstract boolean remove(Widget w)
Removes a widget from the panel.

Parameters

w
the widget to be removed

Return Value

true if the widget was present

removeCell

protected void removeCell(int row, int column)
Removes the specified cell from the table.

Parameters

row
the row of the cell to remove
column
the column of cell to remove

removeRow

protected void removeRow(int row)
Removes the specified row from the table.

Parameters

row
the index of the row to be removed

removeTableListener

public void removeTableListener(TableListener listener)
Removes a previously added listener interface.

Parameters

listener
the listener interface to remove

setBorderWidth

public void setBorderWidth(int width)
Sets the width of the table's border. This border is displayed around all cells in the table.

Parameters

width
the width of the border, in pixels

setCellFormatter

protected void setCellFormatter(HTMLTable.CellFormatter cellFormatter)
Sets the table's CellFormatter.

Parameters

cellFormatter
the table's cell formatter

setCellPadding

public void setCellPadding(int padding)
Sets the amount of padding to be added around all cells.

Parameters

padding
the cell padding, in pixels

setCellSpacing

public void setCellSpacing(int spacing)
Sets the amount of spacing to be added around all cells.

Parameters

spacing

Return Value

the cell spacing, in pixels

setHTML

public void setHTML(int row, int column, String html)
Sets the HTML contents of the specified cell.

Parameters

row
the cell's row
column
the cell's column
html
the cell's HTML contents

setRowFormatter

protected void setRowFormatter(HTMLTable.RowFormatter rowFormatter)
Sets the table's RowFormatter.

Parameters

rowFormatter
the table's row formatter

setText

public void setText(int row, int column, String text)
Sets the text within the specified cell.

Parameters

row
the cell's row
column
cell's column
text
the cell's text contents

setWidget

public void setWidget(int row, int column, Widget widget)
Sets the widget within the specified cell.

Inherited implementations may either throw IndexOutOfBounds exception if the cell does not exist, or allocate a new cell to store the content

Parameters

row
the cell's row
column
the cell's column
widget
The widget to be added