Class SortTableController

All Implemented Interfaces:
Serializable, EventListener, TableModelListener, TableModel

public class SortTableController extends SortTableModel
A controller class for sorting a SortTableModel. SortTableController keeps an internal array of integers, which point to the actual data model in SortTableModel. Sorting is accomplished by re-ordering this internal array of integers.
Author:
Les Thomas
See Also:
  • Constructor Details

    • SortTableController

      public SortTableController()
      Default Constructor. setModel must be called in order for SortTableController to be properly initialized.
    • SortTableController

      public SortTableController(TableModel model)
      Constructs a SortTableController object using the specified model.
      Parameters:
      model - TableModel
  • Method Details

    • setModel

      public void setModel(TableModel model)
      Sets the model for the SortTableController.
      Overrides:
      setModel in class SortTableModel
      Parameters:
      model - TableModel
    • fireTableChangedEvent

      public void fireTableChangedEvent(TableModelEvent e)
      Forwards the given notification event to all TableModelListeners that registered themselves as listeners for this table model.
      Parameters:
      e - the event to be forwarded.
    • tableChanged

      public void tableChanged(TableModelEvent event)
      Forwards the given notification event to all TableModelListeners that registered themselves as listeners for this table model.
      Specified by:
      tableChanged in interface TableModelListener
      Overrides:
      tableChanged in class SortTableModel
      Parameters:
      e - the event to be forwarded.
    • getLastColumnSorted

      public int getLastColumnSorted()
      Returns the index of the last column sorted.
      Returns:
      the column index.
    • setLastColumnSorted

      public void setLastColumnSorted(int columnIndex)
      Sets the last column sorted, based upon the specified index.
      Parameters:
      col - the column index
    • getLastSortOrder

      public boolean getLastSortOrder()
      Returns the last sort order.
      Returns:
      true (ascending), false (descending)
    • setLastSortOrder

      public void setLastSortOrder(boolean sortOrder)
      Sets the last sort order, based upon the specified value.
      Parameters:
      sortOrder - true (ascending), false (descending).
    • getValueAt

      public Object getValueAt(int rowIndex, int columnIndex)
      Returns the value for the cell at columnIndex and rowIndex. A check will be made to determine whether the sort index length is equal to the table model's row count.
      Specified by:
      getValueAt in interface TableModel
      Overrides:
      getValueAt in class SortTableModel
      Parameters:
      rowIndex - the row whose value is to be queried.
      columnIndex - the column whose value is to be queried.
      row - the row whose value is to be queried.
      column - the column whose value is to be queried.
      Returns:
      the value Object at the specified cell.
    • setValueAt

      public void setValueAt(Object aValue, int rowIndex, int columnIndex)
      Sets the value in the cell at columnIndex and rowIndex to aValue. A check will be made to determine whether the sort index length is equal to the table model's row count.
      Specified by:
      setValueAt in interface TableModel
      Overrides:
      setValueAt in class SortTableModel
      Parameters:
      aValue - the new value.
      rowIndex - the row whose value is to be changed.
      columnIndex - the column whose value is to be changed.
    • getDataRow

      public int getDataRow(int row)
      Return the sort row index for the given table row. A check will be made to determine whether the sort index length is equal to the table model's row count.
      Parameters:
      row - the table row.
      Returns:
      the sorted index for the given table row.
    • reSort

      public void reSort(TableColumnModel columnModel)
      Resort the table based upon the specified column model.
      Parameters:
      columnModel - Table column model.
    • reSort

      public void reSort(TableColumnModel columnModel, int viewColumnIndex)
      Resorts the table based upon the specified column model and the view column index.
      Parameters:
      columnModel - Table column model.
      viewColumn - view column index.
    • sort_column

      public void sort_column(int columnIndex, boolean sort_ascending)
      Sort the specified column, in the specified order.
      Parameters:
      column - index of column to be sorted.
      mSortAscending - sort order, ascending (true), descending (false).
    • addSortTableHeaderListener

      public void addSortTableHeaderListener(JTable table)
      Add a mouse listener to the Table, in order to trigger a table sort when a column header is clicked.
      Parameters:
      table - Table to be sorted.
    • setColumnHeader

      public void setColumnHeader(TableColumnModel model, int columnIndex)
      Sets the column header, based upon the specified index, to indicate whether the specified column is being sorted.
      Parameters:
      model - TableColumn model
      columnIndex - the column index
    • saveDataPosition

      public void saveDataPosition(JTable table)
      Concatenates and stores the data from a selected row in a table.

      This will be used to restore the selected row after the data is sorted.

      Parameters:
      table - Table which contains the selected row.
    • restoreDataPosition

      public void restoreDataPosition(JTable table)
      Restores the selected row in a table, after the data has been sorted.

      Each row in the table is concatenated and compared with sSortPositionMap. When a match is found, the row is selected.

      Parameters:
      table - Table which contains the selected row.
    • getMouseListener

      public MouseAdapter getMouseListener()
      Return mouse listener associated with SortTableController.
      Returns:
      listener.
    • setCompare

      public void setCompare(Class c, Comparator compare)
      Allows the user to set a Comparator for an object.
      Parameters:
      c - the object that the Comparator applies to
      compare - the comparator for the given class