Example usage for javax.swing.event MenuListener MenuListener

List of usage examples for javax.swing.event MenuListener MenuListener

Introduction

In this page you can find the example usage for javax.swing.event MenuListener MenuListener.

Prototype

MenuListener

Source Link

Usage

From source file:gdt.jgui.entity.query.JQueryPanel.java

/**
 * Get the context menu.//  www.  ja v  a2s . c  o m
 * @return the context menu.
 */
@Override
public JMenu getContextMenu() {
    menu = new JMenu("Context");
    menu.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            menu.removeAll();
            //            System.out.println("BookmarksEditor:getConextMenu:menu selected");
            JMenuItem selectItem = new JMenuItem("Select");
            selectItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    showHeader();
                    showContent();
                }
            });
            menu.add(selectItem);
            JMenuItem clearHeader = new JMenuItem("Clear all");
            clearHeader.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    clearHeader();
                    showHeader();
                    showContent();
                }
            });
            menu.add(clearHeader);
            Entigrator entigrator = console.getEntigrator(entihome$);
            Sack query = entigrator.getEntityAtKey(entityKey$);
            if (query.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);

            menu.addSeparator();
            JMenuItem addHeader = new JMenuItem("Add column");
            addHeader.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    addHeader();
                }
            });
            menu.add(addHeader);
            JMenuItem removeColumn = new JMenuItem("Remove column ");
            removeColumn.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    removeColumn();
                }
            });
            menu.add(removeColumn);
            ListSelectionModel lsm = table.getSelectionModel();
            if (!lsm.isSelectionEmpty()) {
                JMenuItem excludeRows = new JMenuItem("Exclude rows ");
                excludeRows.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Entigrator entigrator = console.getEntigrator(entihome$);
                        Sack query = entigrator.getEntityAtKey(entityKey$);
                        if (!query.existsElement("exclude"))
                            query.createElement("exclude");
                        //else
                        //   query.clearElement("exclude");
                        ListSelectionModel lsm = table.getSelectionModel();
                        int minIndex = lsm.getMinSelectionIndex();
                        int maxIndex = lsm.getMaxSelectionIndex();
                        for (int i = minIndex; i <= maxIndex; i++) {
                            if (lsm.isSelectedIndex(i)) {
                                System.out.println("JQueryPanel:exclude rows:label=" + table.getValueAt(i, 1));
                                query.putElementItem("exclude",
                                        new Core(null, (String) table.getValueAt(i, 1), null));
                            }
                        }
                        entigrator.save(query);
                        showHeader();
                        showContent();
                    }
                });
                menu.add(excludeRows);
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

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

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

/**
 *Get the context menu./*from w ww  .  j a va 2 s  .c om*/
 *@return the context menu.
 */
@Override
public JMenu getContextMenu() {
    menu = super.getContextMenu();
    menu.addSeparator();
    JMenuItem showStructure = new JMenuItem("Structure");
    showStructure.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String locator$ = getLocator();
            JEntityStructurePanel esp = new JEntityStructurePanel();
            esp.instantiate(console, locator$);
            String espLocator$ = esp.getLocator();
            espLocator$ = Locator.append(espLocator$, Entigrator.ENTIHOME, entihome$);
            espLocator$ = Locator.append(espLocator$, EntityHandler.ENTITY_KEY, entityKey$);
            JConsoleHandler.execute(console, espLocator$);
        }
    });
    menu.add(showStructure);
    JMenuItem showDigest = new JMenuItem("Digest");
    showDigest.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String locator$ = getLocator();
            JEntityDigestDisplay edd = new JEntityDigestDisplay();
            edd.instantiate(console, locator$);
            String eddLocator$ = edd.getLocator();
            eddLocator$ = Locator.append(eddLocator$, Entigrator.ENTIHOME, entihome$);
            eddLocator$ = Locator.append(eddLocator$, EntityHandler.ENTITY_KEY, entityKey$);
            JConsoleHandler.execute(console, eddLocator$);
        }
    });
    menu.add(showDigest);
    menu.addSeparator();
    addFacets = new JMenuItem("Add facets");
    addFacets.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String locator$ = getLocator();
            JEntityAddFacets addFacets = new JEntityAddFacets();
            addFacets.instantiate(console, locator$);
            String facetSelector$ = addFacets.getLocator();
            facetSelector$ = Locator.append(facetSelector$, Entigrator.ENTIHOME, entihome$);
            facetSelector$ = Locator.append(facetSelector$, EntityHandler.ENTITY_KEY, entityKey$);
            JConsoleHandler.execute(console, facetSelector$);
        }
    });
    menu.add(addFacets);
    JMenuItem doneItem = new JMenuItem("Done");
    doneItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String locator$ = getLocator();
            String requesterResponseLocator$ = Locator.getProperty(locator$,
                    JRequester.REQUESTER_RESPONSE_LOCATOR);
            if (requesterResponseLocator$ == null)
                console.back();
            else {
                try {
                    byte[] ba = Base64.decodeBase64(requesterResponseLocator$);
                    String responseLocator$ = new String(ba, "UTF-8");
                    //                         System.out.println("EntityfacetPanel:done:response locator="+responseLocator$);
                    JConsoleHandler.execute(console, responseLocator$);
                } catch (Exception ee) {
                    LOGGER.info(ee.toString());
                }
            }
        }
    });
    menu.add(doneItem);
    menu.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            //System.out.println("EntityEditor:getConextMenu:menu selected");
            if (removeFacets != null)
                menu.remove(removeFacets);
            if (copyFacets != null)
                menu.remove(copyFacets);
            if (hasSelectedItems()) {
                copyFacets = new JMenuItem("Copy facets");
                copyFacets.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        copyFacets();
                    }
                });
                menu.add(copyFacets);
            }
            if (hasSelectedRemovableFacets()) {
                removeFacets = new JMenuItem("Remove facets");
                removeFacets.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        removeFacets();
                    }
                });
                menu.add(removeFacets);
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

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

From source file:com.opendoorlogistics.studio.appframe.AppFrame.java

private void initMenus(ActionFactory actionBuilder, MenuFactory menuBuilder, List<? extends Action> fileActions,
        List<? extends Action> editActions) {
    final JMenuBar menuBar = new JMenuBar();
    class AddSpace {
        void add() {
            JMenu dummy = new JMenu();
            dummy.setEnabled(false);/*from w  ww. j  a v a2s  .  co  m*/
            menuBar.add(dummy);
        }
    }
    AddSpace addSpace = new AddSpace();

    // add file menu ... build on the fly for recent files..
    setJMenuBar(menuBar);
    final JMenu mnFile = new JMenu("File");
    mnFile.setMnemonic('F');
    mnFile.addMenuListener(new MenuListener() {

        @Override
        public void menuSelected(MenuEvent e) {
            initFileMenu(mnFile, fileActions, actionBuilder, menuBuilder);
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void menuCanceled(MenuEvent e) {
            // TODO Auto-generated method stub

        }
    });
    initFileMenu(mnFile, fileActions, actionBuilder, menuBuilder);
    menuBar.add(mnFile);
    addSpace.add();

    // add edit menu
    JMenu mnEdit = new JMenu("Edit");
    mnEdit.setMnemonic('E');
    menuBar.add(mnEdit);
    addSpace.add();
    for (Action action : editActions) {
        mnEdit.add(action);
        //         if (action.accelerator != null) {
        //            item.setAccelerator(action.accelerator);
        //         }
    }

    // add run scripts menu (hidden until a datastore is loaded)
    mnScripts = new JMenu(appPermissions.isScriptEditingAllowed() ? "Run script" : "Run");
    mnScripts.setMnemonic('R');
    mnScripts.setVisible(false);
    mnScripts.addMenuListener(new MenuListener() {

        private void addScriptNode(JMenu parentMenu, boolean usePopupForChildren, ScriptNode node) {
            if (node.isAvailable() == false) {
                return;
            }
            if (node.isRunnable()) {
                parentMenu.add(new AbstractAction(node.getDisplayName(), node.getIcon()) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        postScriptExecution(node.getFile(), node.getLaunchExecutorId());
                    }
                });
            } else if (node.getChildCount() > 0) {
                JMenu newParent = parentMenu;
                if (usePopupForChildren) {
                    newParent = new JMenu(node.getDisplayName());
                    parentMenu.add(newParent);
                }
                ;
                for (int i = 0; i < node.getChildCount(); i++) {
                    addScriptNode(newParent, true, (ScriptNode) node.getChildAt(i));
                }
            }
        }

        @Override
        public void menuSelected(MenuEvent e) {
            mnScripts.removeAll();
            ScriptNode[] scripts = scriptsPanel.getScripts();
            for (final ScriptNode item : scripts) {
                addScriptNode(mnScripts, scripts.length > 1, item);
            }
            mnScripts.validate();
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });
    menuBar.add(mnScripts);
    addSpace.add();

    // add create script menu
    if (appPermissions.isScriptEditingAllowed()) {
        JMenu scriptsMenu = menuBuilder.createScriptCreationMenu(this, scriptManager);
        if (scriptsMenu != null) {
            menuBar.add(scriptsMenu);
        }
        addSpace.add();
    }

    // tools menu
    JMenu tools = new JMenu("Tools");
    menuBar.add(tools);
    JMenu memoryCache = new JMenu("Memory cache");
    tools.add(memoryCache);
    memoryCache.add(new AbstractAction("View cache statistics") {

        @Override
        public void actionPerformed(ActionEvent e) {
            TextInformationDialog dlg = new TextInformationDialog(AppFrame.this, "Memory cache statistics",
                    ApplicationCache.singleton().getUsageReport());
            dlg.setMinimumSize(new Dimension(400, 400));
            dlg.setLocationRelativeTo(AppFrame.this);
            dlg.setVisible(true);
        }
    });
    memoryCache.add(new AbstractAction("Clear memory cache") {

        @Override
        public void actionPerformed(ActionEvent e) {
            ApplicationCache.singleton().clearCache();
        }
    });
    addSpace.add();

    // add window menu
    JMenu mnWindow = menuBuilder.createWindowsMenu(this);
    mnWindow.add(new AbstractAction("Show all tables") {

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

    JMenu mnResizeTo = new JMenu("Resize application to...");
    for (final int[] size : new int[][] { new int[] { 1280, 720 }, new int[] { 1920, 1080 } }) {
        mnResizeTo.add(new AbstractAction("" + size[0] + " x " + size[1]) {

            @Override
            public void actionPerformed(ActionEvent e) {
                // set standard layout
                setSize(size[0], size[1]);
                splitterMain.setDividerLocation(0.175);
                splitterLeftSide.setDividerLocation(0.3);
            }
        });
    }
    mnWindow.add(mnResizeTo);
    menuBar.add(mnWindow);
    addSpace.add();

    menuBar.add(menuBuilder.createHelpMenu(actionBuilder, this));

    addSpace.add();

}

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

private JMenu createMenuFile() {
    final JMenu menuFile = new JMenu(Messages.getString("Menu.file")); //$NON-NLS-1$

    final JMenuItem menuFileOpen = new JMenuItem(Messages.getString("Menu.fileOpen")); //$NON-NLS-1$
    menuFileOpen.setMnemonic(KeyEvent.VK_O);
    menuFileOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.ALT_MASK));
    menuFileOpen.addActionListener(new ActionListener() {
        @Override/*from  w w  w.  j  av a  2s .  com*/
        public void actionPerformed(final ActionEvent e) {
            openFile();
        }
    });
    menuFile.add(menuFileOpen);
    menuFile.add(menuFileRecent);

    final JMenuItem menuFileReload = new JMenuItem(Messages.getString("Menu.fileReload")); //$NON-NLS-1$
    menuFileReload.setMnemonic(KeyEvent.VK_R);
    menuFileReload.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.ALT_MASK));
    menuFileReload.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            reloadDefinition();
        }
    });
    menuFile.add(menuFileReload);

    final JMenuItem menuFileClose = new JMenuItem(Messages.getString("Menu.fileClose")); //$NON-NLS-1$
    menuFileClose.setMnemonic(KeyEvent.VK_C);
    menuFileClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_MASK));
    menuFileClose.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            closeSource();
        }
    });
    menuFile.add(menuFileClose);

    menuFile.addSeparator();

    final JMenuItem menuFileProperties = new JMenuItem(Messages.getString("Menu.properties")); //$NON-NLS-1$
    menuFileProperties.setMnemonic(KeyEvent.VK_P);
    menuFileProperties.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.ALT_MASK));
    menuFileProperties.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            showPropertiesDialog();
        }
    });
    menuFile.add(menuFileProperties);

    menuFile.addSeparator();

    final JMenuItem menuFileExport = createMenuFileExport();
    menuFile.add(menuFileExport);

    menuFile.addSeparator();

    final JMenuItem menuFilePreferences = new JMenuItem(Messages.getString("Menu.preferences")); //$NON-NLS-1$
    menuFilePreferences.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            showPreferencesDialog();
        }
    });
    menuFile.add(menuFilePreferences);

    menuFile.addSeparator();

    final JMenuItem menuFileExit = new JMenuItem(Messages.getString("Menu.exit")); //$NON-NLS-1$
    menuFileExit.setMnemonic(KeyEvent.VK_E);
    menuFileExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_MASK));
    menuFileExit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            for (Frame frame : getFrames()) {
                if (frame.isActive()) {
                    frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
                }
            }
        }
    });
    menuFile.add(menuFileExit);

    menuFile.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(final MenuEvent e) {
            menuFileReload.setEnabled(isSourceOpen() && currentSource.canReopen());
            menuFileClose.setEnabled(isSourceOpen());
            menuFileProperties.setEnabled(isDefinitionOpen());
            menuFileExport.setEnabled(isDefinitionOpen());
        }

        @Override
        public void menuDeselected(final MenuEvent e) {
        }

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

    return menuFile;
}

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

private JMenu createMenuExtra() {
    final JMenu menuExtra = new JMenu(Messages.getString("Menu.extra")); //$NON-NLS-1$

    final JMenuItem menuExtraOpenExternalEditor = new JMenuItem(Messages.getString("Menu.openExternal")); //$NON-NLS-1$
    menuExtraOpenExternalEditor.addActionListener(new ActionListener() {
        @Override/*from  ww  w . j a  va  2s . c o  m*/
        public void actionPerformed(final ActionEvent event) {
            showExternalEditor();
        }
    });
    menuExtra.add(menuExtraOpenExternalEditor);

    menuExtra.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(final MenuEvent e) {
            menuExtraOpenExternalEditor.setEnabled(isDefinitionOpen());
        }

        @Override
        public void menuDeselected(final MenuEvent e) {
        }

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

    return menuExtra;
}

From source file:gdt.jgui.entity.index.JIndexPanel.java

/**
 * Get the context menu.//from ww w  . ja v  a  2 s.com
 * @return the context menu.
 */
@Override
public JMenu getContextMenu() {
    menu = new JMenu("Context");
    menu.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            //System.out.println("IndexPanel:getConextMenu:menu selected");
            menu.removeAll();
            JMenuItem expandItem = new JMenuItem("Expand");
            expandItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    expandAll(tree, new TreePath(rootNode), true);
                }
            });
            menu.add(expandItem);
            JMenuItem collapseItem = new JMenuItem("Collapse");
            collapseItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    expandAll(tree, new TreePath(rootNode), false);
                }
            });
            menu.add(collapseItem);
            final TreePath[] tpa = tree.getSelectionPaths();
            if (tpa != null && tpa.length > 0) {
                menu.addSeparator();
                JMenuItem copyItem = new JMenuItem("Copy");
                copyItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        cut = false;
                        console.clipboard.clear();
                        DefaultMutableTreeNode node;
                        String locator$;
                        for (TreePath tp : tpa) {
                            node = (DefaultMutableTreeNode) tp.getLastPathComponent();
                            locator$ = (String) node.getUserObject();
                            if (locator$ != null)
                                console.clipboard.putString(locator$);
                        }
                    }
                });
                menu.add(copyItem);
                JMenuItem cutItem = new JMenuItem("Cut");
                cutItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        cut = true;
                        console.clipboard.clear();
                        DefaultMutableTreeNode node;
                        String locator$;
                        for (TreePath tp : tpa) {
                            node = (DefaultMutableTreeNode) tp.getLastPathComponent();
                            locator$ = (String) node.getUserObject();
                            if (locator$ != null)
                                console.clipboard.putString(locator$);
                        }
                    }
                });
                menu.add(cutItem);
                JMenuItem deleteItem = new JMenuItem("Delete");
                deleteItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete ?",
                                "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                        if (response == JOptionPane.YES_OPTION) {
                            try {
                                DefaultMutableTreeNode node;
                                String locator$;
                                String nodeKey$;
                                for (TreePath tp : tpa) {
                                    node = (DefaultMutableTreeNode) tp.getLastPathComponent();
                                    locator$ = (String) node.getUserObject();
                                    nodeKey$ = Locator.getProperty(locator$, NODE_KEY);
                                    index.removeElementItem("index.title", nodeKey$);
                                    index.removeElementItem("index.jlocator", nodeKey$);
                                }
                                Entigrator entigrator = console.getEntigrator(entihome$);
                                entigrator.save(index);
                                JConsoleHandler.execute(console, getLocator());
                            } catch (Exception ee) {
                                LOGGER.info(ee.toString());
                            }
                        }
                    }
                });
                menu.add(deleteItem);
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

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

    return menu;
}

From source file:com.opendoorlogistics.studio.AppFrame.java

private void initMenus() {
    final JMenuBar menuBar = new JMenuBar();
    class AddSpace {
        void add() {
            JMenu dummy = new JMenu();
            dummy.setEnabled(false);// w ww  .  jav  a 2  s.  c o m
            menuBar.add(dummy);
        }
    }
    AddSpace addSpace = new AddSpace();

    // add file menu ... build on the fly for recent files..
    setJMenuBar(menuBar);
    final JMenu mnFile = new JMenu("File");
    mnFile.setMnemonic('F');
    mnFile.addMenuListener(new MenuListener() {

        @Override
        public void menuSelected(MenuEvent e) {
            initFileMenu(mnFile);
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void menuCanceled(MenuEvent e) {
            // TODO Auto-generated method stub

        }
    });
    initFileMenu(mnFile);
    menuBar.add(mnFile);
    addSpace.add();

    // add edit menu
    JMenu mnEdit = new JMenu("Edit");
    mnEdit.setMnemonic('E');
    menuBar.add(mnEdit);
    addSpace.add();
    for (MyAction action : editActions) {
        JMenuItem item = mnEdit.add(action);
        if (action.accelerator != null) {
            item.setAccelerator(action.accelerator);
        }
    }

    // add run scripts menu (hidden until a datastore is loaded)
    mnScripts = new JMenu("Run script");
    mnScripts.setMnemonic('R');
    mnScripts.setVisible(false);
    mnScripts.addMenuListener(new MenuListener() {

        @Override
        public void menuSelected(MenuEvent e) {
            mnScripts.removeAll();
            for (final ScriptNode item : scriptsPanel.getScripts()) {
                if (item.isAvailable() == false) {
                    continue;
                }
                if (item.isRunnable()) {
                    mnScripts.add(new AbstractAction(item.getDisplayName(), item.getIcon()) {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            scriptManager.executeScript(item.getFile(), item.getLaunchExecutorId());
                        }
                    });
                } else if (item.getChildCount() > 0) {
                    JMenu popup = new JMenu(item.getDisplayName());
                    mnScripts.add(popup);
                    for (int i = 0; i < item.getChildCount(); i++) {
                        final ScriptNode child = (ScriptNode) item.getChildAt(i);
                        if (child.isRunnable()) {
                            popup.add(new AbstractAction(child.getDisplayName(), child.getIcon()) {

                                @Override
                                public void actionPerformed(ActionEvent e) {
                                    scriptManager.executeScript(child.getFile(), child.getLaunchExecutorId());
                                }
                            });
                        }

                    }
                }
            }
            mnScripts.validate();
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });
    menuBar.add(mnScripts);
    addSpace.add();

    // add create script menu
    menuBar.add(initCreateScriptsMenu());
    addSpace.add();

    // add window menu
    JMenu mnWindow = new JMenu("Window");
    mnWindow.setMnemonic('W');
    menuBar.add(mnWindow);
    addSpace.add();
    initWindowMenus(mnWindow);

    menuBar.add(initHelpMenu());

    addSpace.add();

}

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

private final JMenu buildProfilingMenu() {
    final JMenu menu = new JMenu("Profiling");
    final JMenuItem deleteProfilingSymbol = new JMenuItem("Delete " + "Profiling " + "Symbol");
    final JMenuItem deleteProfilingMessage = new JMenuItem("Delete " + "Profiling " + "Message");

    deleteProfilingSymbol.addActionListener(new DeleteProgramProfilingSymbolListener());
    menu.add(deleteProfilingSymbol);//www  . j av a 2  s. co m

    deleteProfilingMessage.addActionListener(new DeleteProgramProfilingMessageSymbolListener());
    menu.add(deleteProfilingMessage);

    menu.addMenuListener(new MenuListener() {
        public void menuSelected(MenuEvent e) {
            setDeleteProfilingSymbolEnabled();
            setDeleteProfilingMessageEnabled();
        }

        private void setDeleteProfilingSymbolEnabled() {
            int row = profilingSymbolTable.getSelectedRow();

            deleteProfilingSymbol.setEnabled((row != -1) && (row != (profilingSymbolTable.getRowCount() - 1)));
        }

        private void setDeleteProfilingMessageEnabled() {
            int row = profilingMsgTable.getSelectedRow();

            deleteProfilingMessage.setEnabled((row != -1) && (row != (profilingMsgTable.getRowCount() - 1)));
        }

        public void menuCanceled(MenuEvent e) {
        }

        public void menuDeselected(MenuEvent e) {
        }

    });

    return menu;
}

From source file:gdt.jgui.entity.edge.JBondsPanel.java

/**
 * Get the context menu.//from   ww w. jav a 2 s  .c  om
 * @return the context menu.
 */
@Override
public JMenu getContextMenu() {
    menu = super.getContextMenu();
    int cnt = menu.getItemCount();
    mia = new JMenuItem[cnt];
    for (int i = 0; i < cnt; i++)
        mia[i] = menu.getItem(i);
    menu.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            //System.out.println("WeblinkPanel:getConextMenu:menu selected");
            menu.removeAll();
            if (mia != null) {
                for (JMenuItem mi : mia)
                    menu.add(mi);
                menu.addSeparator();
            }
            if (hasSelectedItems()) {
                JMenuItem deleteItem = new JMenuItem("Delete");
                deleteItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {

                        int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete ?",
                                "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                        if (response == JOptionPane.YES_OPTION) {
                            String[] sa = JBondsPanel.this.listSelectedItems();
                            if (sa == null)
                                return;
                            for (String s : sa) {
                                //   System.out.println("JBondsPanel:delete:s="+s);
                                if (isGraphEntity())
                                    removeBondEntry(s);
                                else if (isEdgeEntity())
                                    removeBond(console, s);
                                else if (isDetailEntity()) {
                                    System.out.println("JBondsPanel:delete detail:");
                                    Entigrator entigrator = console.getEntigrator(entihome$);
                                    BondDetailHandler.deleteDetail(entigrator, s);
                                }
                            }
                            close();
                            JBondsPanel bp = new JBondsPanel();
                            String bpLocator$ = bp.getLocator();
                            bpLocator$ = Locator.append(bpLocator$, Entigrator.ENTIHOME, entihome$);
                            bpLocator$ = Locator.append(bpLocator$, EntityHandler.ENTITY_KEY, entityKey$);
                            JConsoleHandler.execute(console, bpLocator$);
                        }
                    }
                });

                menu.add(deleteItem);
                JMenuItem copyItem = new JMenuItem("Copy");
                copyItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {

                        String[] sa = JBondsPanel.this.listSelectedItems();
                        if (sa == null)
                            return;

                        for (String s : sa) {
                            console.clipboard.putString(s);
                        }
                    }
                });
                menu.add(copyItem);

                menu.addSeparator();
            }
            if (isEdgeEntity()) {
                JMenuItem newItem = new JMenuItem("New");
                newItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        //System.out.println("JBondsPanel:new:"+locator$);

                        Entigrator entigrator = console.getEntigrator(entihome$);
                        Sack entity = entigrator.getEntityAtKey(entityKey$);
                        if (!entity.existsElement("bond"))
                            entity.createElement("bond");
                        String bondKey$ = Identity.key();
                        entity.putElementItem("bond", new Core(null, bondKey$, null));
                        //   String icon$=Support.readHandlerIcon(JEntitiesPanel.class, "globe.png");
                        entigrator.save(entity);
                        // JBondsPanel.this.getPanel().removeAll();
                        close();
                        JBondsPanel bp = new JBondsPanel();
                        String bpLocator$ = bp.getLocator();
                        bpLocator$ = Locator.append(bpLocator$, Entigrator.ENTIHOME, entihome$);
                        bpLocator$ = Locator.append(bpLocator$, EntityHandler.ENTITY_KEY, entityKey$);
                        //bpLocator$=Locator.append(bpLocator$, BaseHandler.HANDLER_METHOD,"instantiate");
                        JConsoleHandler.execute(console, bpLocator$);

                    }
                });
                menu.add(newItem);
            }
            if (isGraphEntity()) {
                JMenuItem showItem = new JMenuItem("Show");
                showItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        try {
                            JGraphRenderer gr = new JGraphRenderer();
                            String grLocator$ = gr.getLocator();
                            grLocator$ = Locator.append(grLocator$, Entigrator.ENTIHOME, entihome$);
                            grLocator$ = Locator.append(grLocator$, EntityHandler.ENTITY_KEY, entityKey$);
                            JConsoleHandler.execute(console, grLocator$);
                        } catch (Exception ee) {
                            Logger.getLogger(JGraphRenderer.class.getName()).info(ee.toString());
                        }
                    }
                });
                menu.add(showItem);

                if (hasBondsToPaste()) {
                    JMenuItem pasteItem = new JMenuItem("Paste");
                    pasteItem.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            pasteBonds();
                            JBondsPanel bp = new JBondsPanel();
                            String bpLocator$ = bp.getLocator();
                            bpLocator$ = Locator.append(bpLocator$, Entigrator.ENTIHOME, entihome$);
                            bpLocator$ = Locator.append(bpLocator$, EntityHandler.ENTITY_KEY, entityKey$);
                            JConsoleHandler.execute(console, bpLocator$);
                        }
                    });
                    menu.add(pasteItem);
                }
            }

            JMenuItem doneItem = new JMenuItem("Done");
            doneItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    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(JBondsPanel.class.getName()).severe(ee.toString());
                        }
                    } else
                        console.back();
                }
            });
            menu.add(doneItem);
            menu.addSeparator();
            JMenuItem sortInNode = new JMenuItem("Sort in node");
            sortInNode.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        selectMode$ = SELECT_MODE_IN;
                        JItemPanel[] ipa = getItems();
                        Entigrator entigrator = console.getEntigrator(entihome$);
                        InNodeComparator inc = new InNodeComparator();
                        inc.entigrator = entigrator;
                        ArrayList<JItemPanel> ipl = new ArrayList<JItemPanel>(Arrays.asList(ipa));

                        Collections.sort(ipl, inc);
                        panel.removeAll();
                        //         System.out.println("JBondsPanel:sort in node:ipl="+ipl.size());
                        if (ipa != null)
                            for (JItemPanel ip : ipl) {
                                panel.add(ip);
                            }
                        revalidate();
                        repaint();
                        Sack entity = entigrator.getEntityAtKey(entityKey$);
                        if (!entity.existsElement("parameter"))
                            entity.createElement("parameter");
                        entity.putElementItem("parameter", new Core(null, SELECT_MODE, selectMode$));
                        entigrator.save(entity);
                    } catch (Exception ee) {
                    }
                }
            });
            menu.add(sortInNode);
            JMenuItem sortOutNode = new JMenuItem("Sort out node");
            sortOutNode.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        selectMode$ = SELECT_MODE_OUT;
                        JItemPanel[] ipa = getItems();
                        ArrayList<JItemPanel> ipl = new ArrayList<JItemPanel>(Arrays.asList(ipa));
                        Collections.sort(ipl, new ItemPanelComparator());
                        panel.removeAll();
                        System.out.println("JBondsPanel:sort out node:ipl=" + ipl.size());
                        if (ipa != null)
                            for (JItemPanel ip : ipl) {
                                panel.add(ip);
                            }
                        revalidate();
                        repaint();
                        Entigrator entigrator = console.getEntigrator(entihome$);
                        Sack entity = entigrator.getEntityAtKey(entityKey$);
                        if (!entity.existsElement("parameter"))
                            entity.createElement("parameter");
                        entity.putElementItem("parameter", new Core(null, SELECT_MODE, selectMode$));
                        entigrator.save(entity);
                    } catch (Exception ee) {
                    }
                }
            });
            menu.add(sortOutNode);
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

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

From source file:gdt.jgui.entity.folder.JFolderPanel.java

/**
 * Get the context menu.//from   ww w  . j  a  v a2s  .c o m
 * @return the context menu.
 */
@Override
public JMenu getContextMenu() {
    menu = super.getContextMenu();
    mia = null;
    int cnt = menu.getItemCount();
    if (cnt > 0) {
        mia = new JMenuItem[cnt];
        for (int i = 0; i < cnt; i++)
            mia[i] = menu.getItem(i);
    }
    menu.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            //System.out.println("EntitiesPanel:getConextMenu:menu selected");
            menu.removeAll();
            if (mia != null) {
                for (JMenuItem mi : mia)
                    menu.add(mi);
                menu.addSeparator();
            }
            JMenuItem refreshItem = new JMenuItem("Refresh");
            refreshItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    JConsoleHandler.execute(console, locator$);
                }
            });
            menu.add(refreshItem);
            JMenuItem openItem = new JMenuItem("Open folder");
            openItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        File folder = new File(entihome$ + "/" + entityKey$);
                        if (!folder.exists())
                            folder.mkdir();
                        Desktop.getDesktop().open(folder);
                    } catch (Exception ee) {
                        LOGGER.severe(ee.toString());
                    }
                }
            });
            menu.add(openItem);
            JMenuItem importItem = new JMenuItem("Import");
            importItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        File home = new File(System.getProperty("user.home"));
                        Desktop.getDesktop().open(home);
                    } catch (Exception ee) {
                        LOGGER.severe(ee.toString());
                    }
                }
            });

            menu.add(importItem);
            JMenuItem newItem = new JMenuItem("New text");
            newItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        JTextEditor textEditor = new JTextEditor();
                        String teLocator$ = textEditor.getLocator();
                        teLocator$ = Locator.append(teLocator$, Entigrator.ENTIHOME, entihome$);
                        String text$ = "New" + Identity.key().substring(0, 4) + ".txt";
                        teLocator$ = Locator.append(teLocator$, JTextEditor.TEXT, text$);
                        JFolderPanel fp = new JFolderPanel();
                        String fpLocator$ = fp.getLocator();
                        fpLocator$ = Locator.append(fpLocator$, Entigrator.ENTIHOME, entihome$);
                        fpLocator$ = Locator.append(fpLocator$, EntityHandler.ENTITY_KEY, entityKey$);
                        fpLocator$ = Locator.append(fpLocator$, BaseHandler.HANDLER_METHOD, "response");
                        fpLocator$ = Locator.append(fpLocator$, JRequester.REQUESTER_ACTION,
                                ACTION_CREATE_FILE);
                        String requesterResponseLocator$ = Locator.compressText(fpLocator$);
                        teLocator$ = Locator.append(teLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR,
                                requesterResponseLocator$);
                        JConsoleHandler.execute(console, teLocator$);
                    } catch (Exception ee) {
                        LOGGER.severe(ee.toString());
                    }
                }
            });

            menu.add(newItem);
            //menu.addSeparator();
            if (hasToInsert()) {
                menu.addSeparator();
                JMenuItem insertItem = new JMenuItem("Insert");
                insertItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        try {
                            Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
                            Transferable clipboardContents = systemClipboard.getContents(null);
                            if (clipboardContents == null)
                                return;
                            Object transferData = clipboardContents
                                    .getTransferData(DataFlavor.javaFileListFlavor);
                            List<File> files = (List<File>) transferData;
                            for (int i = 0; i < files.size(); i++) {
                                File file = (File) files.get(i);
                                if (file.exists() && file.isFile()) {
                                    System.out.println("FolderPanel:insert:in=" + file.getPath());
                                    File dir = new File(entihome$ + "/" + entityKey$);
                                    if (!dir.exists())
                                        dir.mkdir();
                                    File out = new File(entihome$ + "/" + entityKey$ + "/" + file.getName());
                                    if (!out.exists())
                                        out.createNewFile();
                                    System.out.println("FolderPanel:insert:out=" + out.getPath());
                                    FileExpert.copyFile(file, out);
                                    JConsoleHandler.execute(console, getLocator());
                                }

                                //      System.out.println("FolderPanel:import:file="+file.getPath());
                            }
                        } catch (Exception ee) {
                            LOGGER.severe(ee.toString());

                        }

                    }
                });
                menu.add(insertItem);
            }
            if (hasToPaste()) {
                menu.addSeparator();
                JMenuItem pasteItem = new JMenuItem("Paste");
                pasteItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        String[] sa = console.clipboard.getContent();
                        Properties locator;
                        String file$;
                        File file;
                        File target;
                        String dir$ = entihome$ + "/" + entityKey$;
                        File dir = new File(dir$);
                        if (!dir.exists())
                            dir.mkdir();
                        for (String aSa : sa) {
                            try {
                                locator = Locator.toProperties(aSa);
                                if (LOCATOR_TYPE_FILE.equals(locator.getProperty(Locator.LOCATOR_TYPE))) {
                                    file$ = locator.getProperty(FILE_PATH);
                                    file = new File(file$);
                                    target = new File(dir$ + "/" + file.getName());
                                    if (!target.exists())
                                        target.createNewFile();
                                    FileExpert.copyFile(file, target);
                                }
                            } catch (Exception ee) {
                                LOGGER.info(ee.toString());
                            }
                        }
                        JConsoleHandler.execute(console, locator$);
                    }
                });
                menu.add(pasteItem);
            }
            if (hasSelectedItems()) {
                menu.addSeparator();
                JMenuItem deleteItem = new JMenuItem("Delete");
                deleteItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete ?",
                                "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                        if (response == JOptionPane.YES_OPTION) {
                            String[] sa = JFolderPanel.this.listSelectedItems();
                            if (sa == null)
                                return;
                            Properties locator;
                            String file$;
                            File file;
                            for (String aSa : sa) {
                                locator = Locator.toProperties(aSa);
                                file$ = locator.getProperty(FILE_PATH);
                                file = new File(file$);
                                try {
                                    if (file.isDirectory())
                                        FileExpert.clear(file$);
                                    file.delete();
                                } catch (Exception ee) {
                                    LOGGER.info(ee.toString());
                                }
                            }
                        }
                        JConsoleHandler.execute(console, locator$);
                    }
                });
                menu.add(deleteItem);
                JMenuItem copyItem = new JMenuItem("Copy");
                copyItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        String[] sa = JFolderPanel.this.listSelectedItems();
                        console.clipboard.clear();
                        if (sa != null)
                            for (String aSa : sa)
                                console.clipboard.putString(aSa);
                    }
                });
                menu.add(copyItem);
                JMenuItem exportItem = new JMenuItem("Export");
                exportItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        try {
                            String[] sa = JFolderPanel.this.listSelectedItems();
                            Properties locator;
                            String file$;
                            File file;
                            ArrayList<File> fileList = new ArrayList<File>();
                            for (String aSa : sa) {
                                try {
                                    locator = Locator.toProperties(aSa);
                                    file$ = locator.getProperty(FILE_PATH);
                                    file = new File(file$);
                                    fileList.add(file);
                                } catch (Exception ee) {
                                    LOGGER.severe(ee.toString());
                                }
                            }
                            File[] fa = fileList.toArray(new File[0]);
                            if (fa.length < 1)
                                return;
                            //                             System.out.println("Folderpanel:finish:list="+fa.length);
                            JFileChooser chooser = new JFileChooser();
                            chooser.setCurrentDirectory(new java.io.File(System.getProperty("user.home")));
                            chooser.setDialogTitle("Export files");
                            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                            chooser.setAcceptAllFileFilterUsed(false);
                            if (chooser.showSaveDialog(JFolderPanel.this) == JFileChooser.APPROVE_OPTION) {
                                String dir$ = chooser.getSelectedFile().getPath();
                                File target;
                                for (File f : fa) {
                                    target = new File(dir$ + "/" + f.getName());
                                    if (!target.exists())
                                        target.createNewFile();
                                    FileExpert.copyFile(f, target);
                                }
                            } else {
                                Logger.getLogger(JMainConsole.class.getName()).info(" no selection");
                            }
                            //                            System.out.println("Folderpanel:finish:list="+fileList.size());  
                        } catch (Exception eee) {
                            LOGGER.severe(eee.toString());
                        }
                    }
                });
                menu.add(exportItem);
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

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