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.loy.MainFrame.java

@SuppressWarnings("rawtypes")
public void init() {

    String src = "ee.png";
    try {//from  w ww. j av a  2  s .  c  om
        ClassPathResource classPathResource = new ClassPathResource(src);
        image = ImageIO.read(classPathResource.getURL());
        this.setIconImage(image);
    } catch (IOException e) {
    }

    menu = new JMenu("LOG CONSOLE");
    this.jmenuBar = new JMenuBar();
    this.jmenuBar.add(menu);

    panel = new JPanel(new BorderLayout());
    this.add(panel);

    ClassPathResource classPathResource = new ClassPathResource("application.yml");
    Yaml yaml = new Yaml();
    Map result = null;
    try {
        result = (Map) yaml.load(classPathResource.getInputStream());
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    String platformStr = result.get("platform").toString();
    String version = result.get("version").toString();
    String jvmOption = result.get("jvmOption").toString();
    @SuppressWarnings("unchecked")
    List<String> projects = (List<String>) result.get("projects");
    platform = Platform.valueOf(platformStr);
    final Runtime runtime = Runtime.getRuntime();
    File pidsForder = new File("./pids");
    if (!pidsForder.exists()) {
        pidsForder.mkdir();
    } else {
        File[] files = pidsForder.listFiles();
        if (files != null) {
            for (File f : files) {
                f.deleteOnExit();
                String pidStr = f.getName();
                try {
                    Long pid = new Long(pidStr);
                    if (Processes.isProcessRunning(platform, pid)) {
                        if (Platform.Windows == platform) {
                            Processes.tryKillProcess(null, platform, new NullProcessor(), pid);
                        } else {
                            Processes.killProcess(null, platform, new NullProcessor(), pid);
                        }

                    }
                } catch (Exception ex) {
                }
            }
        }
    }

    File currentForder = new File("");
    String rootPath = currentForder.getAbsolutePath();
    rootPath = rootPath.replace(File.separator + "build" + File.separator + "libs", "");
    rootPath = rootPath.replace(File.separator + "e-example-ms-start-w", "");

    for (String value : projects) {
        String path = value;
        String[] values = value.split("/");
        value = values[values.length - 1];
        String appName = value;
        value = rootPath + "/" + path + "/build/libs/" + value + "-" + version + ".jar";

        JMenuItem menuItem = new JMenuItem(appName);
        JTextArea textArea = new JTextArea();
        textArea.setVisible(true);
        textArea.setLineWrap(true);
        textArea.setWrapStyleWord(true);
        textArea.setAutoscrolls(true);
        JScrollPane scorll = new JScrollPane(textArea);
        this.textSreaMap.put(appName, scorll);
        EComposite ecomposite = new EComposite();
        ecomposite.setCommand(value);
        ecomposite.setTextArea(textArea);
        composites.put(appName, ecomposite);
        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Collection<JScrollPane> values = textSreaMap.values();
                for (JScrollPane t : values) {
                    t.setVisible(false);
                }
                String actions = e.getActionCommand();
                JScrollPane textArea = textSreaMap.get(actions);
                if (textArea != null) {
                    textArea.setVisible(true);
                    panel.removeAll();
                    panel.add(textArea);
                    panel.repaint();
                    panel.validate();
                    self.repaint();
                    self.validate();
                }
            }
        });
        menu.add(menuItem);
    }

    new Thread(new Runnable() {
        @Override
        public void run() {
            int size = composites.keySet().size();
            int index = 1;
            for (String appName : composites.keySet()) {
                EComposite composite = composites.get(appName);
                try {

                    Process process = runtime.exec(
                            "java " + jvmOption + " -Dfile.encoding=UTF-8 -jar " + composite.getCommand());
                    Long pid = Processes.processId(process);
                    pids.add(pid);
                    File pidsFile = new File("./pids", pid.toString());
                    pidsFile.createNewFile();

                    new WriteLogThread(process.getInputStream(), composite.getTextArea()).start();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                synchronized (lock) {
                    try {
                        if (index < size) {
                            lock.wait();
                        } else {
                            index++;
                        }

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }).start();

}

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

@Override
protected JMenu createWindowMenu() {
    final JMenu menuWindow = new JMenu(Messages.getString("Menu.windows")); //$NON-NLS-1$

    final JMenuItem menuWindowElements = new JMenuItem(Messages.getString("Menu.elements")); //$NON-NLS-1$
    menuWindowElements.setMnemonic(KeyEvent.VK_E);
    menuWindowElements.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_MASK));
    menuWindowElements.addActionListener(new ActionListener() {
        @Override//  w w  w.  j  ava  2s. co  m
        public void actionPerformed(final ActionEvent e) {
            showElementsFrame();
        }
    });
    menuWindow.add(menuWindowElements);

    final JMenuItem menuWindowInstances = new JMenuItem(Messages.getString("Menu.instances")); //$NON-NLS-1$
    menuWindowInstances.setMnemonic(KeyEvent.VK_I);
    menuWindowInstances.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.ALT_MASK));
    menuWindowInstances.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            showInstancesFrame();
        }
    });
    menuWindow.add(menuWindowInstances);

    final JMenu menuWindowDiagram = super.createWindowMenu();
    menuWindowDiagram.setText(Messages.getString("Menu.diagrams"));
    menuWindow.add(menuWindowDiagram);

    return menuWindow;
}

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

/**
 * Get the context menu./* www .  j ava 2 s.  c  o  m*/
 * @return the context menu.
 */
@Override
public JMenu getContextMenu() {
    JMenu menu = new JMenu("Context");
    JMenuItem doneItem = new JMenuItem("Done");
    doneItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            save();
            if (requesterResponseLocator$ != null) {
                try {
                    byte[] ba = Base64.decodeBase64(requesterResponseLocator$);
                    String responseLocator$ = new String(ba, "UTF-8");
                    JConsoleHandler.execute(console, responseLocator$);
                } catch (Exception ee) {
                    Logger.getLogger(getClass().getName()).severe(ee.toString());
                }
            } else
                console.back();

        }
    });
    menu.add(doneItem);
    JMenuItem cancelItem = new JMenuItem("Cancel");
    cancelItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                browseUrl(console, locator$);
            } catch (Exception ee) {
                Logger.getLogger(getClass().getName()).info(ee.toString());
            }
        }
    });
    menu.add(cancelItem);
    menu.addSeparator();
    JMenuItem browseItem = new JMenuItem("Browse");
    browseItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                Desktop.getDesktop().browse(new URI(addressField.getText()));
            } catch (Exception ee) {
                Logger.getLogger(JWeblinkEditor.class.getName()).info(ee.toString());
            }
        }
    });
    menu.add(browseItem);
    return menu;
}

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

private final JMenu buildFileMenu() {
    JMenu file = new JMenu("File");
    JMenuItem exit = new JMenuItem("Exit");

    exit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            doExit();//from   ww w .  jav  a 2s . co m
        }
    });

    file.add(exit);

    return file;
}

From source file:ee.ioc.cs.vsle.editor.Editor.java

/**
 * /*from w  w  w .j  a va2s .  c o m*/
 */
private void makeToolsMenu(JMenuBar _menuBar) {

    JMenu menu = new JMenu(Menu.MENU_TOOLS);
    menu.setMnemonic(KeyEvent.VK_T);
    _menuBar.add(menu);

    JMenuItem menuItem = new JMenuItem(Menu.EXPERT_TABLE);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);

    if (RuntimeProperties.isFromWebstart()) {
        menuItem = new JMenuItem(Menu.ICON_EDITOR);
        menuItem.addActionListener(getActionListener());
        menu.add(menuItem);
    }

    menuItem = new JCheckBoxMenuItem(Menu.SHOW_ALGORITHM, RuntimeProperties.isShowAlgorithm());
    menuItem.setToolTipText("If checked, after planning a window with the synthesized algorithm will be shown");
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);

    menuItem = new JMenuItem(Menu.VIEW_THREADS);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);

    menuItem = new JMenuItem(Menu.JAVA_CONSOLE);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
}

From source file:be.ac.ua.comp.scarletnebula.gui.windows.GUI.java

private JMenu getProviderMenu() {
    final JMenu providerMenu = new JMenu("Providers");
    providerMenu.setMnemonic(KeyEvent.VK_P);
    providerMenu.getAccessibleContext().setAccessibleDescription("Managing cloud providers.");

    final JMenuItem manageProvidersItem = new JMenuItem("Manage Providers");
    manageProvidersItem.setMnemonic(KeyEvent.VK_M);
    manageProvidersItem.addActionListener(new ActionListener() {
        @Override//w w w.j  a v  a2 s . c om
        public void actionPerformed(final ActionEvent e) {
            new ManageProvidersWindow(GUI.this);
        }
    });

    providerMenu.add(manageProvidersItem);

    final JMenuItem detectAllUnlinkedInstances = new JMenuItem("Link/Unlink Instances");
    detectAllUnlinkedInstances.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            new LinkUnlinkWindow(GUI.this);
            // detectAllUnlinkedInstances();
        }
    });
    providerMenu.add(detectAllUnlinkedInstances);
    return providerMenu;
}

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

private List<JComponent> getForcedOptions() {
    List<JComponent> options = new LinkedList<JComponent>();

    final int numRows = model.getRowCount();
    if (numRows > 1) {
        JMenuItem showAllNodes = new JMenuItem("Show all nodes");
        showAllNodes.addActionListener(new ActionListener() {
            @Override/*  www. ja v  a2s .c om*/
            public void actionPerformed(ActionEvent e) {
                for (int row = 0; row < numRows; row++)
                    if (model.getValueAt(row, COLUMN_SHOWHIDE) != null)
                        model.setValueAt(true, row, COLUMN_SHOWHIDE);
            }
        });

        options.add(showAllNodes);

        JMenuItem hideAllNodes = new JMenuItem("Hide all nodes");
        hideAllNodes.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int numRows = model.getRowCount();
                for (int row = 0; row < numRows; row++)
                    if (model.getValueAt(row, COLUMN_SHOWHIDE) != null)
                        model.setValueAt(false, row, COLUMN_SHOWHIDE);
            }
        });

        options.add(hideAllNodes);
    }

    return options;
}

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

private List<JComponent> getExtraAddOptions() {
    List<JComponent> options = new LinkedList<JComponent>();
    NetPlan netPlan = callback.getDesign();
    if (netPlan.getNumberOfNodes() >= 2) {
        final JMenuItem oneBroadcastDemandPerNode = new JMenuItem("Add one broadcast demand per node");
        options.add(oneBroadcastDemandPerNode);
        oneBroadcastDemandPerNode.addActionListener(new BroadcastDemandPerNodeActionListener());
        final JMenuItem oneMulticastDemandPerNode = new JMenuItem(
                "Add one multicast demand per node (ingress) with random egress nodes");
        options.add(oneMulticastDemandPerNode);
        oneMulticastDemandPerNode.addActionListener(new MulticastDemandPerNodeActionListener());
    }/*from   w  ww. j a v a2 s.com*/
    return options;
}

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

private JMenuItem getAddOption() {
    JMenuItem addItem = addItem = new JMenuItem("Add " + networkElementType);
    addItem.addActionListener(new ActionListener() {
        @Override//from w w  w . j a va2  s .c  o m
        public void actionPerformed(ActionEvent e) {
            NetPlan netPlan = callback.getDesign();

            try {
                Node node = netPlan.addNode(0, 0, "Node " + netPlan.getNumberOfNodes(), null);
                callback.getVisualizationState()
                        .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals();
                callback.getVisualizationState().pickNode(node);
                callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE));
                callback.getUndoRedoNavigationManager().addNetPlanChange();

                if (networkElementType == NetworkElementType.NODE)
                    callback.runCanvasOperation(ITopologyCanvas.CanvasOperation.ZOOM_ALL);
            } catch (Throwable ex) {
                ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to add " + networkElementType);
            }
        }
    });
    return addItem;
}

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

/**
 * Creates the file menu.//from   w w  w .ja va 2  s.c om
 *
 * @return the new file menu
 */
protected JMenu createFileMenu() {
    JMenu fileMenu = new JMenu(resourceBundle.getString(RROOT + ".fileMenuName"));
    JMenuItem menuItem;

    fileMenu.setMnemonic(KeyEvent.VK_F);

    JMenu exportMenu = new JMenu(resourceBundle.getString(RROOT + ".file.export"));
    exportMenu.setMnemonic(KeyEvent.VK_A);

    menuItem = new JMenuItem(resourceBundle.getString(RROOT + ".file.export.jordan"), KeyEvent.VK_J);

    menuItem.setToolTipText(resourceBundle.getString(RROOT + ".file.export.jordan.tooltip"));

    menuItem.setActionCommand(ACTION_EXPORT_JORDAN);
    menuItem.addActionListener(this);
    exportMenu.add(menuItem);

    menuItem = new JMenuItem(resourceBundle.getString(RROOT + ".file.export.doug"), KeyEvent.VK_D);

    menuItem.setToolTipText("For Losers");
    menuItem.setActionCommand(ACTION_EXPORT_DOUG);
    menuItem.addActionListener(this);
    exportMenu.add(menuItem);

    exportMenu.addSeparator();
    menuItem = new JMenuItem("XML...", KeyEvent.VK_X);
    menuItem.setActionCommand(ACTION_EXPORT_XML);
    menuItem.addActionListener(this);
    exportMenu.add(menuItem);

    fileMenu.add(exportMenu);

    if (!OsUtil.isMac()) {
        fileMenu.addSeparator();
        menuItem = new JMenuItem("Exit", KeyEvent.VK_X);
        menuItem.setActionCommand(ACTION_EXIT);
        menuItem.addActionListener(this);
        fileMenu.add(menuItem);
    }

    return fileMenu;
}