com.eliad.model
Class GenericGridModel

java.lang.Object
  |
  +--com.eliad.model.AbstractGenericModel
        |
        +--com.eliad.model.AbstractGridModel
              |
              +--com.eliad.model.GenericGridModel

public class GenericGridModel
extends AbstractGridModel
implements RulerModelListener

This is an implementation of GridModel that uses a Vector of Vectors to store the cell value objects.

Version:
0.90 00/04/08
Author:
Patrick Mérissert-Coffinières
See Also:
GridModel, Serialized Form

Fields inherited from class com.eliad.model.AbstractGenericModel
listeners_
 
Constructor Summary
GenericGridModel()
          Constructs a default DefaultGridModel which is a grid of ten columns and ten rows.
GenericGridModel(int numRows, int numColumns)
          Constructs a GenericGridModel with numRows and numColumns of null object values.
GenericGridModel(java.lang.Object[][] data)
          Constructs a GenericGridModel and initializes the grid by passing data and columnNames to the setDataVector method.
GenericGridModel(java.util.Vector data)
          Constructs a GenericGridModel and initializes the grid by passing data to the setDataVector method.
 
Method Summary
 void addColumn(java.lang.Object[] columnData)
          Adds a column to the end of the model.
 void addColumn(java.util.Vector columnData)
          Adds a column to the end of the model.
 void addRow(java.lang.Object[] rowData)
          Adds a row to the end of the model.
 void addRow(java.util.Vector rowData)
          Adds a row to the end of the model.
 void beforeItemsMoved(RulerModelEvent e)
          Calls to send a prenotification that ruler items are to be moved.
protected static java.util.Vector convertToVector(java.lang.Object[] anArray)
          Returns a vector that contains the same objects as the array.
protected static java.util.Vector convertToVector(java.lang.Object[][] anArray)
          Returns a vector of vectors that contains the same objects as the array.
 int getColumnCount()
          Returns the number of columns in this grid.
 int getRowCount()
          Returns the number of rows in this grid.
 java.lang.Object getValueAt(int row, int column)
          Returns an attribute value for the cell at row and column.
 void insertColumn(int column, java.lang.Object[] columnData)
          Inserts a column at column in the model.
 void insertColumn(int column, java.util.Vector columnData)
          Inserts a column at column in the model.
 void insertRow(int row, java.lang.Object[] rowData)
          Inserts a row at row in the model.
 void insertRow(int row, java.util.Vector rowData)
          Inserts a row at row in the model.
 boolean isCellEditable(int row, int column)
          Returns whether a given cell may be edited.
 void removeColumns(int column, int count)
          Removes the column at column from the model.
 void removeRows(int row, int count)
          Removes the row at row from the model.
 void rulerDataChanged(RulerModelEvent e)
          Called whenever some data in the ruler model changes.
 void rulerModelChanged(RulerModelEvent e)
          Called whenever the ruler model changes.
 void rulerStructureChanged(RulerModelEvent e)
          Called whenever the ruler model structure undergoes a local change.
 void setColumnCount(int columnCount)
          Sets the number of columns in the model.
 void setDataVector(java.lang.Object[][] newData)
          Replaces the value in the dataVector instance variable with the values in the array newData.
 void setDataVector(java.util.Vector newData)
          Replaces the current dataVector instance variable with the new Vector of rows, newData.
 void setDataVector(java.util.Vector newData, int columnCount)
          Replaces the current dataVector instance variable with the new Vector of rows, newData.
 void setRowCount(int rowCount)
          Sets the number of rows in the model.
 void setSize(int newRowCount, int newColumnCount)
          Sets the size of the model.
 void setValueAt(java.lang.Object aValue, int row, int column)
          Sets the object value for the cell at column and row.
 
Methods inherited from class com.eliad.model.AbstractGridModel
addGridModelListener, fireGridCellsChanged, fireGridColumnsChanged, fireGridColumnsDeleted, fireGridColumnsInserted, fireGridModelChanged, fireGridRowsChanged, fireGridRowsDeleted, fireGridRowsInserted, fireGridStructureChanged, propagateDataChange, propagateModelChange, propagateStructureChange, removeGridModelListener
 
Methods inherited from class com.eliad.model.AbstractGenericModel
getListenerCount, getListeners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericGridModel

public GenericGridModel()
Constructs a default DefaultGridModel which is a grid of ten columns and ten rows.

GenericGridModel

public GenericGridModel(int numRows,
                        int numColumns)
Constructs a GenericGridModel with numRows and numColumns of null object values.
Parameters:
numRows - the number of rows in the grid
numColumns - the number of columns in the grid
See Also:
setValueAt(java.lang.Object, int, int)

GenericGridModel

public GenericGridModel(java.util.Vector data)
Constructs a GenericGridModel and initializes the grid by passing data to the setDataVector method.
Parameters:
data - the data of the grid
columnNames - vector containing the names of the new columns
See Also:
setDataVector(java.util.Vector, int)

GenericGridModel

public GenericGridModel(java.lang.Object[][] data)
Constructs a GenericGridModel and initializes the grid by passing data and columnNames to the setDataVector method. The first index in the Object[][] array is the row index and the second is the column index.
Parameters:
data - the data of the grid
columnNames - the names of the columns
See Also:
setDataVector(java.util.Vector, int)
Method Detail

setDataVector

public void setDataVector(java.util.Vector newData,
                          int columnCount)
Replaces the current dataVector instance variable with the new Vector of rows, newData. Each row in newData is adjusted to match the number of columns in the first one, either by shortening the Vector if it is too long, or adding null values if it is too short.

Parameters:
newData - the new data vector

setDataVector

public void setDataVector(java.util.Vector newData)
Replaces the current dataVector instance variable with the new Vector of rows, newData. Each row in newData is adjusted to match the number of columns in the first one, either by shortening the Vector if it is too long, or adding null values if it is too short.

Parameters:
newData - the new data vector

setDataVector

public void setDataVector(java.lang.Object[][] newData)
Replaces the value in the dataVector instance variable with the values in the array newData. The first index in the Object[][] array is the row index and the second is the column index. columnNames are the names of the new columns.
Parameters:
newData - the new data vector
See Also:
setDataVector(Vector)

setSize

public void setSize(int newRowCount,
                    int newColumnCount)
Sets the size of the model. If the new size is greater than the current size, new rows/columns are added to the end of the model If the new size is less than the current size, all rows/columns at the end are discarded.

Parameters:
newSize - the new number of rows
See Also:
setRowCount(int)

setRowCount

public void setRowCount(int rowCount)
Sets the number of rows in the model. If the new size is greater than the current size, new rows are added to the end of the model If the new size is less than the current size, all rows at index rowCount and greater are discarded.

See Also:
setColumnCount(int)

setColumnCount

public void setColumnCount(int columnCount)
Sets the number of columns in the model. If the new size is greater than the current size, new columns are added to the end of the model with null cell values. If the new size is less than the current size, all columns at index columnCount and greater are discarded.
Parameters:
columnCount - the new number of columns in the model
See Also:
setColumnCount(int)

addRow

public void addRow(java.util.Vector rowData)
Adds a row to the end of the model. The new row will contain null values unless rowData is specified. Notification of the row being added will be generated.
Parameters:
rowData - optional data of the row being added

addRow

public void addRow(java.lang.Object[] rowData)
Adds a row to the end of the model. The new row will contain null values unless rowData is specified. Notification of the row being added will be generated.
Parameters:
rowData - optional data of the row being added

insertRow

public void insertRow(int row,
                      java.util.Vector rowData)
Inserts a row at row in the model. The new row will contain null values unless rowData is specified. Notification of the row being inserted will be generated.
Parameters:
row - the row index of the row to be inserted
rowData - optional data of the row being added
Throws:
ArrayIndexOutOfBoundsException - if the row was invalid

insertRow

public void insertRow(int row,
                      java.lang.Object[] rowData)
Inserts a row at row in the model. The new row will contain null values unless rowData is specified. Notification of the row being inserted will be generated.
Parameters:
row - the row index of the row to be inserted
rowData - optional data of the row being added
Throws:
ArrayIndexOutOfBoundsException - if the row was invalid

addColumn

public void addColumn(java.util.Vector columnData)
Adds a column to the end of the model. The new column will contain null values unless columnData is specified. Notification of the column being added will be generated.
Parameters:
columnData - optional data of the column being added

addColumn

public void addColumn(java.lang.Object[] columnData)
Adds a column to the end of the model. The new column will contain null values unless columnData is specified. Notification of the column being added will be generated.
Parameters:
columnData - optional data of the column being added

insertColumn

public void insertColumn(int column,
                         java.util.Vector columnData)
Inserts a column at column in the model. The new column will contain null values unless columnData is specified. Notification of the row being inserted will be generated.
Parameters:
column - the column index of the column to be inserted
columnData - optional data of the column being added
Throws:
ArrayIndexOutOfBoundsException - if the column was invalid

insertColumn

public void insertColumn(int column,
                         java.lang.Object[] columnData)
Inserts a column at column in the model. The new column will contain null values unless columnData is specified. Notification of the column being inserted will be generated.
Parameters:
column - the column index of the column to be inserted
columnData - optional data of the column being added
Throws:
ArrayIndexOutOfBoundsException - if the column was invalid

removeRows

public void removeRows(int row,
                       int count)
Removes the row at row from the model. Notification of the row being removed will be sent to all the listeners.
Parameters:
row - the row index of the row to be removed
Throws:
ArrayIndexOutOfBoundsException - if the row was invalid

removeColumns

public void removeColumns(int column,
                          int count)
Removes the column at column from the model. Notification of the column being removed will be sent to all the listeners.
Parameters:
column - the column index of the column to be removed
Throws:
ArrayIndexOutOfBoundsException - if the column was invalid

getRowCount

public int getRowCount()
Returns the number of rows in this grid.
Returns:
the number of rows in the model

getColumnCount

public int getColumnCount()
Returns the number of columns in this grid.
Returns:
the number of columns in the model

isCellEditable

public boolean isCellEditable(int row,
                              int column)
Returns whether a given cell may be edited.
Parameters:
row - the row whose value is to be queried
column - the column whose value is to be queried
Returns:
true regardless of parameter values.
Overrides:
isCellEditable in class AbstractGridModel
See Also:
setValueAt(java.lang.Object, int, int)

getValueAt

public java.lang.Object getValueAt(int row,
                                   int column)
Returns an attribute value for the cell at row and column.
Parameters:
row - the row whose value is to be queried
column - the column whose value is to be queried
Returns:
the value Object at the specified cell
Throws:
ArrayIndexOutOfBoundsException - if an invalid row or column was given

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int row,
                       int column)
Sets the object value for the cell at column and row. aValue is the new value. This method will generate a tableChanged notification.
Parameters:
aValue - the new value; this can be null
row - the row whose value is to be changed
column - the column whose value is to be changed
Throws:
ArrayIndexOutOfBoundsException - if an invalid row or column was given
Overrides:
setValueAt in class AbstractGridModel

convertToVector

protected static java.util.Vector convertToVector(java.lang.Object[] anArray)
Returns a vector that contains the same objects as the array.
Parameters:
anArray - the array to be converted
Returns:
the new vector; if anArray is null, returns null

convertToVector

protected static java.util.Vector convertToVector(java.lang.Object[][] anArray)
Returns a vector of vectors that contains the same objects as the array.
Parameters:
anArray - the double array to be converted
Returns:
the new vector of vectors; if anArray is null, returns null

rulerModelChanged

public void rulerModelChanged(RulerModelEvent e)
Called whenever the ruler model changes.
Specified by:
rulerModelChanged in interface RulerModelListener
Parameters:
e - the event that characterizes the change.

rulerStructureChanged

public void rulerStructureChanged(RulerModelEvent e)
Called whenever the ruler model structure undergoes a local change. Implemented here to catch column or row moves, and implements them as data swapping.
Specified by:
rulerStructureChanged in interface RulerModelListener
Parameters:
e - the event that characterizes the change.

rulerDataChanged

public void rulerDataChanged(RulerModelEvent e)
Called whenever some data in the ruler model changes.
Specified by:
rulerDataChanged in interface RulerModelListener
Parameters:
e - the event that characterizes the change.

beforeItemsMoved

public void beforeItemsMoved(RulerModelEvent e)
                      throws java.beans.PropertyVetoException
Calls to send a prenotification that ruler items are to be moved. No action has yet been taken.
Specified by:
beforeItemsMoved in interface RulerModelListener