CoffeeTable.Grid
Class GridData

java.lang.Object
  |
  +--CoffeeTable.Grid.GridData

public class GridData
extends java.lang.Object
implements GridDataInterface, java.io.Serializable

GridData is a class holds the data for the GridPanel. This class implements the GridDataInterface, which is an abstract interface for storing the data for the Grid's cells, and the Row and Column headers. An instance of this class is stored in the GridPanel and it's methods are called to get or set the data, as well as to resize the GridData as and when needed. The Grid's data can be accessed as Objects or as Strings (uses toString() to get the String representation). The default implementation of the GridPanel and particularly the drawCell() method, always accesses and stores the GridData as Strings using the get/setCellText(), get/setRowHeaderText() and get/setColHeaderText() methods. If an implementation stores the data as any other objects such as Integers, Images etc., then the get/setCellData(), get/setRowHeaderData() and get/setColHeaderData() methods can be used. In addition, the comapre() method may also need to be overridden to deal with non-string data types.

Version:
2.1.3 of October 1, 1999 Copyright © 1996-1999 3Magic
See Also:
Serialized Form

Constructor Summary
GridData()
          Constructs a new empty GridData Object.
GridData(int numRows, int numCols)
          Constructs a new GridData Object.
GridData(int numRows, int numCols, boolean needRowHeaders, boolean needColHeaders)
          Constructs a new GridData Object.
 
Method Summary
 int compare(java.lang.Object aData, java.lang.Object bData, int col)
          The default compare method used by GridPanel.sortRows().
 void deleteCols(int atCol, int count)
          Delete a specified number of columns from a specified position.
 void deleteRows(int atRow, int count)
          Delete a specified number of rows from a specified position.
protected  void finalize()
          Remove all the elements in the internal lists.
 java.lang.Object getCellData(int col, int row)
          Return the data for a cell.
 java.lang.String getCellText(int col, int row)
          Return the text for a cell.
 java.lang.Object getColHeaderData(int col)
          Return the data for a column header.
 java.lang.String getColHeaderText(int col)
          Return the text for a column header.
 int getNumCols()
          Return the number columns in this object.
 int getNumRows()
          Return the number rows in this object.
 java.util.Vector getRowData(int row)
          Return the data for all the cells in a row.
 java.lang.Object getRowHeaderData(int row)
          Return the data for a row header.
 java.lang.String getRowHeaderText(int row)
          Return the text for a row header.
 void insertCols(int atCol, int count)
          Insert a specified number of columns at a specified position.
 void insertRows(int atRow, int count)
          Insert a specified number of rows at a specified position.
 void setCellData(int col, int row, java.lang.Object cellData)
          Sets the data for a cell.
 void setCellText(int col, int row, java.lang.String cellText)
          Sets the text data for a cell.
 void setColHeaderData(int col, java.lang.Object colHeaderData)
          Sets the data for a column header.
 void setColHeaderText(int col, java.lang.String colHeaderText)
          Sets the text data for a column header.
 void setNumCols(int numCols)
          Adjusts the number columns in this object.
 void setNumRows(int numRows)
          Adjusts the number rows in this object.
 void setRowData(int row, java.util.Vector rowData)
          Sets the data for all the cells in a row.
 void setRowHeaderData(int row, java.lang.Object rowHeaderData)
          Sets the data for a row header.
 void setRowHeaderText(int row, java.lang.String rowHeaderText)
          Sets the text data for a row header.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GridData

public GridData()
Constructs a new empty GridData Object.

GridData

public GridData(int numRows,
                int numCols)
Constructs a new GridData Object. It's internal data structures are allocated based on the passed in values for the number of rows and columns.
Parameters:
numRows - the number of rows
numCols - the number of columns

GridData

public GridData(int numRows,
                int numCols,
                boolean needRowHeaders,
                boolean needColHeaders)
Constructs a new GridData Object. It's internal data structures are allocated based on the passed in values for the number of rows and columns.
Parameters:
numRows - the number of rows
numCols - the number of columns
needRowHeaders - whether or not to allocate data for row headers
needColHeaders - whether or not to allocate data for column headers
Method Detail

finalize

protected void finalize()
Remove all the elements in the internal lists. Called when this object is garbage collected.
Overrides:
finalize in class java.lang.Object

setNumRows

public void setNumRows(int numRows)
Adjusts the number rows in this object. This method is called by the GridPanel's setNumRows() method when the Grid's number of rows change.
Specified by:
setNumRows in interface GridDataInterface
Parameters:
numRows - the number of rows
See Also:
GridPanel.setNumRows(int)

getNumRows

public int getNumRows()
Return the number rows in this object.
Specified by:
getNumRows in interface GridDataInterface
Returns:
the number of rows

setNumCols

public void setNumCols(int numCols)
Adjusts the number columns in this object. This method is called by the GridPanel's setNumCols() method when the Grid's number of columns change.
Specified by:
setNumCols in interface GridDataInterface
Parameters:
numRows - the number of rows
See Also:
GridPanel.setNumCols(int)

getNumCols

public int getNumCols()
Return the number columns in this object.
Specified by:
getNumCols in interface GridDataInterface
Returns:
the number of columns

insertRows

public void insertRows(int atRow,
                       int count)
Insert a specified number of rows at a specified position. This method is called by the GridPanel's insertRows() method. This method adjusts the Vectors that store the Grid's data and row header data.
Specified by:
insertRows in interface GridDataInterface
Parameters:
atRow - the index at which new rows will be inserted
count - the number of rows to be inserted
See Also:
GridPanel.insertRows(int, int)

deleteRows

public void deleteRows(int atRow,
                       int count)
Delete a specified number of rows from a specified position. This method is called by the GridPanel's deleteRows() method. This method adjusts the Vectors that store the Grid's data and row header data.
Specified by:
deleteRows in interface GridDataInterface
Parameters:
atRow - the index from which new rows will be deleted
count - the number of rows to be deleted
See Also:
GridPanel.deleteRows(int, int)

insertCols

public void insertCols(int atCol,
                       int count)
Insert a specified number of columns at a specified position. This method is called by the GridPanel's insertCols() method. This method adjusts the Vectors that store the Grid's data and row header data.
Specified by:
insertCols in interface GridDataInterface
Parameters:
atCol - the index at which new columns will be inserted
count - the number of columns to be inserted
See Also:
GridPanel.insertCols(int, int)

deleteCols

public void deleteCols(int atCol,
                       int count)
Delete a specified number of columns from a specified position. This method is called by the GridPanel's deleteCols() method. This method adjusts the Vectors that store the Grid's data and row header data.
Specified by:
deleteCols in interface GridDataInterface
Parameters:
atCol - the index from which new columns will be deleted
count - the number of columns to be deleted
See Also:
GridPanel.deleteCols(int, int)

getCellText

public java.lang.String getCellText(int col,
                                    int row)
Return the text for a cell. This method is called by the GridPanel's getCellText() method, and calls the getCellData() method and returns a string version of the data (using toString()).
Specified by:
getCellText in interface GridDataInterface
Parameters:
col - the column
row - the row
Returns:
a string version of the cell data or an empty string (if null)
See Also:
GridPanel.getCellText(int, int), getCellData(int, int)

getCellData

public java.lang.Object getCellData(int col,
                                    int row)
Return the data for a cell. The method returns a reference to the data object will need to be converted or displayed appropriately.
Specified by:
getCellData in interface GridDataInterface
Parameters:
col - the column
row - the row
Returns:
the data for a cell

getRowHeaderText

public java.lang.String getRowHeaderText(int row)
Return the text for a row header. This method is called by the GridPanel's getRowHeaderText() method, and calls the getRowHeaderData() method and returns a string version of the data (using toString()).
Specified by:
getRowHeaderText in interface GridDataInterface
Parameters:
row - the row
Returns:
a string version of the row header data or an empty string (if null)
See Also:
GridPanel.getRowHeaderText(int), getRowHeaderData(int)

getRowHeaderData

public java.lang.Object getRowHeaderData(int row)
Return the data for a row header. The method returns a reference to the data object will need to be converted or displayed appropriately.
Specified by:
getRowHeaderData in interface GridDataInterface
Parameters:
row - the row
Returns:
the data for a row header

getColHeaderText

public java.lang.String getColHeaderText(int col)
Return the text for a column header. This method is called by the GridPanel's getColHeaderText() method, and calls the getColHeaderData() method and returns a string version of the data (using toString()).
Specified by:
getColHeaderText in interface GridDataInterface
Parameters:
col - the column
Returns:
a string version of the column header data or an empty string (if null)
See Also:
GridPanel.getColHeaderText(int), getColHeaderData(int)

getColHeaderData

public java.lang.Object getColHeaderData(int col)
Return the data for a column header. The method returns a reference to the data object will need to be converted or displayed appropriately.
Specified by:
getColHeaderData in interface GridDataInterface
Parameters:
col - the column
Returns:
the data for a column header

setCellText

public void setCellText(int col,
                        int row,
                        java.lang.String cellText)
Sets the text data for a cell. This method is called by the GridPanel's setCellText() method, and sets the text data for the cell by calling the setCellData() method.
Specified by:
setCellText in interface GridDataInterface
Parameters:
col - the column
row - the row
cellText - the text data for the cell
See Also:
GridPanel.setCellText(int, int, java.lang.String, boolean), setCellData(int, int, java.lang.Object)

setCellData

public void setCellData(int col,
                        int row,
                        java.lang.Object cellData)
Sets the data for a cell. This method stores a reference to the data Object in the GridData structure.
Specified by:
setCellData in interface GridDataInterface
Parameters:
col - the column
row - the row
cellData - a reference to the data for a cell

setRowHeaderText

public void setRowHeaderText(int row,
                             java.lang.String rowHeaderText)
Sets the text data for a row header. This method is called by the GridPanel's setRowHeaderText() method, and sets the text data for the row header by calling the setRowHeaderData() method.
Specified by:
setRowHeaderText in interface GridDataInterface
Parameters:
row - the row
rowHeaderText - the text data for the row header
See Also:
GridPanel.setRowHeaderText(int, java.lang.String, boolean), setRowHeaderData(int, java.lang.Object)

setRowHeaderData

public void setRowHeaderData(int row,
                             java.lang.Object rowHeaderData)
Sets the data for a row header. This method stores a reference to the data Object in the GridData structure.
Specified by:
setRowHeaderData in interface GridDataInterface
Parameters:
row - the row
rowHeaderData - a reference to the data for a row header

setColHeaderText

public void setColHeaderText(int col,
                             java.lang.String colHeaderText)
Sets the text data for a column header. This method is called by the GridPanel's setColHeaderText() method, and sets the text data for the column header by calling the setColHeaderData() method.
Specified by:
setColHeaderText in interface GridDataInterface
Parameters:
col - the column
colHeaderText - the text data for the column header
See Also:
GridPanel.setColHeaderText(int, java.lang.String, boolean), setColHeaderData(int, java.lang.Object)

setColHeaderData

public void setColHeaderData(int col,
                             java.lang.Object colHeaderData)
Sets the data for a column header. This method stores a reference to a Vector containing references to the data objects for all the cells in a row.
Specified by:
setColHeaderData in interface GridDataInterface
Parameters:
col - the column
colHeaderData - a reference to the data for a row header

getRowData

public java.util.Vector getRowData(int row)
Return the data for all the cells in a row. The method returns a Vector containing references to the data objects for all the cells in a row.
Specified by:
getRowData in interface GridDataInterface
Parameters:
row - the row
Returns:
the Vector containg references to the data for all the cells in a row

setRowData

public void setRowData(int row,
                       java.util.Vector rowData)
Sets the data for all the cells in a row. This method stores a reference to a Vector containing reference to the data objects for all the cells in a row.
Specified by:
setRowData in interface GridDataInterface
Parameters:
row - the row
rowData - a Vector containing references to the data for all the cells in a row

compare

public int compare(java.lang.Object aData,
                   java.lang.Object bData,
                   int col)
The default compare method used by GridPanel.sortRows(). This method compares two cell data objects. If the Objects implement the Comparable interface, the compareTo method is called to compare the Objects, otherwise they Objects are compared by comparing their string representations and return 0 if they're equal, a value less than 0 if aData.toString() is less than bData.toString(), and a value greater than 0 if aData.toString() is greater than bData.toString(). This method can be overridden if they cells need to be compared differently.
Specified by:
compare in interface GridDataInterface
Parameters:
aData - the first data object
bData - the second data object
col - the column whose data objects are being compared for the sort