Package: groovy.swing.table

## [Java] Class TableSorter

- groovy.swing.table.TableSorter

-     public class TableSorter
      extends TableMap

  A sorter for TableModels.

  The sorter has a model (conforming to TableModel) and itself implements TableModel. TableSorter does not store or copy the data in the TableModel, instead it maintains an array of integers which it keeps the same size as the number of rows in its model. When the model changes it notifies the sorter that something has changed eg. "rowsAdded" so that its internal array of integers can be reallocated. As requests are made of the sorter (like getValueAt(row, col) it redirects them to its model via the mapping array. That way the TableSorter appears to hold another copy of the table with the rows in a different order. The sorting algorithm used is stable which means that it does not move around rows when its comparison function returns 0 to denote that they are equivalent.

- - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class TableMap` | `model`

  - ### Constructor Summary

    Constructors
    Constructor and description
    `TableSorter()` Creates an empty sorter with no delegate model.
    `TableSorter(TableModel model)` Creates a sorter for the supplied table model.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `addMouseListenerToHeaderInTable(JTable table)` Installs a header listener that resorts the table when a column header is clicked.
    `` | `public void` | `checkModel()` Verifies that the cached index mapping still matches the delegate model.
    `` | `public int` | `compare(int row1, int row2)` Compares two source rows using the active sort columns.
    `` | `public int` | `compareRowsByColumn(int row1, int row2, int column)` Compares two source rows using the values from the supplied column.
    `` | `public Object` | `getValueAt(int aRow, int aColumn)` Returns the value from the source row mapped to the supplied view row.
    `` | `public void` | `n2sort()` Sorts the row mapping using a simple quadratic algorithm.
    `` | `public void` | `reallocateIndexes()` Rebuilds the row index mapping to match the current delegate row count.
    `` | `public void` | `setModel(TableModel model)` Replaces the wrapped model and rebuilds the cached row index mapping.
    `` | `public void` | `setValueAt(Object aValue, int aRow, int aColumn)` Writes a value to the source row mapped from the supplied view row.
    `` | `public void` | `shuttlesort(int[] from, int[] to, int low, int high)` Performs a stable merge sort over the cached row mapping.
    `` | `public void` | `sort(Object sender)` Sorts the cached row mapping using the currently configured sort columns.
    `` | `public void` | `sortByColumn(int column)` Sorts the table by the supplied model column in ascending order.
    `` | `public void` | `sortByColumn(int column, boolean ascending)` Sorts the table by the supplied model column and direction.
    `` | `public void` | `swap(int i, int j)` Swaps two entries in the cached row mapping.
    `` | `public void` | `tableChanged(TableModelEvent e)` Rebuilds the cached row mapping after any delegate table-model change.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class TableMap` | `getColumnClass, getColumnCount, getColumnName, getModel, getRowCount, getValueAt, isCellEditable, setModel, setValueAt, tableChanged`

- - ### Constructor Detail

    - #### public TableSorter()

      Creates an empty sorter with no delegate model.

    - #### public TableSorter(TableModel model)

      Creates a sorter for the supplied table model.

      Parameters:
        `model` - the model to wrap

  - ### Method Detail

    - #### public void addMouseListenerToHeaderInTable(JTable table)

      Installs a header listener that resorts the table when a column header is clicked.

      Parameters:
        `table` - the table whose header should trigger sorting

    - #### public void checkModel()

      Verifies that the cached index mapping still matches the delegate model.

    - #### public int compare(int row1, int row2)

      Compares two source rows using the active sort columns.

      Parameters:
        `row1` - the first source row index
        `row2` - the second source row index
      Returns:
        the comparison result in the currently configured direction

    - #### public int compareRowsByColumn(int row1, int row2, int column)

      Compares two source rows using the values from the supplied column.

      Parameters:
        `row1` - the first source row index
        `row2` - the second source row index
        `column` - the model column index to compare
      Returns:
        a negative value, zero, or a positive value depending on sort order

    - #### public Object getValueAt(int aRow, int aColumn)

      Returns the value from the source row mapped to the supplied view row.

      Parameters:
        `aRow` - the sorted view row
        `aColumn` - the model column
      Returns:
        the mapped cell value

    - #### public void n2sort()

      Sorts the row mapping using a simple quadratic algorithm.

    - #### public void reallocateIndexes()

      Rebuilds the row index mapping to match the current delegate row count.

    - #### public void setModel(TableModel model)

      Replaces the wrapped model and rebuilds the cached row index mapping.

      Parameters:
        `model` - the model to sort

    - #### public void setValueAt(Object aValue, int aRow, int aColumn)

      Writes a value to the source row mapped from the supplied view row.

      Parameters:
        `aValue` - the new cell value
        `aRow` - the sorted view row
        `aColumn` - the model column

    - #### public void shuttlesort(int[] from, int[] to, int low, int high)

      Performs a stable merge sort over the cached row mapping.

      Parameters:
        `from` - the source index array
        `to` - the target index array
        `low` - the inclusive lower bound
        `high` - the exclusive upper bound

    - #### public void sort(Object sender)

      Sorts the cached row mapping using the currently configured sort columns.

      Parameters:
        `sender` - the caller requesting the sort

    - #### public void sortByColumn(int column)

      Sorts the table by the supplied model column in ascending order.

      Parameters:
        `column` - the model column index to sort by

    - #### public void sortByColumn(int column, boolean ascending)

      Sorts the table by the supplied model column and direction.

      Parameters:
        `column` - the model column index to sort by
        `ascending` - `true` for ascending order, `false` for descending order

    - #### public void swap(int i, int j)

      Swaps two entries in the cached row mapping.

      Parameters:
        `i` - the first mapped row index
        `j` - the second mapped row index

    - #### public void tableChanged(TableModelEvent e)

      Rebuilds the cached row mapping after any delegate table-model change.

      Parameters:
        `e` - the table-model event