org.fife.ui
Class FileExplorerTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.fife.ui.FileExplorerTableModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel

public class FileExplorerTableModel
extends javax.swing.table.AbstractTableModel

A table model that simulates the functionality found in the table used in Windows' "details view" in Windows explorer. This is a WIP, and currently is pretty much just a copy of FileExplorerTableModel.java found in java.sun.com's tutorial section.

This model currently allows the user to sort by column, and colors the cells of elements in sorted-by columns slightly darker than normal, to signify that the table is sorted by that row. Future enhancements include a right-click popup menu for the table header that allows you to add or remove columns.

NOTE: If you use this table model in an application that allows the user to change the LaF at runtime, you will get NullPointerExceptions when the user changes from the Windows LaF to another LaF, such as Metal. This is due to Sun bug 6429812. This bug is still open as of 6u18. You'll have to implement a workaround for when the LaF changes if you want to use this class in an application that allows runtime LaF changes. See 6429812 for more information. As an alternative, you can probably use Swing's built-in table sorting support, if you only support Java 6 and up.

Version:
0.4
Author:
Robert Futrell
See Also:
Serialized Form

Nested Class Summary
 class FileExplorerTableModel.SortableHeaderRenderer
          A cell renderer for column headers for sorted tables.
 
Field Summary
static int ASCENDING
           
static java.util.Comparator<?> COMPARABLE_COMPARATOR
          Compares two comparable objects by their compareTo method.
static int DESCENDING
           
static java.util.Comparator<?> LEXICAL_COMPARATOR
          Compares two objects by their string (toString) values.
static int NOT_SORTED
           
protected  javax.swing.table.TableModel tableModel
           
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
FileExplorerTableModel()
          Constructor.
FileExplorerTableModel(javax.swing.table.TableModel tableModel)
          Constructor.
FileExplorerTableModel(javax.swing.table.TableModel tableModel, javax.swing.table.JTableHeader tableHeader)
          Constructor.
 
Method Summary
 java.lang.Class<?> getColumnClass(int column)
           
 int getColumnCount()
           
 java.lang.String getColumnName(int column)
           
protected  java.util.Comparator getComparator(int column)
           
protected  javax.swing.Icon getHeaderRendererIcon(int column, int size)
           
 int getRowCount()
           
 int getSortingStatus(int column)
           
 javax.swing.table.JTableHeader getTableHeader()
          Returns the table header being used.
 javax.swing.table.TableModel getTableModel()
          Returns the table model being used.
 java.lang.Object getValueAt(int row, int column)
           
 boolean isCellEditable(int row, int column)
           
 boolean isSorting()
           
 int modelIndex(int viewIndex)
           
 void setColumnComparator(java.lang.Class<?> type, java.util.Comparator<?> comparator)
           
 void setSortingStatus(int column, int status)
           
 void setTable(javax.swing.JTable table)
          Sets the table this sorter is the model for.
 void setTableModel(javax.swing.table.TableModel tableModel)
          Sets the table model to use.
 void setValueAt(java.lang.Object aValue, int row, int column)
           
 
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

tableModel

protected javax.swing.table.TableModel tableModel

DESCENDING

public static final int DESCENDING
See Also:
Constant Field Values

NOT_SORTED

public static final int NOT_SORTED
See Also:
Constant Field Values

ASCENDING

public static final int ASCENDING
See Also:
Constant Field Values

COMPARABLE_COMPARATOR

public static final java.util.Comparator<?> COMPARABLE_COMPARATOR
Compares two comparable objects by their compareTo method.


LEXICAL_COMPARATOR

public static final java.util.Comparator<?> LEXICAL_COMPARATOR
Compares two objects by their string (toString) values.

Constructor Detail

FileExplorerTableModel

public FileExplorerTableModel()
Constructor.


FileExplorerTableModel

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

Parameters:
tableModel - ???

FileExplorerTableModel

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

Parameters:
tableModel - ???
tableHeader - ???
Method Detail

getComparator

protected java.util.Comparator getComparator(int column)

getHeaderRendererIcon

protected javax.swing.Icon getHeaderRendererIcon(int column,
                                                 int size)

getSortingStatus

public int getSortingStatus(int column)

getTableHeader

public javax.swing.table.JTableHeader getTableHeader()
Returns the table header being used.

Returns:
The table header being used.

getTableModel

public javax.swing.table.TableModel getTableModel()
Returns the table model being used.

Returns:
The table model being used.
See Also:
setTableModel(javax.swing.table.TableModel)

isSorting

public boolean isSorting()

modelIndex

public int modelIndex(int viewIndex)

setColumnComparator

public void setColumnComparator(java.lang.Class<?> type,
                                java.util.Comparator<?> comparator)

setSortingStatus

public void setSortingStatus(int column,
                             int status)

setTable

public void setTable(javax.swing.JTable table)
Sets the table this sorter is the model for. By setting this to a non-null value, any columns by which the table is sorted will be colored with a slightly-darker background (similar to how it's done in Windows XP).

Parameters:
table - The table for which this model is the model.

setTableModel

public void setTableModel(javax.swing.table.TableModel tableModel)
Sets the table model to use.

Parameters:
tableModel - The table model to use.
See Also:
getTableModel()

getRowCount

public int getRowCount()

getColumnCount

public int getColumnCount()

getColumnName

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

getColumnClass

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

isCellEditable

public boolean isCellEditable(int row,
                              int column)
Specified by:
isCellEditable in interface javax.swing.table.TableModel
Overrides:
isCellEditable in class javax.swing.table.AbstractTableModel

getValueAt

public java.lang.Object getValueAt(int row,
                                   int column)

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int row,
                       int column)
Specified by:
setValueAt in interface javax.swing.table.TableModel
Overrides:
setValueAt in class javax.swing.table.AbstractTableModel