com.objectplanet.gui
Class TableData

java.lang.Object
  extended bycom.objectplanet.gui.TableData

public class TableData
extends java.lang.Object

This class contains the data for the table component. The data is organized into rows and colums where one row and column intersection is a table cell.

Rows can be accessed through their index or a key that was specified when the row was added to the data.

This table data can be shared among several table components so they can effectively use the same data set.

All indices to rows and columns are zero based.

Author:
Bjorn J. Kvande., Phillip A. Kolibaba.

Field Summary
protected  java.util.Vector data
          The data of the table.
 
Constructor Summary
TableData(int columns)
          Creates a new table data object with the specified number of columns.
 
Method Summary
 boolean containsRow(int row)
          Checks if the table data contains a specified row.
 java.lang.Object getCell(int row, int col)
          Gets the specified cell from the table.
 int getColumnCount()
          Returns the number of columns in the Ftable data.
 int getLastIndex()
          Returns the greates index of the rows.
 java.lang.Object[] getRow(int row)
          Gets the fields of the specified row.
 int getRowCount()
          Returns the number of rows in the table data.
 int getRowIndex(java.lang.Object key)
          Translates a row key to the index it is stored in.
 boolean hasChangedSince(long time)
          Checks if the table data has been changed since the specified time.
 void removeAll()
          Removes all the rows from the table data.
 void removeRow(int index)
          Removes the specified row from the table data.
 void setCell(int row, int col, java.lang.Object value)
          Sets the value of a cell in the table.
 int setRow(int row, java.lang.Object[] fields)
          Sets a row in the table at the specified row index.
 int setRow(int index, java.lang.Object key, java.lang.Object[] fields)
          Sets a row in the table at the specified row index keyed by the given key object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

protected java.util.Vector data
The data of the table. Each row is an array of Strings

Constructor Detail

TableData

public TableData(int columns)
Creates a new table data object with the specified number of columns.

Parameters:
columns - The number of columns to use for the data.
Method Detail

containsRow

public boolean containsRow(int row)
Checks if the table data contains a specified row.

Parameters:
row - The row index to test for.
Returns:
True if a row is present, false otherwise.

getCell

public java.lang.Object getCell(int row,
                                int col)
Gets the specified cell from the table.

Parameters:
row - The index of the row.
col - The index of the column.
Returns:
The label of the fields as a String, or null if row is empty.
See Also:
setCell(int, int, java.lang.Object)

getColumnCount

public int getColumnCount()
Returns the number of columns in the Ftable data.


getLastIndex

public int getLastIndex()
Returns the greates index of the rows. Remember this is one less than the size you need since the indeces start at 0.


getRow

public java.lang.Object[] getRow(int row)
Gets the fields of the specified row.

Parameters:
row - The row index.
Returns:
An array of strings or null if no row was found.
Throws:
java.lang.ClassCastException - If the fields is not a String[] array.
See Also:
setRow(int, Object[])

getRowCount

public int getRowCount()
Returns the number of rows in the table data.


getRowIndex

public int getRowIndex(java.lang.Object key)
Translates a row key to the index it is stored in.

Parameters:
key - The key of the row.
Returns:
The index of the row, or -1 if not found.

hasChangedSince

public boolean hasChangedSince(long time)
Checks if the table data has been changed since the specified time.

Parameters:
time - The system time to check for.

removeAll

public void removeAll()
Removes all the rows from the table data.


removeRow

public void removeRow(int index)
Removes the specified row from the table data.

Parameters:
index - The index of the row.

setCell

public void setCell(int row,
                    int col,
                    java.lang.Object value)
Sets the value of a cell in the table.

Parameters:
row - The index of the row to set the cell in.
col - The column to set the cell in.
value - The value to set for the cell (String).
Throws:
java.lang.IllegalArgumentException - If the row or column is incorrect.
java.lang.ClassCastException - If the value is not a String.

setRow

public int setRow(int row,
                  java.lang.Object[] fields)
Sets a row in the table at the specified row index. To add a row at the end, specify -1 as the row index. If the row index is larger than the number of rows currently in the table, the row is added at the specified index and empty rows are inserted in between. If a row exists in the specified row index from before, the old row will be replaced.

Parameters:
row - The index of the row. -1 adds the row at the end.
fields - An array of strings.
Returns:
The index of the row added or replaced.

setRow

public int setRow(int index,
                  java.lang.Object key,
                  java.lang.Object[] fields)
Sets a row in the table at the specified row index keyed by the given key object. The row can then be retrieved by this key at a later time. If a row exists with the same index or key from before, it will be replaced. If the row index is larger than the number of rows currently in the table, the row is added at the specified index and empty rows are inserted in between. If the index is -1 it will be added a the end.

Parameters:
index - The index of the row. -1 adds the row at the end.
key - The key of the row.
fields - The text for each field of the row.
Returns:
The index where the row was set.