Package weka.gui
Class SortedTableModel
java.lang.Object
javax.swing.table.AbstractTableModel
weka.gui.SortedTableModel
- All Implemented Interfaces:
Serializable
,EventListener
,TableModelListener
,TableModel
- Direct Known Subclasses:
ArffSortedTableModel
Represents a TableModel with sorting functionality.
- Version:
- $Revision: 14293 $
- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Helper class for sorting the columns. -
Constructor Summary
ConstructorDescriptioninitializes with no modelSortedTableModel
(TableModel model) initializes with the given model -
Method Summary
Modifier and TypeMethodDescriptionvoid
addMouseListenerToHeader
(JTable table) Adds a mouselistener to the header: left-click on the header sorts in ascending manner, using shift-left-click in descending manner.int
getActualRow
(int visibleRow) Returns the actual underlying row the given visible one represents.Class<?>
getColumnClass
(int columnIndex) Returns the most specific superclass for all the cell values in the column.int
Returns the number of columns in the modelgetColumnName
(int columnIndex) Returns the name of the column at columnIndexgetModel()
returns the current model, can be nullint
Returns the number of rows in the model.getValueAt
(int rowIndex, int columnIndex) Returns the value for the cell at columnIndex and rowIndex.boolean
isCellEditable
(int rowIndex, int columnIndex) Returns true if the cell at rowIndex and columnIndex is editable.boolean
isSorted()
returns whether the table was sortedvoid
setModel
(TableModel value) sets the model to usevoid
setValueAt
(Object aValue, int rowIndex, int columnIndex) Sets the value in the cell at columnIndex and rowIndex to aValue.void
sort
(int columnIndex) sorts the table over the given column (ascending)void
sort
(int columnIndex, boolean ascending) sorts the table over the given column, either ascending or descendingvoid
This fine grain notification tells listeners the exact range of cells, rows, or columns that changed.Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
-
Constructor Details
-
SortedTableModel
public SortedTableModel()initializes with no model -
SortedTableModel
initializes with the given model- Parameters:
model
- the model to initialize the sorted model with
-
-
Method Details
-
setModel
sets the model to use- Parameters:
value
- the model to use
-
getModel
returns the current model, can be null- Returns:
- the current model
-
isSorted
public boolean isSorted()returns whether the table was sorted- Returns:
- true if the table was sorted
-
getActualRow
public int getActualRow(int visibleRow) Returns the actual underlying row the given visible one represents. Useful for retrieving "non-visual" data that is also stored in a TableModel.- Parameters:
visibleRow
- the displayed row to retrieve the original row for- Returns:
- the original row
-
getColumnClass
Returns the most specific superclass for all the cell values in the column.- Specified by:
getColumnClass
in interfaceTableModel
- Overrides:
getColumnClass
in classAbstractTableModel
- Parameters:
columnIndex
- the index of the column- Returns:
- the class of the specified column
-
getColumnCount
public int getColumnCount()Returns the number of columns in the model- Specified by:
getColumnCount
in interfaceTableModel
- Returns:
- the number of columns in the model
-
getColumnName
Returns the name of the column at columnIndex- Specified by:
getColumnName
in interfaceTableModel
- Overrides:
getColumnName
in classAbstractTableModel
- Parameters:
columnIndex
- the column to retrieve the name for- Returns:
- the name of the specified column
-
getRowCount
public int getRowCount()Returns the number of rows in the model.- Specified by:
getRowCount
in interfaceTableModel
- Returns:
- the number of rows in the model
-
getValueAt
Returns the value for the cell at columnIndex and rowIndex.- Specified by:
getValueAt
in interfaceTableModel
- Parameters:
rowIndex
- the rowcolumnIndex
- the column- Returns:
- the value of the sepcified cell
-
isCellEditable
public boolean isCellEditable(int rowIndex, int columnIndex) Returns true if the cell at rowIndex and columnIndex is editable.- Specified by:
isCellEditable
in interfaceTableModel
- Overrides:
isCellEditable
in classAbstractTableModel
- Parameters:
rowIndex
- the rowcolumnIndex
- the column- Returns:
- true if the cell is editable
-
setValueAt
Sets the value in the cell at columnIndex and rowIndex to aValue.- Specified by:
setValueAt
in interfaceTableModel
- Overrides:
setValueAt
in classAbstractTableModel
- Parameters:
aValue
- the new value of the cellrowIndex
- the rowcolumnIndex
- the column
-
sort
public void sort(int columnIndex) sorts the table over the given column (ascending)- Parameters:
columnIndex
- the column to sort over
-
sort
public void sort(int columnIndex, boolean ascending) sorts the table over the given column, either ascending or descending- Parameters:
columnIndex
- the column to sort overascending
- ascending if true, otherwise descending
-
tableChanged
This fine grain notification tells listeners the exact range of cells, rows, or columns that changed.- Specified by:
tableChanged
in interfaceTableModelListener
- Parameters:
e
- the event
-
addMouseListenerToHeader
Adds a mouselistener to the header: left-click on the header sorts in ascending manner, using shift-left-click in descending manner.- Parameters:
table
- the table to add the listener to
-