Class MenuSelector<T>


  • public class MenuSelector<T>
    extends java.lang.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​(java.lang.String name, T[] options)
      Constructs a menu selector with an implicit default, the first element of the supplied options array.
      MenuSelector​(java.lang.String name, T[] options, T dflt)
      Constructs a menu selector with an explicit default.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addActionListener​(java.awt.event.ActionListener l)
      Adds a listener that will be notified whenever the selection changes.
      javax.swing.JMenuItem getMenuItem()
      Returns the menu item that presents this selector.
      T getSelectedItem()
      Returns the currently selected option.
      void removeActionListener​(java.awt.event.ActionListener l)
      Removes a previously-added listener.
      void setSelectedItem​(T option)
      Sets the currently selected option.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MenuSelector

        public MenuSelector​(java.lang.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​(java.lang.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 Detail

      • getMenuItem

        public javax.swing.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:
        java.lang.IllegalArgumentException - if option is not one of the options
      • addActionListener

        public void addActionListener​(java.awt.event.ActionListener l)
        Adds a listener that will be notified whenever the selection changes.
        Parameters:
        l - listener to add
      • removeActionListener

        public void removeActionListener​(java.awt.event.ActionListener l)
        Removes a previously-added listener.
        Parameters:
        l - listener to remove