Package uk.ac.starlink.topcat
Class OptionsListModel<T>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<T>
-
- uk.ac.starlink.topcat.OptionsListModel<T>
-
- All Implemented Interfaces:
java.lang.Iterable<T>
,java.util.Collection<T>
,java.util.List<T>
,javax.swing.ListModel
public class OptionsListModel<T> extends java.util.AbstractList<T> implements javax.swing.ListModel
Provides storage for a list of options with listeners. This class implements bothList
andListModel
(which ListModel really ought to do itself), and also provides methods to create some useful models like JComboBoxModel based on the same data.- Author:
- Mark Taylor (Starlink)
-
-
Constructor Summary
Constructors Constructor Description OptionsListModel()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(T obj)
void
addListDataListener(javax.swing.event.ListDataListener l)
void
fireContentsChanged(int i0, int i1)
void
fireIntervalAdded(int i0, int i1)
void
fireIntervalRemoved(int i0, int i1)
T
get(int index)
T
getElementAt(int index)
int
getSize()
int
idToIndex(int id)
Returns the index at which an option with the given ID currently resides.int
indexToId(int index)
Returns the unique ID value for the option currently at a given index in this list.CheckBoxMenu
makeCheckBoxMenu(java.lang.String menuName)
javax.swing.JComboBox
makeComboBox()
Makes a new JComboBox from this model.javax.swing.ComboBoxModel
makeComboBoxModel()
Constructs a new ComboBoxModel backed by this list.javax.swing.JMenu
makeJMenu(java.lang.String menuName, javax.swing.Action menuAction)
Constructs a new JMenu backed by this list.T
remove(int irow)
void
removeListDataListener(javax.swing.event.ListDataListener l)
T
set(int irow, T obj)
int
size()
-
Methods inherited from class java.util.AbstractList
add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
-
-
-
-
Method Detail
-
get
public T get(int index)
-
getElementAt
public T getElementAt(int index)
- Specified by:
getElementAt
in interfacejavax.swing.ListModel<T>
-
size
public int size()
-
getSize
public int getSize()
- Specified by:
getSize
in interfacejavax.swing.ListModel<T>
-
add
public boolean add(T obj)
-
remove
public T remove(int irow)
-
indexToId
public int indexToId(int index)
Returns the unique ID value for the option currently at a given index in this list. The ID value for a given option is a small integer which does not change. ID values are not re-used within a given instance of this class.- Parameters:
index
- current index for option- Returns:
- identifier for option
-
idToIndex
public int idToIndex(int id)
Returns the index at which an option with the given ID currently resides. If no option with the given ID is present, -1 is returned.- Parameters:
id
- unique identifier- Returns:
- index of option with
id
, or -1 - See Also:
indexToId(int)
-
makeComboBoxModel
public javax.swing.ComboBoxModel makeComboBoxModel()
Constructs a new ComboBoxModel backed by this list.- See Also:
makeComboBox()
-
makeComboBox
public javax.swing.JComboBox makeComboBox()
Makes a new JComboBox from this model. This adds to the functionality ofmakeComboBoxModel()
by ensuring that the box is revalidated when new items are added to the model; otherwise the box can end up too small. It also ensures that the box is rendered by using the name of the RowSubset is written.- Returns:
- a combo box from which items in this model can be selected
-
makeJMenu
public javax.swing.JMenu makeJMenu(java.lang.String menuName, javax.swing.Action menuAction)
Constructs a new JMenu backed by this list. One entry is added to the menu for each option in this list; the menu item will be labelled by the list item (using its toString method) and will activate the supplied menuAction action if selected. In this case the action's actionPerformed method will be called with an ActionEvent that has an id corresponding to its position in this list and a command string which is the same as its toString method.- Parameters:
menuName
- the name of the menumenuAction
- the action to activate
-
makeCheckBoxMenu
public CheckBoxMenu makeCheckBoxMenu(java.lang.String menuName)
-
addListDataListener
public void addListDataListener(javax.swing.event.ListDataListener l)
- Specified by:
addListDataListener
in interfacejavax.swing.ListModel<T>
-
removeListDataListener
public void removeListDataListener(javax.swing.event.ListDataListener l)
- Specified by:
removeListDataListener
in interfacejavax.swing.ListModel<T>
-
fireContentsChanged
public void fireContentsChanged(int i0, int i1)
-
fireIntervalAdded
public void fireIntervalAdded(int i0, int i1)
-
fireIntervalRemoved
public void fireIntervalRemoved(int i0, int i1)
-
-