Example usage for javax.swing JMenuItem addActionListener

List of usage examples for javax.swing JMenuItem addActionListener

Introduction

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

Prototype

public void addActionListener(ActionListener l) 

Source Link

Document

Adds an ActionListener to the button.

Usage

From source file:javazoom.jlgui.player.amp.playlist.ui.PlaylistUI.java

public void loadUI() {
    removeAll();// w  w  w. j ava 2s . com
    ui.getPlaylistPanel().setParent(this);
    add(ui.getAcPlSlider(), ui.getAcPlSlider().getConstraints());
    ui.getAcPlSlider().setValue(100);
    ui.getAcPlSlider().removeChangeListener(this);
    ui.getAcPlSlider().addChangeListener(this);
    add(ui.getAcPlUp(), ui.getAcPlUp().getConstraints());
    ui.getAcPlUp().removeActionListener(this);
    ui.getAcPlUp().addActionListener(this);
    add(ui.getAcPlDown(), ui.getAcPlDown().getConstraints());
    ui.getAcPlDown().removeActionListener(this);
    ui.getAcPlDown().addActionListener(this);
    // Add menu
    add(ui.getAcPlAdd(), ui.getAcPlAdd().getConstraints());
    ui.getAcPlAdd().removeActionListener(this);
    ui.getAcPlAdd().addActionListener(this);
    add(ui.getAcPlAddPopup(), ui.getAcPlAddPopup().getConstraints());
    ui.getAcPlAddPopup().setVisible(false);
    ActiveJButton[] items = ui.getAcPlAddPopup().getItems();
    for (int i = 0; i < items.length; i++) {
        items[i].addActionListener(this);
    }
    // Remove menu
    add(ui.getAcPlRemove(), ui.getAcPlRemove().getConstraints());
    ui.getAcPlRemove().removeActionListener(this);
    ui.getAcPlRemove().addActionListener(this);
    add(ui.getAcPlRemovePopup(), ui.getAcPlRemovePopup().getConstraints());
    ui.getAcPlRemovePopup().setVisible(false);
    items = ui.getAcPlRemovePopup().getItems();
    for (int i = 0; i < items.length; i++) {
        items[i].removeActionListener(this);
        items[i].addActionListener(this);
    }
    // Select menu
    add(ui.getAcPlSelect(), ui.getAcPlSelect().getConstraints());
    ui.getAcPlSelect().removeActionListener(this);
    ui.getAcPlSelect().addActionListener(this);
    add(ui.getAcPlSelectPopup(), ui.getAcPlSelectPopup().getConstraints());
    ui.getAcPlSelectPopup().setVisible(false);
    items = ui.getAcPlSelectPopup().getItems();
    for (int i = 0; i < items.length; i++) {
        items[i].removeActionListener(this);
        items[i].addActionListener(this);
    }
    // Misc menu
    add(ui.getAcPlMisc(), ui.getAcPlMisc().getConstraints());
    ui.getAcPlMisc().removeActionListener(this);
    ui.getAcPlMisc().addActionListener(this);
    add(ui.getAcPlMiscPopup(), ui.getAcPlMiscPopup().getConstraints());
    ui.getAcPlMiscPopup().setVisible(false);
    items = ui.getAcPlMiscPopup().getItems();
    for (int i = 0; i < items.length; i++) {
        items[i].removeActionListener(this);
        items[i].addActionListener(this);
    }
    // List menu
    add(ui.getAcPlList(), ui.getAcPlList().getConstraints());
    ui.getAcPlList().removeActionListener(this);
    ui.getAcPlList().addActionListener(this);
    add(ui.getAcPlListPopup(), ui.getAcPlListPopup().getConstraints());
    ui.getAcPlListPopup().setVisible(false);
    items = ui.getAcPlListPopup().getItems();
    for (int i = 0; i < items.length; i++) {
        items[i].removeActionListener(this);
        items[i].addActionListener(this);
    }
    // Popup menu
    fipopup = new JPopupMenu();
    JMenuItem mi = new JMenuItem(ui.getResource("playlist.popup.info"));
    mi.setActionCommand(PlayerActionEvent.ACPLINFO);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    fipopup.add(mi);
    fipopup.addSeparator();
    mi = new JMenuItem(ui.getResource("playlist.popup.play"));
    mi.setActionCommand(PlayerActionEvent.ACPLPLAY);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    fipopup.add(mi);
    fipopup.addSeparator();
    mi = new JMenuItem(ui.getResource("playlist.popup.remove"));
    mi.setActionCommand(PlayerActionEvent.ACPLREMOVE);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    fipopup.add(mi);
    validate();
    repaint();
}

From source file:edu.ku.brc.specify.config.init.secwiz.SpecifyDBSecurityWizardFrame.java

/**
 * @return/*  ww w .j  a v  a  2  s  .  com*/
 */
public JMenuBar createMenus() {
    JMenuBar mb = new JMenuBar();
    JMenuItem mi;

    //--------------------------------------------------------------------
    //-- File Menu
    //--------------------------------------------------------------------

    if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) {
        JMenu menu = UIHelper.createLocalizedMenu(mb, "Specify.FILE_MENU", "Specify.FILE_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$

        menu.addSeparator();
        String title = "Specify.EXIT"; //$NON-NLS-1$
        String mnu = "Specify.Exit_MNEU"; //$NON-NLS-1$
        mi = UIHelper.createLocalizedMenuItem(menu, title, mnu, title, true, null);
        mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                doExit(true);
            }
        });
    }

    JMenu helpMenu = UIHelper.createLocalizedMenu(mb, "Specify.HELP_MENU", "Specify.HELP_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$
    HelpMgr.createHelpMenuItem(helpMenu, "Specify"); //$NON-NLS-1$
    helpMenu.addSeparator();

    if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) {
        String ttle = "Specify.ABOUT";//$NON-NLS-1$ 
        String mneu = "Specify.ABOUTMNEU";//$NON-NLS-1$ 
        String desc = "Specify.ABOUT";//$NON-NLS-1$ 
        mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null);
        mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                doAbout();
            }
        });
    }
    return mb;
}

From source file:edu.ku.brc.af.ui.forms.validation.ValComboBox.java

/**
 * @param txtComp//www  .j a  v a  2 s . c o  m
 */
private void addPopupMenu(final JTextComponent txtComp) {
    final JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem mi = new JMenuItem(UIRegistry.getResourceString("DELETE"));
    popupMenu.add(mi);
    mi.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            PickListItemIFace pli = (PickListItemIFace) comboBox.getSelectedItem();
            if (pli != null) {
                PickListIFace pl = adapter.getPickList();
                pl.removeItem(pli);
            }
        }
    });
}

From source file:ucar.unidata.idv.control.chart.ChartHolder.java

/**
 * Add in the zoom menu items/*from   ww  w  .ja  v  a 2s.com*/
 *
 * @param items items
 */
private void addZoomMenuItems(List items) {
    JMenuItem mi;
    JMenu menu;

    items.add(menu = new JMenu("Zoom In"));
    menu.add(mi = new JMenuItem("All Axes"));
    mi.setActionCommand(ChartPanel.ZOOM_IN_BOTH_COMMAND);
    mi.addActionListener(chartPanel);
    menu.addSeparator();

    menu.add(mi = new JMenuItem("Domain Axis"));
    mi.setActionCommand(ChartPanel.ZOOM_IN_DOMAIN_COMMAND);
    mi.addActionListener(chartPanel);

    menu.add(mi = new JMenuItem("Range Axis"));
    mi.setActionCommand(ChartPanel.ZOOM_IN_RANGE_COMMAND);
    mi.addActionListener(chartPanel);

    items.add(menu = new JMenu("Zoom Out"));

    menu.add(mi = new JMenuItem("All Axes"));
    mi.setActionCommand(ChartPanel.ZOOM_OUT_BOTH_COMMAND);
    mi.addActionListener(chartPanel);

    menu.addSeparator();

    menu.add(mi = new JMenuItem("Domain Axis"));
    mi.setActionCommand(ChartPanel.ZOOM_OUT_DOMAIN_COMMAND);
    mi.addActionListener(chartPanel);

    menu.add(mi = new JMenuItem("Range Axis"));
    mi.setActionCommand(ChartPanel.ZOOM_OUT_RANGE_COMMAND);
    mi.addActionListener(chartPanel);

    items.add(menu = new JMenu("Auto Range"));

    menu.add(mi = new JMenuItem("All Axes"));
    mi.setActionCommand(ChartPanel.ZOOM_RESET_BOTH_COMMAND);
    mi.addActionListener(chartPanel);

    menu.addSeparator();

    menu.add(mi = new JMenuItem("Domain Axis"));
    mi.setActionCommand(ChartPanel.ZOOM_RESET_DOMAIN_COMMAND);
    mi.addActionListener(chartPanel);

    menu.add(mi = new JMenuItem("Range Axis"));
    mi.setActionCommand(ChartPanel.ZOOM_RESET_RANGE_COMMAND);
    mi.addActionListener(chartPanel);
}

From source file:net.liuxuan.device.VACVBS.JIF_DrawChart_vacvbs.java

/**
 * ????//from ww w. j  a  v  a 2s .  c o m
 */
public void initChartMenu() {
    GetPointAction action = new GetPointAction();
    JMenu fx = new JMenu("?");
    JMenuItem jmenuitem_select1 = new JMenuItem("");
    jmenuitem_select1.addActionListener(action);
    fx.add(jmenuitem_select1);
    JMenuItem jmenuitem_select2 = new JMenuItem("");
    jmenuitem_select2.addActionListener(action);
    fx.add(jmenuitem_select2);
    JMenuItem jmenuitem_avg = new JMenuItem("?");
    jmenuitem_avg.addActionListener(action);
    fx.add(jmenuitem_avg);
    JMenuItem jmenuitem_parse = new JMenuItem("?");
    jmenuitem_parse.addActionListener(action);
    fx.add(jmenuitem_parse);

    JMenuItem jmenuitem_compute = new JMenuItem("?");
    jmenuitem_compute.addActionListener(action);
    fx.add(jmenuitem_compute);

    JMenuItem jmenuitem_zz1 = new JMenuItem("1");
    jmenuitem_zz1.addActionListener(action);
    fx.add(jmenuitem_zz1);
    JMenuItem jmenuitem_zz2 = new JMenuItem("2");
    jmenuitem_zz2.addActionListener(action);
    fx.add(jmenuitem_zz2);
    chartPanel.getPopupMenu().add(fx);

    JMenu bx = new JMenu("");

    JMenuItem jmenuitem7 = new JMenuItem("");
    jmenuitem7.addActionListener(action);
    bx.add(jmenuitem7);
    JMenuItem jmenuitem9 = new JMenuItem("");
    jmenuitem9.addActionListener(action);
    bx.add(jmenuitem9);
    JMenuItem jmenuitem10 = new JMenuItem("");
    jmenuitem10.addActionListener(action);
    bx.add(jmenuitem10);

    chartPanel.getPopupMenu().add(bx);
}

From source file:edu.ku.brc.specify.plugins.ipadexporter.iPadDBExporterPlugin.java

@Override
public List<MenuItemDesc> getMenuItems() {
    String menuDesc = "Specify.SYSTEM_MENU";

    menuItems = new Vector<MenuItemDesc>();

    if (permissions == null || permissions.canView()) {
        loadAndPushResourceBundle(RESOURCE_NAME);
        String menuTitle = "iPadDBExporterPlugin.PLUGIN_MENU"; //$NON-NLS-1$
        String mneu = "t";//"iPadDBExporterPlugin.PLUGIN_MNEU"; //$NON-NLS-1$
        String desc = menuTitle;//"iPadDBExporterPlugin.PLUGIN_DESC"; //$NON-NLS-1$
        JMenuItem mi = createLocalizedMenuItem(menuTitle, mneu, desc, true, null);
        mi.addActionListener(new ActionListener() {
            @Override/*  w w  w. j  a va2s  .  c o  m*/
            public void actionPerformed(ActionEvent ae) {
                iPadDBExporterPlugin.this.requestContext();
            }
        });
        MenuItemDesc rsMI = new MenuItemDesc(mi, menuDesc);
        rsMI.setPosition(MenuItemDesc.Position.After);
        rsMI.setSepPosition(MenuItemDesc.Position.Before);
        menuItems.add(rsMI);
        popResourceBundle();
    }

    return menuItems;

}

From source file:gdt.jgui.entity.webset.JWeblinkEditor.java

private void showLoginMenu(MouseEvent e) {
    try {//from  w w w.  j  ava  2 s .  c o m
        JPopupMenu logonMenu = new JPopupMenu();
        JMenuItem copyItem = new JMenuItem("Copy");
        logonMenu.add(copyItem);
        copyItem.setHorizontalTextPosition(JMenuItem.RIGHT);
        copyItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    StringSelection stringSelection = new StringSelection(loginField.getText());
                    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
                    clipboard.setContents(stringSelection, JWeblinkEditor.this);
                } catch (Exception ee) {
                    Logger.getLogger(getClass().getName()).info(ee.toString());
                }
            }
        });
        logonMenu.show(e.getComponent(), e.getX(), e.getY());
    } catch (Exception ee) {
        Logger.getLogger(getClass().getName()).severe(ee.toString());
    }
}

From source file:edu.clemson.cs.nestbed.client.gui.TestbedManagerFrame.java

private final JMenu buildProjectMenu() {
    final JMenu menu = new JMenu("Project");
    final JMenuItem addProject = new JMenuItem("Add");
    final JMenuItem deleteProject = new JMenuItem("Delete");

    addProject.addActionListener(new AddProjectActionListener());
    menu.add(addProject);//from  ww w  .ja v  a2  s.  c  o m

    deleteProject.addActionListener(new DeleteProjectActionListener());
    menu.add(deleteProject);

    menu.addMenuListener(new ProjectMenuListener(addProject, deleteProject));
    return menu;
}

From source file:Main.java

Main() {
    JFrame f = new JFrame("Menu Demo");
    f.setSize(220, 200);//  w  ww.j  a  v  a2s  . c  o  m

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar jmb = new JMenuBar();

    JMenu jmFile = new JMenu("File");
    JMenuItem jmiOpen = new JMenuItem("Open");
    JMenuItem jmiClose = new JMenuItem("Close");
    JMenuItem jmiSave = new JMenuItem("Save");
    JMenuItem jmiExit = new JMenuItem("Exit");
    jmFile.add(jmiOpen);
    jmFile.add(jmiClose);
    jmFile.add(jmiSave);
    jmFile.addSeparator();
    jmFile.add(jmiExit);
    jmb.add(jmFile);

    JMenu jmOptions = new JMenu("Options");
    JMenu a = new JMenu("A");
    JMenuItem b = new JMenuItem("B");
    JMenuItem c = new JMenuItem("C");
    JMenuItem d = new JMenuItem("D");
    a.add(b);
    a.add(c);
    a.add(d);
    jmOptions.add(a);

    JMenu e = new JMenu("E");
    e.add(new JMenuItem("F"));
    e.add(new JMenuItem("G"));
    jmOptions.add(e);

    jmb.add(jmOptions);

    JMenu jmHelp = new JMenu("Help");
    JMenuItem jmiAbout = new JMenuItem("About");
    jmHelp.add(jmiAbout);
    jmb.add(jmHelp);

    jmiOpen.addActionListener(this);
    jmiClose.addActionListener(this);
    jmiSave.addActionListener(this);
    jmiExit.addActionListener(this);
    b.addActionListener(this);
    c.addActionListener(this);
    d.addActionListener(this);
    jmiAbout.addActionListener(this);

    f.setJMenuBar(jmb);
    f.setVisible(true);
}

From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_multicastDemand.java

private List<JComponent> getExtraOptions(final int row, final Object itemId) {
    List<JComponent> options = new LinkedList<JComponent>();

    final int numRows = model.getRowCount();
    final NetPlan netPlan = callback.getDesign();
    final List<MulticastDemand> visibleRows = getVisibleElementsInTable();

    JMenuItem offeredTrafficToAll = new JMenuItem("Set offered traffic to all");
    offeredTrafficToAll.addActionListener(new ActionListener() {
        @Override//from w  w w  . j  a v  a2s  . com
        public void actionPerformed(ActionEvent e) {
            double h_d;

            while (true) {
                String str = JOptionPane.showInputDialog(null, "Offered traffic volume",
                        "Set traffic value to all table multicast demands", JOptionPane.QUESTION_MESSAGE);
                if (str == null)
                    return;

                try {
                    h_d = Double.parseDouble(str);
                    if (h_d < 0)
                        throw new RuntimeException();

                    break;
                } catch (Throwable ex) {
                    ErrorHandling.showErrorDialog(
                            "Non-valid multicast demand offered traffic value. Please, introduce a non-negative number",
                            "Error setting link length");
                }
            }

            try {
                for (MulticastDemand demand : visibleRows)
                    demand.setOfferedTraffic(h_d);
                callback.updateVisualizationAfterChanges(
                        Collections.singleton(NetworkElementType.MULTICAST_DEMAND));
                callback.getUndoRedoNavigationManager().addNetPlanChange();
            } catch (Throwable ex) {
                ErrorHandling.showErrorDialog(ex.getMessage(),
                        "Unable to set offered traffic to all multicast demands");
            }
        }
    });

    options.add(offeredTrafficToAll);

    if (itemId != null && netPlan.isMultilayer()) {
        final long demandId = (long) itemId;
        final MulticastDemand demand = netPlan.getMulticastDemandFromId(demandId);
        if (demand.isCoupled()) {
            JMenuItem decoupleDemandItem = new JMenuItem("Decouple multicast demand");
            decoupleDemandItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    demand.decouple();
                    model.setValueAt("", row, COLUMN_COUPLEDTOLINKS);
                    callback.getVisualizationState().resetPickedState();
                    callback.updateVisualizationAfterChanges(
                            Sets.newHashSet(NetworkElementType.MULTICAST_DEMAND, NetworkElementType.LINK));
                    callback.getUndoRedoNavigationManager().addNetPlanChange();
                }
            });

            options.add(decoupleDemandItem);
        }
        if (numRows > 1) {
            JMenuItem decoupleAllDemandsItem = null;
            JMenuItem createUpperLayerLinksFromDemandsItem = null;

            final Set<MulticastDemand> coupledDemands = visibleRows.stream().filter(e -> e.isCoupled())
                    .collect(Collectors.toSet());
            if (!coupledDemands.isEmpty()) {
                decoupleAllDemandsItem = new JMenuItem("Decouple all table demands");
                decoupleAllDemandsItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        for (MulticastDemand d : coupledDemands)
                            d.decouple();
                        int numRows = model.getRowCount();
                        for (int i = 0; i < numRows; i++)
                            model.setValueAt("", i, COLUMN_COUPLEDTOLINKS);
                        callback.getVisualizationState().resetPickedState();
                        callback.updateVisualizationAfterChanges(
                                Sets.newHashSet(NetworkElementType.MULTICAST_DEMAND, NetworkElementType.LINK));
                        callback.getUndoRedoNavigationManager().addNetPlanChange();
                    }
                });
            }

            if (coupledDemands.size() < visibleRows.size()) {
                createUpperLayerLinksFromDemandsItem = new JMenuItem(
                        "Create upper layer links from uncoupled demands");
                createUpperLayerLinksFromDemandsItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        List<Long> layerIds = netPlan.getNetworkLayerIds();
                        final JComboBox layerSelector = new WiderJComboBox();
                        for (long layerId : layerIds) {
                            if (layerId == netPlan.getNetworkLayerDefault().getId())
                                continue;

                            final String layerName = netPlan.getNetworkLayerFromId(layerId).getName();
                            String layerLabel = "Layer " + layerId;
                            if (!layerName.isEmpty())
                                layerLabel += " (" + layerName + ")";

                            layerSelector.addItem(StringLabeller.of(layerId, layerLabel));
                        }

                        layerSelector.setSelectedIndex(0);

                        JPanel pane = new JPanel();
                        pane.add(new JLabel("Select layer: "));
                        pane.add(layerSelector);

                        while (true) {
                            int result = JOptionPane.showConfirmDialog(null, pane,
                                    "Please select the upper layer to create links",
                                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
                            if (result != JOptionPane.OK_OPTION)
                                return;

                            try {
                                long layerId = (long) ((StringLabeller) layerSelector.getSelectedItem())
                                        .getObject();
                                NetworkLayer layer = netPlan.getNetworkLayerFromId(layerId);
                                for (MulticastDemand demand : visibleRows)
                                    if (!demand.isCoupled())
                                        demand.coupleToNewLinksCreated(layer);
                                callback.getVisualizationState()
                                        .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals();
                                callback.updateVisualizationAfterChanges(Sets.newHashSet(
                                        NetworkElementType.MULTICAST_DEMAND, NetworkElementType.LINK));
                                callback.getUndoRedoNavigationManager().addNetPlanChange();
                                break;
                            } catch (Throwable ex) {
                                ErrorHandling.showErrorDialog(ex.getMessage(),
                                        "Error creating upper layer links");
                            }
                        }
                    }
                });
            }

            if (!options.isEmpty()
                    && (decoupleAllDemandsItem != null || createUpperLayerLinksFromDemandsItem != null)) {
                options.add(new JPopupMenu.Separator());
                if (decoupleAllDemandsItem != null)
                    options.add(decoupleAllDemandsItem);
                if (createUpperLayerLinksFromDemandsItem != null)
                    options.add(createUpperLayerLinksFromDemandsItem);
            }

        }
    }

    return options;
}