Search in sources :

Example 1 with TurnoutOperationFrame

use of jmri.jmrit.turnoutoperations.TurnoutOperationFrame in project JMRI by JMRI.

the class TurnoutTableAction method setMenuBar.

/**
     * Insert a table specific Operations menu. Account for the Window and Help
     * menus, which are already added to the menu bar as part of the creation of
     * the JFrame, by adding the Operations menu 2 places earlier unless the
     * table is part of the ListedTableFrame, that adds the Help menu later on.
     *
     * @param f the JFrame of this table
     */
@Override
public void setMenuBar(BeanTableFrame f) {
    // needed for anonymous ActionListener class
    final jmri.util.JmriJFrame finalF = f;
    JMenuBar menuBar = f.getJMenuBar();
    // check for menu
    boolean menuAbsent = true;
    for (int m = 0; m < menuBar.getMenuCount(); ++m) {
        String name = menuBar.getMenu(m).getAccessibleContext().getAccessibleName();
        if (name.equals(Bundle.getMessage("TurnoutAutomationMenu"))) {
            // using first menu for check, should be identical to next JMenu Bundle
            menuAbsent = false;
            break;
        }
    }
    if (menuAbsent) {
        // create it
        // count the number of menus to insert the TableMenu before 'Window' and 'Help'
        int pos = menuBar.getMenuCount() - 1;
        int offset = 1;
        log.debug("setMenuBar number of menu items = " + pos);
        for (int i = 0; i <= pos; i++) {
            if (menuBar.getComponent(i) instanceof JMenu) {
                if (((JMenu) menuBar.getComponent(i)).getText().equals(Bundle.getMessage("MenuHelp"))) {
                    // correct for use as part of ListedTableAction where the Help Menu is not yet present
                    offset = -1;
                }
            }
        }
        JMenu opsMenu = new JMenu(Bundle.getMessage("TurnoutAutomationMenu"));
        JMenuItem item = new JMenuItem(Bundle.getMessage("TurnoutAutomationMenuItemEdit"));
        opsMenu.add(item);
        item.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                new TurnoutOperationFrame(finalF);
            }
        });
        menuBar.add(opsMenu, pos + offset);
        JMenu speedMenu = new JMenu(Bundle.getMessage("SpeedsMenu"));
        item = new JMenuItem(Bundle.getMessage("SpeedsMenuItemDefaults"));
        speedMenu.add(item);
        item.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                setDefaultSpeeds(finalF);
            }
        });
        // add this menu to the right of the previous
        menuBar.add(speedMenu, pos + offset + 1);
    }
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) TurnoutOperationFrame(jmri.jmrit.turnoutoperations.TurnoutOperationFrame) JmriJFrame(jmri.util.JmriJFrame) JMenuItem(javax.swing.JMenuItem) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Aggregations

ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 JMenu (javax.swing.JMenu)1 JMenuBar (javax.swing.JMenuBar)1 JMenuItem (javax.swing.JMenuItem)1 TurnoutOperationFrame (jmri.jmrit.turnoutoperations.TurnoutOperationFrame)1 JmriJFrame (jmri.util.JmriJFrame)1