org.archiviststoolkit.swing
Class SortableTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.archiviststoolkit.swing.SortableTableModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel

public class SortableTableModel
extends javax.swing.table.AbstractTableModel

Facade which allows for sorting of tables.

See Also:
Serialized Form

Field Summary
static int ASCENDING
          Ascending.
static java.util.Comparator COMPARABLE_COMAPRATOR
          Comparator.
static int DESCENDING
          are we sorting in descending mode.
static java.util.Comparator LEXICAL_COMPARATOR
          Lexical comparitor.
static int NOT_SORTED
          are we sorted at all.
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
SortableTableModel()
          Constructor.
SortableTableModel(javax.swing.table.TableModel tableModel)
          Constructor.
SortableTableModel(javax.swing.table.TableModel tableModel, javax.swing.table.JTableHeader tableHeader)
          Constructor.
 
Method Summary
 java.lang.Class getColumnClass(int column)
          Get the column class.
 int getColumnCount()
          Get the column count.
 java.lang.String getColumnName(int column)
          Get the column name.
protected  java.util.Comparator getComparator(int column)
          Get the comparator for a column.
protected  javax.swing.Icon getHeaderRendererIcon(int column, int size)
          Get the header icon to render.
 int getRowCount()
          Get the row count.
 int getSortingStatus(int column)
          Get the sorting status.
 javax.swing.table.JTableHeader getTableHeader()
          Get the table header.
 javax.swing.table.TableModel getTableModel()
          Get the table model.
 java.lang.Object getValueAt(int row, int column)
          Get the value at a cell.
 boolean isCellEditable(int row, int column)
          Is the cell editable.
 boolean isSorting()
          Is the column sorted.
 int modelIndex(int viewIndex)
          Get the model index.
 void setColumnComparator(java.lang.Class type, java.util.Comparator comparator)
          Set the comparator for a column.
 void setSortingStatus(int column, int status)
          Set the sorting status.
 void setTableHeader(javax.swing.table.JTableHeader tableHeader)
          Set the table header.
 void setTableModel(javax.swing.table.TableModel tableModel)
          Set the table model.
 void setValueAt(java.lang.Object aValue, int row, int column)
          Set value at a cell.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DESCENDING

public static final int DESCENDING
are we sorting in descending mode.

See Also:
Constant Field Values

NOT_SORTED

public static final int NOT_SORTED
are we sorted at all.

See Also:
Constant Field Values

ASCENDING

public static final int ASCENDING
Ascending.

See Also:
Constant Field Values

COMPARABLE_COMAPRATOR

public static final java.util.Comparator COMPARABLE_COMAPRATOR
Comparator.


LEXICAL_COMPARATOR

public static final java.util.Comparator LEXICAL_COMPARATOR
Lexical comparitor.

Constructor Detail

SortableTableModel

public SortableTableModel()
Constructor.


SortableTableModel

public SortableTableModel(javax.swing.table.TableModel tableModel)
Constructor.

Parameters:
tableModel - the table we will facade.

SortableTableModel

public SortableTableModel(javax.swing.table.TableModel tableModel,
                          javax.swing.table.JTableHeader tableHeader)
Constructor.

Parameters:
tableModel - the table model to facade.
tableHeader - a table header to use.
Method Detail

getTableModel

public javax.swing.table.TableModel getTableModel()
Get the table model.

Returns:
the table model.

setTableModel

public void setTableModel(javax.swing.table.TableModel tableModel)
Set the table model.

Parameters:
tableModel - the table model.

getTableHeader

public javax.swing.table.JTableHeader getTableHeader()
Get the table header.

Returns:
the table header.

setTableHeader

public void setTableHeader(javax.swing.table.JTableHeader tableHeader)
Set the table header.

Parameters:
tableHeader - the table header.

isSorting

public boolean isSorting()
Is the column sorted.

Returns:
true or false

getSortingStatus

public int getSortingStatus(int column)
Get the sorting status.

Parameters:
column - the column
Returns:
the status.

setSortingStatus

public void setSortingStatus(int column,
                             int status)
Set the sorting status.

Parameters:
column - the column
status - the status.

getHeaderRendererIcon

protected javax.swing.Icon getHeaderRendererIcon(int column,
                                                 int size)
Get the header icon to render.

Parameters:
column - the column
size - the size
Returns:
the icon

setColumnComparator

public void setColumnComparator(java.lang.Class type,
                                java.util.Comparator comparator)
Set the comparator for a column.

Parameters:
type - the type.
comparator - the comparator.

getComparator

protected java.util.Comparator getComparator(int column)
Get the comparator for a column.

Parameters:
column - the column.
Returns:
the comparator.

modelIndex

public int modelIndex(int viewIndex)
Get the model index.

Parameters:
viewIndex - the index
Returns:
the model index

getRowCount

public int getRowCount()
Get the row count.

Returns:
the row count.

getColumnCount

public int getColumnCount()
Get the column count.

Returns:
the number of columns.

getColumnName

public java.lang.String getColumnName(int column)
Get the column name.

Specified by:
getColumnName in interface javax.swing.table.TableModel
Overrides:
getColumnName in class javax.swing.table.AbstractTableModel
Parameters:
column - the index of the column
Returns:
the name of the column.

getColumnClass

public java.lang.Class getColumnClass(int column)
Get the column class.

Specified by:
getColumnClass in interface javax.swing.table.TableModel
Overrides:
getColumnClass in class javax.swing.table.AbstractTableModel
Parameters:
column - the column index.
Returns:
the class of the column

isCellEditable

public boolean isCellEditable(int row,
                              int column)
Is the cell editable.

Specified by:
isCellEditable in interface javax.swing.table.TableModel
Overrides:
isCellEditable in class javax.swing.table.AbstractTableModel
Parameters:
row - the row index.
column - the column index.
Returns:
is the cell editable.

getValueAt

public java.lang.Object getValueAt(int row,
                                   int column)
Get the value at a cell.

Parameters:
row - the row
column - the column
Returns:
the object.

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int row,
                       int column)
Set value at a cell.

Specified by:
setValueAt in interface javax.swing.table.TableModel
Overrides:
setValueAt in class javax.swing.table.AbstractTableModel
Parameters:
aValue - the value
row - the row
column - the column