uk.ac.starlink.topcat
Class MetaColumnModel

java.lang.Object
  extended by javax.swing.table.DefaultTableColumnModel
      extended by uk.ac.starlink.topcat.MetaColumnModel
All Implemented Interfaces:
PropertyChangeListener, Serializable, EventListener, ListSelectionListener, TableColumnModel

public class MetaColumnModel
extends DefaultTableColumnModel

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:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.DefaultTableColumnModel
changeEvent, columnMargin, columnSelectionAllowed, listenerList, selectionModel, tableColumns, totalColumnWidth
 
Constructor Summary
MetaColumnModel(TableColumnModel baseColumnModel, TableModel tableModel)
          Constructs a new MetaColumnModel from a base ColumnModel and a TableModel.
 
Method Summary
 void addColumn(TableColumn tcol)
          When a column is added to this TableColumnModel, add it to the listModel and set it visible in the visibleModel
 ListModel getListModel()
          Returns the ListModel representing all the columns in the original TableColumnModel.
 ListSelectionModel 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).
 JMenu makeCheckBoxMenu(String name)
          Returns a menu component which can be used to control the visibility of columns in the model.
 void purgeEmptyColumns()
          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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MetaColumnModel

public MetaColumnModel(TableColumnModel baseColumnModel,
                       TableModel tableModel)
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 ColumnModel
tableModel - the TableModel which supplies the data for the columns this object describes; must refer to the same data as baseColumnModel
Method Detail

getListModel

public ListModel getListModel()
Returns the ListModel representing all the columns in the original TableColumnModel. Every entry in this ListModel will be a TableColumn.

Returns:
the list model

getVisibleModel

public ListSelectionModel 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

public void addColumn(TableColumn tcol)
When a column is added to this TableColumnModel, add it to the listModel and set it visible in the visibleModel

Specified by:
addColumn in interface TableColumnModel
Overrides:
addColumn in class DefaultTableColumnModel

removeColumn

public void removeColumn(TableColumn tcol)
When a column is removed from this TableColumnModel, set it invisible in the visibleModel.

Specified by:
removeColumn in interface TableColumnModel
Overrides:
removeColumn in class DefaultTableColumnModel

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

public JMenu makeCheckBoxMenu(String name)
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


Copyright © 2003-2018 CCLRC: Council for the Central Laboratory of the Research Councils. All Rights Reserved.