com.altair.hwm.beans.utils
Class HWMTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.altair.hwm.beans.utils.HWMTableModel
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, javax.swing.table.TableModel

public class HWMTableModel
extends javax.swing.table.AbstractTableModel
implements java.io.Externalizable

Title: HWMTableModel

Description: A useful table model for a JTable.

Company: Altair Engineering, Inc.

See Also:
Serialized Form

Constructor Summary
HWMTableModel(java.lang.String[] arrszHeaders)
          Constructor
 
Method Summary
 boolean AddRow(java.lang.Object[] arrRowData)
          This method adds a row of objects to the current data.
 void DeleteRow(int nRow)
          Deletes a row from the table
 void DeleteRows(int[] arrnRows)
          Deletes a number of rows for the table.
 java.lang.Class getColumnClass(int nColIndex)
          Returns the most specific superclass for all the cell values in the column.
 int getColumnCount()
          Returns the number of columns in the model.
 java.lang.String getColumnName(int nColIndex)
          Returns the name of the column at columnIndex.
 java.lang.Object[][] GetData()
          Gets the table data all at once.
 int getRowCount()
          Returns the number of rows in the model.
 java.lang.Object getValueAt(int nRowIndex, int nColIndex)
          Returns the value for the cell at columnIndex and rowIndex.
 void InsertRow(java.lang.Object[] arrobjNewData, int nIndex)
          Inserts a row at the specified index
 boolean isCellEditable(int nRowIndex, int nColIndex)
          Returns true if the cell at rowIndex and columnIndex is editable.
 void readExternal(java.io.ObjectInput objInput)
          Reads the Object
 void SetColumnEditable(int nColIndex, boolean bState)
          Sets the editable state of the specified column.
 void SetData(java.lang.Object[][] arr2Data)
          Allows the data to be changed all at once.
 void setValueAt(java.lang.Object objValue, int nRowIndex, int nColIndex)
          Sets the value in the cell at columnIndex and rowIndex to aValue.
 void writeExternal(java.io.ObjectOutput objOutput)
          Writes the Object
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HWMTableModel

public HWMTableModel(java.lang.String[] arrszHeaders)
Constructor

Method Detail

getColumnCount

public int getColumnCount()
Returns the number of columns in the model. The JTable uses this method to determine how many columns it should create and display by default.

Specified by:
getColumnCount in interface javax.swing.table.TableModel
Returns:
The number of columns in the model

getValueAt

public java.lang.Object getValueAt(int nRowIndex,
                                   int nColIndex)
Returns the value for the cell at columnIndex and rowIndex.

Specified by:
getValueAt in interface javax.swing.table.TableModel
Parameters:
nRowIndex - -- the row whose value is to be queried
nColIndex - -- the column whose value is to be queried
Returns:
The value Object at the specified cell

getRowCount

public int getRowCount()
Returns the number of rows in the model. The JTable uses this method to determine how many rows it should display.

Specified by:
getRowCount in interface javax.swing.table.TableModel
Returns:
The number of rows in the model

getColumnName

public java.lang.String getColumnName(int nColIndex)
Returns the name of the column at columnIndex. This is used to initialize the table's column header name. Note: this name does not need to be unique; two columns in a table can have the same name.

Specified by:
getColumnName in interface javax.swing.table.TableModel
Overrides:
getColumnName in class javax.swing.table.AbstractTableModel
Parameters:
nColIndex - -- the index of the column
Returns:
The name of the column

setValueAt

public void setValueAt(java.lang.Object objValue,
                       int nRowIndex,
                       int nColIndex)
Sets the value in the cell at columnIndex and rowIndex to aValue.

Specified by:
setValueAt in interface javax.swing.table.TableModel
Overrides:
setValueAt in class javax.swing.table.AbstractTableModel
Parameters:
aValue - -- the new value
nRowIndex - -- the row whose value is to be changed

getColumnClass

public java.lang.Class getColumnClass(int nColIndex)
Returns the most specific superclass for all the cell values in the column. This is used by the JTable to set up a default renderer and editor for the column.

Specified by:
getColumnClass in interface javax.swing.table.TableModel
Overrides:
getColumnClass in class javax.swing.table.AbstractTableModel
Parameters:
nColIndex - - the index of the column
Returns:
The common ancestor class of the object values in the model.

isCellEditable

public boolean isCellEditable(int nRowIndex,
                              int nColIndex)
Returns true if the cell at rowIndex and columnIndex is editable. Otherwise, setValueAt on the cell will not change the value of that cell.

Specified by:
isCellEditable in interface javax.swing.table.TableModel
Overrides:
isCellEditable in class javax.swing.table.AbstractTableModel
Parameters:
nRowIndex - - the row whose value to be queried
nColIndex - - the column whose value to be queried
Returns:
True if the cell is editable

SetData

public void SetData(java.lang.Object[][] arr2Data)
Allows the data to be changed all at once.

Parameters:
arr2Data - - the new data for the table

GetData

public java.lang.Object[][] GetData()
Gets the table data all at once.

Returns:
The 2D array describing the data for the table

AddRow

public boolean AddRow(java.lang.Object[] arrRowData)
This method adds a row of objects to the current data.


InsertRow

public void InsertRow(java.lang.Object[] arrobjNewData,
                      int nIndex)
Inserts a row at the specified index

Parameters:
arrobjNewData - The new data to be inserted
nRow - The insertion location

DeleteRow

public void DeleteRow(int nRow)
Deletes a row from the table

Parameters:
nRow - The row to delete

DeleteRows

public void DeleteRows(int[] arrnRows)
Deletes a number of rows for the table.

Parameters:
arrnRows - An array of indexes

SetColumnEditable

public void SetColumnEditable(int nColIndex,
                              boolean bState)
Sets the editable state of the specified column.

Parameters:
nColIndex - The index of the column
state - The editable state of the column

writeExternal

public void writeExternal(java.io.ObjectOutput objOutput)
                   throws java.io.IOException
Writes the Object

Specified by:
writeExternal in interface java.io.Externalizable
Parameters:
ObjectOutput - The stream to which this instance is to be written into.
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput objInput)
                  throws java.lang.ClassNotFoundException,
                         java.io.IOException
Reads the Object

Specified by:
readExternal in interface java.io.Externalizable
Parameters:
ObjectInput - The stream from which data is to be read from.
Throws:
IOException, - ClassNotFoundException
java.lang.ClassNotFoundException
java.io.IOException