Package uk.ac.starlink.topcat
Class MetaColumnModel
java.lang.Object
javax.swing.table.DefaultTableColumnModel
uk.ac.starlink.topcat.MetaColumnModel
- All Implemented Interfaces:
PropertyChangeListener
,Serializable
,EventListener
,ListSelectionListener
,TableColumnModel
This ColumnModel provides enhanced functionality over a normal
ColumnModel, aimed at making it easy to select which columns
in a related TableModel are shown (appear in this ColumnModel)
or not shown (don't appear in this ColumnModel).
It does this by using an associated ListModel and ListSelectionModel.
- See Also:
-
Field Summary
Fields inherited from class javax.swing.table.DefaultTableColumnModel
changeEvent, columnMargin, columnSelectionAllowed, listenerList, selectionModel, tableColumns, totalColumnWidth
-
Constructor Summary
ConstructorsConstructorDescriptionMetaColumnModel
(TableColumnModel baseColumnModel, TableModel tableModel) Constructs a new MetaColumnModel from a base ColumnModel and a TableModel. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addColumn
(TableColumn tcol) When a column is added to this TableColumnModel, add it to the listModel and set it visible in the visibleModelReturns the ListModel representing all the columns in the original TableColumnModel.Returns the ListSelectionModel representing which columns in the original TableColumnModel are currently visible (are represented in this ColumnModel) and which are invisible (are not represented in this ColumnModel).makeCheckBoxMenu
(String name) Returns a menu component which can be used to control the visibility of columns in the model.void
Purges this column model of any column which contains nothing but blank entries.void
removeColumn
(int ipos) Sets a column invisible.void
removeColumn
(TableColumn tcol) When a column is removed from this TableColumnModel, set it invisible in the visibleModel.Methods inherited from class javax.swing.table.DefaultTableColumnModel
addColumnModelListener, createSelectionModel, fireColumnAdded, fireColumnMarginChanged, fireColumnMoved, fireColumnRemoved, fireColumnSelectionChanged, getColumn, getColumnCount, getColumnIndex, getColumnIndexAtX, getColumnMargin, getColumnModelListeners, getColumns, getColumnSelectionAllowed, getListeners, getSelectedColumnCount, getSelectedColumns, getSelectionModel, getTotalColumnWidth, moveColumn, propertyChange, recalcWidthCache, removeColumnModelListener, setColumnMargin, setColumnSelectionAllowed, setSelectionModel, valueChanged
-
Constructor Details
-
MetaColumnModel
Constructs a new MetaColumnModel from a base ColumnModel and a TableModel. The base ColumnModel is taken as the initial list of columns that can appear in this ColumnModel, but they can be deleted from and reinstated to this model without affecting the base. Subsequent changes to the base don't change this either.- Parameters:
baseColumnModel
- the base ColumnModeltableModel
- the TableModel which supplies the data for the columns this object describes; must refer to the same data as baseColumnModel
-
-
Method Details
-
getListModel
Returns the ListModel representing all the columns in the original TableColumnModel.- Returns:
- the list model
-
getVisibleModel
Returns the ListSelectionModel representing which columns in the original TableColumnModel are currently visible (are represented in this ColumnModel) and which are invisible (are not represented in this ColumnModel).- Returns:
- the selection model
-
addColumn
When a column is added to this TableColumnModel, add it to the listModel and set it visible in the visibleModel- Specified by:
addColumn
in interfaceTableColumnModel
- Overrides:
addColumn
in classDefaultTableColumnModel
-
removeColumn
When a column is removed from this TableColumnModel, set it invisible in the visibleModel.- Specified by:
removeColumn
in interfaceTableColumnModel
- Overrides:
removeColumn
in classDefaultTableColumnModel
-
removeColumn
public void removeColumn(int ipos) Sets a column invisible. The column is identified by its position in the list model, equal to its position in the visible model, equal to its position in the base column model from which this model was initialised.- Parameters:
ipos
- position of the column to remove
-
purgeEmptyColumns
public void purgeEmptyColumns()Purges this column model of any column which contains nothing but blank entries. Columns purged in this way can be reinstated later by modifying the visibleModel. Such a column will also become visible automatically if at a later date it acquires a non-blank entry. -
makeCheckBoxMenu
Returns a menu component which can be used to control the visibility of columns in the model.- Parameters:
name
- the name of the menu- Returns:
- a new JMenu with checkboxes for each column
-