com.zfqjava.swing
Class DefaultDataGridModel

java.lang.Object
  |
  +--com.zfqjava.swing.AbstractDataGridModel
        |
        +--com.zfqjava.swing.DefaultDataGridModel
All Implemented Interfaces:
DataGridModel, java.io.Serializable, javax.swing.table.TableModel

public class DefaultDataGridModel
extends AbstractDataGridModel
implements java.io.Serializable

DefaultDataGridModel provides a default data grid model.

Note:All methods with Cell parameter pass null value will throws java.lang.NullPointerException.

See Also:
Serialized Form

Fields inherited from class com.zfqjava.swing.AbstractDataGridModel
listenerList
 
Constructor Summary
DefaultDataGridModel()
          Constructs a data grid model with 0 rows and 0 cols.
DefaultDataGridModel(int rowCount, int columnCount)
          Constructs a data grid model with rowCount rows and columnCount columns.
 
Method Summary
 void addColumn(int firstColumn, int lastColumn, java.util.List[] l)
          Adds column from firstColumn to lastColumn use the specified list data.
 void addColumn(int columnIndex, java.util.List l)
          Adds a column at the columnIndex of the model use the specified list.
 void addColumn(java.util.List l)
          Adds a column at the end of the model use the specified list.
 void addRow(int firstRow, int lastRow, java.util.List[] l)
          Adds row from firstRow to lastRow use the specified list.
 void addRow(int rowIndex, java.util.List l)
          Adds a row at the rowIndex of the model use the specified list.
 void addRow(java.util.List l)
          Adds a row to the end of the model use the specified list.
 boolean clear(Cell c)
          Clears the cell data for the specified cell area c.
 boolean clearCellAttributes(Cell c)
          Clears the cell attributes for the specified cell area c.
 boolean clearCellClass(Cell c)
          Clears the cell class for the specified cell area c.
 boolean clearCellEditable(Cell c)
          Clears the cell editable for the specified cell area c.
 boolean clearValue(Cell c)
          Clears the cell value for the specified cell area c.
 boolean equals(java.lang.Object o)
           
 boolean fillCellAttributes(Cell c, java.util.List[] l)
          Fills the cell attributes of the cell area c use the specified data.
 boolean fillCellClass(Cell c, java.util.List[] l)
          Fills the cell class of the cell area c use the specified data.
 boolean fillCellEditable(Cell c, java.util.List[] l)
          Fills the cell editable of the cell area c use the specified data.
 boolean fillValue(Cell c, java.util.List[] l)
          Fills the value of the cell area c use the specified data.
 javax.swing.text.AttributeSet getCellAttributes(int rowIndex, int columnIndex)
          Returns the cell attributes.
 java.lang.Class getCellClass(int rowIndex, int columnIndex)
          Returns the cell class.
 Cell getCellSpans(int rowIndex, int columnIndex)
          Returns the cell that spans the specified cell at rowIndex and columnIndex.
 Cell[] getCellSpans(int firstRow, int lastRow, int firstColumn, int lastColumn)
          Returns the cells that spans the specified cell area.
 java.lang.Class getColumnClass(int columnIndex)
          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 columnIndex)
          Returns the name of the column at columnIndex.
 int getRowCount()
          Returns the number of rows in the model.
 Cell[] getSpannedCells()
          Returns all spanned cells.
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
          Returns the value for the cell at columnIndex and rowIndex.
 boolean hasCellSpans(int rowIndex, int columnIndex)
          Returns true if has cell spans the specified cell at rowIndex and columnIndex.
 boolean hasCellSpans(int firstRow, int lastRow, int firstColumn, int lastColumn)
          Returns true if has some cells spans the specified cell area.
 int hashCode()
           
 boolean isCellEditable(int rowIndex, int columnIndex)
          Returns true if the cell at rowIndex and columnIndex is editable.
 boolean isSpannedCell(Cell c)
          Determines whether the cell is spanned cell.
 boolean merge(Cell c)
          Merges the cell.
 boolean move(Cell from, Cell to)
          Moves the cell area from to to.
 void removeColumn(int columnIndex)
          Removes a column at the columnIndex of the model.
 void removeColumn(int firstColumn, int lastColumn)
          Removes column from firstColumn to lastColumn.
 void removeRow(int rowIndex)
          Removes a row at the rowIndex of the model.
 void removeRow(int firstRow, int lastRow)
          Removes row from firstRow to lastRow
 void setCellAttributes(javax.swing.text.AttributeSet attributes, Cell c)
          Sets the cell attributes.
 void setCellAttributes(javax.swing.text.AttributeSet attributes, int rowIndex, int columnIndex)
          Sets the cell attributes.
 void setCellClass(java.lang.Class cc, Cell c)
          Sets the cell class.
 void setCellClass(java.lang.Class c, int rowIndex, int columnIndex)
          Sets the cell class.
 void setCellEditable(boolean editable, Cell c)
          Sets the cell editable.
 void setCellEditable(boolean editable, int rowIndex, int columnIndex)
          Sets the editable value for the specified cell at rowIndex and columnIndex.
 void setColumnClass(java.lang.Class c, int columnIndex)
          Sets the column class for the specified columnIndex.
 void setColumnCount(int columnCount)
          Sets the number of columns in the model.
 void setColumnName(java.lang.String name, int columnIndex)
          Sets the column name for the specified columnIndex.
 void setRowCount(int rowCount)
          Sets the number of rows in the model.
 void setValueAt(java.lang.Object aValue, Cell c)
          Sets the cell value.
 void setValueAt(java.lang.Object aValue, int rowIndex, int columnIndex)
          Sets the value in the cell at columnIndex and rowIndex to aValue.
 boolean sort(Cell c, boolean ascending)
          Sorts the cell area.Returns true if this model changes as a result of the call.
 boolean split(Cell c)
          Splits the cell.
 java.lang.String toString()
           
 
Methods inherited from class com.zfqjava.swing.AbstractDataGridModel
addDataGridModelListener, addTableModelListener, addUndoableEditListener, fireCellAttributesChanged, fireCellAttributesChanged, fireCellChanged, fireCellChanged, fireCellClassChanged, fireCellClassChanged, fireCellEditableChanged, fireCellEditableChanged, fireCellSpanChanged, fireCellSpanChanged, fireCellValueChanged, fireTableCellUpdated, fireTableChanged, fireTableColumnsDeleted, fireTableColumnsInserted, fireTableColumnsUpdated, fireTableColumnUpdated, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableRowUpdated, fireTableStructureChanged, fireUndoableEditHappened, getDataGridModelListeners, getListeners, getTableModelListeners, getUndoableEditListeners, removeDataGridModelListener, removeTableModelListener, removeUndoableEditListener
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultDataGridModel

public DefaultDataGridModel()
Constructs a data grid model with 0 rows and 0 cols.

DefaultDataGridModel

public DefaultDataGridModel(int rowCount,
                            int columnCount)
Constructs a data grid model with rowCount rows and columnCount columns.
Method Detail

addRow

public void addRow(java.util.List l)
Adds a row to the end of the model use the specified list.
Parameters:
l - the specified list
See Also:
addRow(int,List), removeRow(int)

addRow

public void addRow(int rowIndex,
                   java.util.List l)
Adds a row at the rowIndex of the model use the specified list.
Parameters:
rowIndex - the rowIndex
l - the specified list
See Also:
addRow(List), removeRow(int)

addRow

public void addRow(int firstRow,
                   int lastRow,
                   java.util.List[] l)
Adds row from firstRow to lastRow use the specified list.
Parameters:
firstRow - the first row index
lastRow - the last row index
l - the specified list data
Since:
JDataGrid 1.1

removeRow

public void removeRow(int rowIndex)
Removes a row at the rowIndex of the model.
Parameters:
rowIndex - the rowIndex
See Also:
addRow(List), addRow(int,List)

removeRow

public void removeRow(int firstRow,
                      int lastRow)
Removes row from firstRow to lastRow
Parameters:
firstRow - the first row index
lastRow - the last row index
Since:
JDataGrid 1.1

addColumn

public void addColumn(java.util.List l)
Adds a column at the end of the model use the specified list.
Parameters:
l - the specified list
See Also:
addColumn(int,List), removeColumn(int)

addColumn

public void addColumn(int columnIndex,
                      java.util.List l)
Adds a column at the columnIndex of the model use the specified list.
Parameters:
columnIndex - the column index
l - the specified list
See Also:
addColumn(List), removeColumn(int)

addColumn

public void addColumn(int firstColumn,
                      int lastColumn,
                      java.util.List[] l)
Adds column from firstColumn to lastColumn use the specified list data.
Parameters:
firstColumn - the first column index
lastColumn - the last column index
l - the specified list data
Since:
JDataGrid 1.1

removeColumn

public void removeColumn(int columnIndex)
Removes a column at the columnIndex of the model.
Parameters:
columnIndex - the column index
See Also:
addColumn(List), addColumn(int,List)

removeColumn

public void removeColumn(int firstColumn,
                         int lastColumn)
Removes column from firstColumn to lastColumn.
Parameters:
firstColumn - the first column index
lastColumn - the last column index
Since:
JDataGrid 1.1

getRowCount

public int getRowCount()
Returns the number of rows in the model. A JTable uses this method to determine how many rows it should display. This method should be quick, as it is called frequently during rendering.
Returns:
the number of rows in the model
See Also:
getColumnCount(), setColumnCount(int), getColumnCount()

setRowCount

public void setRowCount(int rowCount)
Sets the number of rows in the model.
Parameters:
rowCount - the number of rows in the model
See Also:
getRowCount(), setColumnCount(int), getColumnCount()

getColumnCount

public int getColumnCount()
Returns the number of columns in the model. A JTable uses this method to determine how many columns it should create and display by default.
Returns:
the number of columns in the model
See Also:
getRowCount(), setRowCount(int), setColumnCount(int)

setColumnCount

public void setColumnCount(int columnCount)
Sets the number of columns in the model.
Parameters:
columnCount - the number of columns in the model
See Also:
getRowCount(), setRowCount(int), getColumnCount()

getColumnName

public java.lang.String getColumnName(int columnIndex)
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.
Overrides:
getColumnName in class AbstractDataGridModel
Parameters:
columnIndex - the index of the column
Returns:
the name of the column
See Also:
setColumnName(String,int)

setColumnName

public void setColumnName(java.lang.String name,
                          int columnIndex)
Sets the column name for the specified columnIndex.
Parameters:
name - the column name
columnIndex - the specified columnIndex
See Also:
getColumnName(int)

getColumnClass

public java.lang.Class getColumnClass(int columnIndex)
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.
Overrides:
getColumnClass in class AbstractDataGridModel
Parameters:
columnIndex - the index of the column
Returns:
the common ancestor class of the object values in the model.
See Also:
setColumnClass(Class,int)

setColumnClass

public void setColumnClass(java.lang.Class c,
                           int columnIndex)
Sets the column class for the specified columnIndex.
Parameters:
c - the column class
columnIndex - the specified columnIndex
See Also:
getColumnClass(int)

hasCellSpans

public boolean hasCellSpans(int rowIndex,
                            int columnIndex)
Returns true if has cell spans the specified cell at rowIndex and columnIndex.
Parameters:
rowIndex - the row index of the specified cell
columnIndex - the column index of the specified cell
See Also:
getCellSpans(int,int)

getCellSpans

public Cell getCellSpans(int rowIndex,
                         int columnIndex)
Returns the cell that spans the specified cell at rowIndex and columnIndex.
Parameters:
rowIndex - the row index of the specified cell
columnIndex - the column index of the specified cell
Returns:
the cell that spans the specified cell
See Also:
hasCellSpans(int,int)

hasCellSpans

public boolean hasCellSpans(int firstRow,
                            int lastRow,
                            int firstColumn,
                            int lastColumn)
Returns true if has some cells spans the specified cell area.

Note:Some cell spans the area can have row and column index out of the area index.

Parameters:
firstRow - the first row index of the specified cell area
lastRow - the last row index of the specified cell area
firstColumn - the first column index of the specified cell area
lastColumn - the last column index of the specified cell area
Returns:
true if has some cells spans the specified cell area
See Also:
getCellSpans(int,int,int,int)

getCellSpans

public Cell[] getCellSpans(int firstRow,
                           int lastRow,
                           int firstColumn,
                           int lastColumn)
Returns the cells that spans the specified cell area. Returns 0 length array if no such cells.

Note:Some cell spans the area can have row and column index out of the area index.

Parameters:
firstRow - the first row index of the specified cell area
lastRow - the last row index of the specified cell area
firstColumn - the first column index of the specified cell area
lastColumn - the last column index of the specified cell area
Returns:
the cells that spans the specified cell area
See Also:
hasCellSpans(int,int,int,int)

isSpannedCell

public boolean isSpannedCell(Cell c)
Determines whether the cell is spanned cell.
Parameters:
c - the cell
Returns:
true if the cell has merged use the merge(Cell).

getSpannedCells

public Cell[] getSpannedCells()
Returns all spanned cells.
Returns:
all spannned cells that merged use the merge(Cell).

merge

public boolean merge(Cell c)
Merges the cell. Returns true if this model changes as a result of the call. (Returns false if this model already contains such spanned cell c or does not permit such operation.)

Parameters:
c - the cell
Returns:
true if this model changed as a result of the call
See Also:
split(com.zfqjava.swing.cell.Cell)

split

public boolean split(Cell c)
Splits the cell. Returns true if this model changes as a result of the call. (Returns false if this model have not such spanned cell or does not permit such operation.)

Parameters:
c - the cell
Returns:
true if this model changed as a result of the call
See Also:
merge(com.zfqjava.swing.cell.Cell)

sort

public boolean sort(Cell c,
                    boolean ascending)
Sorts the cell area.Returns true if this model changes as a result of the call. (Returns false if this model does not permit such operation.)

Note:Current only support single column or row sorting. Multiple cell sorting may be supported in the future.

Parameters:
c - the cell area
ascending - the sort direction
Returns:
true if this model changed as a result of the call
Since:
JDataGrid 1.1

move

public boolean move(Cell from,
                    Cell to)
Moves the cell area from to to. The from cell area will clear.
Parameters:
from - the from cell area
to - the to cell area
Returns:
true if this model changed as a result of the call
Throws:
java.lang.IllegalArgumentException - if the cell area is not same width and height or out of the model row and column count
Since:
JDataGrid 1.1

fillCellAttributes

public boolean fillCellAttributes(Cell c,
                                  java.util.List[] l)
Fills the cell attributes of the cell area c use the specified data.
Parameters:
c - the cell area
l - the cell data
Returns:
true if this model changed as a result of the call
Throws:
java.lang.IllegalArgumentException - if the cell area out of the model row and column count or list data is not enough
Since:
JDataGrid 1.1

fillCellClass

public boolean fillCellClass(Cell c,
                             java.util.List[] l)
Fills the cell class of the cell area c use the specified data.
Parameters:
c - the cell area
l - the cell data
Returns:
true if this model changed as a result of the call
Throws:
java.lang.IllegalArgumentException - if the cell area out of the model row and column count or list data is not enough
Since:
JDataGrid 1.1

fillCellEditable

public boolean fillCellEditable(Cell c,
                                java.util.List[] l)
Fills the cell editable of the cell area c use the specified data.
Parameters:
c - the cell area
l - the cell data
Returns:
true if this model changed as a result of the call
Throws:
java.lang.IllegalArgumentException - if the cell area out of the model row and column count or list data is not enough
Since:
JDataGrid 1.1

fillValue

public boolean fillValue(Cell c,
                         java.util.List[] l)
Fills the value of the cell area c use the specified data.
Parameters:
c - the cell area
l - the cell data
Returns:
true if this model changed as a result of the call
Throws:
java.lang.IllegalArgumentException - if the cell area out of the model row and column count or list data is not enough
Since:
JDataGrid 1.1

clear

public boolean clear(Cell c)
Clears the cell data for the specified cell area c.
Parameters:
c - the cell area
Returns:
true if this model changed as a result of the call
Since:
JDataGrid 1.1

clearCellAttributes

public boolean clearCellAttributes(Cell c)
Clears the cell attributes for the specified cell area c.
Parameters:
c - the cell area
Returns:
true if this model changed as a result of the call
Since:
JDataGrid 1.1

clearCellClass

public boolean clearCellClass(Cell c)
Clears the cell class for the specified cell area c.
Parameters:
c - the cell area
Returns:
true if this model changed as a result of the call
Since:
JDataGrid 1.1

clearCellEditable

public boolean clearCellEditable(Cell c)
Clears the cell editable for the specified cell area c.
Parameters:
c - the cell area
Returns:
true if this model changed as a result of the call
Since:
JDataGrid 1.1

clearValue

public boolean clearValue(Cell c)
Clears the cell value for the specified cell area c.
Parameters:
c - the cell area
Returns:
true if this model changed as a result of the call
Since:
JDataGrid 1.1

setCellAttributes

public void setCellAttributes(javax.swing.text.AttributeSet attributes,
                              Cell c)
Sets the cell attributes.
Parameters:
attributes - the cell attributes
c - the cell area
Since:
JDataGrid 1.1
See Also:
getCellAttributes(int, int)

setCellClass

public void setCellClass(java.lang.Class cc,
                         Cell c)
Sets the cell class.
Parameters:
class - the cell class
c - the cell area
Since:
JDataGrid 1.1
See Also:
getCellClass(int, int)

setCellEditable

public void setCellEditable(boolean editable,
                            Cell c)
Sets the cell editable.
Parameters:
editable - the cell editable
c - the cell area
Since:
JDataGrid 1.1
See Also:
isCellEditable(int, int)

setValueAt

public void setValueAt(java.lang.Object aValue,
                       Cell c)
Sets the cell value.
Parameters:
aValue - the cell value
c - the cell area
Since:
JDataGrid 1.1
See Also:
#getValutAt

getCellAttributes

public javax.swing.text.AttributeSet getCellAttributes(int rowIndex,
                                                       int columnIndex)
Returns the cell attributes.
Parameters:
rowIndex - the index of the row
columnIndex - the index of the column
Returns:
the attributes for the specified cell
See Also:
setCellAttributes(javax.swing.text.AttributeSet, com.zfqjava.swing.cell.Cell)

setCellAttributes

public void setCellAttributes(javax.swing.text.AttributeSet attributes,
                              int rowIndex,
                              int columnIndex)
Sets the cell attributes.
Parameters:
attributes - the cell attributes
rowIndex - the index of the row
columnIndex - the index of the column
See Also:
getCellAttributes(int, int)

getCellClass

public java.lang.Class getCellClass(int rowIndex,
                                    int columnIndex)
Returns the cell class.
Parameters:
rowIndex - the index of the row
columnIndex - the index of the column
Returns:
the class for the specified cell
See Also:
setCellClass(java.lang.Class, com.zfqjava.swing.cell.Cell)

setCellClass

public void setCellClass(java.lang.Class c,
                         int rowIndex,
                         int columnIndex)
Sets the cell class.
Parameters:
c - the class for the specified cell
rowIndex - the index of the row
columnIndex - the index of the column
See Also:
getCellClass(int, int)

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Returns true if the cell at rowIndex and columnIndex is editable. Otherwise, setValueAt on the cell will not change the value of that cell.
Parameters:
rowIndex - the row whose value to be queried
columnIndex - the column whose value to be queried
Returns:
true if the cell is editable
See Also:
setValueAt(java.lang.Object, com.zfqjava.swing.cell.Cell), setCellEditable(boolean,int,int)

setCellEditable

public void setCellEditable(boolean editable,
                            int rowIndex,
                            int columnIndex)
Sets the editable value for the specified cell at rowIndex and columnIndex.
Parameters:
editable - the cell editable value
rowIndex - the row whose value to be queried
columnIndex - the column whose value to be queried
See Also:
setValueAt(java.lang.Object, com.zfqjava.swing.cell.Cell), isCellEditable(int,int)

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
Returns the value for the cell at columnIndex and rowIndex.
Parameters:
rowIndex - the row whose value is to be queried
columnIndex - the column whose value is to be queried
Returns:
the value Object at the specified cell
See Also:
setValueAt(java.lang.Object, com.zfqjava.swing.cell.Cell), isCellEditable(int, int), setCellEditable(boolean,int,int)

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int rowIndex,
                       int columnIndex)
Sets the value in the cell at columnIndex and rowIndex to aValue.
Parameters:
aValue - the new value
rowIndex - the row whose value is to be changed
columnIndex - the column whose value is to be changed
See Also:
getValueAt(int, int), isCellEditable(int, int), setCellEditable(boolean,int,int)

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2001-2003 Extreme Component, Inc. All rights reserved.