JIDE 3.5.15

com.jidesoft.grid
Class DefaultTableSelectionModel

java.lang.Object
  extended by com.jidesoft.grid.DefaultTableSelectionModel
All Implemented Interfaces:
TableSelectionModel, PropertyChangeListener, Serializable, EventListener, ListSelectionListener, TableColumnModelListener, TableModelListener

public class DefaultTableSelectionModel
extends Object
implements ListSelectionListener, TableSelectionModel

TableSelectionModel is a table selection model that can support non-contiguous selection. It is used by JideTable when JideTable.setNonContiguousCellSelection(boolean) is set to true.

See Also:
Serialized Form

Field Summary
protected  int _anchorColumnIndex
           
protected  int _anchorRowIndex
           
protected  boolean _isValueAdjusting
           
protected  int _leadColumnIndex
           
protected  int _leadRowIndex
           
protected  Vector<ListSelectionModel> _listSelectionModels
          contains a ListSelectionModel for each column
protected  int _maxColumnIndex
           
protected  int _maxRowIndex
           
protected  int _minColumnIndex
           
protected  int _minRowIndex
           
protected  boolean _withinOneSelection
           
protected  EventListenerList listenerList
          List of Listeners which will be notified when the selection value changes
 
Constructor Summary
DefaultTableSelectionModel()
           
 
Method Summary
protected  void addColumn()
          Adds a column to the end of the model.
 void addSelection(int row, int column)
          Adds the cell specified by row and column to the selection.
 void addTableSelectionListener(TableSelectionListener l)
          Add a listener to the list that's notified each time a change to the selection occurs.
 void clearSelection()
          Clears all the selections.
 void columnAdded(int columnIndex)
          Notifies the selection model that a column is added to TableColumnModel.
 void columnAdded(TableColumnModelEvent e)
          The event listener to handle the column added event
 void columnMarginChanged(ChangeEvent e)
          The event listener to handle the column margin changed event.
 void columnMoved(int fromColumnIndex, int toColumnIndex)
          Notifies the selection model that a column is added to TableColumnModel.
 void columnMoved(TableColumnModelEvent e)
          The event listener to handle the column moved event.
 void columnRemoved(int columnIndex)
          Notifies the selection model that a column is removed from TableColumnModel.
 void columnRemoved(TableColumnModelEvent e)
          The event listener to handle the column removed event.
 void columnSelectionChanged(ListSelectionEvent e)
          The event listener to handle the column selection changed event.
protected  void fireValueChanged()
           
protected  void fireValueChanged(boolean isAdjusting)
          Notifies listeners that we have ended a series of adjustments.
protected  void fireValueChanged(Object source, int firstIndex, int lastIndex, int columnIndex, boolean isAdjusting)
          Notify listeners that we have ended a series of adjustments.
protected  void fireValueChanged(Object source, int firstIndex, int lastIndex, int firstColumnIndex, int lastColumnIndex, boolean isAdjusting)
          Notify listeners that we have ended a series of adjustments.
 int getAnchorColumnIndex()
          Gets the anchor column index.
 int getAnchorRowIndex()
          Gets the anchor row index.
 int getLeadColumnIndex()
          Gets the lead column index.
 int getLeadRowIndex()
          Gets the lead row index.
 ListSelectionModel getListSelectionModelAt(int columnIndex)
          Returns the ListSelectionModel at the specified column.
 int getMaxSelectedColumnIndex()
          Returns the last selected column index or -1 if the selection is empty.
 int getMaxSelectedRowIndex()
          Returns the last selected row index or -1 if the selection is empty.
 int getMinSelectedColumnIndex()
          Returns the first selected column index or -1 if the selection is empty.
 int getMinSelectedRowIndex()
          Returns the first selected row index or -1 if the selection is empty.
 int getSelectedColumnCount()
          Returns the number of selected columns.
 int[] getSelectedColumns()
          Returns an array of indices of all selected columns.
 int getSelectedRowCount()
          Returns the number of selected rows.
 int[] getSelectedRows()
          Returns an array of indices of all selected rows.
protected  void insertColumn(int index)
          Inserts a column at the specified index of the model.
 boolean isColumnSelected(int columnIndex)
          Checks if the column at column index has any selected cells.
 boolean isRowSelected(int rowIndex)
          Checks if the row at row index has any selected cells.
 boolean isSelected(int row, int column)
          Checks if the specified cell is selected.
 boolean isSelectionEmpty()
          Checks if there is any selection in the selection model.
 boolean isValueAdjusting()
          Checks if the value is adjusting.
 void markAsDirty(int firstRow, int lastRow, int firstColumn, int lastColumn)
           
 void moveLeadSelection(int row, int column)
          Moves the lead selection at the cell specified by row and column and leaving all selection values unchanged.
 void propertyChange(PropertyChangeEvent evt)
          When the TableModel changes, the TableSelectionModel has to adapt to the new Model.
protected  void removeColumn()
          Removes last column from model.
 void removeSelection(int row, int column)
          Removes the cell specified by row and column from the selection.
 void removeTableSelectionListener(TableSelectionListener l)
          Remove a listener from the list that's notified each time a change to the selection occurs.
 void selectAll(int rowCount, int columnCount)
          Selects all the cells.
 void setAnchorSelection(int row, int column)
          Sets the anchor selection at the cell specified by row and column.
 void setColumns(int count)
          Set the number of columns.
 void setLeadSelection(int row, int column)
          Sets the lead selection at the cell specified by row and column.
 void setSelection(int row, int column)
          Adds the cell specified by row and column to the selection.
 void setSelectionInterval(int row1, int row2, int column)
          Adds the cells of the specified column between row1 and row2 to the selection.
 void setValueAdjusting(boolean valueAdjusting)
          Sets the value adjusting flag.
 void tableChanged(TableModelEvent e)
          Is called when the TableModel changes.
 String toString()
           
 void valueChanged(ListSelectionEvent e)
          Is called when the selection of a ListSelectionModel of a column has changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

listenerList

protected EventListenerList listenerList
List of Listeners which will be notified when the selection value changes


_listSelectionModels

protected Vector<ListSelectionModel> _listSelectionModels
contains a ListSelectionModel for each column


_withinOneSelection

protected boolean _withinOneSelection

_anchorRowIndex

protected int _anchorRowIndex

_anchorColumnIndex

protected int _anchorColumnIndex

_leadRowIndex

protected int _leadRowIndex

_leadColumnIndex

protected int _leadColumnIndex

_minRowIndex

protected int _minRowIndex

_minColumnIndex

protected int _minColumnIndex

_maxRowIndex

protected int _maxRowIndex

_maxColumnIndex

protected int _maxColumnIndex

_isValueAdjusting

protected boolean _isValueAdjusting
Constructor Detail

DefaultTableSelectionModel

public DefaultTableSelectionModel()
Method Detail

isValueAdjusting

public boolean isValueAdjusting()
Description copied from interface: TableSelectionModel
Checks if the value is adjusting. If so, no event will be fired till this flag is set to false.

Specified by:
isValueAdjusting in interface TableSelectionModel
Returns:
true or false.

setValueAdjusting

public void setValueAdjusting(boolean valueAdjusting)
Description copied from interface: TableSelectionModel
Sets the value adjusting flag. If true, no event will be fired till this flag is set to false.

This method has to be sync with JTable#getSelectionModel() and JTable#getColumnModel()#getSelectionModel() if you choose to invoke this method directly.

Specified by:
setValueAdjusting in interface TableSelectionModel
Parameters:
valueAdjusting - true or false.

markAsDirty

public void markAsDirty(int firstRow,
                        int lastRow,
                        int firstColumn,
                        int lastColumn)

addSelection

public void addSelection(int row,
                         int column)
Adds the cell specified by row and column to the selection.

Specified by:
addSelection in interface TableSelectionModel
Parameters:
row - the row index
column - the column index

removeSelection

public void removeSelection(int row,
                            int column)
Removes the cell specified by row and column from the selection.

Specified by:
removeSelection in interface TableSelectionModel
Parameters:
row - the row index
column - the column index

setSelection

public void setSelection(int row,
                         int column)
Adds the cell specified by row and column to the selection. It will clear out other selections in the same column.

Specified by:
setSelection in interface TableSelectionModel
Parameters:
row - the row index
column - the column index

setSelectionInterval

public void setSelectionInterval(int row1,
                                 int row2,
                                 int column)
Adds the cells of the specified column between row1 and row2 to the selection. It will clear out other selections in the same column.

Specified by:
setSelectionInterval in interface TableSelectionModel
Parameters:
row1 - the start row index
row2 - the end row index
column - the column index

setAnchorSelection

public void setAnchorSelection(int row,
                               int column)
Sets the anchor selection at the cell specified by row and column. This call will clear out the lead selection.

Specified by:
setAnchorSelection in interface TableSelectionModel
Parameters:
row - the row index
column - the column index

setLeadSelection

public void setLeadSelection(int row,
                             int column)
Sets the lead selection at the cell specified by row and column. All cells in the range of anchor cell and lead cell will be selected after this call.

Specified by:
setLeadSelection in interface TableSelectionModel
Parameters:
row - the new lead selection row index
column - the new lead selection column index

moveLeadSelection

public void moveLeadSelection(int row,
                              int column)
Moves the lead selection at the cell specified by row and column and leaving all selection values unchanged.

Specified by:
moveLeadSelection in interface TableSelectionModel
Parameters:
row - the new lead selection row index
column - the new lead selection column index

clearSelection

public void clearSelection()
Clears all the selections.

Specified by:
clearSelection in interface TableSelectionModel

selectAll

public void selectAll(int rowCount,
                      int columnCount)
Selects all the cells.

Specified by:
selectAll in interface TableSelectionModel
Parameters:
rowCount - the row count
columnCount - the column count

isSelected

public boolean isSelected(int row,
                          int column)
Checks if the specified cell is selected.

Specified by:
isSelected in interface TableSelectionModel
Parameters:
row - the row index
column - the column index
Returns:
true if the specified cell is selected. Otherwise false.

getListSelectionModelAt

public ListSelectionModel getListSelectionModelAt(int columnIndex)
Returns the ListSelectionModel at the specified column.

Parameters:
columnIndex - the column
Returns:
the ListSelectionModel for the column

setColumns

public void setColumns(int count)
Set the number of columns.

Specified by:
setColumns in interface TableSelectionModel
Parameters:
count - the number of columns

addColumn

protected void addColumn()
Adds a column to the end of the model.


insertColumn

protected void insertColumn(int index)
Inserts a column at the specified index of the model.

Parameters:
index - the column index.

removeColumn

protected void removeColumn()
Removes last column from model.


propertyChange

public void propertyChange(PropertyChangeEvent evt)
When the TableModel changes, the TableSelectionModel has to adapt to the new Model. This method is called if a new TableModel is set to the JTable.

Specified by:
propertyChange in interface PropertyChangeListener

addTableSelectionListener

public void addTableSelectionListener(TableSelectionListener l)
Add a listener to the list that's notified each time a change to the selection occurs.

Specified by:
addTableSelectionListener in interface TableSelectionModel
Parameters:
l - the listener

removeTableSelectionListener

public void removeTableSelectionListener(TableSelectionListener l)
Remove a listener from the list that's notified each time a change to the selection occurs.

Specified by:
removeTableSelectionListener in interface TableSelectionModel
Parameters:
l - the listener

tableChanged

public void tableChanged(TableModelEvent e)
Is called when the TableModel changes. If the number of columns had changed this class will adapt to it.

Specified by:
tableChanged in interface TableModelListener

valueChanged

public void valueChanged(ListSelectionEvent e)
Is called when the selection of a ListSelectionModel of a column has changed.

Specified by:
valueChanged in interface ListSelectionListener

fireValueChanged

protected void fireValueChanged(boolean isAdjusting)
Notifies listeners that we have ended a series of adjustments.

Parameters:
isAdjusting - true or false.

fireValueChanged

protected void fireValueChanged(Object source,
                                int firstIndex,
                                int lastIndex,
                                int columnIndex,
                                boolean isAdjusting)
Notify listeners that we have ended a series of adjustments.

Parameters:
source - the source to fire the event
firstIndex - the first row index
lastIndex - the last row index
columnIndex - the column index
isAdjusting - the flag indicating if the selection is adjusting

fireValueChanged

protected void fireValueChanged()

fireValueChanged

protected void fireValueChanged(Object source,
                                int firstIndex,
                                int lastIndex,
                                int firstColumnIndex,
                                int lastColumnIndex,
                                boolean isAdjusting)
Notify listeners that we have ended a series of adjustments.

Parameters:
source - the source to fire the event
firstIndex - the first row index
lastIndex - the last row index
firstColumnIndex - the first column index
lastColumnIndex - the last column index
isAdjusting - the flag indicating if the selection is adjusting

toString

public String toString()
Overrides:
toString in class Object

getAnchorRowIndex

public int getAnchorRowIndex()
Gets the anchor row index.

Specified by:
getAnchorRowIndex in interface TableSelectionModel
Returns:
the anchor row index.

getAnchorColumnIndex

public int getAnchorColumnIndex()
Gets the anchor column index.

Specified by:
getAnchorColumnIndex in interface TableSelectionModel
Returns:
the anchor column index.

getLeadRowIndex

public int getLeadRowIndex()
Gets the lead row index.

Specified by:
getLeadRowIndex in interface TableSelectionModel
Returns:
the lead row index.

getLeadColumnIndex

public int getLeadColumnIndex()
Gets the lead column index.

Specified by:
getLeadColumnIndex in interface TableSelectionModel
Returns:
the lead column index.

isSelectionEmpty

public boolean isSelectionEmpty()
Checks if there is any selection in the selection model.

Specified by:
isSelectionEmpty in interface TableSelectionModel
Returns:
true if there is no selection. Otherwise false.

getSelectedColumns

public int[] getSelectedColumns()
Description copied from interface: TableSelectionModel
Returns an array of indices of all selected columns.

Specified by:
getSelectedColumns in interface TableSelectionModel
Returns:
an array of integers containing the indices of all selected columns; or an empty array if nothing is selected

getSelectedColumnCount

public int getSelectedColumnCount()
Description copied from interface: TableSelectionModel
Returns the number of selected columns.

Specified by:
getSelectedColumnCount in interface TableSelectionModel
Returns:
the number of selected columns; or 0 if no columns are selected

getSelectedRows

public int[] getSelectedRows()
Description copied from interface: TableSelectionModel
Returns an array of indices of all selected rows.

Specified by:
getSelectedRows in interface TableSelectionModel
Returns:
an array of integers containing the indices of all selected rows; or an empty array if nothing is selected

getSelectedRowCount

public int getSelectedRowCount()
Description copied from interface: TableSelectionModel
Returns the number of selected rows.

Specified by:
getSelectedRowCount in interface TableSelectionModel
Returns:
the number of selected rows; or 0 if no rows are selected

isRowSelected

public boolean isRowSelected(int rowIndex)
Description copied from interface: TableSelectionModel
Checks if the row at row index has any selected cells.

Specified by:
isRowSelected in interface TableSelectionModel
Parameters:
rowIndex - the row index
Returns:
true if the row at row index has any selected cells.

isColumnSelected

public boolean isColumnSelected(int columnIndex)
Description copied from interface: TableSelectionModel
Checks if the column at column index has any selected cells.

Specified by:
isColumnSelected in interface TableSelectionModel
Parameters:
columnIndex - the column index
Returns:
true if the column at column index has any selected cells.

getMinSelectedRowIndex

public int getMinSelectedRowIndex()
Description copied from interface: TableSelectionModel
Returns the first selected row index or -1 if the selection is empty.

Specified by:
getMinSelectedRowIndex in interface TableSelectionModel
Returns:
the first selected row index or -1 if the selection is empty.

getMaxSelectedRowIndex

public int getMaxSelectedRowIndex()
Description copied from interface: TableSelectionModel
Returns the last selected row index or -1 if the selection is empty.

Specified by:
getMaxSelectedRowIndex in interface TableSelectionModel
Returns:
the last selected row index or -1 if the selection is empty.

getMinSelectedColumnIndex

public int getMinSelectedColumnIndex()
Description copied from interface: TableSelectionModel
Returns the first selected column index or -1 if the selection is empty.

Specified by:
getMinSelectedColumnIndex in interface TableSelectionModel
Returns:
the first selected column index or -1 if the selection is empty.

getMaxSelectedColumnIndex

public int getMaxSelectedColumnIndex()
Description copied from interface: TableSelectionModel
Returns the last selected column index or -1 if the selection is empty.

Specified by:
getMaxSelectedColumnIndex in interface TableSelectionModel
Returns:
the last selected column index or -1 if the selection is empty.

columnAdded

public void columnAdded(int columnIndex)
Description copied from interface: TableSelectionModel
Notifies the selection model that a column is added to TableColumnModel.

Specified by:
columnAdded in interface TableSelectionModel
Parameters:
columnIndex - the added column index.

columnRemoved

public void columnRemoved(int columnIndex)
Description copied from interface: TableSelectionModel
Notifies the selection model that a column is removed from TableColumnModel.

Specified by:
columnRemoved in interface TableSelectionModel
Parameters:
columnIndex - the removed column index.

columnMoved

public void columnMoved(int fromColumnIndex,
                        int toColumnIndex)
Description copied from interface: TableSelectionModel
Notifies the selection model that a column is added to TableColumnModel.

Specified by:
columnMoved in interface TableSelectionModel
Parameters:
fromColumnIndex - the column index which is moved.
toColumnIndex - the column index where the column is moved.

columnAdded

public void columnAdded(TableColumnModelEvent e)
The event listener to handle the column added event

Specified by:
columnAdded in interface TableColumnModelListener
Parameters:
e - the event
Since:
3.3.0

columnRemoved

public void columnRemoved(TableColumnModelEvent e)
The event listener to handle the column removed event.

Specified by:
columnRemoved in interface TableColumnModelListener
Parameters:
e - the event
Since:
3.3.0

columnMoved

public void columnMoved(TableColumnModelEvent e)
The event listener to handle the column moved event.

Specified by:
columnMoved in interface TableColumnModelListener
Parameters:
e - the event
Since:
3.3.0

columnMarginChanged

public void columnMarginChanged(ChangeEvent e)
The event listener to handle the column margin changed event.

Specified by:
columnMarginChanged in interface TableColumnModelListener
Parameters:
e - the event
Since:
3.3.0

columnSelectionChanged

public void columnSelectionChanged(ListSelectionEvent e)
The event listener to handle the column selection changed event.

Specified by:
columnSelectionChanged in interface TableColumnModelListener
Parameters:
e - the event
Since:
3.3.0

JIDE 3.5.15