Package uk.ac.starlink.util.gui
Class ArrayTableModel<R>
- java.lang.Object
-
- javax.swing.table.AbstractTableModel
-
- uk.ac.starlink.util.gui.ArrayTableModel<R>
-
- All Implemented Interfaces:
java.io.Serializable
,javax.swing.table.TableModel
public class ArrayTableModel<R> extends javax.swing.table.AbstractTableModel
TableModel which contains its data as an array of objects, one per row. TheArrayTableSorter
class can be used in conjunction with this class to provide tables which can be sorted by clicking on column headers. The model works by having an array of column objects which know how to interrogate the array of data objects in such a way as to return cell values. The implementation of the column and data item objects is therefore interlinked.- Since:
- 14 Oct 2009
- Author:
- Mark Taylor
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ArrayTableModel(R[] items)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Class<?>
getColumnClass(int icol)
int
getColumnCount()
java.lang.String
getColumnName(int icol)
java.util.List<ArrayTableColumn<R,?>>
getColumns()
Returns the column specifiers used by this table.R[]
getItems()
Returns the row data items used by this model.int
getRowCount()
java.lang.Object
getValueAt(int irow, int icol)
void
setColumns(java.util.List<? extends ArrayTableColumn<? extends R,?>> columns)
Sets the column specifiers to be used by this table.void
setItems(R[] items)
Sets the row data items to be used by this table.void
sortByColumn(int icol, boolean descending)
Sorts the rows in this table according to the ordering of the data in one of the columns.-
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt
-
-
-
-
Constructor Detail
-
ArrayTableModel
public ArrayTableModel(R[] items)
Constructor.- Parameters:
items
- initial list of items
-
-
Method Detail
-
setColumns
public void setColumns(java.util.List<? extends ArrayTableColumn<? extends R,?>> columns)
Sets the column specifiers to be used by this table.- Parameters:
columns
- column specifiers
-
getColumns
public java.util.List<ArrayTableColumn<R,?>> getColumns()
Returns the column specifiers used by this table.- Returns:
- column specifiers
-
setItems
public void setItems(R[] items)
Sets the row data items to be used by this table.- Parameters:
items
- row data items, one per row
-
getItems
public R[] getItems()
Returns the row data items used by this model.- Returns:
- row data items, one per row
-
sortByColumn
public void sortByColumn(int icol, boolean descending)
Sorts the rows in this table according to the ordering of the data in one of the columns. The ordering may not be maintained if the data changes.- Parameters:
icol
- index of column to sort bydescending
- true to sort down, false to sort up
-
getColumnCount
public int getColumnCount()
-
getRowCount
public int getRowCount()
-
getValueAt
public java.lang.Object getValueAt(int irow, int icol)
-
getColumnName
public java.lang.String getColumnName(int icol)
- Specified by:
getColumnName
in interfacejavax.swing.table.TableModel
- Overrides:
getColumnName
in classjavax.swing.table.AbstractTableModel
-
getColumnClass
public java.lang.Class<?> getColumnClass(int icol)
- Specified by:
getColumnClass
in interfacejavax.swing.table.TableModel
- Overrides:
getColumnClass
in classjavax.swing.table.AbstractTableModel
-
-