Package uk.ac.starlink.topcat
Class ViewerTableModel
java.lang.Object
javax.swing.table.AbstractTableModel
uk.ac.starlink.topcat.ViewerTableModel
- All Implemented Interfaces:
Serializable
,TableModel
A TableModel which is based on a StarTable but
also provides methods for ordering rows and selecting which rows will
be visible. This class is used as the TableModel for the
TableViewer widget.
- Author:
- Mark Taylor (Starlink)
- See Also:
-
Field Summary
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
-
Constructor Summary
ConstructorsConstructorDescriptionViewerTableModel
(PlasticStarTable startable) Constructs a ViewerTableModel from a StarTable. -
Method Summary
Modifier and TypeMethodDescriptionlong
getBaseRow
(int irow) Returns the index of the data model row corresponding to a given row in this view model.int
int
Returns an iterator over the base table row indices represented by this view.int[]
Returns the mapping from row index visible in this model to row index in the base table.uk.ac.starlink.table.StarTable
getRowPermutedView
(uk.ac.starlink.table.StarTable table) Returns a view of a given table whose rows are permuted in the same way as the current view is permuted with respect to the basic table.uk.ac.starlink.table.StarTable
Returns a new StarTable whose data corresponds to the current state of this ViewerTableModel.Returns the RowSubset currently used by the viewer model.getValueAt
(int irow, int icol) int
getViewRow
(long lrow) Returns the index at which a given table row appears in this view model.boolean
isCellEditable
(int irow, int icol) void
setOrder
(int[] order) Configures this view to view the rows of the base model in a given order.void
setRowMap
(int[] rowMap) Sets the mapping from row index visible in this model to row index in the base table.void
Configures this view to view only a subset of the rows of the base model.void
setValueAt
(Object val, int irow, int icol) Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getColumnName, getListeners, getTableModelListeners, removeTableModelListener
-
Constructor Details
-
ViewerTableModel
Constructs a ViewerTableModel from a StarTable. The supplied StarTable must provide random access.- Parameters:
startable
- the StarTable object- Throws:
IllegalArgumentException
- if startable.isRandom returns false
-
-
Method Details
-
setOrder
public void setOrder(int[] order) Configures this view to view the rows of the base model in a given order. The supplied order array should be a 1:1 mapping of rows in the base table to the order in which they will be viewed. This method triggers a suitable TableModelEvent to listeners.- Parameters:
order
- mapping of rows in the table view, or null to indicate natural ordering
-
setSubset
Configures this view to view only a subset of the rows of the base model. This method triggers a suitable TableModelEvent to listeners.- Parameters:
rset
- RowSubset object indicating inclusion in subset of rows to be viewed
-
getSubset
Returns the RowSubset currently used by the viewer model.- Returns:
- the row subset
-
getRowMap
public int[] getRowMap()Returns the mapping from row index visible in this model to row index in the base table.- Returns:
- row mapping; may be null to indicate a unit map
-
getRowIndexIterator
Returns an iterator over the base table row indices represented by this view. This is an iteration over the values in therowMap
if it is non-null, or an iterator over all the rows if it is null. The number of elements iterated over is given bygetRowCount()
.- Returns:
- row index iterator
-
setRowMap
public void setRowMap(int[] rowMap) Sets the mapping from row index visible in this model to row index in the base table.- Parameters:
rowMap
- row mapping; may be null to indicate a unit map
-
getColumnCount
public int getColumnCount() -
getRowCount
public int getRowCount() -
getBaseRow
public long getBaseRow(int irow) Returns the index of the data model row corresponding to a given row in this view model.- Parameters:
irow
- index of the row in this view model- Returns:
- index of the row in the base table
-
getViewRow
public int getViewRow(long lrow) Returns the index at which a given table row appears in this view model. If the given table row doesn't appear in the view model (it's not included in the current subset) then -1 is returned.- Parameters:
lrow
- index of the row in the base table- Returns:
- index of the row in this view model, or -1
-
getValueAt
-
isCellEditable
public boolean isCellEditable(int irow, int icol) - Specified by:
isCellEditable
in interfaceTableModel
- Overrides:
isCellEditable
in classAbstractTableModel
-
setValueAt
- Specified by:
setValueAt
in interfaceTableModel
- Overrides:
setValueAt
in classAbstractTableModel
-
getSnapshot
public uk.ac.starlink.table.StarTable getSnapshot()Returns a new StarTable whose data corresponds to the current state of this ViewerTableModel. It has the same row ordering and subset, but subsequent changes to this model will not affect the data viewed from the resulting object.- Returns:
- StarTable view of a snapshot of the data available from this model
-
getRowPermutedView
public uk.ac.starlink.table.StarTable getRowPermutedView(uk.ac.starlink.table.StarTable table) Returns a view of a given table whose rows are permuted in the same way as the current view is permuted with respect to the basic table. The submitted table may be returned if no permutation is in force.- Parameters:
table
- table to be permuted- Returns:
- a table which is a possibly permuted view of table
-