Search in sources :

Example 11 with JRadioButtonMenuItem

use of javax.swing.JRadioButtonMenuItem in project JMRI by JMRI.

the class ControlPanelEditor method makeSelectLevelMenu.

private JMenu makeSelectLevelMenu() {
    JMenu menu = new JMenu(Bundle.getMessage("SelectLevel"));
    ButtonGroup levelGroup = new ButtonGroup();
    JRadioButtonMenuItem button = null;
    for (int i = 0; i < 11; i++) {
        button = new JRadioButtonMenuItem(Bundle.getMessage("selectLevel", "" + i));
        levelGroup.add(button);
        menu.add(button);
        button.addActionListener(new ActionListener() {

            int j;

            ActionListener init(int k) {
                j = k;
                return this;
            }

            @Override
            public void actionPerformed(ActionEvent event) {
                selectLevel(j);
            }
        }.init(i));
    }
    return menu;
}
Also used : ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) ActionEvent(java.awt.event.ActionEvent) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JMenu(javax.swing.JMenu) Point(java.awt.Point)

Example 12 with JRadioButtonMenuItem

use of javax.swing.JRadioButtonMenuItem in project JMRI by JMRI.

the class LogixTableAction method setMenuBar.

/**
     * Insert 2 table specific menus.
     * <p>
     * Accounts 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 new menus 2 places earlier
     * unless the table is part of the ListedTableFrame, which adds the Help menu later on.
     * @param f the JFrame of this table
     */
@Override
public void setMenuBar(BeanTableFrame f) {
    loadSelectionMode();
    JMenu menu = new JMenu(Bundle.getMessage("MenuOptions"));
    menu.setMnemonic(KeyEvent.VK_O);
    javax.swing.JMenuBar menuBar = f.getJMenuBar();
    // count the number of menus to insert the TableMenus 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;
            }
        }
    }
    ButtonGroup enableButtonGroup = new ButtonGroup();
    JRadioButtonMenuItem r = new JRadioButtonMenuItem(rbx.getString("EnableAll"));
    r.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            enableAll(true);
        }
    });
    enableButtonGroup.add(r);
    r.setSelected(true);
    menu.add(r);
    r = new JRadioButtonMenuItem(rbx.getString("DisableAll"));
    r.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            enableAll(false);
        }
    });
    enableButtonGroup.add(r);
    menu.add(r);
    menu.addSeparator();
    ButtonGroup modeButtonGroup = new ButtonGroup();
    r = new JRadioButtonMenuItem(rbx.getString("UseMultiPick"));
    r.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            setSelectionMode(SelectionMode.USEMULTI);
        }
    });
    modeButtonGroup.add(r);
    menu.add(r);
    r.setSelected(_selectionMode == SelectionMode.USEMULTI);
    r = new JRadioButtonMenuItem(rbx.getString("UseSinglePick"));
    r.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            setSelectionMode(SelectionMode.USESINGLE);
        }
    });
    modeButtonGroup.add(r);
    menu.add(r);
    r.setSelected(_selectionMode == SelectionMode.USESINGLE);
    r = new JRadioButtonMenuItem(rbx.getString("UseComboNameBoxes"));
    r.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            setSelectionMode(SelectionMode.USECOMBO);
        }
    });
    modeButtonGroup.add(r);
    menu.add(r);
    r.setSelected(_selectionMode == SelectionMode.USECOMBO);
    menuBar.add(menu, pos + offset);
    menu = new JMenu(Bundle.getMessage("MenuTools"));
    menu.setMnemonic(KeyEvent.VK_T);
    JMenuItem item = new JMenuItem(rbx.getString("OpenPickListTables"));
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            OpenPickListTable();
        }
    });
    menu.add(item);
    item = new JMenuItem(rbx.getString("FindOrphans"));
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            findOrphansPressed(e);
        }
    });
    menu.add(item);
    item = new JMenuItem(rbx.getString("EmptyConditionals"));
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            findEmptyPressed(e);
        }
    });
    menu.add(item);
    item = new JMenuItem(rbx.getString("CrossReference"));
    item.addActionListener(new ActionListener() {

        BeanTableFrame parent;

        @Override
        public void actionPerformed(ActionEvent e) {
            new RefDialog(parent);
        }

        ActionListener init(BeanTableFrame f) {
            parent = f;
            return this;
        }
    }.init(f));
    menu.add(item);
    item = new JMenuItem(rbx.getString("DisplayWhereUsed"));
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            makeWhereUsedWindow();
        }
    });
    menu.add(item);
    // add this menu to the right of the previous
    menuBar.add(menu, pos + offset + 1);
}
Also used : ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) ItemListener(java.awt.event.ItemListener) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Example 13 with JRadioButtonMenuItem

use of javax.swing.JRadioButtonMenuItem in project JMRI by JMRI.

the class ControlPanelEditor method makeSelectTypeButton.

private JRadioButtonMenuItem makeSelectTypeButton(String label, String className) {
    JRadioButtonMenuItem button = new JRadioButtonMenuItem(Bundle.getMessage(label));
    button.addActionListener(new ActionListener() {

        String cName;

        ActionListener init(String name) {
            cName = name;
            return this;
        }

        @Override
        public void actionPerformed(ActionEvent event) {
            selectType(cName);
        }
    }.init(className));
    return button;
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem)

Example 14 with JRadioButtonMenuItem

use of javax.swing.JRadioButtonMenuItem in project JMRI by JMRI.

the class PanelEditor method addColorMenuEntry.

protected void addColorMenuEntry(JMenu menu, ButtonGroup colorButtonGroup, final String name, Color color) {
    ActionListener a = new ActionListener() {

        //final String desiredName = name;
        Color desiredColor;

        @Override
        public void actionPerformed(ActionEvent e) {
            if (desiredColor != null) {
                setBackgroundColor(desiredColor);
            } else {
                clearBackgroundColor();
            }
        }

        ActionListener init(Color c) {
            desiredColor = c;
            return this;
        }
    }.init(color);
    JRadioButtonMenuItem r = new JRadioButtonMenuItem(name);
    r.addActionListener(a);
    if (color == null) {
        color = defaultBackgroundColor;
    }
    setColorButton(getBackgroundColor(), color, r);
    colorButtonGroup.add(r);
    menu.add(r);
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) Color(java.awt.Color) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem)

Example 15 with JRadioButtonMenuItem

use of javax.swing.JRadioButtonMenuItem in project JMRI by JMRI.

the class AnalogClock2Display method addRateMenuEntry.

@SuppressFBWarnings(value = "FE_FLOATING_POINT_EQUALITY", justification = "fixed number of possible values")
void addRateMenuEntry(JMenu menu, final int newrate) {
    JRadioButtonMenuItem button = new JRadioButtonMenuItem("" + newrate + ":1");
    button.addActionListener(new ActionListener() {

        final int r = newrate;

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                clock.userSetRate(r);
                rate = r;
            } catch (TimebaseRateException t) {
                log.error("TimebaseRateException for rate= " + r + ". " + t);
            }
        }
    });
    rateButtonGroup.add(button);
    // next line is the FE_FLOATING_POINT_EQUALITY annotated above
    if (rate == newrate) {
        button.setSelected(true);
    } else {
        button.setSelected(false);
    }
    menu.add(button);
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) TimebaseRateException(jmri.TimebaseRateException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

JRadioButtonMenuItem (javax.swing.JRadioButtonMenuItem)109 ButtonGroup (javax.swing.ButtonGroup)57 JMenu (javax.swing.JMenu)57 ActionEvent (java.awt.event.ActionEvent)55 ActionListener (java.awt.event.ActionListener)48 JMenuItem (javax.swing.JMenuItem)44 ItemEvent (java.awt.event.ItemEvent)24 ItemListener (java.awt.event.ItemListener)24 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)19 JPopupMenu (javax.swing.JPopupMenu)14 JPanel (javax.swing.JPanel)13 BorderLayout (java.awt.BorderLayout)12 JLabel (javax.swing.JLabel)12 JTextField (javax.swing.JTextField)12 JOptionPane (javax.swing.JOptionPane)10 MenuEvent (javax.swing.event.MenuEvent)10 MenuListener (javax.swing.event.MenuListener)10 JRadioButton (javax.swing.JRadioButton)9 HousePart (org.concord.energy3d.model.HousePart)9 AbstractAction (javax.swing.AbstractAction)8