Class SortedTableModel

java.lang.Object
noaa.coastwatch.gui.SortedTableModel
All Implemented Interfaces:
TableModel

public class SortedTableModel extends Object implements TableModel
A SortedTableModel can be used to provide row sorting services for any javax.swing.table.TableModel. The new model simply wraps the old one and translates row indicies through the wrapper so as to make it appear that the table is sorted according to the values held in a specific column of the table.
Since:
3.2.1
Author:
Peter Hollemans
  • Constructor Details

    • SortedTableModel

      public SortedTableModel(TableModel model)
      Creates a sorted model using the specified unsorted model for its data. The table is initially unsorted so that rows in the sorted table model are in exactly the same order as rows in the unsorted model.
      Parameters:
      model - the model to use for row and column data.
  • Method Details

    • setSort

      public void setSort(int sortColumn, boolean isAscending)
      Set the sorting column and order.
      Parameters:
      sortColumn - the new sorting column, or -1 for no sorting.
      isAscending - the new sorting order, true for ascending.
    • getSortColumn

      public int getSortColumn()
      Gets the current sorting column, or -1 for no sorting.
    • getIsAscending

      public boolean getIsAscending()
      Gets the current sorting order.
    • convertRowIndexToModel

      public int convertRowIndexToModel(int row)
      Converts a row index in the sorted model to a row index in the underlying model.
      Parameters:
      row - the row index to convert.
      Returns:
      the row index in the underlying table model.
    • convertRowIndexToView

      public int convertRowIndexToView(int row)
      Converts a row index in the underlying model to a row index in the sorted model.
      Parameters:
      row - the row index to convert.
      Returns:
      the row index in the sorted table model.
    • getRowCount

      public int getRowCount()
      Specified by:
      getRowCount in interface TableModel
    • getColumnCount

      public int getColumnCount()
      Specified by:
      getColumnCount in interface TableModel
    • getColumnName

      public String getColumnName(int columnIndex)
      Specified by:
      getColumnName in interface TableModel
    • getColumnClass

      public Class getColumnClass(int columnIndex)
      Specified by:
      getColumnClass in interface TableModel
    • isCellEditable

      public boolean isCellEditable(int rowIndex, int columnIndex)
      Specified by:
      isCellEditable in interface TableModel
    • getValueAt

      public Object getValueAt(int rowIndex, int columnIndex)
      Specified by:
      getValueAt in interface TableModel
    • setValueAt

      public void setValueAt(Object aValue, int rowIndex, int columnIndex)
      Specified by:
      setValueAt in interface TableModel
    • addTableModelListener

      public void addTableModelListener(TableModelListener l)
      Specified by:
      addTableModelListener in interface TableModel
    • removeTableModelListener

      public void removeTableModelListener(TableModelListener l)
      Specified by:
      removeTableModelListener in interface TableModel