com.sas.swing.visuals.tableview
Class DefaultTableRowModel

com.sas.swing.visuals.tableview.DefaultTableRowModel
All Implemented Interfaces:
TableRowModel, java.beans.PropertyChangeListener, java.io.Serializable, java.util.EventListener, javax.swing.event.ListSelectionListener, javax.swing.event.TableModelListener, javax.swing.SwingConstants

public class DefaultTableRowModel
implements TableRowModel, java.beans.PropertyChangeListener, javax.swing.event.TableModelListener, javax.swing.event.ListSelectionListener, java.io.Serializable, javax.swing.SwingConstants

See Also:
Serialized Form

Field Summary
protected  javax.swing.event.ChangeEvent changeEvent
          Change event (only one needed)
protected  javax.swing.event.EventListenerList listenerList
          List of TableRowModelListener
protected  int rowMargin
          Height margin between each row
protected  boolean rowSelectionAllowed
          Row selection allowed in this row model
protected  javax.swing.ListSelectionModel selectionModel
          Model for keeping track of row selections
protected  java.util.List tableRows
          List of Integers representing the rows in this model
 
Constructor Summary
DefaultTableRowModel(TableView table)
          Creates a default table row model.
 
Method Summary
 void addRowModelListener(TableRowModelListener x)
          Adds a listener for table row model events.
 void clearRowMoves()
          This will reset the row indexes back to their original values, before any calls to moveRow were made, that is unless a row is held.
 int convertRowIndexToModel(int viewRowIndex)
          Maps the index of the row in the view at viewRowIndex to the index of the row in the table model.
 int convertRowIndexToView(int modelRowIndex)
          Maps the index of the row in the table model at modelRowIndex to the index of the row in the view.
protected  javax.swing.ListSelectionModel createSelectionModel()
          Creates a new default list selection model.
protected  void fireRowMarginChanged()
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireRowMoved(TableRowModelEvent e)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireRowSelectionChanged(javax.swing.event.ListSelectionEvent e)
          Notifies all listeners that have registered interest for notification on this event type.
 java.util.EventListener[] getListeners(java.lang.Class listenerType)
          Returns an array of all the objects currently registered as FooListeners upon this model.
 int getRowCount()
          Returns the number of rows in the tableRows array.
 int getRowMargin()
          Returns the Height margin for TableRow.
 TableRowModelListener[] getRowModelListeners()
          Returns an array of all the row model listeners registered on this model.
 boolean getRowSelectionAllowed()
          Returns true if row selection is allowed, otherwise false.
 int getSelectedRowCount()
          Returns the number of rows selected.
 int[] getSelectedRows()
          Returns an array of selected rows.
 javax.swing.ListSelectionModel getSelectionModel()
          Returns the ListSelectionModel that is used to maintain row selection state.
 TableView getTable()
          Returns the TableView associated with the row model
 void moveRow(int rowIndex, int newIndex)
          Moves the row and heading at rowIndex to newIndex.
 void propertyChange(java.beans.PropertyChangeEvent evt)
          Property Change Listener change method.
 void removeRowModelListener(TableRowModelListener x)
          Removes a listener for table row model events.
 void setRowMargin(int newMargin)
          Sets the row margin to newMargin.
 void setRowSelectionAllowed(boolean flag)
          Sets whether row selection is allowed.
 void setSelectionModel(javax.swing.ListSelectionModel newModel)
          Sets the selection model for this TableRowModel to newModel and registers for listener notifications from the new selection model.
 void setTable(TableView newTable)
          Sets the TableView associated with this row model, should not be null.
 void tableChanged(javax.swing.event.TableModelEvent e)
          Invoked when this table's TableModel generates a TableModelEvent.
protected  void tableRowsDeleted(javax.swing.event.TableModelEvent e)
           
protected  void tableRowsInserted(javax.swing.event.TableModelEvent e)
           
 void valueChanged(javax.swing.event.ListSelectionEvent e)
          A ListSelectionListener that forwards ListSelectionEvents when there is a row selection change.
 

Field Detail

tableRows

protected java.util.List tableRows
List of Integers representing the rows in this model


selectionModel

protected javax.swing.ListSelectionModel selectionModel
Model for keeping track of row selections


rowMargin

protected int rowMargin
Height margin between each row


listenerList

protected javax.swing.event.EventListenerList listenerList
List of TableRowModelListener


changeEvent

protected transient javax.swing.event.ChangeEvent changeEvent
Change event (only one needed)


rowSelectionAllowed

protected boolean rowSelectionAllowed
Row selection allowed in this row model

Constructor Detail

DefaultTableRowModel

public DefaultTableRowModel(TableView table)
Creates a default table row model.

Method Detail

getTable

public TableView getTable()
Returns the TableView associated with the row model

Returns:
the TableView associated with this row model, should not be null
See Also:
setTable(TableView)

setTable

public void setTable(TableView newTable)
Sets the TableView associated with this row model, should not be null. The TableView is used for listening to when rows are added or deleted from the model.

Parameters:
newTable - the new TableView associated with this row model
See Also:
getTable()

moveRow

public void moveRow(int rowIndex,
                    int newIndex)
Moves the row and heading at rowIndex to newIndex. The old row at rowIndex will now be found at newIndex. The row that used to be at newIndex is shifted left or right to make room. This will not move any rows if rowIndex equals newIndex. This method also posts a rowMoved event to its listeners.

Specified by:
moveRow in interface TableRowModel
Parameters:
rowIndex - the index of row to be moved
newIndex - new index to move the row
Throws:
java.lang.IllegalArgumentException - if row or newIndex are not in the valid range

clearRowMoves

public void clearRowMoves()
This will reset the row indexes back to their original values, before any calls to moveRow were made, that is unless a row is held. Any held row will remain held even after a call to clearRowMoves. This allows users to clear the row moves whenever they want as there may have been a change in the model that requires such.

Specified by:
clearRowMoves in interface TableRowModel

convertRowIndexToModel

public int convertRowIndexToModel(int viewRowIndex)
Maps the index of the row in the view at viewRowIndex to the index of the row in the table model. Returns the index of the corresponding row in the model. If viewRowIndex is less than zero, returns viewRowIndex.

Specified by:
convertRowIndexToModel in interface TableRowModel
Parameters:
viewRowIndex - the index of the row in the view
Returns:
the index of the corresponding row in the model
See Also:
convertRowIndexToView(int)

convertRowIndexToView

public int convertRowIndexToView(int modelRowIndex)
Maps the index of the row in the table model at modelRowIndex to the index of the row in the view. Returns the index of the corresponding row in the view; returns -1 if this row is not being displayed. If modelRowIndex is less than zero, returns modelRowIndex.

Specified by:
convertRowIndexToView in interface TableRowModel
Parameters:
modelRowIndex - the index of the row in the model
Returns:
the index of the corresponding row in the view
See Also:
convertRowIndexToModel(int)

setRowMargin

public void setRowMargin(int newMargin)
Sets the row margin to newMargin. This method also posts a rowMarginChanged event to its listeners.

Specified by:
setRowMargin in interface TableRowModel
Parameters:
newMargin - the new margin Height, in pixels
See Also:
getRowMargin()

getRowCount

public int getRowCount()
Returns the number of rows in the tableRows array.

Specified by:
getRowCount in interface TableRowModel
Returns:
the number of rows in the tableRows array

getRowMargin

public int getRowMargin()
Returns the Height margin for TableRow. The default rowMargin is 1.

Specified by:
getRowMargin in interface TableRowModel
Returns:
the maximum Height for the TableRow
See Also:
setRowMargin(int)

setSelectionModel

public void setSelectionModel(javax.swing.ListSelectionModel newModel)
Sets the selection model for this TableRowModel to newModel and registers for listener notifications from the new selection model. If newModel is null, an exception is thrown.

Specified by:
setSelectionModel in interface TableRowModel
Parameters:
newModel - the new selection model
Throws:
java.lang.IllegalArgumentException - if newModel is null
See Also:
getSelectionModel()

getSelectionModel

public javax.swing.ListSelectionModel getSelectionModel()
Returns the ListSelectionModel that is used to maintain row selection state.

Specified by:
getSelectionModel in interface TableRowModel
Returns:
the object that provides row selection state. Or null if row selection is not allowed.
See Also:
setSelectionModel(javax.swing.ListSelectionModel)

setRowSelectionAllowed

public void setRowSelectionAllowed(boolean flag)
Sets whether row selection is allowed. The default is false.

Specified by:
setRowSelectionAllowed in interface TableRowModel
Parameters:
true - if row selection will be allowed, false otherwise
See Also:
TableRowModel.getRowSelectionAllowed()

getRowSelectionAllowed

public boolean getRowSelectionAllowed()
Returns true if row selection is allowed, otherwise false. The default is false.

Specified by:
getRowSelectionAllowed in interface TableRowModel
Returns:
the rowSelectionAllowed property
See Also:
TableRowModel.setRowSelectionAllowed(boolean)

getSelectedRows

public int[] getSelectedRows()
Returns an array of selected rows. If selectionModel is null, returns an empty array.

Specified by:
getSelectedRows in interface TableRowModel
Returns:
an array of selected rows or an empty array if nothing is selected or the selectionModel is null

getSelectedRowCount

public int getSelectedRowCount()
Returns the number of rows selected.

Specified by:
getSelectedRowCount in interface TableRowModel
Returns:
the number of rows selected

addRowModelListener

public void addRowModelListener(TableRowModelListener x)
Adds a listener for table row model events.

Specified by:
addRowModelListener in interface TableRowModel
Parameters:
x - a TableRowModelListener object

removeRowModelListener

public void removeRowModelListener(TableRowModelListener x)
Removes a listener for table row model events.

Specified by:
removeRowModelListener in interface TableRowModel
Parameters:
x - a TableRowModelListener object

getRowModelListeners

public TableRowModelListener[] getRowModelListeners()
Returns an array of all the row model listeners registered on this model.

Returns:
all of this default table row model's RowModelListeners or an empty array if no row model listeners are currently registered
See Also:
addRowModelListener(com.sas.swing.visuals.tableview.TableRowModelListener), removeRowModelListener(com.sas.swing.visuals.tableview.TableRowModelListener)

fireRowMoved

protected void fireRowMoved(TableRowModelEvent e)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
e - the event received
See Also:
EventListenerList

fireRowSelectionChanged

protected void fireRowSelectionChanged(javax.swing.event.ListSelectionEvent e)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
e - the event received
See Also:
EventListenerList

fireRowMarginChanged

protected void fireRowMarginChanged()
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
e - the event received
See Also:
EventListenerList

getListeners

public java.util.EventListener[] getListeners(java.lang.Class listenerType)
Returns an array of all the objects currently registered as FooListeners upon this model. FooListeners are registered using the addFooListener method.

You can specify the listenerType argument with a class literal, such as FooListener.class. For example, you can query a DefaultTableRowModel m for its row model listeners with the following code:

RowModelListener[] cmls = (RowModelListener[])(m.getListeners(RowModelListener.class));
If no such listeners exist, this method returns an empty array.

Parameters:
listenerType - the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
Returns:
an array of all objects registered as FooListeners on this model, or an empty array if no such listeners have been added
Throws:
java.lang.ClassCastException - if listenerType doesn't specify a class or interface that implements java.util.EventListener
See Also:
getRowModelListeners()

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
Property Change Listener change method. Used to track changes to the table model

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
evt - PropertyChangeEvent

tableChanged

public void tableChanged(javax.swing.event.TableModelEvent e)
Invoked when this table's TableModel generates a TableModelEvent. The TableModelEvent should be constructed in the coordinate system of the model; the appropriate mapping to the view coordinate system is performed by this TableView when it receives the event.

Application code will not use these methods explicitly, they are used internally by TableView.

Specified by:
tableChanged in interface javax.swing.event.TableModelListener

tableRowsInserted

protected void tableRowsInserted(javax.swing.event.TableModelEvent e)

tableRowsDeleted

protected void tableRowsDeleted(javax.swing.event.TableModelEvent e)

valueChanged

public void valueChanged(javax.swing.event.ListSelectionEvent e)
A ListSelectionListener that forwards ListSelectionEvents when there is a row selection change.

Specified by:
valueChanged in interface javax.swing.event.ListSelectionListener
Parameters:
e - the change event

createSelectionModel

protected javax.swing.ListSelectionModel createSelectionModel()
Creates a new default list selection model.




Copyright © 2009 SAS Institute Inc. All Rights Reserved.