org.pentaho.chart.data
Class ChartTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.pentaho.chart.data.ChartTableModel
All Implemented Interfaces:
Serializable, TableModel, ChartData

public class ChartTableModel
extends AbstractTableModel

Contains the data and metadata using with the charting API.

Author:
David Kincade
See Also:
Serialized Form

Field Summary
static String COL_NAME
          Column name.
static String ROW_NAME
          Row name.
 
Constructor Summary
ChartTableModel()
          Creats an empty ChartTableModel
ChartTableModel(boolean rotation)
          Creats an empty ChartTableModel
 
Method Summary
 int findRow(String rowName)
          Returns the row number of the 1st row with the specified row name.
 Object getCellMetadata(int row, int col, Object key)
          Retrieves the valid of the metadata for the specified cell and key
 Object getColMetadata(int col, Object key)
          Retrieves the metadata for the specified key and column
 int getColumnCount()
          Returns the number of columns in the table
 String getColumnName(int col)
          Returns the name of the specified 0-based column number
 int getRowCount()
          Returns the number of rows in the table
 Object getRowMetadata(int row, Object key)
          Retrieves the metadata for the specified row and key.
 String getRowName(int row)
          Returns the name of the specified 0-based row
 Object getValueAt(int row, int col)
          Returns the data at the specified (row, col)
 boolean isRotated()
          Returns the current rotation
 void setCellMetadata(int row, int col, Object key, Object value)
          Sets a piece of metadata for a specified cell
 void setColMetadata(int col, Object key, Object value)
          Sets a pieces of metadata for the specified column
 void setColumnName(int col, String name)
          Sets the name of the column for the specified 0-based column number
 void setData(Object[][] inData)
          Sets the data based on the input Object array passed.
 void setRotated(boolean rotated)
          Sets the rotation.
 void setRowMetadata(int row, Object key, Object value)
          Sets a piece of metadata for the specified row
 void setRowName(int row, String name)
          Sets the name of the specified row
 void setValueAt(Object value, int row, int col)
          Sets the data at the specified (row, col)
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.pentaho.chart.ChartData
findColumn
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, getColumnClass, isCellEditable, removeTableModelListener
 

Field Detail

ROW_NAME

public static final String ROW_NAME
Row name.

See Also:
Constant Field Values

COL_NAME

public static final String COL_NAME
Column name.

See Also:
Constant Field Values
Constructor Detail

ChartTableModel

public ChartTableModel()
Creats an empty ChartTableModel


ChartTableModel

public ChartTableModel(boolean rotation)
Creats an empty ChartTableModel

Method Detail

isRotated

public boolean isRotated()
Returns the current rotation


setRotated

public void setRotated(boolean rotated)
Sets the rotation. If the rotation is true, then the rows will be accessed as columns and the columns will be accessed as rows. If the rotation is false, then the table will be accessed as normal.


getColumnCount

public int getColumnCount()
Returns the number of columns in the table

Specified by:
getColumnCount in interface TableModel

getRowCount

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

Specified by:
getRowCount in interface TableModel

getColumnName

public String getColumnName(int col)
Returns the name of the specified 0-based column number

Specified by:
getColumnName in interface TableModel
See Also:
Column name is ofcourse column specific, so we use COL as a placeholder to get Column specific data

setColumnName

public void setColumnName(int col,
                          String name)
Sets the name of the column for the specified 0-based column number

Specified by:
setColumnName in interface ChartData
Parameters:
col - the 0-based column number
name - the name for the specified column

getValueAt

public Object getValueAt(int row,
                         int col)
Returns the data at the specified (row, col)

Specified by:
getValueAt in interface TableModel
See Also:
TableModel.getValueAt(int, int)

setValueAt

public void setValueAt(Object value,
                       int row,
                       int col)
                throws ArrayIndexOutOfBoundsException,
                       IllegalStateException
Sets the data at the specified (row, col)

Specified by:
setValueAt in interface TableModel
Parameters:
value - The value to be set
row - The row number to be used
col - The col number to be used
Throws:
ArrayIndexOutOfBoundsException - indicates the row or column are invalid
IllegalStateException - indicates there is no data in the table

setRowMetadata

public void setRowMetadata(int row,
                           Object key,
                           Object value)
                    throws IllegalArgumentException
Sets a piece of metadata for the specified row

Specified by:
setRowMetadata in interface ChartData
Parameters:
row - the 0-based row number upon which to set the metadata
key - the key for the metadata
value - the value of the metadata
Throws:
IllegalArgumentException - indicates an invalid parameter value

getRowMetadata

public Object getRowMetadata(int row,
                             Object key)
                      throws IllegalArgumentException
Retrieves the metadata for the specified row and key.

Specified by:
getRowMetadata in interface ChartData
Parameters:
row - the 0-based row number to check for the metadata
key - the metadata key used to retrieve the metadata value
Returns:
the metadata value for the specified row and key. This method will return null if the metadata or row do not exist.
Throws:
IllegalArgumentException - indicates an invalid row number or key

setColMetadata

public void setColMetadata(int col,
                           Object key,
                           Object value)
                    throws IllegalArgumentException
Sets a pieces of metadata for the specified column

Specified by:
setColMetadata in interface ChartData
Parameters:
col - the 0-based column number upon which the metadata will be set
key - the metadata key
value - the metadata value
Throws:
IllegalArgumentException - indicates an invalid parameter value

getColMetadata

public Object getColMetadata(int col,
                             Object key)
                      throws IllegalArgumentException
Retrieves the metadata for the specified key and column

Specified by:
getColMetadata in interface ChartData
Parameters:
col - the 0-based column from which the metadata will be retrieved
key - the key used to retrieve the metadata
Returns:
the value of the metadata. If the data does not exist, null will be returned
Throws:
IllegalArgumentException - indicates an invalid patameter

setCellMetadata

public void setCellMetadata(int row,
                            int col,
                            Object key,
                            Object value)
                     throws IllegalArgumentException
Sets a piece of metadata for a specified cell

Specified by:
setCellMetadata in interface ChartData
Parameters:
row - the 0-based row of the cell for which the metadata will be set
col - the 0-based column of the cell for which the metadata will be set
key - the key of the metadata
value - the value of the metadata
Throws:
IllegalArgumentException - indicates an invalid parameter

getCellMetadata

public Object getCellMetadata(int row,
                              int col,
                              Object key)
Retrieves the valid of the metadata for the specified cell and key

Specified by:
getCellMetadata in interface ChartData
Parameters:
row - the 0-based row for the cell
col - the 0-based column for the cell
key - the metadata key
Returns:
the value of the metadata

getRowName

public String getRowName(int row)
Returns the name of the specified 0-based row

Specified by:
getRowName in interface ChartData
Parameters:
row - the 0-based row number for which the name should be returned
Returns:
the name of the specified row

setRowName

public void setRowName(int row,
                       String name)
Sets the name of the specified row

Specified by:
setRowName in interface ChartData
Parameters:
row - the 0-based row index
name - the name to assign to the specified row

findRow

public int findRow(String rowName)
Returns the row number of the 1st row with the specified row name.

Specified by:
findRow in interface ChartData
Parameters:
rowName - the row name
Returns:
the row number of the 1st row with the specified row name, or -1 if none found.

setData

public void setData(Object[][] inData)
             throws IllegalStateException
Sets the data based on the input Object array passed.

Parameters:
inData - The input data
Throws:
IllegalStateException - if any data element within the array is null.