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:me.mayo.telnetkek.MainPanel.java

public final void setupTablePopup() {
    this.tblPlayers.addMouseListener(new MouseAdapter() {
        @Override/*from w w w .  j  a v  a  2s  . c om*/
        public void mouseReleased(final MouseEvent mouseEvent) {
            final JTable table = MainPanel.this.tblPlayers;

            final int r = table.rowAtPoint(mouseEvent.getPoint());
            if (r >= 0 && r < table.getRowCount()) {
                table.setRowSelectionInterval(r, r);
            } else {
                table.clearSelection();
            }

            final int rowindex = table.getSelectedRow();
            if (rowindex < 0) {
                return;
            }

            if ((SwingUtilities.isRightMouseButton(mouseEvent) || mouseEvent.isControlDown())
                    && mouseEvent.getComponent() instanceof JTable) {
                final PlayerInfo player = getSelectedPlayer();
                if (player != null) {
                    final JPopupMenu popup = new JPopupMenu(player.getName());

                    final JMenuItem header = new JMenuItem("Apply action to " + player.getName() + ":");
                    header.setEnabled(false);
                    popup.add(header);

                    popup.addSeparator();

                    final ActionListener popupAction = (ActionEvent actionEvent) -> {
                        Object _source = actionEvent.getSource();
                        if (_source instanceof PlayerListPopupItem_Command) {
                            final PlayerListPopupItem_Command source = (PlayerListPopupItem_Command) _source;
                            final String output = source.getCommand().buildOutput(source.getPlayer(), true);
                            MainPanel.this.getConnectionManager().sendDelayedCommand(output, true, 100);
                        } else if (_source instanceof PlayerListPopupItem) {
                            final PlayerListPopupItem source = (PlayerListPopupItem) _source;

                            final PlayerInfo _player = source.getPlayer();

                            switch (actionEvent.getActionCommand()) {
                            case "Copy IP": {
                                copyToClipboard(_player.getIp());
                                MainPanel.this.writeToConsole(
                                        new ConsoleMessage("Copied IP to clipboard: " + _player.getIp()));
                                break;
                            }
                            case "Copy Name": {
                                copyToClipboard(_player.getName());
                                MainPanel.this.writeToConsole(
                                        new ConsoleMessage("Copied name to clipboard: " + _player.getName()));
                                break;
                            }
                            case "Copy UUID": {
                                copyToClipboard(_player.getUuid());
                                MainPanel.this.writeToConsole(
                                        new ConsoleMessage("Copied UUID to clipboard: " + _player.getUuid()));
                                break;
                            }
                            }
                        }
                    };

                    TelnetKek.config.getCommands().stream().map(
                            (command) -> new PlayerListPopupItem_Command(command.getName(), player, command))
                            .map((item) -> {
                                item.addActionListener(popupAction);
                                return item;
                            }).forEach((item) -> {
                                popup.add(item);
                            });

                    popup.addSeparator();

                    JMenuItem item;

                    item = new PlayerListPopupItem("Copy Name", player);
                    item.addActionListener(popupAction);
                    popup.add(item);

                    item = new PlayerListPopupItem("Copy IP", player);
                    item.addActionListener(popupAction);
                    popup.add(item);

                    item = new PlayerListPopupItem("Copy UUID", player);
                    item.addActionListener(popupAction);
                    popup.add(item);

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

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

private JMenuItem getAddOption() {
    final NetworkElementType networkElementType = NetworkElementType.DEMAND;
    JMenuItem addItem = new JMenuItem("Add " + networkElementType);
    addItem.addActionListener(new ActionListener() {
        @Override/* ww  w.  j a v  a  2 s .  co m*/
        public void actionPerformed(ActionEvent e) {
            NetPlan netPlan = callback.getDesign();

            try {
                createLinkDemandGUI(networkElementType, callback);
            } catch (Throwable ex) {
                ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to add " + networkElementType);
            }
        }
    });

    if (callback.getDesign().getNumberOfNodes() < 2)
        addItem.setEnabled(false);

    return addItem;

}

From source file:burlov.ultracipher.swing.SwingGuiApplication.java

private JMenuBar createMenuBar() {
    JMenuBar bar = new JMenuBar();
    JMenu menu = null;//from w ww.j  a  v  a2s  . com
    /*
     * 'File' Menue
     */
    menu = new JMenu("File");
    menu.setMnemonic(KeyEvent.VK_F);
    bar.add(menu);

    JMenuItem item = new JMenuItem("Save database");
    item.setAccelerator(KeyStroke.getKeyStroke("control S"));
    item.setMnemonic(KeyEvent.VK_S);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            saveDatabase();
        }
    });
    menu.add(item);

    item = new JMenuItem("Download database");
    item.setMnemonic(KeyEvent.VK_L);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            downloadAndMergeData();
        }
    });
    menu.add(item);

    item = new JMenuItem("Edit sync account");
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            editSyncAccount();
        }
    });
    menu.add(item);
    menu.add(new JSeparator());

    JMenu submenu = new JMenu("Import");
    menu.add(submenu);

    item = new JMenuItem("From CSV");
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            importCSV();
        }
    });
    submenu.add(item);

    submenu = new JMenu("Export");
    menu.add(submenu);

    item = new JMenuItem("As CSV");
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            exportCSV();
        }
    });
    submenu.add(item);
    item = new JMenuItem("Change passphrase");
    menu.add(item);
    item.addActionListener(new ActionListener() {

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

    /*
     * 'Edit' Menue
     */
    menu = new JMenu("Edit");
    menu.setMnemonic(KeyEvent.VK_E);
    bar.add(menu);
    item = menu.add(mainPanel.getNewEntryAction());
    item.setMnemonic(KeyEvent.VK_N);
    item = menu.add(mainPanel.getDeleteEntryAction());
    item.setMnemonic(KeyEvent.VK_D);

    menu.add(new JSeparator());

    menu = new JMenu("Tools");
    // item = new JMenuItem("Passwort generator");
    // menu.add(item);
    // item.addActionListener(new ActionListener() {
    //
    // @Override
    // public void actionPerformed(ActionEvent e) {
    // passGenerator.setVisible(false);
    // passGenerator.setLocationRelativeTo(getMainFrame());
    // passGenerator.setVisible(true);
    // }
    // });
    item = new JMenuItem("Screen keyboard");
    menu.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            screenKeyboard.setLocationRelativeTo(getMainFrame());
            screenKeyboard.setVisible(true);

        }
    });
    item = new JMenuItem("File digester");
    menu.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            digester.setLocationRelativeTo(getMainFrame());
            digester.setVisible(true);

        }
    });
    bar.add(menu);
    /*
     * 'Help' Menue
     */
    menu = new JMenu("Help");
    menu.setMnemonic(KeyEvent.VK_H);
    bar.add(menu);

    item = new JMenuItem("Performance test");
    menu.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            measurePerformance();
        }
    });
    item = new JMenuItem("System info");
    menu.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            showSystemInfo();
        }
    });
    item = new JMenuItem("About");
    menu.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            String text = "<html>Ultracipher 6.1<br>(C) Copyright 2015 Paul Burlov<br><br>"
                    + "Encryption strength: 768Bit (6 x 128Bit keys)<br>Cipher cascade: AES/Twofish/Serpent/CAST6/SEED/Camellia"
                    + "<br>Encryption mode: Two pass CBC"
                    + "<br>Key derivation algorithm: SCrypt with N=2^14,P=8,R=1<br><br> "
                    + "This product includes software developed by the<br>"
                    + "<ul><li>Apache Software Foundation "
                    + "<a href='http://www.apache.org'>http://www.apache.org</a>"
                    + "<li>Legion of the Bouncy Castle <a href='http://bouncycastle.org/'>http://bouncycastle.org</a>"
                    + "<li>Project SwingX" + "<li>Bytecode Pty Ltd." + "</ul></html>";
            JOptionPane.showMessageDialog(getMainFrame(), text, "", JOptionPane.INFORMATION_MESSAGE,
                    getAppIcon());
        }
    });
    bar.add(Box.createHorizontalGlue());
    menu = new JMenu("Keyboard");
    ButtonGroup group = new ButtonGroup();
    JRadioButtonMenuItem radioitem = new JRadioButtonMenuItem("System");
    radioitem.setSelected(true);
    group.add(radioitem);
    radioitem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            translator.resetMapping();
        }
    });
    menu.add(radioitem);
    radioitem = new JRadioButtonMenuItem("Futhark runes");
    group.add(radioitem);
    radioitem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            translator.initForFuthark();
        }
    });
    menu.add(radioitem);
    radioitem = new JRadioButtonMenuItem("Anglo-Saxon runes");
    group.add(radioitem);
    radioitem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            translator.initForAngloSaxon();
        }
    });
    menu.add(radioitem);
    bar.add(menu);
    // bar.add(Box.createHorizontalGlue());
    // bar.add(new PassGeneratorPanel());
    return bar;
}

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

private void showContextMenu(MouseEvent e) {
    final FormDataObjIFace selection = iconTray.getSelectedValue();

    if (selection instanceof ObjectAttachmentIFace<?>) {
        final File original = AttachmentUtils
                .getAttachmentFile(((ObjectAttachmentIFace) selection).getAttachment());

        JPopupMenu popup = new JPopupMenu();
        JMenuItem menuItem = new JMenuItem(UIRegistry.getResourceString("AttachmentUtils.OPEN_IN_EV"));
        menuItem.addActionListener(new ActionListener() {
            @Override//from w  w  w . j  a  va 2  s  . c  o  m
            public void actionPerformed(ActionEvent actionEvent) {
                try {
                    AttachmentUtils.openFile(original);
                } catch (Exception ex) {
                    UIRegistry.showLocalizedMsg("AttachmentUtils.NEV_TITLE", "AttachmentUtils.NEV_MSG");
                }
            }
        });
        popup.add(menuItem);
        popup.show(e.getComponent(), e.getX(), e.getY());
    }
}

From source file:org.gumtree.vis.awt.time.TimePlotPanel.java

@Override
protected void displayPopupMenu(int x, int y) {
    LegendTitle legend = getChart().getLegend();
    if (legend != null) {
        boolean isVisable = legend.isVisible();
        RectangleEdge location = legend.getPosition();
        if (isVisable) {
            if (location.equals(RectangleEdge.BOTTOM)) {
                legendBottom.setSelected(true);
                legendNone.setSelected(false);
                legendRight.setSelected(false);
            } else if (isVisable && location.equals(RectangleEdge.RIGHT)) {
                legendRight.setSelected(true);
                legendNone.setSelected(false);
                legendBottom.setSelected(false);
            }//from   w  w  w .  j a va2s  .  c  o m
        } else {
            legendNone.setSelected(true);
            legendRight.setSelected(false);
            legendBottom.setSelected(false);
        }
    }
    curveManagementMenu.removeAll();
    curveResetMenu.removeAll();
    if (getXYPlot().getDatasetCount() > 0) {
        curveManagementMenu.setEnabled(true);
        curveResetMenu.setEnabled(true);

        JMenuItem focusNoneCurveItem = new JRadioButtonMenuItem();
        focusNoneCurveItem.setText("None");
        focusNoneCurveItem.setActionCommand(UNFOCUS_CURVE_COMMAND);
        focusNoneCurveItem.addActionListener(this);
        curveManagementMenu.add(focusNoneCurveItem);

        JMenuItem resetAllCurveItem = new JMenuItem();
        resetAllCurveItem.setText("RESET ALL");
        resetAllCurveItem.setActionCommand(RESET_ALL_CURVE_COMMAND);
        resetAllCurveItem.addActionListener(this);
        curveResetMenu.add(resetAllCurveItem);

        boolean isCurveFocused = false;
        for (int j = 0; j < getXYPlot().getDatasetCount(); j++) {
            XYDataset dataset = getChart().getXYPlot().getDataset(j);
            if (dataset != null) {
                for (int i = 0; i < dataset.getSeriesCount(); i++) {
                    String seriesKey = (String) dataset.getSeriesKey(i);
                    JMenuItem focusOnCurveItem = new JRadioButtonMenuItem();
                    focusOnCurveItem.setText(seriesKey);
                    focusOnCurveItem.setActionCommand(FOCUS_ON_COMMAND + "-" + seriesKey);
                    focusOnCurveItem.addActionListener(this);
                    curveManagementMenu.add(focusOnCurveItem);
                    if (dataset == selectedDataset && i == selectedSeriesIndex) {
                        focusOnCurveItem.setSelected(true);
                        isCurveFocused = true;
                    }

                    JMenuItem resetCurveItem = new JMenuItem();
                    resetCurveItem.setText("Reset " + seriesKey);
                    resetCurveItem.setActionCommand(RESET_CURVE_COMMAND + "-" + seriesKey);
                    resetCurveItem.addActionListener(this);
                    curveResetMenu.add(resetCurveItem);

                }
            }
        }
        if (!isCurveFocused) {
            focusNoneCurveItem.setSelected(true);
        }
    } else {
        curveManagementMenu.setEnabled(false);
        curveResetMenu.setEnabled(false);
    }

    showMultiAxesMenuItem.setSelected(isShowMultiaxes());

    if (isPaused) {
        pauseMenuItem.setText("Paused");
    } else {
        pauseMenuItem.setText("Click to Pause");
    }
    pauseMenuItem.setSelected(isPaused);
    super.displayPopupMenu(x, y);
}

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

private final JMenu buildConfigurationMenu() {
    final JMenu menu = new JMenu("Configuration");
    final JMenuItem addConfig = new JMenuItem("Add");
    final JMenuItem cloneConfig = new JMenuItem("Clone");
    final JMenuItem modifyConfig = new JMenuItem("Modify");
    final JMenuItem deleteConfig = new JMenuItem("Delete");
    final JMenuItem viewNetMonitor = new JMenuItem("View Network Monitor");

    addConfig.addActionListener(new AddConfigurationActionListener());
    menu.add(addConfig);//from ww w .  j av  a  2 s  . com

    cloneConfig.addActionListener(new CloneConfigurationActionListener());
    menu.add(cloneConfig);

    modifyConfig.addActionListener(new ViewConfigurationActionListener());
    menu.add(modifyConfig);

    deleteConfig.addActionListener(new DeleteConfigurationActionListener());
    menu.add(deleteConfig);

    menu.add(new JSeparator());
    viewNetMonitor.addActionListener(new ViewNetworkMonitorActionListener());
    menu.add(viewNetMonitor);

    menu.addMenuListener(
            new ConfigurationMenuListener(addConfig, cloneConfig, deleteConfig, modifyConfig, viewNetMonitor));
    return menu;
}

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

private List<JComponent> getExtraOptions(final int row, final Object itemId) {
    List<JComponent> options = new LinkedList<JComponent>();
    final int numRows = model.getRowCount();
    final List<Node> tableVisibleNodes = getVisibleElementsInTable();

    if (itemId != null) {
        JMenuItem switchCoordinates_thisNode = new JMenuItem("Switch node coordinates from (x,y) to (y,x)");

        switchCoordinates_thisNode.addActionListener(new ActionListener() {
            @Override/*from  w  w w  .j  av  a 2  s .com*/
            public void actionPerformed(ActionEvent e) {
                NetPlan netPlan = callback.getDesign();
                Node node = netPlan.getNodeFromId((long) itemId);
                Point2D currentPosition = node.getXYPositionMap();
                node.setXYPositionMap(new Point2D.Double(currentPosition.getY(), currentPosition.getX()));
                callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE));
                callback.runCanvasOperation(ITopologyCanvas.CanvasOperation.ZOOM_ALL);
                callback.getUndoRedoNavigationManager().addNetPlanChange();
            }
        });

        options.add(switchCoordinates_thisNode);

        JMenuItem xyPositionFromAttributes_thisNode = new JMenuItem("Set node coordinates from attributes");

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

                Set<String> attributeSet = new LinkedHashSet<String>();
                Node node = netPlan.getNodeFromId((long) itemId);
                attributeSet.addAll(node.getAttributes().keySet());

                try {
                    if (attributeSet.isEmpty())
                        throw new Exception("No attribute to select");

                    final JComboBox latSelector = new WiderJComboBox();
                    final JComboBox lonSelector = new WiderJComboBox();
                    for (String attribute : attributeSet) {
                        latSelector.addItem(attribute);
                        lonSelector.addItem(attribute);
                    }

                    JPanel pane = new JPanel(new MigLayout("", "[][grow]", "[][]"));
                    pane.add(new JLabel("X-coordinate / Longitude: "));
                    pane.add(lonSelector, "growx, wrap");
                    pane.add(new JLabel("Y-coordinate / Latitude: "));
                    pane.add(latSelector, "growx, wrap");

                    while (true) {
                        int result = JOptionPane.showConfirmDialog(null, pane,
                                "Please select the attributes for coordinates", JOptionPane.OK_CANCEL_OPTION,
                                JOptionPane.QUESTION_MESSAGE);
                        if (result != JOptionPane.OK_OPTION)
                            return;

                        try {
                            String latAttribute = latSelector.getSelectedItem().toString();
                            String lonAttribute = lonSelector.getSelectedItem().toString();

                            node.setXYPositionMap(
                                    new Point2D.Double(Double.parseDouble(node.getAttribute(lonAttribute)),
                                            Double.parseDouble(node.getAttribute(latAttribute))));
                            callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE));
                            callback.getUndoRedoNavigationManager().addNetPlanChange();
                            break;
                        } catch (Throwable ex) {
                            ErrorHandling.showErrorDialog(ex.getMessage(),
                                    "Error retrieving coordinates from attributes");
                            break;
                        }
                    }
                    callback.runCanvasOperation(ITopologyCanvas.CanvasOperation.ZOOM_ALL);
                } catch (Throwable ex) {
                    ErrorHandling.showErrorDialog(ex.getMessage(),
                            "Error retrieving coordinates from attributes");
                }
            }
        });

        options.add(xyPositionFromAttributes_thisNode);

        JMenuItem nameFromAttribute_thisNode = new JMenuItem("Set node name from attribute");
        nameFromAttribute_thisNode.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                NetPlan netPlan = callback.getDesign();

                Set<String> attributeSet = new LinkedHashSet<String>();
                long nodeId = (long) itemId;
                attributeSet.addAll(netPlan.getNodeFromId(nodeId).getAttributes().keySet());

                try {
                    if (attributeSet.isEmpty())
                        throw new Exception("No attribute to select");

                    final JComboBox selector = new WiderJComboBox();
                    for (String attribute : attributeSet)
                        selector.addItem(attribute);

                    JPanel pane = new JPanel(new MigLayout("", "[][grow]", "[]"));
                    pane.add(new JLabel("Name: "));
                    pane.add(selector, "growx, wrap");

                    while (true) {
                        int result = JOptionPane.showConfirmDialog(null, pane,
                                "Please select the attribute for name", JOptionPane.OK_CANCEL_OPTION,
                                JOptionPane.QUESTION_MESSAGE);
                        if (result != JOptionPane.OK_OPTION)
                            return;

                        try {
                            String name = selector.getSelectedItem().toString();
                            netPlan.getNodeFromId(nodeId)
                                    .setName(netPlan.getNodeFromId(nodeId).getAttribute(name));
                            callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE));
                            callback.getUndoRedoNavigationManager().addNetPlanChange();

                            break;
                        } catch (Throwable ex) {
                            ErrorHandling.showErrorDialog(ex.getMessage(),
                                    "Error retrieving name from attribute");
                            break;
                        }
                    }
                } catch (Throwable ex) {
                    ErrorHandling.showErrorDialog(ex.getMessage(), "Error retrieving name from attribute");
                }
            }
        });

        options.add(nameFromAttribute_thisNode);
    }

    if (numRows > 1) {
        if (!options.isEmpty())
            options.add(new JPopupMenu.Separator());

        JMenuItem switchCoordinates_allNodes = new JMenuItem(
                "Switch all table node coordinates from (x,y) to (y,x)");

        switchCoordinates_allNodes.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                for (Node n : tableVisibleNodes) {
                    Point2D currentPosition = n.getXYPositionMap();
                    double newX = currentPosition.getY();
                    double newY = currentPosition.getX();
                    Point2D newPosition = new Point2D.Double(newX, newY);
                    n.setXYPositionMap(newPosition);
                }
                callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE));
                callback.runCanvasOperation(ITopologyCanvas.CanvasOperation.ZOOM_ALL);
                callback.getUndoRedoNavigationManager().addNetPlanChange();
            }
        });

        options.add(switchCoordinates_allNodes);

        JMenuItem xyPositionFromAttributes_allNodes = new JMenuItem(
                "Set all table node coordinates from attributes");

        xyPositionFromAttributes_allNodes.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Set<String> attributeSet = new LinkedHashSet<String>();
                for (Node node : tableVisibleNodes)
                    attributeSet.addAll(node.getAttributes().keySet());

                try {
                    if (attributeSet.isEmpty())
                        throw new Exception("No attribute to select");

                    final JComboBox latSelector = new WiderJComboBox();
                    final JComboBox lonSelector = new WiderJComboBox();
                    for (String attribute : attributeSet) {
                        latSelector.addItem(attribute);
                        lonSelector.addItem(attribute);
                    }

                    JPanel pane = new JPanel(new MigLayout("", "[][grow]", "[][]"));
                    pane.add(new JLabel("X-coordinate / Longitude: "));
                    pane.add(lonSelector, "growx, wrap");
                    pane.add(new JLabel("Y-coordinate / Latitude: "));
                    pane.add(latSelector, "growx, wrap");

                    while (true) {
                        int result = JOptionPane.showConfirmDialog(null, pane,
                                "Please select the attributes for coordinates", JOptionPane.OK_CANCEL_OPTION,
                                JOptionPane.QUESTION_MESSAGE);
                        if (result != JOptionPane.OK_OPTION)
                            return;

                        try {
                            String latAttribute = latSelector.getSelectedItem().toString();
                            String lonAttribute = lonSelector.getSelectedItem().toString();

                            for (Node node : tableVisibleNodes)
                                node.setXYPositionMap(
                                        new Point2D.Double(Double.parseDouble(node.getAttribute(lonAttribute)),
                                                Double.parseDouble(node.getAttribute(latAttribute))));
                            callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE));
                            callback.getUndoRedoNavigationManager().addNetPlanChange();
                            break;
                        } catch (Throwable ex) {
                            ErrorHandling.showErrorDialog(ex.getMessage(),
                                    "Error retrieving coordinates from attributes");
                            break;
                        }
                    }
                    callback.runCanvasOperation(ITopologyCanvas.CanvasOperation.ZOOM_ALL);
                } catch (Throwable ex) {
                    ErrorHandling.showErrorDialog(ex.getMessage(),
                            "Error retrieving coordinates from attributes");
                }
            }
        });

        options.add(xyPositionFromAttributes_allNodes);

        JMenuItem nameFromAttribute_allNodes = new JMenuItem("Set all table node names from attribute");
        nameFromAttribute_allNodes.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

                Set<String> attributeSet = new LinkedHashSet<String>();
                for (Node node : tableVisibleNodes)
                    attributeSet.addAll(node.getAttributes().keySet());

                try {
                    if (attributeSet.isEmpty())
                        throw new Exception("No attribute to select");

                    final JComboBox selector = new WiderJComboBox();
                    for (String attribute : attributeSet)
                        selector.addItem(attribute);

                    JPanel pane = new JPanel(new MigLayout("", "[][grow]", "[]"));
                    pane.add(new JLabel("Name: "));
                    pane.add(selector, "growx, wrap");

                    while (true) {
                        int result = JOptionPane.showConfirmDialog(null, pane,
                                "Please select the attribute for name", JOptionPane.OK_CANCEL_OPTION,
                                JOptionPane.QUESTION_MESSAGE);
                        if (result != JOptionPane.OK_OPTION)
                            return;

                        try {
                            String name = selector.getSelectedItem().toString();

                            for (Node node : tableVisibleNodes)
                                node.setName(node.getAttribute(name) != null ? node.getAttribute(name) : "");
                            callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE));
                            callback.getUndoRedoNavigationManager().addNetPlanChange();
                            break;
                        } catch (Throwable ex) {
                            ErrorHandling.showErrorDialog(ex.getMessage(),
                                    "Error retrieving name from attribute");
                            break;
                        }
                    }
                } catch (Throwable ex) {
                    ErrorHandling.showErrorDialog(ex.getMessage(), "Error retrieving name from attribute");
                }
            }
        });

        options.add(nameFromAttribute_allNodes);
    }

    return options;
}

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

private List<JComponent> getExtraAddOptions() {
    List<JComponent> options = new LinkedList<JComponent>();
    NetPlan netPlan = callback.getDesign();

    if (netPlan.getNumberOfNodes() >= 2) {
        final JMenuItem oneDemandPerNodePair = new JMenuItem("Add one demand per node pair");
        options.add(oneDemandPerNodePair);

        oneDemandPerNodePair.addActionListener(new FullMeshTrafficActionListener());
    }//from w w  w  . j a  v  a  2s  .  c om

    return options;
}

From source file:com.igormaznitsa.sciareto.ui.MainFrame.java

public MainFrame(@Nonnull @MustNotContainNull final String... args) {
    super();//  w w  w .  j  a v a 2 s .  c  om
    initComponents();

    this.stackPanel = new JPanel();
    this.stackPanel.setFocusable(false);
    this.stackPanel.setOpaque(false);
    this.stackPanel.setBorder(BorderFactory.createEmptyBorder(32, 32, 16, 32));
    this.stackPanel.setLayout(new BoxLayout(this.stackPanel, BoxLayout.Y_AXIS));

    final JPanel glassPanel = (JPanel) this.getGlassPane();
    glassPanel.setOpaque(false);

    this.setGlassPane(glassPanel);

    glassPanel.setLayout(new BorderLayout(8, 8));
    glassPanel.add(Box.createGlue(), BorderLayout.CENTER);

    final JPanel ppanel = new JPanel(new BorderLayout(0, 0));
    ppanel.setFocusable(false);
    ppanel.setOpaque(false);
    ppanel.setCursor(null);
    ppanel.add(this.stackPanel, BorderLayout.SOUTH);

    glassPanel.add(ppanel, BorderLayout.EAST);

    this.stackPanel.add(Box.createGlue());

    glassPanel.setVisible(false);

    this.setTitle("Scia Reto");

    setIconImage(UiUtils.loadImage("logo256x256.png"));

    this.stateless = args.length > 0;

    final MainFrame theInstance = this;

    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(@Nonnull final WindowEvent e) {
            if (doClosing()) {
                dispose();
            }
        }
    });

    this.tabPane = new EditorTabPane(this);

    this.explorerTree = new ExplorerTree(this);

    final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.setOneTouchExpandable(true);
    splitPane.setDividerLocation(250);
    splitPane.setResizeWeight(0.0d);
    splitPane.setLeftComponent(this.explorerTree);
    splitPane.setRightComponent(this.tabPane);

    add(splitPane, BorderLayout.CENTER);

    this.menuOpenRecentProject.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            final File[] lastOpenedProjects = FileHistoryManager.getInstance().getLastOpenedProjects();
            if (lastOpenedProjects.length > 0) {
                for (final File folder : lastOpenedProjects) {
                    final JMenuItem item = new JMenuItem(folder.getName());
                    item.setToolTipText(folder.getAbsolutePath());
                    item.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            openProject(folder, false);
                        }
                    });
                    menuOpenRecentProject.add(item);
                }
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            menuOpenRecentProject.removeAll();
        }

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

    this.menuOpenRecentFile.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            final File[] lastOpenedFiles = FileHistoryManager.getInstance().getLastOpenedFiles();
            if (lastOpenedFiles.length > 0) {
                for (final File file : lastOpenedFiles) {
                    final JMenuItem item = new JMenuItem(file.getName());
                    item.setToolTipText(file.getAbsolutePath());
                    item.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            openFileAsTab(file);
                        }
                    });
                    menuOpenRecentFile.add(item);
                }
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            menuOpenRecentFile.removeAll();
        }

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

    if (!this.stateless) {
        restoreState();
    } else {
        boolean openedProject = false;
        for (final String filePath : args) {
            final File file = new File(filePath);
            if (file.isDirectory()) {
                openedProject = true;
                openProject(file, true);
            } else if (file.isFile()) {
                openFileAsTab(file);
            }
        }
        if (!openedProject) {
            //TODO try to hide project panel!
        }
    }

    final LookAndFeel current = UIManager.getLookAndFeel();
    final ButtonGroup lfGroup = new ButtonGroup();
    final String currentLFClassName = current.getClass().getName();
    for (final UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(info.getName());
        lfGroup.add(menuItem);
        if (currentLFClassName.equals(info.getClassName())) {
            menuItem.setSelected(true);
        }
        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(@Nonnull final ActionEvent e) {
                try {
                    UIManager.setLookAndFeel(info.getClassName());
                    SwingUtilities.updateComponentTreeUI(theInstance);
                    PreferencesManager.getInstance().getPreferences().put(Main.PROPERTY_LOOKANDFEEL,
                            info.getClassName());
                    PreferencesManager.getInstance().flush();
                } catch (Exception ex) {
                    LOGGER.error("Can't change LF", ex);
                }
            }
        });
        this.menuLookAndFeel.add(menuItem);
    }
}

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

private final JMenu buildFileMenu() {
    JMenu menu = new JMenu("File");
    JMenuItem close = new JMenuItem("Close");

    close.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ConfigManagerFrame.this.setVisible(false);
        }/*from w ww  .j  a  v a  2s  .  c  o  m*/
    });
    menu.add(close);

    return menu;
}