ui/src/main/java/ucar/nc2/ui/widget/BAMutil.java
public static JMenuItem addActionToMenu( JMenu menu, Action act, int menuPos) {
    JMenuItem mi = makeMenuItemFromAction( act);
    if (menuPos >= 0)
      menu.add( mi, menuPos);
    else
      menu.add( mi);

    Boolean tog = (Boolean) act.getValue( BAMutil.TOGGLE);
    boolean is_toggle = (tog == null ) ? false : tog.booleanValue();

    // set state for toggle buttons
    if (is_toggle) {
      if (debugToggle)
        System.out.println("addActionToMenu: "+ act.getValue( Action.SHORT_DESCRIPTION)+" "+act.getValue( BAMutil.STATE));
      Boolean state = (Boolean) act.getValue( BAMutil.STATE);
      if (state == null) state = Boolean.FALSE;
      act.putValue(BAMutil.STATE, state);
      mi.setSelected(state.booleanValue());
    }

      // add event listeners
    Action myAct = is_toggle ? new ToggleAction( act) : act;
    mi.addActionListener( myAct);
    act.addPropertyChangeListener(new myActionChangedListener(mi));

    return mi;
  }
public static JMenuItem addActionToMenu( JMenu menu, Action act, int menuPos) {
    JMenuItem mi = makeMenuItemFromAction( act);
    if (menuPos >= 0)
      menu.add( mi, menuPos);
    else
      menu.add( mi);

    Boolean tog = (Boolean) act.getValue( BAMutil.TOGGLE);
    boolean is_toggle = (tog == null ) ? false : tog.booleanValue();

    // set state for toggle buttons
    if (is_toggle) {
      if (debugToggle)
        System.out.println("addActionToMenu: "+ act.getValue( Action.SHORT_DESCRIPTION)+" "+act.getValue( BAMutil.STATE));
      Boolean state = (Boolean) act.getValue( BAMutil.STATE);
      if (state == null) state = Boolean.FALSE;
      act.putValue(BAMutil.STATE, state);
      mi.setSelected(state.booleanValue());
    }

      // add event listeners
    Action myAct = is_toggle ? new ToggleAction( act) : act;
    mi.addActionListener( myAct);
    act.addPropertyChangeListener(new myActionChangedListener(mi));

    return mi;
  }
creates a MenuItem using the given Action and adds it to the given Menu.
Uses Properties that have been set on the Action (see setActionProperties()). All
are optional except for Action.SHORT_DESCRIPTION:  <pre>
Action.SHORT_DESCRIPTION   String     MenuItem text (required)
Action.SMALL_ICON          Icon       the Icon to Use
BAMutil.SELECTED_ICON      Icon       the Icon when selected (optional)
BAMutil.TOGGLE             Boolean    true if its a toggle
BAMutil.MNEMONIC           Integer    menu item shortcut
BAMutil.ACCEL              Integer    menu item global keyboard accelerator
</pre><br>
The Action is triggered when the MenuItem is selected. Enabling and disabling the Action
does the same for the MenuItem. For toggles, state is maintained in the Action,
and MenuItem state changes when the Action state changes. <br><br>
The point of all this is that once you set it up, you work exclusively with the action object,
and all changes are automatically reflected in the UI.

@param menu  add to this menu
@param act the Action to make it out of
@param menuPos if >= 0, add at this position, otherwise append
@return the MenuItem created