Example usage for javax.swing JRadioButtonMenuItem addActionListener

List of usage examples for javax.swing JRadioButtonMenuItem addActionListener

Introduction

In this page you can find the example usage for javax.swing JRadioButtonMenuItem addActionListener.

Prototype

public void addActionListener(ActionListener l) 

Source Link

Document

Adds an ActionListener to the button.

Usage

From source file:it.cnr.icar.eric.client.ui.swing.metal.MetalThemeMenu.java

/**
 * Constucts a JMenu named 'name' with a a RadioButton for each
 * object in 'themeArray'.// w ww. j a v  a 2s  .c  om
 *
 * @param name the visible name for the Menu.
 * @param themeArray the array of themes to put in the menu.
 */
public MetalThemeMenu(String name, MetalTheme[] themeArray) {
    super(name);
    themeNames = ResourceBundle.getBundle(BASE_NAME, Locale.getDefault());
    themes = themeArray;

    ButtonGroup group = new ButtonGroup();
    JRadioButtonMenuItem defaultItem = null;

    for (int i = 0; i < themes.length; i++) {
        String themeName;

        try {
            themeName = themeNames.getString(themes[i].getName().replaceAll("\\s", ""));
        } catch (MissingResourceException mre) {
            themeName = themes[i].getName();

            Object[] noResourceArgs = { themes[i].getName(), getLocale() };
            MessageFormat form = new MessageFormat(themeNames.getString("message.error.noResource"));
            log.error(form.format(noResourceArgs));
        }

        JRadioButtonMenuItem item = new JRadioButtonMenuItem(themeName);
        group.add(item);
        add(item);
        item.setActionCommand(i + "");
        item.addActionListener(this);

        // Theme name without spaces is the key for looking up localized item text.
        item.setName(themes[i].getName().replaceAll(" ", ""));

        if (i == 0) {
            item.setSelected(true);
            defaultItem = item;
        }
    }

    //add listener for 'locale' bound property
    RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_LOCALE, this);

    defaultItem.doClick();
}

From source file:net.sf.firemox.AbstractMainForm.java

/**
 * Initialize the components of this form.
 *//*w  w  w.j  ava2 s .  com*/
protected void initAbstractMenu() {
    // "TBS" menu
    tbsMenu = UIHelper.buildMenu("menu_options_tbs");
    ButtonGroup group4 = new ButtonGroup();
    final MdbListener mdbListener = new MdbListener(this);
    final File[] mdbs = MToolKit.getFile(IdConst.TBS_DIR)
            .listFiles((FileFilter) FileFilterUtils.suffixFileFilter("xml"));
    String defaultTbs = MToolKit.tbsName;
    for (File mdb : mdbs) {
        String mdbName = FilenameUtils.getBaseName(mdb.getName());
        JRadioButtonMenuItem itemChck = new JRadioButtonMenuItem();
        MToolKit.tbsName = mdbName;
        updateMdbMenu(mdbName, itemChck);
        itemChck.setActionCommand(mdbName);
        itemChck.setFont(MToolKit.defaultFont);
        itemChck.addActionListener(mdbListener);
        group4.add(itemChck);
        tbsMenu.add(itemChck);
        if (mdbName.equals(defaultTbs)) {
            itemChck.setSelected(true);
        }
    }
    MToolKit.tbsName = defaultTbs;
    tbsMenu.add(new JSeparator());

    // "More TBS" menu item
    tbsMenu.add(UIHelper.buildMenu("menu_options_tbs_more", mdbListener));
    tbsMenu.add(new JSeparator());
    final JMenuItem updateMdbMenu = UIHelper.buildMenu("menu_options_tbs_update", mdbListener);
    updateMdbMenu.setEnabled(false);
    tbsMenu.add(updateMdbMenu);
    tbsMenu.add(UIHelper.buildMenu("menu_options_tbs_rebuild", mdbListener));
    optionMenu.add(new JSeparator());
    optionMenu.add(tbsMenu);
}

From source file:de.burrotinto.jKabel.dispalyAS.DisplayAAS.java

private JMenu getjTypSortMenu() {
    JMenu typSortMenu = new JMenu("Typ Sortierung");

    JRadioButtonMenuItem inOrder = new JRadioButtonMenuItem("Aufsteigend Sortieren");
    inOrder.setSelected(ConfigReader.getInstance().isTypeInOrder());
    inOrder.addActionListener(new ActionListener() {
        @Override/*from  w  w  w. ja v a2  s . c  o  m*/
        public void actionPerformed(ActionEvent actionEvent) {
            try {
                ConfigReader.getInstance().setTypeInOrder(inOrder.isSelected());
                //                    if (kabelTypAuswahlAAS != null) {
                //                        kabelTypAuswahlAAS.typSelected(kabelTypAuswahlAAS.getSelected());
                //                    }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
    typSortMenu.add(inOrder);
    typSortMenu.addSeparator();

    ButtonGroup group = new ButtonGroup();
    for (AbstractTypeSort aTS : ConfigReader.getInstance().getAllTypSort()) {

        JRadioButtonMenuItem sw = new JRadioButtonMenuItem(aTS.getName());
        sw.setSelected(aTS.equals(ConfigReader.getInstance().getKabeltypSort()));
        group.add(sw);
        typSortMenu.add(sw);

        sw.addActionListener(aTS);
    }
    return typSortMenu;
}

From source file:de.burrotinto.jKabel.dispalyAS.DisplayAAS.java

private JMenu getjTrommelSortMenu() {
    JMenu trommelSortMenu = new JMenu("Trommel Sortierung");

    JRadioButtonMenuItem inOrder = new JRadioButtonMenuItem("Aufsteigend Sortieren");
    inOrder.setSelected(ConfigReader.getInstance().isTypeInOrder());
    inOrder.addActionListener(new ActionListener() {
        @Override/*from   ww  w  .  j a v  a2 s.  co m*/
        public void actionPerformed(ActionEvent actionEvent) {
            try {
                ConfigReader.getInstance().setTrommelInOrder(inOrder.isSelected());
                //                    if (kabelTypAuswahlAAS != null) {
                //                        kabelTypAuswahlAAS.typSelected(kabelTypAuswahlAAS.getSelected());
                //                    }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
    trommelSortMenu.add(inOrder);

    trommelSortMenu.addSeparator();

    ButtonGroup group = new ButtonGroup();
    for (AbstractTrommelSort aTS : ConfigReader.getInstance().getAllTrommelSort()) {

        JRadioButtonMenuItem sw = new JRadioButtonMenuItem(aTS.getName());
        sw.setSelected(aTS.equals(ConfigReader.getInstance().getTrommelSort()));
        group.add(sw);
        trommelSortMenu.add(sw);

        sw.addActionListener(aTS);
    }
    return trommelSortMenu;
}

From source file:com.haskins.cloudtrailviewer.sidebar.AbstractChart.java

private void addTopMenu() {

    JRadioButtonMenuItem mnuTop5 = new JRadioButtonMenuItem("Top 5");
    JRadioButtonMenuItem mnuTop10 = new JRadioButtonMenuItem("Top 10");

    mnuTop5.setActionCommand("top.5");
    mnuTop5.addActionListener(this);
    mnuTop5.setSelected(true);//from  ww  w. j av  a2  s .c  om

    mnuTop10.setActionCommand("top.10");
    mnuTop10.addActionListener(this);

    topGroup.add(mnuTop5);
    topGroup.add(mnuTop10);

    JMenu menuTop = new JMenu("Top");
    menuTop.add(mnuTop5);
    menuTop.add(mnuTop10);

    menu.add(menuTop);
}

From source file:com.haskins.cloudtrailviewer.sidebar.AbstractChart.java

private void addOrientationMenu() {

    JRadioButtonMenuItem mnuHorizontal = new JRadioButtonMenuItem("Horizontal");
    JRadioButtonMenuItem mnuVertical = new JRadioButtonMenuItem("Vertical");

    mnuHorizontal.setActionCommand("orientation.horizontal");
    mnuHorizontal.addActionListener(this);
    mnuHorizontal.setSelected(true);//ww w  . j  av a  2  s  . com

    mnuVertical.setActionCommand("orientation.vertical");
    mnuVertical.addActionListener(this);

    orientationGroup.add(mnuHorizontal);
    orientationGroup.add(mnuVertical);

    JMenu menuOrientation = new JMenu("Orientation");
    menuOrientation.add(mnuHorizontal);
    menuOrientation.add(mnuVertical);

    menu.add(menuOrientation);
}

From source file:com.haskins.cloudtrailviewer.sidebar.EventsChart.java

private JMenu getSessionIssuerMenu(ButtonGroup buttonGroup) {

    JRadioButtonMenuItem mnuSiType = new JRadioButtonMenuItem("Type");
    JRadioButtonMenuItem mnuSiArn = new JRadioButtonMenuItem("Arn");
    JRadioButtonMenuItem mnuSiPrincipalId = new JRadioButtonMenuItem("Principal Id");
    JRadioButtonMenuItem mnuSiAccountId = new JRadioButtonMenuItem("Account Id");
    JRadioButtonMenuItem mnuSiUsername = new JRadioButtonMenuItem("Username");

    mnuSiType.setActionCommand("UserIdentity.SessionContext.SessionIssuer.Type");
    mnuSiType.addActionListener(this);

    mnuSiPrincipalId.setActionCommand("UserIdentity.SessionContext.SessionIssuer.PrincipalId");
    mnuSiPrincipalId.addActionListener(this);

    mnuSiArn.setActionCommand("UserIdentity.SessionContext.SessionIssuer.Arn");
    mnuSiArn.addActionListener(this);

    mnuSiAccountId.setActionCommand("UserIdentity.SessionContext.SessionIssuer.AccountId");
    mnuSiAccountId.addActionListener(this);

    mnuSiUsername.setActionCommand("UserIdentity.SessionContext.SessionIssuer.UserName");
    mnuSiUsername.addActionListener(this);

    buttonGroup.add(mnuSiType);/* ww w. j  av a 2  s. com*/
    buttonGroup.add(mnuSiPrincipalId);
    buttonGroup.add(mnuSiArn);
    buttonGroup.add(mnuSiAccountId);
    buttonGroup.add(mnuSiUsername);

    JMenu siMenu = new JMenu("Session Issuer");
    siMenu.add(mnuSiType);
    siMenu.add(mnuSiPrincipalId);
    siMenu.add(mnuSiArn);
    siMenu.add(mnuSiAccountId);
    siMenu.add(mnuSiUsername);

    return siMenu;
}

From source file:com.haskins.cloudtrailviewer.sidebar.AbstractChart.java

private void addStyleMenu() {

    JRadioButtonMenuItem mnuPie = new JRadioButtonMenuItem("Pie");
    JRadioButtonMenuItem mnuPie3d = new JRadioButtonMenuItem("Pie 3D");
    JRadioButtonMenuItem mnuBar = new JRadioButtonMenuItem("Bar");
    JRadioButtonMenuItem mnuBar3d = new JRadioButtonMenuItem("Bar 3d");

    mnuPie.setActionCommand("style.Pie");
    mnuPie.addActionListener(this);
    mnuPie.setSelected(true);/*from w w  w  . j  a  va 2s.c  om*/

    mnuPie3d.setActionCommand("style.Pie3d");
    mnuPie3d.addActionListener(this);

    mnuBar.setActionCommand("style.Bar");
    mnuBar.addActionListener(this);

    mnuBar3d.setActionCommand("style.Bar3d");
    mnuBar3d.addActionListener(this);

    styleGroup.add(mnuPie);
    styleGroup.add(mnuPie3d);
    styleGroup.add(mnuBar);
    styleGroup.add(mnuBar3d);

    JMenu menuStyle = new JMenu("Style");
    menuStyle.add(mnuPie);
    menuStyle.add(mnuPie3d);
    menuStyle.add(mnuBar);
    menuStyle.add(mnuBar3d);

    menu.add(menuStyle);
}

From source file:com.mightypocket.ashot.Mediator.java

void addDevice(final String deviceStr) {
    if (!devices.containsKey(deviceStr)) {
        try {/*  w ww  .  ja  v a2s  .c om*/
            SwingUtilities.invokeAndWait(new Runnable() {
                @Override
                public void run() {
                    JRadioButtonMenuItem item = new JRadioButtonMenuItem(deviceStr);
                    item.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            JRadioButtonMenuItem source = (JRadioButtonMenuItem) e.getSource();
                            String device = source.getText();
                            demon.connectTo(device);
                        }
                    });
                    devicesGroup.add(item);
                    devices.put(deviceStr, item);
                    menuFileDevices.add(item);
                    pcs.firePropertyChange(PROP_DEVICES, null, null);
                }
            });
        } catch (Exception ignore) {
        }
    }
}

From source file:com.haskins.cloudtrailviewer.sidebar.EventsChart.java

private JMenu getUserIdentityMenu(ButtonGroup buttonGroup) {

    JRadioButtonMenuItem mnuUiType = new JRadioButtonMenuItem("Type");
    JRadioButtonMenuItem mnuUiPrincipalId = new JRadioButtonMenuItem("Principal Id");
    JRadioButtonMenuItem mnuUiArn = new JRadioButtonMenuItem("Arn");
    JRadioButtonMenuItem mnuUiAccountId = new JRadioButtonMenuItem("Account Id");
    JRadioButtonMenuItem mnuUiAccessKeyId = new JRadioButtonMenuItem("Access Key Id");
    JRadioButtonMenuItem mnuUiUsername = new JRadioButtonMenuItem("Username");
    JRadioButtonMenuItem mnuUiInvokedBy = new JRadioButtonMenuItem("Invoked By");

    mnuUiType.setActionCommand("UserIdentity.Type");
    mnuUiType.addActionListener(this);

    mnuUiPrincipalId.setActionCommand("UserIdentity.PrincipalId");
    mnuUiPrincipalId.addActionListener(this);

    mnuUiArn.setActionCommand("UserIdentity.Arn");
    mnuUiArn.addActionListener(this);

    mnuUiAccountId.setActionCommand("UserIdentity.AccountId");
    mnuUiAccountId.addActionListener(this);

    mnuUiAccessKeyId.setActionCommand("UserIdentity.AccessKeyId");
    mnuUiAccessKeyId.addActionListener(this);

    mnuUiUsername.setActionCommand("UserIdentity.UserName");
    mnuUiUsername.addActionListener(this);

    mnuUiInvokedBy.setActionCommand("UserIdentity.InvokedBy");
    mnuUiInvokedBy.addActionListener(this);

    buttonGroup.add(mnuUiType);/*  www  .j a v a 2s .co  m*/
    buttonGroup.add(mnuUiPrincipalId);
    buttonGroup.add(mnuUiArn);
    buttonGroup.add(mnuUiAccountId);
    buttonGroup.add(mnuUiAccessKeyId);
    buttonGroup.add(mnuUiUsername);
    buttonGroup.add(mnuUiInvokedBy);

    JMenu userIdentityMenu = new JMenu("User Identity");
    userIdentityMenu.add(mnuUiType);
    userIdentityMenu.add(mnuUiPrincipalId);
    userIdentityMenu.add(mnuUiArn);
    userIdentityMenu.add(mnuUiAccountId);
    userIdentityMenu.add(mnuUiAccessKeyId);
    userIdentityMenu.add(mnuUiUsername);
    userIdentityMenu.add(mnuUiInvokedBy);
    userIdentityMenu.add(getSessionContextMenu(buttonGroup));

    return userIdentityMenu;
}