# Class MenuSelector<T>

java.lang.Object
uk.ac.starlink.topcat.MenuSelector<T>

public class MenuSelector<T> extends Object
Provides a menu item with a submenu that can select one of a given set of options. At present, the list of options is fixed.

Since:
  19 Sep 2017
Author:
  Mark Taylor

## Constructor Summary

Constructors
Constructor
Description
`MenuSelector(String name, T[] options)`
Constructs a menu selector with an implicit default, the first element of the supplied options array.
`MenuSelector(String name, T[] options, T dflt)`
Constructs a menu selector with an explicit default.

## Method Summary

Modifier and Type
Method
Description
`void`
`addActionListener(ActionListener l)`
Adds a listener that will be notified whenever the selection changes.
`JMenuItem`
`getMenuItem()`
Returns the menu item that presents this selector.
`T`
`getSelectedItem()`
Returns the currently selected option.
`void`
`removeActionListener(ActionListener l)`
Removes a previously-added listener.
`void`
`setSelectedItem(T option)`
Sets the currently selected option.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### MenuSelector

public MenuSelector(String name, T[] options, T dflt)
Constructs a menu selector with an explicit default.

Parameters:
  `name` - menu name
  `options` - list of options that can be selected
  `dflt` - initial default value; should be one of `options`

### MenuSelector

public MenuSelector(String name, T[] options)
Constructs a menu selector with an implicit default, the first element of the supplied options array.

Parameters:
  `name` - menu name
  `options` - list of options that can be selected

## Method Details

### getMenuItem

public JMenuItem getMenuItem()
Returns the menu item that presents this selector. It has a submenu hanging off it that provides the actual selection options (currently JRadioButtonMenuItems).

Returns:
  menu item

### getSelectedItem

public T getSelectedItem()
Returns the currently selected option.

Returns:
  selected option

### setSelectedItem

public void setSelectedItem(T option)
Sets the currently selected option.

Parameters:
  `option` - option to select
Throws:
  `IllegalArgumentException` - if `option` is not one of the options

### addActionListener

public void addActionListener(ActionListener l)
Adds a listener that will be notified whenever the selection changes.

Parameters:
  `l` - listener to add

### removeActionListener

public void removeActionListener(ActionListener l)
Removes a previously-added listener.

Parameters:
  `l` - listener to remove