Mp3dings 
20100427

de.mospace.swing.table
Interface SortableTableModel

All Superinterfaces:
TableModel
All Known Subinterfaces:
Mp3dingsTableModel
All Known Implementing Classes:
AbstractTableModel, DataTableModel, DependentTableModel, FileTableModel, ID3TagTableModel

public interface SortableTableModel
extends TableModel

A row-sortable TableModel where sorting is managed by translating between two sets of indices, an index set identifying the table entries (entries) and another index set representing the current position of an entry in the table (rows).

All TableModel methods accept and return rows because this is what the associated JTables need. If one wants to access the same entry in two SortableTableModels the row numbers have to be transformed accordingly. E. g. this.setValueAt(anotherSTM.getValueAt(anotherSTM.getRows(getEntries(row)),col), row, col)

Version:
$Revision: 12 $ ($Date: 2007-07-27 11:48:53 +0200 (Fr, 27 Jul 2007) $)
Author:
Moritz Ringler

Field Summary
static int ASCENDING
          Constant for ascending sort order
static int DESCENDING
          Constant for descending sort order
 
Method Summary
 int getEntries(int row)
          Gets the entry represented by the specified row in the current sorting.
 int[] getEntries(int[] rows)
          Gets the entries represented by the specified rows in the current sorting.
 int getRows(int entry)
          Gets the current row number of an entry.
 int[] getRows(int[] entries)
          Gets the current row numbers for a list of entries.
 int getSortingColumn()
          Gets the column with top sorting precedence.
 int[][] getSortOrder()
          Gets the columns by which this table is sorted.
 boolean isSorted()
          Returns whether the model is currently sorted or not.
 void randomize()
          Shuffles the entries in this TableModel.
 void setSortBy(int col)
          Sets the column with top sorting precedence.
 void setSortBy(int col, boolean asc)
          Sets the column with top sorting precedence and the way it is to be sorted.
 void sort()
          Sorts the entries in this TableModel according to the criteria set by setSortBy(int, boolean).
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, getColumnClass, getColumnCount, getColumnName, getRowCount, getValueAt, isCellEditable, removeTableModelListener, setValueAt
 

Field Detail

ASCENDING

static final int ASCENDING
Constant for ascending sort order

See Also:
Constant Field Values

DESCENDING

static final int DESCENDING
Constant for descending sort order

See Also:
Constant Field Values
Method Detail

sort

void sort()
Sorts the entries in this TableModel according to the criteria set by setSortBy(int, boolean).


randomize

void randomize()
Shuffles the entries in this TableModel.


setSortBy

void setSortBy(int col,
               boolean asc)
Sets the column with top sorting precedence and the way it is to be sorted. Implementations can but do not need to remember previous calls to this method to determine what to do when two entries have equal fields in this column.

Parameters:
col - the table column
asc - true for ascending order

setSortBy

void setSortBy(int col)
Sets the column with top sorting precedence. If col is already the column with top sorting precedence the sort order will be reversed, otherwise the entries in this model will be sorted in ascending order.

Implementations can but do not need to remember previous calls to this method to determine what to do when two entries have equal fields in this column.

Parameters:
col - the table column
See Also:
setSortBy(int, boolean)

getSortingColumn

int getSortingColumn()
Gets the column with top sorting precedence.

Returns:
the column by which this table model is sorted.

isSorted

boolean isSorted()
Returns whether the model is currently sorted or not.


getSortOrder

int[][] getSortOrder()
Gets the columns by which this table is sorted. The returned array holds the information used for sorting the table. The array holds n pairs of integers in the order of decreasing sorting precedence. The first integer in each pair is a column number, if it is -1 this element and all following elements must be ignored. The second integer is either ASCENDING or DESCENDING.

Returns:
an array of {column, order} pairs with decreasing sorting precedence

getRows

int getRows(int entry)
Gets the current row number of an entry.


getRows

int[] getRows(int[] entries)
Gets the current row numbers for a list of entries.


getEntries

int getEntries(int row)
Gets the entry represented by the specified row in the current sorting.


getEntries

int[] getEntries(int[] rows)
Gets the entries represented by the specified rows in the current sorting.


Mp3dings 
20100427