Package uk.ac.starlink.topcat
Class OptionsListModel<T>
java.lang.Object
java.util.AbstractCollection<T>
java.util.AbstractList<T>
uk.ac.starlink.topcat.OptionsListModel<T>
- All Implemented Interfaces:
Iterable<T>,Collection<T>,List<T>,SequencedCollection<T>,ListModel<T>
Provides storage for a list of options with listeners.
This class implements both
List and
ListModel (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)
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidvoidfireContentsChanged(int i0, int i1) voidfireIntervalAdded(int i0, int i1) voidfireIntervalRemoved(int i0, int i1) get(int index) getElementAt(int index) intgetSize()intidToIndex(int id) Returns the index at which an option with the given ID currently resides.intindexToId(int index) Returns the unique ID value for the option currently at a given index in this list.makeCheckBoxMenu(String menuName) Makes a new JComboBox from this model.Constructs a new ComboBoxModel backed by this list.Constructs a new JMenu backed by this list.remove(int irow) voidintsize()Methods inherited from class java.util.AbstractList
add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subListMethods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addAll, addFirst, addLast, contains, containsAll, getFirst, getLast, isEmpty, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort, spliterator, toArray, toArray
-
Constructor Details
-
OptionsListModel
public OptionsListModel()
-
-
Method Details
-
get
-
getElementAt
- Specified by:
getElementAtin interfaceListModel<T>
-
size
public int size()- Specified by:
sizein interfaceCollection<T>- Specified by:
sizein interfaceList<T>- Specified by:
sizein classAbstractCollection<T>
-
getSize
public int getSize() -
add
- Specified by:
addin interfaceCollection<T>- Specified by:
addin interfaceList<T>- Overrides:
addin classAbstractList<T>
-
set
-
remove
-
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:
-
makeComboBoxModel
Constructs a new ComboBoxModel backed by this list.- See Also:
-
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.Note however that no renderer is installed, so custom rendering must be as required handled by client code.
- Returns:
- a combo box from which items in this model can be selected
-
makeJMenu
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 suppliedmenuActionaction if selected. In this case the action'sactionPerformedmethod will be called with anActionEventthat has anidcorresponding to its position in this list and acommandstring which is the same as its toString method.- Parameters:
menuName- the name of the menumenuAction- the action to activate
-
makeCheckBoxMenu
-
addListDataListener
- Specified by:
addListDataListenerin interfaceListModel<T>
-
removeListDataListener
- Specified by:
removeListDataListenerin interfaceListModel<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)
-