Package weka.gui
Class SortedTableModel
- java.lang.Object
-
- javax.swing.table.AbstractTableModel
-
- weka.gui.SortedTableModel
-
- All Implemented Interfaces:
java.io.Serializable,java.util.EventListener,javax.swing.event.TableModelListener,javax.swing.table.TableModel
- Direct Known Subclasses:
ArffSortedTableModel
public class SortedTableModel extends javax.swing.table.AbstractTableModel implements javax.swing.event.TableModelListenerRepresents a TableModel with sorting functionality.- Version:
- $Revision: 7059 $
- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSortedTableModel.SortContainerHelper class for sorting the columns.
-
Constructor Summary
Constructors Constructor Description SortedTableModel()initializes with no modelSortedTableModel(javax.swing.table.TableModel model)initializes with the given model
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMouseListenerToHeader(javax.swing.JTable table)Adds a mouselistener to the header: left-click on the header sorts in ascending manner, using shift-left-click in descending manner.intgetActualRow(int visibleRow)Returns the actual underlying row the given visible one represents.java.lang.ClassgetColumnClass(int columnIndex)Returns the most specific superclass for all the cell values in the column.intgetColumnCount()Returns the number of columns in the modeljava.lang.StringgetColumnName(int columnIndex)Returns the name of the column at columnIndexjavax.swing.table.TableModelgetModel()returns the current model, can be nullintgetRowCount()Returns the number of rows in the model.java.lang.ObjectgetValueAt(int rowIndex, int columnIndex)Returns the value for the cell at columnIndex and rowIndex.booleanisCellEditable(int rowIndex, int columnIndex)Returns true if the cell at rowIndex and columnIndex is editable.booleanisSorted()returns whether the table was sortedvoidsetModel(javax.swing.table.TableModel value)sets the model to usevoidsetValueAt(java.lang.Object aValue, int rowIndex, int columnIndex)Sets the value in the cell at columnIndex and rowIndex to aValue.voidsort(int columnIndex)sorts the table over the given column (ascending)voidsort(int columnIndex, boolean ascending)sorts the table over the given column, either ascending or descendingvoidtableChanged(javax.swing.event.TableModelEvent e)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
-
-
-
-
Method Detail
-
setModel
public void setModel(javax.swing.table.TableModel value)
sets the model to use- Parameters:
value- the model to use
-
getModel
public javax.swing.table.TableModel 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
public java.lang.Class getColumnClass(int columnIndex)
Returns the most specific superclass for all the cell values in the column.- Specified by:
getColumnClassin interfacejavax.swing.table.TableModel- Overrides:
getColumnClassin classjavax.swing.table.AbstractTableModel- 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:
getColumnCountin interfacejavax.swing.table.TableModel- Returns:
- the number of columns in the model
-
getColumnName
public java.lang.String getColumnName(int columnIndex)
Returns the name of the column at columnIndex- Specified by:
getColumnNamein interfacejavax.swing.table.TableModel- Overrides:
getColumnNamein classjavax.swing.table.AbstractTableModel- 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:
getRowCountin interfacejavax.swing.table.TableModel- Returns:
- the number of rows in the model
-
getValueAt
public java.lang.Object getValueAt(int rowIndex, int columnIndex)Returns the value for the cell at columnIndex and rowIndex.- Specified by:
getValueAtin interfacejavax.swing.table.TableModel- 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:
isCellEditablein interfacejavax.swing.table.TableModel- Overrides:
isCellEditablein classjavax.swing.table.AbstractTableModel- Parameters:
rowIndex- the rowcolumnIndex- the column- Returns:
- true if the cell is editable
-
setValueAt
public void setValueAt(java.lang.Object aValue, int rowIndex, int columnIndex)Sets the value in the cell at columnIndex and rowIndex to aValue.- Specified by:
setValueAtin interfacejavax.swing.table.TableModel- Overrides:
setValueAtin classjavax.swing.table.AbstractTableModel- 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
public void tableChanged(javax.swing.event.TableModelEvent e)
This fine grain notification tells listeners the exact range of cells, rows, or columns that changed.- Specified by:
tableChangedin interfacejavax.swing.event.TableModelListener- Parameters:
e- the event
-
addMouseListenerToHeader
public void addMouseListenerToHeader(javax.swing.JTable table)
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
-
-