org.mars_sim.msp.ui.standard.tool.monitor
Class TableSorter

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.mars_sim.msp.ui.standard.tool.monitor.TableSorter
All Implemented Interfaces:
java.io.Serializable, java.util.EventListener, javax.swing.event.TableModelListener, javax.swing.table.TableModel

public class TableSorter
extends javax.swing.table.AbstractTableModel
implements javax.swing.event.TableModelListener

This TableModel acts as a proxy to provide sorting on a remote Table Model. It is based on the TableSorter provided as part of the Swing UI Tutorial but this version has been simplified as it assumes that only column types that are Comparable will be sorted. Also only one column can be used as a sorting key

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
TableSorter(org.mars_sim.msp.ui.standard.tool.monitor.MonitorModel model)
          Create a sorter model that provides sorting in front of the specified model.
 
Method Summary
 void destroy()
          Prepares the model for deletion.
 java.lang.Class<?> getColumnClass(int columnIndex)
           
 int getColumnCount()
           
 java.lang.String getColumnName(int columnIndex)
           
 java.lang.String getCountString()
          Gets the model count string.
 java.lang.String getName()
          Get the name of this model.
 java.lang.Object getObject(int row)
          Get a list of objects from the source model.
 boolean getOrdered()
          This method signifies whether this model has a natural ordering.
 int getRowCount()
           
 java.lang.Object getValueAt(int aRow, int aColumn)
          Return the cell value according to the ordered rows.
 void setValueAt(java.lang.Object aValue, int aRow, int aColumn)
          The mapping only affects the contents of the data rows.
 void sortByColumn(int column, boolean ascending)
          Sort the table model by the column specified in an particular order.
 void tableChanged(javax.swing.event.TableModelEvent e)
          Fired when there are changed to the source table.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, isCellEditable, removeTableModelListener
 

Constructor Detail

TableSorter

public TableSorter(org.mars_sim.msp.ui.standard.tool.monitor.MonitorModel model)
Create a sorter model that provides sorting in front of the specified model.

Parameters:
model - Real source of data.
Method Detail

getOrdered

public boolean getOrdered()
This method signifies whether this model has a natural ordering.

Returns:
TRUE as this model has embedded sorting.

tableChanged

public void tableChanged(javax.swing.event.TableModelEvent e)
Fired when there are changed to the source table. If any rows have been deleted/inserted or a change to the sorted column, then re-sort

Specified by:
tableChanged in interface javax.swing.event.TableModelListener

getColumnCount

public int getColumnCount()
Specified by:
getColumnCount in interface javax.swing.table.TableModel

getColumnClass

public java.lang.Class<?> getColumnClass(int columnIndex)
Specified by:
getColumnClass in interface javax.swing.table.TableModel
Overrides:
getColumnClass in class javax.swing.table.AbstractTableModel

getColumnName

public java.lang.String getColumnName(int columnIndex)
Specified by:
getColumnName in interface javax.swing.table.TableModel
Overrides:
getColumnName in class javax.swing.table.AbstractTableModel

getName

public java.lang.String getName()
Get the name of this model. The name will be a description helping the user understand the contents.

Returns:
Descriptive name.

getRowCount

public int getRowCount()
Specified by:
getRowCount in interface javax.swing.table.TableModel

getValueAt

public java.lang.Object getValueAt(int aRow,
                                   int aColumn)
Return the cell value according to the ordered rows. This method will remap the specified row according to the sorted mapping.

Specified by:
getValueAt in interface javax.swing.table.TableModel
Parameters:
aRow - Row offset.
aColumn - Column offset.
Returns:
Value of cell.

getObject

public java.lang.Object getObject(int row)
Get a list of objects from the source model. The row indexes are remapped according to the sorted mappings.

Parameters:
row - Indexes of rows in the sorted model.
Returns:
List of objects.

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int aRow,
                       int aColumn)
The mapping only affects the contents of the data rows. Pass all requests to these rows through the mapping array: "indexes".

Specified by:
setValueAt in interface javax.swing.table.TableModel
Overrides:
setValueAt in class javax.swing.table.AbstractTableModel
Parameters:
aValue - New value for cell.
aRow - Row offset.
aColumn - Column offset.

getCountString

public java.lang.String getCountString()
Gets the model count string.


sortByColumn

public void sortByColumn(int column,
                         boolean ascending)
Sort the table model by the column specified in an particular order. If the specified column does not use a Comparable object then it can not be sorted.

Parameters:
column - Column index of sorted column.
ascending - Sort in the ascending order.

destroy

public void destroy()
Prepares the model for deletion.