Class MetaColumnModel

java.lang.Object
javax.swing.table.DefaultTableColumnModel
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:
  • Constructor Details

    • 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 Details

    • getListModel

      public ListModel<TableColumn> getListModel()
      Returns the ListModel representing all the columns in the original TableColumnModel.
      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