org.netbeans.microedition.lcdui
Class SimpleTableModel

java.lang.Object
  extended by org.netbeans.microedition.lcdui.SimpleTableModel
All Implemented Interfaces:
TableModel

public class SimpleTableModel
extends java.lang.Object
implements TableModel

Simple implementation of TableModel. This model can hold a matrix of String values. A matrix means all rows have to have the same number of columns and rows cannot be null.


Constructor Summary
SimpleTableModel()
          Creates a new empty table model.
SimpleTableModel(int rows, int cols)
          Creates a model with given number of rows and columns.
SimpleTableModel(java.lang.String[][] values, java.lang.String[] columnNames)
          Creates a model with given values and column names.
 
Method Summary
 void addTableModelListener(TableModelListener listener)
          Adds a TableModelListener to this instance of the model.
 void fireTableModelChanged()
          Fires an event that the values in the table has been changed and the table should be repainted.
 int getColumnCount()
          Gets number of columns of the supplied values matrix.
 java.lang.String getColumnName(int column)
          Gets the column name for the specified index
 int getRowCount()
          Gets number of rows of the supplied values matrix.
 java.lang.Object getValue(int col, int row)
          Gets the value of a table cell at a specified location.
 java.lang.String[][] getValues()
          Gets values of the model
 boolean isUsingHeaders()
          Decides wheter this table is using headers (column names).
 void removeTableModelListener(TableModelListener listener)
          Removes a TableModelListener from this instance of the model.
 void setColumnNames(java.lang.String[] columnNames)
          Sets the column names for this model.
 void setValue(int col, int row, java.lang.String value)
          Sets the value to the defined row and column of the model.
 void setValues(java.lang.String[][] values)
          Sets the values of the model.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleTableModel

public SimpleTableModel(java.lang.String[][] values,
                        java.lang.String[] columnNames)
                 throws java.lang.IllegalArgumentException
Creates a model with given values and column names.

Parameters:
values - values to be used in this table model. Please note, the values cannot be null and have to be a valid matrix.
columnNames - column names to be used. Can be null if the column names are not going to be used (see @isUsingHeaders method).
Throws:
java.lang.IllegalArgumentException - If the values parameter is null, or if it is not a valid rectangular matrix.

SimpleTableModel

public SimpleTableModel(int rows,
                        int cols)
                 throws java.lang.IllegalArgumentException
Creates a model with given number of rows and columns.

Parameters:
rows - number of rows to be used in the model. Cannot be negative.
cols - number of columns to be used in the model. Cannot be negative.
Throws:
java.lang.IllegalArgumentException - if the cols or rows argument are lower than zero

SimpleTableModel

public SimpleTableModel()
Creates a new empty table model.

Method Detail

getColumnCount

public int getColumnCount()
Gets number of columns of the supplied values matrix.

Specified by:
getColumnCount in interface TableModel
Returns:
values matrix column count

getRowCount

public int getRowCount()
Gets number of rows of the supplied values matrix.

Specified by:
getRowCount in interface TableModel
Returns:
values matrix row count

setValue

public void setValue(int col,
                     int row,
                     java.lang.String value)
              throws java.lang.IllegalArgumentException
Sets the value to the defined row and column of the model.

Please note, this method does not call fireTableModelChanged method automatically, so you have to call it manually if you would like to redraw the table. This is designed in this way, because of the performance reasons - you might want to update several values at a time and repaint the table at the end of the update.

Throws:
java.lang.IllegalArgumentException - if the values are not defined, or the specifed row or column is larger than the size of the values.

setValues

public void setValues(java.lang.String[][] values)
               throws java.lang.IllegalArgumentException
Sets the values of the model. Values of this model have to be a rectangular matrix - this means all rows have to have the same number of columns and rows canot be null.

Please note, this class is holding just reference to the passed values array, so any change you do to the model via setValue method is actually made in the array.

Parameters:
values - values to be used in this table model. Please note, the values cannot be null and have to be a valid matrix.
Throws:
java.lang.IllegalArgumentException - If the values parameter is null, or if it is not a valid rectangular matrix.

getValues

public java.lang.String[][] getValues()
Gets values of the model

Returns:
values matrix

getValue

public java.lang.Object getValue(int col,
                                 int row)
Gets the value of a table cell at a specified location. Always returns String.

Specified by:
getValue in interface TableModel
Parameters:
col - col index of the value
row - row index of the value
Returns:
value for the given cell coordinates. May return null if there is no value.

isUsingHeaders

public boolean isUsingHeaders()
Decides wheter this table is using headers (column names). This simple model simply checks whether the supplied column names are null and in such a case this method returns true.

Specified by:
isUsingHeaders in interface TableModel
Returns:
true if the column names are being supplied and should be visualized, false otherwise

setColumnNames

public void setColumnNames(java.lang.String[] columnNames)
Sets the column names for this model. The array of names should have the same length as the column count.

Parameters:
columnNames - array of names. May be null if the column headers should not be visualized

getColumnName

public java.lang.String getColumnName(int column)
Gets the column name for the specified index

Specified by:
getColumnName in interface TableModel
Parameters:
column - column index
Returns:
column name

fireTableModelChanged

public void fireTableModelChanged()
Fires an event that the values in the table has been changed and the table should be repainted. This method is intended to be used by the user, since the model cannot track changes of values in the supplied arrays.


addTableModelListener

public void addTableModelListener(TableModelListener listener)
Adds a TableModelListener to this instance of the model.

Specified by:
addTableModelListener in interface TableModel
Parameters:
listener - listener to be addded

removeTableModelListener

public void removeTableModelListener(TableModelListener listener)
Removes a TableModelListener from this instance of the model.

Specified by:
removeTableModelListener in interface TableModel
Parameters:
listener - listener to be removed