JClass DesktopViews 6.3.0 API
Documentation

com.klg.jclass.util.swing
Class DefaultRowSortTableModel

java.lang.Object
  |
  +--javax.swing.table.AbstractTableModel
        |
        +--com.klg.jclass.util.swing.DefaultRowSortTableModel
All Implemented Interfaces:
EventListener, JCRowSortModel, JCRowSortTableModel, Serializable, TableModel, TableModelListener

public class DefaultRowSortTableModel
extends AbstractTableModel
implements JCRowSortTableModel, TableModelListener

Wrap a table model with a sorted table model

See Also:
JCRowSortTableModel, TableModelListener, Serialized Form

Field Summary
protected  boolean autoSort
           
static int FORWARD
          Valid value for SortOrder
protected  int[] indices
           
protected  int[][] keyColumnsArray
           
protected  boolean needsReordering
           
protected  boolean needsResorting
           
protected  int order
           
static int REVERSE
          Valid value for SortOrder
protected  int[] reverseIndices
           
protected  com.klg.jclass.util.swing.JCRowComparator rowComparator
           
protected  com.klg.jclass.util.swing.DefaultRowSortTableModel.RowIntComparator rowIntComparator
           
protected  int sortColumn
           
protected  TableModel tableModel
           
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
DefaultRowSortTableModel(TableModel tableModel)
          Constructs a JCRowSortModel that wraps a given instance of a TableModel and provides a sorted mapping of the TableModel to the view.
DefaultRowSortTableModel(TableModel tableModel, com.klg.jclass.util.swing.JCRowComparator comparator)
          Constructs a JCRowSortModel that wraps a given instance of a TableModel and provides a sorted mapping of the TableModel to the view.
 
Method Summary
protected  void doReverseMapping()
          Do the reverse mapping so we can get a sorted row from an unsorted row.
 boolean getAutoSort()
          Returns whether the data is automatically sorted when it changes according the current comparator.
 Class getColumnClass(int columnIndex)
          Returns the lowest common denominator Class for the TableModel column.
 int getColumnCount()
          Returns the number of columns in the TableModel.
 String getColumnName(int column)
          Returns a TableModel default column name.
 com.klg.jclass.util.swing.JCRowComparator getComparator()
          Returns the current comparator.
 int[] getKeyColumns(int column)
          Returns the key columns used to sort the table model when clicking on the specified column.
 TableModel getModel()
          Returns the table model this model wraps.
 int getRowCount()
          Returns the number of rows in the TableModel.
 int getSortColumn()
          Gets the sorting column.
 int getSortedRow(int row)
          Returns the sorted row index of the specified unsorted row
 int getSortOrder()
          Gets the sorting order.
 int getUnsortedRow(int sortedRow)
          Returns the unsorted row index of specified sorted row.
 Object getValueAt(int rowIndex, int columnIndex)
          Gets a value for the record in the TableModel cell at columnIndex and rowIndex.
 boolean isCellEditable(int rowIndex, int columnIndex)
          Returns true if the TableModel cell at rowIndex and columnIndex is editable.
 boolean isDataSorted()
          Returns whether or not the data set is currently sorted.
 void setAutoSort(boolean autoSort)
          Sets whether the data should be automatically sorted when it changes.
 void setComparator(com.klg.jclass.util.swing.JCRowComparator comparator)
          Sets the Comparator property defining the sort order to provide a sorted mapping of the given TableModel to the view.
 void setDataSorted(boolean sorted)
          Sorts the indices of rows using the quicksort algorithm.
 void setKeyColumns(int column, int[] keyColumns)
          Sets the key columns used to sort the table model when clicking on a specified column.
 void setModel(TableModel newModel)
          Sets the table model wrapped by this model.
 void setSortColumn(int column)
          Sets the sort column.
 void setSortOrder(int order)
          Sets the sorting order.
 void setValueAt(Object aValue, int rowIndex, int columnIndex)
          Sets a value for the record in the TableModel cell at columnIndex and rowIndex.
 void tableChanged(TableModelEvent e)
          The table model has changed.
 void toggleSortOrder()
          Toggles the sorting order.
 void unsort()
          Restores the unsorted order.
 
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FORWARD

public static final int FORWARD
Valid value for SortOrder

See Also:
Constant Field Values

REVERSE

public static final int REVERSE
Valid value for SortOrder

See Also:
Constant Field Values

order

protected int order

tableModel

protected TableModel tableModel

sortColumn

protected int sortColumn

indices

protected int[] indices

reverseIndices

protected int[] reverseIndices

rowComparator

protected com.klg.jclass.util.swing.JCRowComparator rowComparator

keyColumnsArray

protected int[][] keyColumnsArray

rowIntComparator

protected com.klg.jclass.util.swing.DefaultRowSortTableModel.RowIntComparator rowIntComparator

autoSort

protected boolean autoSort

needsResorting

protected boolean needsResorting

needsReordering

protected boolean needsReordering
Constructor Detail

DefaultRowSortTableModel

public DefaultRowSortTableModel(TableModel tableModel,
                                com.klg.jclass.util.swing.JCRowComparator comparator)
Constructs a JCRowSortModel that wraps a given instance of a TableModel and provides a sorted mapping of the TableModel to the view. The sort order is defined by the configurable Comparator property.

Parameters:
tableModel - The TableModel to wrap
comparator - The comparator to do the sorting

DefaultRowSortTableModel

public DefaultRowSortTableModel(TableModel tableModel)
Constructs a JCRowSortModel that wraps a given instance of a TableModel and provides a sorted mapping of the TableModel to the view.

Parameters:
tableModel - The TableModel to wrap
Method Detail

getModel

public TableModel getModel()
Returns the table model this model wraps.

Returns:
The TableModel which is wrapped my this model

setModel

public void setModel(TableModel newModel)
Sets the table model wrapped by this model.

Parameters:
newModel - The new TableModel to wrap

setKeyColumns

public void setKeyColumns(int column,
                          int[] keyColumns)
Sets the key columns used to sort the table model when clicking on a specified column.

Specified by:
setKeyColumns in interface JCRowSortModel
Parameters:
column - index of column in TableModel.
keyColumns - columns to use as keys to sort when sorting on the specified column.

getKeyColumns

public int[] getKeyColumns(int column)
Returns the key columns used to sort the table model when clicking on the specified column. If the user has not set the key columns, the method returns an array of length 1 with the specified column as the only member.

Specified by:
getKeyColumns in interface JCRowSortModel
Parameters:
column - index of column in TableModel.
Returns:
The key columns used to sort the table for the given column

isDataSorted

public boolean isDataSorted()
Returns whether or not the data set is currently sorted.

Specified by:
isDataSorted in interface JCRowSortModel
Returns:
Is the data currently sorted?

getAutoSort

public boolean getAutoSort()
Returns whether the data is automatically sorted when it changes according the current comparator.

Specified by:
getAutoSort in interface JCRowSortModel
Returns:
Is the data automatically sorted?

setAutoSort

public void setAutoSort(boolean autoSort)
Sets whether the data should be automatically sorted when it changes.

Specified by:
setAutoSort in interface JCRowSortModel
Parameters:
autoSort - The new value of autoSort

getSortColumn

public int getSortColumn()
Gets the sorting column.

Specified by:
getSortColumn in interface JCRowSortModel
Returns:
The current sort column

setSortColumn

public void setSortColumn(int column)
Sets the sort column.

Specified by:
setSortColumn in interface JCRowSortModel
Parameters:
column - The new sort column

getSortOrder

public int getSortOrder()
Gets the sorting order.

Specified by:
getSortOrder in interface JCRowSortModel
Returns:
The current sorting order

setSortOrder

public void setSortOrder(int order)
Sets the sorting order.

Specified by:
setSortOrder in interface JCRowSortModel
Parameters:
order - The new sorting order

toggleSortOrder

public void toggleSortOrder()
Toggles the sorting order.

Specified by:
toggleSortOrder in interface JCRowSortModel

getUnsortedRow

public int getUnsortedRow(int sortedRow)
Returns the unsorted row index of specified sorted row.

Specified by:
getUnsortedRow in interface JCRowSortTableModel
Parameters:
sortedRow - The sorted row index
Returns:
The unsorted row index

getSortedRow

public int getSortedRow(int row)
Returns the sorted row index of the specified unsorted row

Specified by:
getSortedRow in interface JCRowSortTableModel
Parameters:
row - The unsorted row index
Returns:
The sorted row index

setComparator

public void setComparator(com.klg.jclass.util.swing.JCRowComparator comparator)
Sets the Comparator property defining the sort order to provide a sorted mapping of the given TableModel to the view.

Parameters:
comparator - The new comparator for sorting

getComparator

public com.klg.jclass.util.swing.JCRowComparator getComparator()
Returns the current comparator.

Returns:
The current comparator for sorting

setDataSorted

public void setDataSorted(boolean sorted)
Sorts the indices of rows using the quicksort algorithm.

Specified by:
setDataSorted in interface JCRowSortModel
Parameters:
sorted - If true and the data is not sorted, sorts the data. If false, unsorts the data.

unsort

public void unsort()
Restores the unsorted order.


doReverseMapping

protected void doReverseMapping()
Do the reverse mapping so we can get a sorted row from an unsorted row.


getColumnCount

public int getColumnCount()
Returns the number of columns in the TableModel.

Specified by:
getColumnCount in interface TableModel
Returns:
The current number of columns

getRowCount

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

Specified by:
getRowCount in interface TableModel
Returns:
The current number of rows

getColumnName

public String getColumnName(int column)
Returns a TableModel default column name.

Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel
Parameters:
column - The column number whose name is required
Returns:
The name for the required column

getColumnClass

public Class getColumnClass(int columnIndex)
Returns the lowest common denominator Class for the TableModel column.

Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel
Parameters:
columnIndex - The index of the column whose class is required
Returns:
The current class for the given column

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Returns true if the TableModel cell at rowIndex and columnIndex is editable.

Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class AbstractTableModel
Parameters:
rowIndex - The row index of the cell
columnIndex - The column index of the cell
Returns:
Is the cell at the given row and column index editable?

getValueAt

public Object getValueAt(int rowIndex,
                         int columnIndex)
Gets a value for the record in the TableModel cell at columnIndex and rowIndex.

Specified by:
getValueAt in interface TableModel
Parameters:
rowIndex - The row index of the cell
columnIndex - The column index of the cell
Returns:
The value at the given row and column index

setValueAt

public void setValueAt(Object aValue,
                       int rowIndex,
                       int columnIndex)
Sets a value for the record in the TableModel cell at columnIndex and rowIndex.

Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class AbstractTableModel
Parameters:
aValue - The new value for the cell with the given row and cell index
rowIndex - The row index of the cell
columnIndex - The column index of the cell

tableChanged

public void tableChanged(TableModelEvent e)
The table model has changed.

Specified by:
tableChanged in interface TableModelListener
Parameters:
e - The event that generated this call

Copyright © 2004 Quest Software Inc..
All rights reserved.