Class OptionsListModel<T>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<T>
uk.ac.starlink.topcat.OptionsListModel<T>
All Implemented Interfaces:
Iterable<T>, Collection<T>, List<T>, ListModel<T>

public class OptionsListModel<T> extends AbstractList<T> implements 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)
  • Constructor Details

    • OptionsListModel

      public OptionsListModel()
  • Method Details

    • get

      public T get(int index)
      Specified by:
      get in interface List<T>
      Specified by:
      get in class AbstractList<T>
    • getElementAt

      public T getElementAt(int index)
      Specified by:
      getElementAt in interface ListModel<T>
    • size

      public int size()
      Specified by:
      size in interface Collection<T>
      Specified by:
      size in interface List<T>
      Specified by:
      size in class AbstractCollection<T>
    • getSize

      public int getSize()
      Specified by:
      getSize in interface ListModel<T>
    • add

      public boolean add(T obj)
      Specified by:
      add in interface Collection<T>
      Specified by:
      add in interface List<T>
      Overrides:
      add in class AbstractList<T>
    • set

      public T set(int irow, T obj)
      Specified by:
      set in interface List<T>
      Overrides:
      set in class AbstractList<T>
    • remove

      public T remove(int irow)
      Specified by:
      remove in interface List<T>
      Overrides:
      remove in class AbstractList<T>
    • 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

      public ComboBoxModel<T> makeComboBoxModel()
      Constructs a new ComboBoxModel backed by this list.
      See Also:
    • makeComboBox

      public JComboBox<T> makeComboBox()
      Makes a new JComboBox from this model. This adds to the functionality of makeComboBoxModel() 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

      public JMenu makeJMenu(String menuName, 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 menu
      menuAction - the action to activate
    • makeCheckBoxMenu

      public CheckBoxMenu makeCheckBoxMenu(String menuName)
    • addListDataListener

      public void addListDataListener(ListDataListener l)
      Specified by:
      addListDataListener in interface ListModel<T>
    • removeListDataListener

      public void removeListDataListener(ListDataListener l)
      Specified by:
      removeListDataListener in interface 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)