Package uk.ac.starlink.topcat
Class MenuSelector<T>
java.lang.Object
uk.ac.starlink.topcat.MenuSelector<T>
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
ConstructorsConstructorDescriptionMenuSelector
(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 TypeMethodDescriptionvoid
Adds a listener that will be notified whenever the selection changes.Returns the menu item that presents this selector.Returns the currently selected option.void
Removes a previously-added listener.void
setSelectedItem
(T option) Sets the currently selected option.
-
Constructor Details
-
MenuSelector
Constructs a menu selector with an explicit default.- Parameters:
name
- menu nameoptions
- list of options that can be selecteddflt
- initial default value; should be one ofoptions
-
MenuSelector
Constructs a menu selector with an implicit default, the first element of the supplied options array.- Parameters:
name
- menu nameoptions
- list of options that can be selected
-
-
Method Details
-
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
Returns the currently selected option.- Returns:
- selected option
-
setSelectedItem
Sets the currently selected option.- Parameters:
option
- option to select- Throws:
IllegalArgumentException
- ifoption
is not one of the options
-
addActionListener
Adds a listener that will be notified whenever the selection changes.- Parameters:
l
- listener to add
-
removeActionListener
Removes a previously-added listener.- Parameters:
l
- listener to remove
-