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:com.AandR.beans.plotting.LinePlotPanel.LinePlotPanel.java

private JMenu createLinePropMenu() {
    JMenuItem symMenu = new JMenuItem("Show/Hide Symbols");
    symMenu.setActionCommand(ACTION_SHOW_SYMBOLS);
    symMenu.addActionListener(plotPanelListener);

    JMenuItem lineMenu = new JMenuItem("Show/Hide Lines");
    lineMenu.setActionCommand(ACTION_HIDE_LINES);
    lineMenu.addActionListener(plotPanelListener);

    JMenu menu = new JMenu("Line Properties");
    menu.add(symMenu);/*from www . j a va 2 s. c  o  m*/
    menu.add(lineMenu);
    return menu;
}

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

private JMenuItem getAddOption() {
    JMenuItem addItem = new JMenuItem("Add " + networkElementType);
    addItem.addActionListener(new ActionListener() {
        @Override/*from w ww .  ja  v a2 s .  c o  m*/
        public void actionPerformed(ActionEvent e) {
            NetPlan netPlan = callback.getDesign();
            try {
                createMulticastDemandGUI(networkElementType, callback);
            } catch (Throwable ex) {
                ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to add " + networkElementType);
            }
        }
    });
    return addItem;
}

From source file:gdt.jgui.entity.procedure.JProcedurePanel.java

/**
 * Get the context menu.// w w w.  ja v a2 s  . c  om
 * @return the context menu.
 */
@Override
public JMenu getContextMenu() {
    menu = new JMenu("Context");
    menu.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            menu.removeAll();
            JMenuItem runItem = new JMenuItem("Run");
            runItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    run();
                }
            });
            menu.add(runItem);
            Entigrator entigrator = console.getEntigrator(entihome$);
            Sack procedure = entigrator.getEntityAtKey(entityKey$);
            if (procedure.getElementItem("parameter", "noreset") == null) {
                JMenuItem resetItem = new JMenuItem("Reset");
                resetItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        int response = JOptionPane.showConfirmDialog(console.getContentPanel(),
                                "Reset source to default ?", "Confirm", JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE);
                        if (response == JOptionPane.YES_OPTION)
                            reset();
                    }
                });
                menu.add(resetItem);
            }
            JMenuItem folderItem = new JMenuItem("Open folder");
            folderItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        File file = new File(entihome$ + "/" + entityKey$);
                        Desktop.getDesktop().open(file);
                    } catch (Exception ee) {
                        Logger.getLogger(getClass().getName()).info(ee.toString());
                    }
                }
            });
            menu.add(folderItem);
            try {
                //Entigrator entigrator=console.getEntigrator(entihome$);
                Sack entity = entigrator.getEntityAtKey(entityKey$);
                String template$ = entity.getAttributeAt("template");
                if (template$ != null) {
                    JMenuItem adaptClone = new JMenuItem("Adapt clone");
                    adaptClone.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            try {
                                adaptClone(console, getLocator());
                            } catch (Exception ee) {
                                Logger.getLogger(getClass().getName()).info(ee.toString());
                            }
                        }
                    });
                    menu.add(adaptClone);
                }
            } catch (Exception ee) {
                Logger.getLogger(getClass().getName()).info(ee.toString());
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });
    return menu;
}

From source file:desmoj.extensions.visualization2d.engine.modelGrafic.StatisticGrafic.java

/**
 * Build the popup menu to switch between typeAnimation.
 * works only when statistic has observations 
 * Called by MouseListener   /*from   w  w  w  . j  av  a 2s .c  o m*/
 * Event wird nur bearbeitet, wenn die Simulation angehalten ist
 * Im anderen Fall kann der Viewer (inbes. Applet) ueberlastet sein
 * @param event      MouseEvent
 */
private void checkPopupMenu(MouseEvent event) {
    //System.out.println("StatisticGrafic.checkPopupMenu");
    ViewerPanel viewer = this.statistic.getModel().getViewer();
    if (viewer != null && viewer.getSimulationThread() != null && !viewer.getSimulationThread().isWorking()) {
        // Event wird nur bearbeitet, wenn die Simulation angehalten ist
        // Im anderen Fall kann der Viewer (inbes. Applet) ueberlastet sein
        if (event.isPopupTrigger() && this.statistic.hasValue()) {
            JPopupMenu popup = new JPopupMenu();
            JMenuItem mi = new JMenuItem(StatisticGrafic.TEXT_POPUP_MENU[0]);
            mi.addActionListener(this);
            popup.add(mi);
            mi = new JMenuItem(StatisticGrafic.TEXT_POPUP_MENU[1]);
            mi.addActionListener(this);
            popup.add(mi);
            popup.show(event.getComponent(), event.getX(), event.getY());
        }
    }
}

From source file:net.chaosserver.timelord.swingui.TimelordMenu.java

/**
 * Creates the task menu./*from   w w  w. j  av  a 2 s  .  c o  m*/
 *
 * @return the new task menu
 */
protected JMenu createTaskMenu() {
    JMenuItem menuItem;
    JMenu taskMenu = new JMenu("Task");
    taskMenu.setMnemonic(KeyEvent.VK_T);
    this.add(taskMenu);

    menuItem = new JMenuItem("New Task", KeyEvent.VK_N);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    menuItem.setActionCommand(ACTION_ADDTASK);
    menuItem.addActionListener(this);
    taskMenu.add(menuItem);

    menuItem = new JMenuItem("Hide Old Tasks", KeyEvent.VK_H);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_H, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    menuItem.setActionCommand(ACTION_HIDETASK);
    menuItem.addActionListener(this);
    taskMenu.add(menuItem);

    menuItem = new JMenuItem("Unhide Task", KeyEvent.VK_U);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_U, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    menuItem.setActionCommand(ACTION_UNHIDETASK);
    menuItem.addActionListener(this);
    taskMenu.add(menuItem);

    taskMenu.addSeparator();

    menuItem = new JMenuItem("Add Time", KeyEvent.VK_A);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    menuItem.setActionCommand(ACTION_ADDTIME);
    menuItem.addActionListener(this);
    taskMenu.add(menuItem);

    menuItem = new JMenuItem("Find Task", KeyEvent.VK_F);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    menuItem.setActionCommand(ACTION_FINDTASK);
    menuItem.addActionListener(this);
    taskMenu.add(menuItem);

    return taskMenu;
}

From source file:com.googlecode.bpmn_simulator.gui.BPMNSimulatorFrame.java

private JMenu createMenuHelp() {
    final JMenu menuHelp = new JMenu(Messages.getString("Menu.help")); //$NON-NLS-1$

    final JMenuItem menuHelpAbout = new JMenuItem(Messages.getString("Menu.about")); //$NON-NLS-1$
    menuHelpAbout.setMnemonic(KeyEvent.VK_A);
    menuHelpAbout.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.ALT_MASK));
    menuHelpAbout.addActionListener(new ActionListener() {
        @Override//from w w  w . j a v  a 2 s.c  o m
        public void actionPerformed(final ActionEvent e) {
            showAboutDialog();
        }
    });
    menuHelp.add(menuHelpAbout);

    return menuHelp;
}

From source file:gdt.jgui.entity.JEntityDigestDisplay.java

private JPopupMenu getFacetComponentMenu() {

    JPopupMenu popup = new JPopupMenu();
    JMenuItem openItem = new JMenuItem("Open");
    popup.add(openItem);/*ww  w. j av a2  s.  c o  m*/
    openItem.setHorizontalTextPosition(JMenuItem.RIGHT);
    openItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            //System.out.println("JEmailFacetOpenItem:edit:digest locator="+digestLocator$);
            try {
                Properties locator = Locator.toProperties(selection$);
                String entihome$ = locator.getProperty(Entigrator.ENTIHOME);
                String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);
                JEntityFacetPanel efp = new JEntityFacetPanel();
                String efpLocator$ = efp.getLocator();
                efpLocator$ = Locator.append(efpLocator$, Entigrator.ENTIHOME, entihome$);
                efpLocator$ = Locator.append(efpLocator$, EntityHandler.ENTITY_KEY, entityKey$);
                //System.out.println("JEmailFacetOpenItem:edit:text editor="+teLocator$);
                JConsoleHandler.execute(console, efpLocator$);
            } catch (Exception ee) {
                Logger.getLogger(JEntityDigestDisplay.class.getName()).info(ee.toString());
            }
        }
    });
    return popup;
}

From source file:coolmap.application.widget.impl.WidgetUserGroup.java

private void initPopup() {
    JPopupMenu popup = new JPopupMenu();
    table.setComponentPopupMenu(popup);//from w  ww  .j ava  2 s  . c  om

    JMenuItem item = new JMenuItem("Rename");
    popup.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            List<String> groupNames = getSelectedGroups();
            if (groupNames.isEmpty()) {
                return;
            }

            String returnVal = JOptionPane.showInputDialog(CoolMapMaster.getCMainFrame(),
                    "Please provide a new name:");
            if (returnVal == null || returnVal.length() == 0) {
                returnVal = "Untitled";
            }

            int counter = 0;
            String newName;
            for (String groupName : groupNames) {
                if (counter == 0) {
                    newName = returnVal;
                } else {
                    newName = returnVal + "_" + counter;
                }

                //new name must not exist
                int subCounter = 0;
                String name = newName;
                while (nodeGroups.containsKey(name)) {
                    subCounter++;
                    name = newName + "_" + subCounter;
                }
                newName = name;

                Color c = nodeColor.get(groupName);
                Set<VNode> nodes = new HashSet(nodeGroups.get(groupName));

                nodeColor.remove(groupName);
                nodeGroups.removeAll(groupName);

                nodeColor.put(newName, c);
                nodeGroups.putAll(newName, nodes);

                //                    System.out.println(newName + " " + c + " " + nodes);
                counter++;
            }

            updateTable();

        }
    });
    ////////////////////////////////////////////////////////////////////////

    //remove operations
    item = new JMenuItem("Remove");
    popup.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            List<String> groupNames = getSelectedGroups();
            for (String group : groupNames) {
                nodeColor.remove(group);
                nodeGroups.removeAll(group);
            }
            updateTable();
        }
    });

    //add separarator
    popup.addSeparator();
    JMenu insertRow = new JMenu("Add selected to row");
    popup.add(insertRow);

    JMenu insertColumn = new JMenu("Add selected to column");
    popup.add(insertColumn);

    item = new JMenuItem("prepend", UI.getImageIcon("prependRow"));
    insertRow.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            insertRow(0);
        }
    });

    item = new JMenuItem("prepend", UI.getImageIcon("prependColumn"));
    insertColumn.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            insertColumn(0);
        }
    });

    item = new JMenuItem("insert", UI.getImageIcon("insertRow"));
    item.setToolTipText("Insert selected groups to the selected region in the active coolmap view");
    insertRow.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            CoolMapObject obj = CoolMapMaster.getActiveCoolMapObject();
            if (obj == null) {
                return;
            }

            int index = 0;
            ArrayList selectedRows = obj.getCoolMapView().getSelectedRows();
            if (!selectedRows.isEmpty()) {
                index = ((Range<Integer>) selectedRows.iterator().next()).lowerEndpoint();
            }
            insertRow(index);
        }
    });

    item = new JMenuItem("insert", UI.getImageIcon("insertColumn"));
    item.setToolTipText("Insert selected groups to the selected region in the active coolmap view");
    insertColumn.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            CoolMapObject obj = CoolMapMaster.getActiveCoolMapObject();
            if (obj == null) {
                return;
            }

            int index = 0;
            ArrayList selectedColumns = obj.getCoolMapView().getSelectedColumns();
            if (!selectedColumns.isEmpty()) {
                index = ((Range<Integer>) selectedColumns.iterator().next()).lowerEndpoint();
            }
            insertColumn(index);
        }
    });

    item = new JMenuItem("append", UI.getImageIcon("appendRow"));
    insertRow.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (CoolMapMaster.getActiveCoolMapObject() == null) {
                return;
            }
            insertRow(CoolMapMaster.getActiveCoolMapObject().getViewNumRows());
        }
    });

    item = new JMenuItem("append", UI.getImageIcon("appendColumn"));
    insertColumn.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (CoolMapMaster.getActiveCoolMapObject() == null) {
                return;
            }
            insertColumn(CoolMapMaster.getActiveCoolMapObject().getViewNumColumns());
        }
    });

    item = new JMenuItem("replace", UI.getImageIcon("replaceRow"));
    insertRow.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            replaceRow();
        }
    });

    item = new JMenuItem("replace", UI.getImageIcon("replaceColumn"));
    insertColumn.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            replaceColumn();
        }
    });
}

From source file:OptPaneComparison.java

public OptPaneComparison(final String message) {
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    final int msgType = JOptionPane.QUESTION_MESSAGE;
    final int optType = JOptionPane.OK_CANCEL_OPTION;
    final String title = message;

    setSize(350, 200);/*www  .java2  s  .c  o  m*/

    // Create a desktop for internal frames
    final JDesktopPane desk = new JDesktopPane();
    setContentPane(desk);

    // Add a simple menu bar
    JMenuBar mb = new JMenuBar();
    setJMenuBar(mb);

    JMenu menu = new JMenu("Dialog");
    JMenu imenu = new JMenu("Internal");
    mb.add(menu);
    mb.add(imenu);
    final JMenuItem construct = new JMenuItem("Constructor");
    final JMenuItem stat = new JMenuItem("Static Method");
    final JMenuItem iconstruct = new JMenuItem("Constructor");
    final JMenuItem istat = new JMenuItem("Static Method");
    menu.add(construct);
    menu.add(stat);
    imenu.add(iconstruct);
    imenu.add(istat);

    // Create our JOptionPane. We're asking for input, so we call
    // setWantsInput.
    // Note that we cannot specify this via constructor parameters.
    optPane = new JOptionPane(message, msgType, optType);
    optPane.setWantsInput(true);

    // Add a listener for each menu item that will display the appropriate
    // dialog/internal frame
    construct.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {

            // Create and display the dialog
            JDialog d = optPane.createDialog(desk, title);
            d.setVisible(true);

            respond(getOptionPaneValue());
        }
    });

    stat.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            String s = JOptionPane.showInputDialog(desk, message, title, msgType);
            respond(s);
        }
    });

    iconstruct.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {

            // Create and display the dialog
            JInternalFrame f = optPane.createInternalFrame(desk, title);
            f.setVisible(true);

            // Listen for the frame to close before getting the value from
            // it.
            f.addPropertyChangeListener(new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent ev) {
                    if ((ev.getPropertyName().equals(JInternalFrame.IS_CLOSED_PROPERTY))
                            && (ev.getNewValue() == Boolean.TRUE)) {
                        respond(getOptionPaneValue());
                    }
                }
            });
        }
    });

    istat.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            String s = JOptionPane.showInternalInputDialog(desk, message, title, msgType);
            respond(s);
        }
    });
}

From source file:gdt.jgui.entity.JEntityDigestDisplay.java

private JPopupMenu getCollapsePopupMenu() {
    //System.out.println("JEntityDigestDisplay:getCollapsePopupMenu:selection="+Locator.remove(selection$, Locator.LOCATOR_ICON));
    JPopupMenu popup = new JPopupMenu();
    JMenuItem collapseItem = new JMenuItem("Collapse");
    popup.add(collapseItem);/* w  w  w  . jav  a2 s.  c  o  m*/
    collapseItem.setHorizontalTextPosition(JMenuItem.RIGHT);
    collapseItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
                int cnt = node.getChildCount();
                Stack<DefaultMutableTreeNode> s = new Stack<DefaultMutableTreeNode>();
                if (cnt > 0) {
                    DefaultMutableTreeNode child;
                    for (int i = 0; i < cnt; i++) {
                        child = (DefaultMutableTreeNode) node.getChildAt(i);
                        s.push(child);
                    }
                }
                while (!s.isEmpty())
                    tree.collapsePath(new TreePath(s.pop().getPath()));
            } catch (Exception ee) {
            }
        }
    });
    return popup;
}