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:eu.europa.ec.markt.dss.applet.view.validationpolicy.EditView.java

private void valueLeafActionEdit(final MouseEvent mouseEvent, final TreePath selectedPath,
        final XmlDomAdapterNode clickedItem, final JTree tree) {

    final JPopupMenu popup = new JPopupMenu();

    // Basic type : edit
    final JMenuItem menuItem = new JMenuItem(ResourceUtils.getI18n("EDIT"));
    menuItem.addActionListener(new ActionListener() {
        @Override//  w  w w  .  jav  a2  s. c  o m
        public void actionPerformed(ActionEvent actionEvent) {
            final String newValue = JOptionPane.showInputDialog(ResourceUtils.getI18n("EDIT"),
                    clickedItem.node.getNodeValue());
            if (newValue != null) {
                try {
                    if (clickedItem.node instanceof Attr) {
                        ((Attr) clickedItem.node).setValue(newValue);
                    } else {
                        clickedItem.node.setNodeValue(newValue);
                    }
                    //clickedItem.setNewValue(newValue);
                } catch (NumberFormatException e) {
                    showErrorMessage(newValue, tree);
                }
                validationPolicyTreeModel.fireTreeChanged(selectedPath);
            }
        }
    });
    popup.add(menuItem);

    popup.show(tree, mouseEvent.getX(), mouseEvent.getY());

}

From source file:it.unibas.spicygui.controllo.provider.MyPopupProviderJoinCondition.java

private void createPopupMenu() {
    bindingGroup = new BindingGroup();

    menu = new JPopupMenu("Popup menu");
    JMenuItem item1;
    JCheckBoxMenuItem item2;/*from   ww  w  .  j a  v a 2 s .  com*/
    JCheckBoxMenuItem item3;
    JCheckBoxMenuItem item4;

    item1 = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.GENERIC_DELETE));
    item1.setActionCommand(DELETE);
    item1.addActionListener(this);

    item2 = new JCheckBoxMenuItem(NbBundle.getMessage(Costanti.class, Costanti.TOGGLE_MANDATORY));
    Binding binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, joinCondition,
            ELProperty.create("${mandatory}"), item2, BeanProperty.create("selected"));
    bindingGroup.addBinding(binding);
    item2.setActionCommand(TOGGLE_MANDATORY);
    item2.addActionListener(this);

    item3 = new JCheckBoxMenuItem(NbBundle.getMessage(Costanti.class, Costanti.TOGGLE_FOREIGN));
    Binding binding2 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, joinCondition,
            ELProperty.create("${monodirectional}"), item3, BeanProperty.create("selected"));
    bindingGroup.addBinding(binding2);
    item3.setActionCommand(TOGGLE_FOREIGN);
    item3.addActionListener(this);

    item4 = new JCheckBoxMenuItem(NbBundle.getMessage(Costanti.class, Costanti.TOGGLE_MATCH_STRING));
    Binding binding3 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, joinCondition,
            ELProperty.create("${matchString}"), item4, BeanProperty.create("selected"));
    bindingGroup.addBinding(binding3);
    item4.setActionCommand(TOGGLE_MATCH_STRING);
    item4.addActionListener(this);

    menu.add(item1);
    menu.add(item2);
    menu.add(item3);
    menu.add(item4);

    bindingGroup.bind();
}

From source file:it.unibas.spicygui.controllo.provider.composition.MyPopupProviderWidgetChainComposition.java

private void createPopupMenu() {
    menu = new JPopupMenu("Popup menu");

    JMenuItem itemDeleteWidget;

    itemDeleteWidget = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.DELETE_WIDGET_COMPOSITION));
    itemDeleteWidget.setActionCommand(DELETE);
    itemDeleteWidget.addActionListener(this);
    menu.add(itemDeleteWidget);/*w  ww  . j av a  2  s.c  om*/

    itemLoadDataSource = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.LOAD_DATASOURCE_FOR_CHAIN));
    itemLoadDataSource.setActionCommand(LOAD);
    itemLoadDataSource.addActionListener(this);
    menu.add(itemLoadDataSource);
}

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

@Override
public void doPopup(MouseEvent e, int row, final Object itemId) {
    JPopupMenu popup = new JPopupMenu();

    if (callback.getVisualizationState().isNetPlanEditable()) {
        popup.add(getAddOption());//from   w w  w .  j  ava 2  s .c  om
        for (JComponent item : getExtraAddOptions())
            popup.add(item);
    }

    if (!isTableEmpty()) {
        if (callback.getVisualizationState().isNetPlanEditable()) {
            if (row != -1) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();

                if (networkElementType == NetworkElementType.LAYER
                        && callback.getDesign().getNumberOfLayers() == 1) {

                } else {
                    JMenuItem removeItem = new JMenuItem("Remove " + networkElementType);

                    removeItem.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            NetPlan netPlan = callback.getDesign();

                            try {
                                netPlan.removeNetworkLayer(netPlan.getNetworkLayerFromId((long) itemId));

                                final VisualizationState vs = callback.getVisualizationState();
                                Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer, Boolean>> res = vs
                                        .suggestCanvasUpdatedVisualizationLayerInfoForNewDesign(
                                                new HashSet<>(callback.getDesign().getNetworkLayers()));
                                vs.setCanvasLayerVisibilityAndOrder(callback.getDesign(), res.getFirst(),
                                        res.getSecond());
                                callback.updateVisualizationAfterChanges(
                                        Sets.newHashSet(NetworkElementType.LAYER));
                                callback.getUndoRedoNavigationManager().addNetPlanChange();
                            } catch (Throwable ex) {
                                ErrorHandling.addErrorOrException(ex, getClass());
                                ErrorHandling.showErrorDialog("Unable to remove " + networkElementType);
                            }
                        }
                    });

                    popup.add(removeItem);
                }

                addPopupMenuAttributeOptions(e, row, itemId, popup);
            }
            List<JComponent> extraOptions = getExtraOptions(row, itemId);
            if (!extraOptions.isEmpty()) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();
                for (JComponent item : extraOptions)
                    popup.add(item);
            }
        }

        List<JComponent> forcedOptions = getForcedOptions();
        if (!forcedOptions.isEmpty()) {
            if (popup.getSubElements().length > 0)
                popup.addSeparator();
            for (JComponent item : forcedOptions)
                popup.add(item);
        }
    }

    popup.show(e.getComponent(), e.getX(), e.getY());
}

From source file:gdt.jgui.entity.email.JEmailFacetOpenItem.java

@Override
public JPopupMenu getPopupMenu(final String digestLocator$) {

    JPopupMenu popup = new JPopupMenu();
    JMenuItem editItem = new JMenuItem("Edit");
    popup.add(editItem);//w w w. ja  v  a 2  s  . c o m
    editItem.setHorizontalTextPosition(JMenuItem.RIGHT);
    editItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            //System.out.println("JEmailFacetOpenItem:edit:digest locator="+digestLocator$);
            try {
                Properties locator = Locator.toProperties(digestLocator$);
                String entihome$ = locator.getProperty(Entigrator.ENTIHOME);
                String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);
                Entigrator entigrator = console.getEntigrator(entihome$);
                Sack entity = entigrator.getEntityAtKey(entityKey$);
                String email$ = entity.getProperty("email");
                JTextEditor te = new JTextEditor();
                String teLocator$ = te.getLocator();
                teLocator$ = Locator.append(teLocator$, JTextEditor.TEXT, email$);
                String foiLocator$ = getLocator();
                foiLocator$ = Locator.append(foiLocator$, BaseHandler.HANDLER_METHOD, METHOD_RESPONSE);
                foiLocator$ = Locator.append(foiLocator$, JRequester.REQUESTER_ACTION, ACTION_DIGEST_CALL);
                foiLocator$ = Locator.append(foiLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR,
                        Locator.compressText(digestLocator$));
                teLocator$ = Locator.append(teLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR,
                        Locator.compressText(foiLocator$));
                //System.out.println("JEmailFacetOpenItem:edit:text editor="+teLocator$);
                JConsoleHandler.execute(console, teLocator$);
            } catch (Exception ee) {
                Logger.getLogger(JEmailFacetOpenItem.class.getName()).info(ee.toString());
            }
        }
    });
    return popup;

}

From source file:gdt.jgui.entity.phone.JPhoneFacetOpenItem.java

@Override
public JPopupMenu getPopupMenu(final String digestLocator$) {
    JPopupMenu popup = new JPopupMenu();
    JMenuItem editItem = new JMenuItem("Edit");
    popup.add(editItem);//w  w  w .  j ava  2 s. co m
    editItem.setHorizontalTextPosition(JMenuItem.RIGHT);
    editItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("JPhoneFacetOpenItem:edit:digest locator=" + digestLocator$);
            try {
                Properties locator = Locator.toProperties(digestLocator$);
                String entihome$ = locator.getProperty(Entigrator.ENTIHOME);
                String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);
                Entigrator entigrator = console.getEntigrator(entihome$);
                Sack entity = entigrator.getEntityAtKey(entityKey$);
                String phone$ = entity.getProperty("phone");
                JTextEditor te = new JTextEditor();
                String teLocator$ = te.getLocator();
                teLocator$ = Locator.append(teLocator$, JTextEditor.TEXT, phone$);
                String foiLocator$ = getLocator();
                foiLocator$ = Locator.append(foiLocator$, BaseHandler.HANDLER_METHOD, METHOD_RESPONSE);
                foiLocator$ = Locator.append(foiLocator$, JRequester.REQUESTER_ACTION, ACTION_DIGEST_CALL);
                foiLocator$ = Locator.append(foiLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR,
                        Locator.compressText(digestLocator$));
                teLocator$ = Locator.append(teLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR,
                        Locator.compressText(foiLocator$));
                System.out.println("JPhoneFacetOpenItem:edit:text editor=" + teLocator$);
                JConsoleHandler.execute(console, teLocator$);
            } catch (Exception ee) {
                Logger.getLogger(JPhoneFacetOpenItem.class.getName()).info(ee.toString());
            }
        }
    });
    return popup;
}

From source file:edu.harvard.mcz.imagecapture.DeterminationFrame.java

/**
 * This method initializes jTable   // w w  w  . jav a 2 s  . c om
 *    
 * @return javax.swing.JTable   
 */
private JTable getJTable() {
    if (jTableDeterminations == null) {
        jTableDeterminations = new JTable();
        DeterminationTableModel model = new DeterminationTableModel();
        jTableDeterminations.setModel(model);
        if (determinations != null) {
            jTableDeterminations.setModel(determinations);
        }

        FilteringAgentJComboBox field = new FilteringAgentJComboBox();
        jTableDeterminations.getColumnModel().getColumn(DeterminationTableModel.ROW_IDENTIFIEDBY)
                .setCellEditor(new ComboBoxCellEditor(field));

        setTableColumnEditors();

        jTableDeterminations.setRowHeight(jTableDeterminations.getRowHeight() + 4);

        jTableDeterminations.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                if (e.isPopupTrigger()) {
                    clickedOnDetsRow = ((JTable) e.getComponent()).getSelectedRow();
                    jPopupDets.show(e.getComponent(), e.getX(), e.getY());
                }
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                if (e.isPopupTrigger()) {
                    clickedOnDetsRow = ((JTable) e.getComponent()).getSelectedRow();
                    jPopupDets.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        });

        jPopupDets = new JPopupMenu();
        JMenuItem mntmDeleteRow = new JMenuItem("Delete Row");
        mntmDeleteRow.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    log.debug(clickedOnDetsRow);
                    if (clickedOnDetsRow >= 0) {
                        int ok = JOptionPane.showConfirmDialog(thisFrame, "Delete the selected determination?",
                                "Delete Determination", JOptionPane.OK_CANCEL_OPTION);
                        if (ok == JOptionPane.OK_OPTION) {
                            log.debug("deleting determination row " + clickedOnDetsRow);
                            ((DeterminationTableModel) jTableDeterminations.getModel())
                                    .deleteRow(clickedOnDetsRow);
                        } else {
                            log.debug("determination row delete canceled by user.");
                        }
                    } else {
                        JOptionPane.showMessageDialog(thisFrame, "Unable to select row to delete.");
                    }
                } catch (Exception ex) {
                    log.error(ex.getMessage());
                    JOptionPane.showMessageDialog(thisFrame,
                            "Failed to delete a determination row. " + ex.getMessage());
                }
            }
        });
        jPopupDets.add(mntmDeleteRow);

    }
    return jTableDeterminations;
}

From source file:de.tbuchloh.kiskis.gui.widgets.PasswordElement.java

private void initCreatePopup() {
    _pwdCreateMenu = new JPopupMenu();
    final JMenuItem secure = new JMenuItem(M.getString("secure_item")); //$NON-NLS-1$
    secure.addActionListener(new PasswordActionListener(PasswordFactory.SECURE));
    _pwdCreateMenu.add(secure);/*w w  w.j a  v  a 2s  . c  o  m*/

    final JMenuItem human = new JMenuItem(M.getString("human_readable_item")); //$NON-NLS-1$
    human.addActionListener(new PasswordActionListener(PasswordFactory.HUMAN_READABLE));
    _pwdCreateMenu.add(human);

    final JMenuItem template = new JMenuItem(M.createAction(this, "onCreateByTemplate"));
    _pwdCreateMenu.add(template);

    _specialActionsMenu = new JPopupMenu();
    _specialActionsMenu.add(M.createAction(this, "onCopyToClipboard"));

    _pwdField.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(final MouseEvent e) {
            if (e.getButton() != MouseEvent.BUTTON3) {
                return;
            }
            final int x = e.getX(); // _pwdField.getWidth()
            // - _specialActionsMenu.getWidth();
            final int y = e.getY();

            LOG.debug("Show context menu x=" + x + ", y=" + y);
            _specialActionsMenu.show(_pwdField, x, y);
        }
    });
}

From source file:jmap2gml.ScriptGui.java

/**
 * Formats the window, initializes the JMap2Script object, and sets up all
 * the necessary events.//from   ww w  . java2 s .  c  o  m
 */
public ScriptGui() {
    setTitle("jmap to gml script converter");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    getContentPane().setLayout(new GridBagLayout());

    this.addWindowListener(new WindowListener() {
        @Override
        public void windowOpened(WindowEvent we) {
        }

        @Override
        public void windowClosing(WindowEvent we) {
            saveConfig();
        }

        @Override
        public void windowClosed(WindowEvent we) {
        }

        @Override
        public void windowIconified(WindowEvent we) {
        }

        @Override
        public void windowDeiconified(WindowEvent we) {
        }

        @Override
        public void windowActivated(WindowEvent we) {
        }

        @Override
        public void windowDeactivated(WindowEvent we) {
        }
    });

    GridBagConstraints c = new GridBagConstraints();

    setResizable(true);
    setIconImage((new ImageIcon("spikeup.png")).getImage());

    jta = new JTextArea(38, 30);

    loadConfig();

    JScrollPane jsp = new JScrollPane(jta);
    jsp.setRowHeaderView(new TextLineNumber(jta));
    jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    jsp.setSize(jsp.getWidth(), 608);

    // menu bar
    JMenuBar menubar = new JMenuBar();

    // file menu
    JMenu file = new JMenu("File");

    // load button
    JMenuItem load = new JMenuItem("Load jmap");
    load.addActionListener(ae -> {
        JFileChooser fileChooser = new JFileChooser(prevDirectory);
        fileChooser.setFileFilter(new FileNameExtensionFilter("jmap file", "jmap", "jmap"));

        int returnValue = fileChooser.showOpenDialog(null);

        if (returnValue == JFileChooser.APPROVE_OPTION) {
            File selectedFile = fileChooser.getSelectedFile();

            prevDirectory = selectedFile.getAbsolutePath();

            jm2s = new ScriptFromJmap(selectedFile.getPath(), false);

            jta.setText("");
            jta.append(jm2s.toString());
            jta.setCaretPosition(0);

            writeFile.setEnabled(true);

            drawPanel.setItems(jta.getText().split("\n"));
        }
    });

    // add load to file menu
    file.add(load);

    // button to save script to file
    writeFile = new JMenuItem("Write file");
    writeFile.addActionListener(ae -> {
        if (jm2s != null) {
            PrintWriter out;
            try {
                File f = new File(
                        jm2s.getFileName().substring(0, jm2s.getFileName().lastIndexOf(".jmap")) + ".gml");
                out = new PrintWriter(f);
                out.append(jm2s.toString());
                out.close();
            } catch (FileNotFoundException ex) {
                Logger.getLogger(ScriptGui.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
    writeFile.setEnabled(false);

    JMenuItem gmx = new JMenuItem("Export as gmx");
    gmx.addActionListener(ae -> {
        String fn = String.format("%s.room.gmx", prevDirectory);

        JFileChooser fc = new JFileChooser(prevDirectory);
        fc.setSelectedFile(new File(fn));
        fc.setFileFilter(new FileNameExtensionFilter("Game Maker XML", "gmx", "gmx"));
        fc.showDialog(null, "Save");
        File f = fc.getSelectedFile();

        if (f != null) {
            try {
                GMX.itemsToGMX(drawPanel.items, new FileOutputStream(f));
            } catch (FileNotFoundException ex) {
                Logger.getLogger(ScriptGui.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });

    // add to file menu
    file.add(writeFile);
    file.add(gmx);

    // add file menu to the menubar
    menubar.add(file);

    // Edit menu

    // display menu
    JMenu display = new JMenu("Display");

    JMenuItem update = new JMenuItem("Update");

    update.addActionListener(ae -> {
        drawPanel.setItems(jta.getText().split("\n"));
    });

    display.add(update);

    JMenuItem gridToggle = new JMenuItem("Toggle Grid");
    gridToggle.addActionListener(ae -> {
        drawPanel.toggleGrid();
    });
    display.add(gridToggle);

    JMenuItem gridOptions = new JMenuItem("Modify Grid");
    gridOptions.addActionListener(ae -> {
        drawPanel.modifyGrid();
    });
    display.add(gridOptions);

    menubar.add(display);

    // sets the menubar
    setJMenuBar(menubar);

    // add the text area to the window
    c.gridx = 0;
    c.gridy = 0;
    add(jsp, c);

    // initialize the preview panel
    drawPanel = new Preview(this);
    JScrollPane scrollPane = new JScrollPane(drawPanel);

    // add preview panel to the window
    c.gridx = 1;
    c.gridwidth = 2;
    add(scrollPane, c);

    pack();
    setMinimumSize(this.getSize());
    setLocationRelativeTo(null);
    setVisible(true);
    drawPanel.setItems(jta.getText().split("\n"));
}

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

public DisplayAAS() {
    dbAuswahlAAS = JKabelS.getSpringContext().getBean(DBAuswahlAAS.class);

    setTitle("jKabel");

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(south = getSouth(), BorderLayout.SOUTH);

    //File menue/*from ww w  .j  a  v  a2s. c o  m*/
    JMenu menue = new JMenu("File");
    menue.add(edit);
    menue.add(search);

    menue.add(auchf);

    menue.addSeparator();
    menue.add(getjTypSortMenu());
    menue.add(getjTrommelSortMenu());
    menue.addSeparator();
    menue.add(exit);

    edit.addActionListener(this);
    search.addActionListener(this);
    exit.addActionListener(this);
    auchf.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            try {
                ConfigReader.getInstance().setZeigeAlle(auchf.isSelected());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });

    //License and more
    JMenu lMenue = new JMenu("Hilfe");
    lMenue.add(help);
    lMenue.add(gpl);

    help.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            new HelpAAS();
        }
    });
    gpl.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            new GPLAAS();
        }
    });

    // und zusammenbauen
    menuBar.add(menue);
    menuBar.add(lMenue);
    menuBar.add(new Version());

    // Trommelsuchband
    JMenuItem sbt = new JMenuItem("Suchen nach Trommelnummer");
    menuBar.add(sbt);
    sbt.addActionListener(JKabelS.getSpringContext().getBean(SearchTrommelNrAAS.class));
    JKabelS.getSpringContext().getBean(SearchTrommelNrAAS.class).setVisible(false);
    getContentPane().add(JKabelS.getSpringContext().getBean(SearchTrommelNrAAS.class), BorderLayout.NORTH);

    setJMenuBar(menuBar);

    IDBWrapper db = dbAuswahlAAS.getDBWrapper();

    bearbeitenPanel = (JPanel) JKabelS.getSpringContext().getBean("bearbeitenPanel");

    if (db == null) {
        center.add(new JLabel("Es konnte keine Verbindung zur DB hergestellt werden."));
        center.add(new JLabel(
                "Wenn !!!sicher!!! ist das kein anderer auf der DB arbeitet die lock.lck Datei lschen"));
        DisplayAAS d = this;
        getContentPane().add(center, BorderLayout.CENTER);
    } else {
        setDb(db);
    }

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
    setVisible(true);
}