Search in sources :

Example 6 with JRadioButtonMenuItem

use of javax.swing.JRadioButtonMenuItem in project jgnash by ccavanaugh.

the class ThemeManager method buildLookAndFeelMenu.

/**
     * Loads the menu with the available look and feels for the application
     * 
     * @return l and f menu
     */
JMenu buildLookAndFeelMenu() {
    String activeLookAndFeelName = UIManager.getLookAndFeel().getName();
    // ButtonGroup buttonGroup = new ButtonGroup();
    JMenu lfMenu = new JMenu();
    lfMenu.setText(rb.getString("Menu.LookAndFeel.Name"));
    lfMenu.add(buildSubstanceMenu());
    List<String> lookAndFeels = new ArrayList<>();
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if (isLookAndFeelAvailable(info.getClassName())) {
            lookAndFeels.add(info.getClassName());
        }
    }
    for (String lookAndFeel : KNOWN) {
        if (isLookAndFeelAvailable(lookAndFeel)) {
            lookAndFeels.add(lookAndFeel);
        }
    }
    Collections.sort(lookAndFeels);
    for (String lookAndFeel : lookAndFeels) {
        try {
            Class<?> lnfClass = Class.forName(lookAndFeel);
            LookAndFeel newLAF = (LookAndFeel) lnfClass.newInstance();
            JRadioButtonMenuItem button = new JRadioButtonMenuItem();
            button.setText(newLAF.getName());
            button.setActionCommand(lookAndFeel);
            button.setName(newLAF.getName());
            button.addActionListener(e -> {
                Preferences pref = Preferences.userNodeForPackage(ThemeManager.class);
                pref.put(LF, e.getActionCommand());
                restartUI();
            });
            lfButtonGroup.add(button);
            lfMenu.add(button);
            if (newLAF.getName().equals(activeLookAndFeelName)) {
                button.setSelected(true);
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            Logger.getLogger(ThemeManager.class.getName()).log(Level.WARNING, null, e);
        }
    }
    return lfMenu;
}
Also used : LookAndFeelInfo(javax.swing.UIManager.LookAndFeelInfo) ArrayList(java.util.ArrayList) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) LookAndFeel(javax.swing.LookAndFeel) NimbusLookAndFeel(javax.swing.plaf.nimbus.NimbusLookAndFeel) SubstanceLookAndFeel(org.pushingpixels.substance.api.SubstanceLookAndFeel) MetalLookAndFeel(javax.swing.plaf.metal.MetalLookAndFeel) Preferences(java.util.prefs.Preferences) JMenu(javax.swing.JMenu)

Example 7 with JRadioButtonMenuItem

use of javax.swing.JRadioButtonMenuItem in project jgnash by ccavanaugh.

the class ActionParser method createMenuItem.

private JMenuItem createMenuItem(final ActionNode node) {
    JMenuItem menu;
    Action a = actionMap.get(node.idref);
    if (node.size() > 0) {
        menu = new JMenu(a);
        for (int i = 0; i < node.size(); i++) {
            ActionNode n = node.getChildAt(i);
            if (n.id == null && n.idref == null) {
                // detect a separator
                ((JMenu) menu).addSeparator();
            } else {
                JMenuItem item = createMenuItem(n);
                menu.add(item);
            }
        }
    } else {
        if (node.type == null || node.type.isEmpty()) {
            menu = new JMenuItem(a);
        } else {
            switch(node.type) {
                case "single":
                    menu = new JCheckBoxMenuItem(a);
                    break;
                case "toggle":
                    menu = new JRadioButtonMenuItem(a);
                    if (node.group != null) {
                        // create a group
                        ButtonGroup bGroup;
                        if (buttonGroups.get(node.group) != null) {
                            bGroup = buttonGroups.get(node.group);
                        } else {
                            bGroup = new ButtonGroup();
                            buttonGroups.put(node.group, bGroup);
                        }
                        bGroup.add(menu);
                    }
                    break;
                default:
                    menu = new JMenuItem(a);
                    break;
            }
        }
    }
    menuItemMap.put(node.idref, menu);
    // store the idref in the JMenuItem
    menu.putClientProperty(ID_REF_ATTRIBUTE, node.idref);
    return menu;
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) ButtonGroup(javax.swing.ButtonGroup) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem)

Example 8 with JRadioButtonMenuItem

use of javax.swing.JRadioButtonMenuItem in project jabref by JabRef.

the class OpenOfficePanel method showSettingsPopup.

private void showSettingsPopup() {
    JPopupMenu menu = new JPopupMenu();
    final JCheckBoxMenuItem autoSync = new JCheckBoxMenuItem(Localization.lang("Automatically sync bibliography when inserting citations"), preferences.syncWhenCiting());
    final JRadioButtonMenuItem useActiveBase = new JRadioButtonMenuItem(Localization.lang("Look up BibTeX entries in the active tab only"));
    final JRadioButtonMenuItem useAllBases = new JRadioButtonMenuItem(Localization.lang("Look up BibTeX entries in all open libraries"));
    final JMenuItem clearConnectionSettings = new JMenuItem(Localization.lang("Clear connection settings"));
    ButtonGroup bg = new ButtonGroup();
    bg.add(useActiveBase);
    bg.add(useAllBases);
    if (preferences.useAllDatabases()) {
        useAllBases.setSelected(true);
    } else {
        useActiveBase.setSelected(true);
    }
    autoSync.addActionListener(e -> preferences.setSyncWhenCiting(autoSync.isSelected()));
    useAllBases.addActionListener(e -> preferences.setUseAllDatabases(useAllBases.isSelected()));
    useActiveBase.addActionListener(e -> preferences.setUseAllDatabases(!useActiveBase.isSelected()));
    clearConnectionSettings.addActionListener(e -> frame.output(preferences.clearConnectionSettings()));
    menu.add(autoSync);
    menu.addSeparator();
    menu.add(useActiveBase);
    menu.add(useAllBases);
    menu.addSeparator();
    menu.add(clearConnectionSettings);
    menu.show(settingsB, 0, settingsB.getHeight());
}
Also used : ButtonGroup(javax.swing.ButtonGroup) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem)

Example 9 with JRadioButtonMenuItem

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

the class JMenuUtil method createMenuGroupFromElement.

@Nonnull
static JMenu createMenuGroupFromElement(@CheckForNull Element main, WindowInterface wi, Object context) {
    String name = "<none>";
    if (main == null) {
        log.warn("Menu from element called without an element");
        return new JMenu(name);
    }
    name = LocaleSelector.getAttribute(main, "name");
    //Next statement left in if the xml file hasn't been converted
    if ((name == null) || (name.equals(""))) {
        if (main.getChild("name") != null) {
            name = main.getChild("name").getText();
        }
    }
    JMenu menu = new JMenu(name);
    ButtonGroup group = new ButtonGroup();
    for (Object item : main.getChildren("node")) {
        Element elem = (Element) item;
        Action act = actionFromNode(elem, wi, context);
        JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(act);
        group.add(menuItem);
        menu.add(menuItem);
        if (elem.getChild("current") != null) {
            setMenuItemInterAction(context, elem.getChild("current").getText(), menuItem);
        }
    }
    return menu;
}
Also used : Action(javax.swing.Action) ButtonGroup(javax.swing.ButtonGroup) Element(org.jdom2.Element) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JMenu(javax.swing.JMenu) Nonnull(javax.annotation.Nonnull)

Example 10 with JRadioButtonMenuItem

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

the class PositionablePopupUtil method addFontMenuEntry.

void addFontMenuEntry(JMenu menu, ButtonGroup fontButtonGroup, final int size) {
    JRadioButtonMenuItem r = new JRadioButtonMenuItem("" + size);
    r.addActionListener((ActionEvent e) -> {
        setFontSize(size);
    });
    fontButtonGroup.add(r);
    if (_textComponent.getFont().getSize() == size) {
        r.setSelected(true);
    } else {
        r.setSelected(false);
    }
    menu.add(r);
}
Also used : ActionEvent(java.awt.event.ActionEvent) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem)

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