uk.ac.starlink.topcat
Class ColumnComboBoxModel

java.lang.Object
  extended by javax.swing.AbstractListModel
      extended by uk.ac.starlink.topcat.ColumnComboBoxModel
All Implemented Interfaces:
Serializable, EventListener, ComboBoxModel, TableColumnModelListener, ListModel
Direct Known Subclasses:
RestrictedColumnComboBoxModel

public class ColumnComboBoxModel
extends AbstractListModel
implements TableColumnModelListener, ComboBoxModel

Adaptor class which turns a TableColumnModel into a ComboBoxModel. This model is designed to reflect the contents of a column model rather than the other way around, so in general you wouldn't want to add a ListDataListener to this model, you'd add it to the underlying column model.

Selections in the column model are not reflected by selections in this model, but columns added/moved/removed are.

Author:
Mark Taylor (Starlink)
See Also:
Serialized Form

Field Summary
static uk.ac.starlink.table.gui.StarTableColumn NO_COLUMN
           
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
ColumnComboBoxModel(TableColumnModel colModel, boolean hasNone)
          Constructs a new ComboBoxModel based on a given column model, optionally with a null entry at the head of the list.
 
Method Summary
 void columnAdded(TableColumnModelEvent evt)
           
 void columnMarginChanged(ChangeEvent evt)
           
 void columnMoved(TableColumnModelEvent evt)
           
 void columnRemoved(TableColumnModelEvent evt)
           
 void columnSelectionChanged(ListSelectionEvent evt)
           
 TableColumnModel getColumnModel()
           
 Object getElementAt(int index)
           
 Object getSelectedItem()
          The returned object is guaranteed to be a TableColumn or null.
 int getSize()
           
 JComboBox makeComboBox()
          Returns a new JComboBox based on this model.
 void setHasNone(boolean hasNone)
          Sets whether there should be a null entry at the head of the list.
 void setSelectedItem(Object item)
          The selected item must be a TableColumn object.
 
Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.ListModel
addListDataListener, removeListDataListener
 

Field Detail

NO_COLUMN

public static final uk.ac.starlink.table.gui.StarTableColumn NO_COLUMN
Constructor Detail

ColumnComboBoxModel

public ColumnComboBoxModel(TableColumnModel colModel,
                           boolean hasNone)
Constructs a new ComboBoxModel based on a given column model, optionally with a null entry at the head of the list.

Parameters:
colModel - the column model
hasNone - true iff an additional null entry at the head of the list is required
Method Detail

setHasNone

public void setHasNone(boolean hasNone)
Sets whether there should be a null entry at the head of the list.

Parameters:
hasNone - true iff an additional null entry at the head of the list is required

getColumnModel

public TableColumnModel getColumnModel()

getElementAt

public Object getElementAt(int index)
Specified by:
getElementAt in interface ListModel

getSize

public int getSize()
Specified by:
getSize in interface ListModel

getSelectedItem

public Object getSelectedItem()
The returned object is guaranteed to be a TableColumn or null.

Specified by:
getSelectedItem in interface ComboBoxModel
Returns:
the selected TableColumn

setSelectedItem

public void setSelectedItem(Object item)
The selected item must be a TableColumn object.

Specified by:
setSelectedItem in interface ComboBoxModel
Parameters:
item - a table column to select
Throws:
ClassCastException - if item is not null or a TableColumn

makeComboBox

public JComboBox makeComboBox()
Returns a new JComboBox based on this model. This convenience method, as well as installing this model into a new JComboBox instance, also installs a suitable renderer for displaying the elements.

Returns:
new combo box displaying this model
See Also:
ColumnCellRenderer

columnAdded

public void columnAdded(TableColumnModelEvent evt)
Specified by:
columnAdded in interface TableColumnModelListener

columnRemoved

public void columnRemoved(TableColumnModelEvent evt)
Specified by:
columnRemoved in interface TableColumnModelListener

columnMoved

public void columnMoved(TableColumnModelEvent evt)
Specified by:
columnMoved in interface TableColumnModelListener

columnMarginChanged

public void columnMarginChanged(ChangeEvent evt)
Specified by:
columnMarginChanged in interface TableColumnModelListener

columnSelectionChanged

public void columnSelectionChanged(ListSelectionEvent evt)
Specified by:
columnSelectionChanged in interface TableColumnModelListener


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