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:corelyzer.ui.CorelyzerApp.java

private void setupPopupMenu() {
    // session popup
    sessionPopupMenu = new JPopupMenu("Sessions");

    JMenuItem hideSession = new JMenuItem("Hide");
    hideSession.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            JMenuItem m = (JMenuItem) e.getSource();
            Session s = (Session) sessionList.getSelectedValue();
            String l = s.isShow() ? "Show" : "Hide";
            controller.setSessionVisible(!s.isShow());
            m.setText(l);/*w w  w. ja  v a2 s  . c o  m*/
        }
    });
    sessionPopupMenu.add(hideSession);

    JMenuItem renameSession = new JMenuItem("Rename...");
    renameSession.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            controller.renameSession();
        }
    });
    sessionPopupMenu.add(renameSession);

    JMenuItem removeSession = new JMenuItem("Close");
    removeSession.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            Session s = (Session) sessionList.getSelectedValue();
            controller.removeSession(s);
        }
    });
    sessionPopupMenu.add(removeSession);

    // track popup
    trackPopupMenu = new JPopupMenu("Tracks");

    JMenuItem hide = new JMenuItem("Hide");
    hide.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            controller.setTrackVisible();
        }
    });
    trackPopupMenu.add(hide);

    JMenuItem rename = new JMenuItem("Rename...");
    rename.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            controller.renameTrack();
        }
    });
    trackPopupMenu.add(rename);

    trackPopupDeleteMenuItem = new JMenuItem("Delete");
    trackPopupDeleteMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.deleteTrack();
        }
    });
    trackPopupMenu.add(trackPopupDeleteMenuItem);

    // data popup
    dataPopupMenu = new JPopupMenu("Datasets");

    dataPopupGraphMenuItem = new JMenuItem("Graph...");
    dataPopupGraphMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.showGraphDialog();
        }
    });

    JMenuItem dataPopupDeleteMenuItem = new JMenuItem("Delete");
    dataPopupDeleteMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.deleteDataset();
        }
    });

    dataPopupMenu.add(dataPopupGraphMenuItem);
    dataPopupMenu.add(dataPopupDeleteMenuItem);
}

From source file:com.gele.tools.wow.wdbearmanager.WDBearManager.java

public void init(String[] args) {

    // copy ARGs// w  ww  . j  av a 2s . c o m
    this.parseCommandLine(args);

    // Usefull for debugging
    this.myLogger.debug("java.version: " + System.getProperty("java.version"));
    this.myLogger.debug("java.vendor: " + System.getProperty("java.vendor"));
    this.myLogger.debug("java.vendor.url: " + System.getProperty("java.vendor.url"));
    this.myLogger.debug("os.name: " + System.getProperty("os.name"));
    this.myLogger.debug("os.arch: " + System.getProperty("os.arch"));
    this.myLogger.debug("os.version: " + System.getProperty("os.version"));

    if (this.paramDBconfig.length() != 0) {
        this.WDB_DB_CONFIG_FILE = this.paramDBconfig;
    }

    WDBearManager_API myAPI = new WDBearManager_API(this.WDB_DB_CONFIG_FILE);

    // Create all tables
    // -> Needed for the updata script <-
    // -> Otherwise it may crash with an empty database
    try {
        myAPI.getCountOfTable("creaturecache");
        myAPI.getCountOfTable("gameobjectcache");
        myAPI.getCountOfTable("itemcache");
        myAPI.getCountOfTable("itemnamecache");
        myAPI.getCountOfTable("itemtextchaxhe");
        myAPI.getCountOfTable("npccache");
        myAPI.getCountOfTable("pagetextcache");
        myAPI.getCountOfTable("questcache");
    } catch (Exception ex) {
        // ignore
        ex.printStackTrace();
        System.exit(0);
    }

    // Check, if database must be re-newed
    DBUpdater myDBU = new DBUpdater();
    myDBU.checkForUpdate(myAPI);

    WDBearManager_I myWoWWDBearManager_API = myAPI;

    //
    // print out some statistics
    //

    if (this.useGUI == false) {

        boolean paramSpec = false;
        // ASSERT
        DTO_Interface myDTO = null;

        if (this.paramWdbfile.length() != 0) {
            paramSpec = true;
            // Open WDB
            try {
                this.items = myWoWWDBearManager_API.readWDBfile(this.paramWdbfile);
            } catch (Exception ex) {
                this.myLogger.error("Error reading the WDB file");
                return;
            }
            // first dto -> to identify the data
            Iterator itWDBS = this.items.iterator();
            if (itWDBS.hasNext()) {
                myDTO = (DTO_Interface) itWDBS.next();
            }
        }
        // Create CSV?
        if (this.paramCSVFolder.length() != 0) {
            if (myDTO == null) {
                // NO WDB specified -> exit
                this.myLogger.error("Error: You did not specify -" + this.PARAM_WDBFILE + "\n");
                usage(this.options);
                return;
            }
            File csvFile = new File(this.paramCSVFolder, myDTO.getTableName() + ".csv");
            if (this.useVerbose) {
                this.myLogger.info("Creating CSV file: " + csvFile.getAbsolutePath());
            }
            try {
                WriteCSV.writeCSV(new File(this.paramCSVFolder), this.items);
                this.myLogger.info("CSV file written: " + csvFile.getAbsolutePath());
            } catch (Exception ex) {
                ex.printStackTrace();
                this.myLogger.error("Error writing the CSV file");
                return;
            }
        }
        // Create TXT?
        if (this.paramTXTFolder.length() != 0) {
            if (myDTO == null) {
                // NO WDB specified -> exit
                this.myLogger.error("Error: You did not specify -" + this.PARAM_WDBFILE + "\n");
                usage(this.options);
                return;
            }
            if (this.useVerbose) {
                String table = myDTO.getTableName();
                File txtFile = new File(this.paramTXTFolder, table + ".txt");
                this.myLogger.info("Creating TXT file: " + txtFile.getAbsolutePath());
            }
            try {
                WriteTXT.writeTXT(new File(this.paramTXTFolder), this.items);
            } catch (Exception ex) {
                //ex.printStackTrace();
                this.myLogger.error("Error writing the TXT file: " + ex.getMessage());
                return;
            }
        }
        // Store inside SQL database?
        if (this.writeSQL == true) {
            paramSpec = true;
            if (myDTO == null) {
                // NO WDB specified -> exit
                this.myLogger.error("Error: You did not specify -" + this.PARAM_WDBFILE + "\n");
                usage(this.options);
                return;
            }
            if (this.useVerbose) {
                this.myLogger.info("Storing data inside SQL database");
            }
            SQLManager myWriteSQL = null;
            try {
                myWriteSQL = new SQLManager(this.WDB_DB_CONFIG_FILE);
                ObjectsWritten myOWr = myWriteSQL.insertOrUpdateToSQLDB(this.items, this.doUpdate);
                this.myLogger.info("Operation successfull");
                if (this.useVerbose) {
                    this.myLogger.info("DB statistics");
                    this.myLogger.info("INSERT: " + myOWr.getNumInsert());
                    this.myLogger.info("UPDATE: " + myOWr.getNumUpdate());
                    this.myLogger.info("Error INSERT: " + myOWr.getNumErrorInsert());
                    this.myLogger.info("Error UPDATE: " + myOWr.getNumErrorUpdate());
                    if (this.doUpdate == false) {
                        this.myLogger.info("Objects skipped: " + myOWr.getNumSkipped());
                        System.out.println("If you want to overwrite/update objects, use 'update' param");
                    }
                    this.myLogger.info(WDBearManager.VERSION_INFO);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                this.myLogger.error("Error importing to database");
                this.myLogger.error(ex.getMessage());
                return;
            }
        } // writeSQL

        // Patch *.SCP with contents of database
        if (this.paramSCPname.length() != 0) {
            if (this.paramPatchSCP.length() == 0) {
                this.myLogger.error("Error: You did not specify -" + WDBearManager.PATCH_SCP + "\n");
                usage(this.options);
                return;
            }

            paramSpec = true;
            this.myLogger.info("Patch scp file with the contents of the database");
            try {

                SCPWritten mySCPW = myWoWWDBearManager_API.patchSCP(this.paramSCPname, this.paramPatchSCP,
                        this.patchUTF8, this.paramLocale);
                if (this.useVerbose) {
                    this.myLogger.info("Merge statistics");
                    System.out.println("Entries in database:    " + mySCPW.getNumInDB());
                    this.myLogger.info("Merged with SCP: " + mySCPW.getNumPatched());
                    this.myLogger.info("Patched IDs:      " + mySCPW.getPatchedIDs());
                }
                this.myLogger.info("Patched file: " + this.paramSCPname + "_patch");
            } catch (WDBMgr_IOException ex) {
                this.myLogger.error("The destination SCP file could not be created");
                this.myLogger.error(ex.getMessage());
                return;
            } catch (WDBMgr_NoDataAvailableException ex) {
                this.myLogger.info("Merging impossible");
                this.myLogger.info("There are no entries inside the database");
            } catch (Exception ex) {
                this.myLogger.error("Error while merging quests.scp with database");
                this.myLogger.error(ex.getMessage());
                return;
            }
        } // PatchSCP

        // Call jython script?
        if (this.paramScript.length() != 0) {
            paramSpec = true;
            this.myLogger.info("Calling Jython script");
            this.myLogger.info("---");
            PythonInterpreter interp = new PythonInterpreter();

            interp.set("wdbmgrapi", myWoWWDBearManager_API);
            // set parameters
            Set setKeys = this.paramJython.keySet();
            Iterator itKeys = setKeys.iterator();
            String jyParam = "";
            while (itKeys.hasNext()) {
                jyParam = (String) itKeys.next();
                interp.set(jyParam, (String) this.paramJython.get(jyParam));
            }
            interp.execfile(this.paramScript);

            this.myLogger.info("---");
            System.out.println("Jython script executed, " + WDBearManager.VERSION_INFO);
            return;
        } // paramScript

        if (paramSpec == false) {
            usage(this.options);
            return;
        }

        // Exit
        return;
    } // Command Line Version

    //
    // GUI
    //
    PlasticLookAndFeel.setMyCurrentTheme(new DesertBlue());
    try {
        UIManager.put("ClassLoader", LookUtils.class.getClassLoader());
        UIManager.setLookAndFeel(new Plastic3DLookAndFeel());
    } catch (Exception e) {
    }
    //    try {
    //      com.incors.plaf.kunststoff.KunststoffLookAndFeel kunststoffLnF = new com.incors.plaf.kunststoff.KunststoffLookAndFeel();
    //      KunststoffLookAndFeel
    //          .setCurrentTheme(new com.incors.plaf.kunststoff.KunststoffTheme());
    //      UIManager.setLookAndFeel(kunststoffLnF);
    //    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
    //      // handle exception or not, whatever you prefer
    //    }
    //     this line needs to be implemented in order to make JWS work properly
    UIManager.getLookAndFeelDefaults().put("ClassLoader", getClass().getClassLoader());

    this.setTitle(WDBearManager.VERSION_INFO);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.getContentPane().setLayout(new BorderLayout());

    // construct GUI to display the stuff
    // Menu
    //  Where the GUI is created:
    JMenuBar menuBar;
    JMenu menu; //, submenu;
    JMenuItem menuItem;
    //JRadioButtonMenuItem rbMenuItem;
    //JCheckBoxMenuItem cbMenuItem;

    //    Create the menu bar.
    menuBar = new JMenuBar();

    //    Build the first menu.
    menu = new JMenu("File");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescription("Process WDB files");
    menuBar.add(menu);

    // Exit
    menuItem = new JMenuItem(MENU_EXIT, KeyEvent.VK_T);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Exit program");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    //    Build the first menu.
    menu = new JMenu("About");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescription("Whassup?");
    menuBar.add(menu);
    // Help
    menuItem = new JMenuItem(MENU_HELP, KeyEvent.VK_H);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Help me...");
    menuItem.addActionListener(this);
    menu.add(menuItem);
    // JavaDocs
    menuItem = new JMenuItem(MENU_JDOCS, KeyEvent.VK_J);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Show API docs...");
    menuItem.addActionListener(this);
    menu.add(menuItem);
    // separator
    menu.addSeparator();
    // CheckForUpdate
    menuItem = new JMenuItem(MENU_CHECKUPDATE, KeyEvent.VK_U);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Check for update...");
    menuItem.addActionListener(this);
    menu.add(menuItem);
    // separator
    menu.addSeparator();
    // ABOUT
    menuItem = new JMenuItem(MENU_ABOUT, KeyEvent.VK_T);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Ueber...");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    this.setJMenuBar(menuBar);

    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new GridLayout(0, 1));

    JTabbedPane tabbedPane = new JTabbedPane();
    ImageIcon wowIcon = createImageIcon("images/fromdisk.gif");

    JComponent panel1 = new WDB_Panel(myWoWWDBearManager_API);
    tabbedPane.addTab("WDB-Module", wowIcon, panel1, "Handle WDB files");
    tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);

    ImageIcon panelIcon = createImageIcon("images/hsql.gif");
    JComponent panel2 = null;
    try {
        panel2 = new SQL_Panel(myWoWWDBearManager_API);
    } catch (Throwable ex) {
        System.err.println("Error while instantiating SQL Panel: ");
        System.err.println(ex.getMessage());
        ex.printStackTrace();
        System.exit(0);
    }
    tabbedPane.addTab("DB-Module", panelIcon, panel2, "Handle database");
    tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);

    panelIcon = createImageIcon("images/pythonpoweredsmall.gif");
    JComponent panel3 = new Python_Panel(myWoWWDBearManager_API);
    tabbedPane.addTab("Scripts", panelIcon, panel3, "Scripting");
    tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);

    // maybe user PLUGIN availabe
    // -> check for folders below "plugins"
    File filUserPanels = new File("plugins");
    // 1) find user plugins (scan for directories)
    // 2) scan for <name>.properties, where <name> is the name of the directory
    // 3) load the properties file and get the plugin running
    String[] strUserPlugins = filUserPanels.list(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return (new File(dir, name).isDirectory());
        }
    });
    if (strUserPlugins != null) {
        ArrayList urlJars = new ArrayList();

        //URL[] urlJars = new URL[strUserPlugins.length];
        String strCurrJar = "";
        String strPlugins[] = new String[strUserPlugins.length];
        try {
            for (int i = 0; i < strUserPlugins.length; i++) {
                File baseFile = new File("plugins", strUserPlugins[i]);
                File filProperties = new File(baseFile, strUserPlugins[i] + ".properties");
                if (filProperties.exists()) {
                    // set plugin folder and .properties name
                    strPlugins[i] = strUserPlugins[i];
                    this.myLogger.info("Found 'plugin' : " + baseFile.getAbsolutePath());
                    this.myLogger.info("                 Trying to load .jar file");

                    // Scan for JAR files and include them
                    //System.out.println(baseFile.getAbsolutePath());
                    String[] strJars = baseFile.list(new FilenameFilter() {
                        public boolean accept(File dir, String name) {
                            return name.endsWith(".jar");
                        }
                    });
                    for (int j = 0; j < strJars.length; j++) {
                        File filJAR = new File(baseFile, strJars[j]);
                        strCurrJar = filJAR.getAbsolutePath();

                        this.myLogger.info("Loading external 'plugin' JAR: " + strCurrJar);
                        URL jarfile = new URL("jar", "", "file:" + strCurrJar + "!/");
                        urlJars.add(jarfile);
                    }

                } else {
                    // print warning - a directory inside plugins, but there is no plugin
                    this.myLogger.warn("Found directory inside plugins folder, but no .properties file");
                    this.myLogger.warn("      Name of directory: " + strUserPlugins[i]);
                    this.myLogger.warn("      Please review the directory!");
                }
            } // for... all user plugins
        } catch (Exception ex) {
            this.myLogger.error("Plugin: Error loading " + strCurrJar);
            this.myLogger.error("Please check your 'plugin' folder");
        }
        URLClassLoader cl = null;
        try {
            //      File file = new File("plugins", strUserJars[i]);
            //      this.myLogger.info("Lade externes JAR: " + file.getAbsolutePath());
            //      URL jarfile = new URL("jar", "", "file:" + file.getAbsolutePath() + "!/");
            URL[] loadURLs = new URL[urlJars.toArray().length];
            for (int j = 0; j < urlJars.toArray().length; j++) {
                loadURLs[j] = (URL) urlJars.get(j);
            }
            cl = URLClassLoader.newInstance(loadURLs);

            Thread.currentThread().setContextClassLoader(cl);

            //      String lcStr = "Test";
            //      Class loadedClass = cl.loadClass(lcStr);
            //      this.myLogger.info("Smooth...");

        } catch (Exception ex) {
            ex.printStackTrace();
        }

        // 2) load properties and instantiate the plugin
        //      String[] strPlugins = filUserPanels.list(new FilenameFilter() {
        //        public boolean accept(File dir, String name) {
        //          return (name.endsWith("_plugin.properties"));
        //        }
        //      });
        String strPluginName = "";
        String strPluginClass = "";
        String strPluginImage = "";
        WDBearPlugin pluginPanel = null;
        for (int i = 0; i < strPlugins.length; i++) {
            //this.myLogger.info(strPlugins[i]);
            Properties prpPlugin = null;
            try {
                prpPlugin = ReadPropertiesFile.readProperties(
                        new File("plugins", strPlugins[i] + "/" + strPlugins[i]).getAbsolutePath()
                                + ".properties");
            } catch (Exception ex) {
                this.myLogger.error("Error with plugin: " + strPlugins[i]);
                this.myLogger.error("Could not load properties file");
                continue;
            }
            if ((strPluginClass = prpPlugin.getProperty(this.PLUGIN_CLASS)) == null) {
                this.myLogger.error("Error with plugin: " + strPlugins[i]);
                this.myLogger.error("Property '" + this.PLUGIN_CLASS + "' not found");
                continue;
            }
            if ((strPluginName = prpPlugin.getProperty(this.PLUGIN_NAME)) == null) {
                this.myLogger.error("Error with plugin: " + strPlugins[i]);
                this.myLogger.error("Property '" + this.PLUGIN_NAME + "' not found");
                continue;
            }
            if ((strPluginImage = prpPlugin.getProperty(this.PLUGIN_IMAGE)) == null) {
                this.myLogger.error("Error with plugin: " + strPlugins[i]);
                this.myLogger.error("Property '" + this.PLUGIN_IMAGE + "' not found");
                continue;
            }

            File filPlgImg = new File("plugins", strPlugins[i] + "/" + strPluginImage);
            panelIcon = createImageIcon(filPlgImg.getAbsolutePath());
            if (panelIcon == null) {
                this.myLogger.error("Error with plugin: " + strPlugins[i]);
                this.myLogger.error("Could not read image '" + strPluginImage + "'");
                continue;
            }
            try {
                pluginPanel = (WDBearPlugin) (cl.loadClass(strPluginClass).newInstance());
                pluginPanel.runPlugin(myAPI);
            } catch (Exception ex) {
                this.myLogger.error("Error with plugin: " + strPlugins[i]);
                this.myLogger.error("Could not instantiate '" + strPluginClass + "'");
                ex.printStackTrace();
                continue;
            }
            tabbedPane.addTab(strPluginName, panelIcon, pluginPanel, strPluginName);
        } // Plugins
    } // plugins folder found

    mainPanel.add(tabbedPane);

    this.getContentPane().add(mainPanel, BorderLayout.CENTER);

    this.setSize(1024, 768);
    //this.pack();
    this.show();

}

From source file:edu.harvard.i2b2.query.ui.QueryConceptTreePanel.java

private void createPopupMenu() {
    JMenuItem menuItem;

    //Create the popup menu.
    JPopupMenu popup = new JPopupMenu();
    /*menuItem = new JMenuItem("Constrain Item ...");
      menuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, 
      java.awt.event.InputEvent.CTRL_MASK));
      menuItem.addActionListener(this);/*from w  w  w . j ava 2s . c o m*/
      popup.add(menuItem);*/

    menuItem = new JMenuItem("Delete Item");
    menuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X,
            java.awt.event.InputEvent.CTRL_MASK));
    menuItem.addActionListener(this);
    popup.add(menuItem);

    /*popup.add(new javax.swing.JSeparator());
            
      menuItem = new JMenuItem("Exclude All Items");
      menuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, 
      java.awt.event.InputEvent.CTRL_MASK));
      menuItem.addActionListener(this);
      popup.add(menuItem);*/

    popup.add(new javax.swing.JSeparator());

    menuItem = new JMenuItem("Set Value ...");
    menuItem.setEnabled(false);
    menuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S,
            java.awt.event.InputEvent.CTRL_MASK));
    menuItem.addActionListener(this);
    popup.add(menuItem);

    //Add listener to the tree
    MouseListener popupListener = new ConceptTreePopupListener(popup);
    jTree1.addMouseListener(popupListener);
}

From source file:com.pironet.tda.TDA.java

/**
 * create a instance of this menu for a category
 *//* w ww . j a  v  a2  s . co m*/
private PopupListener getCatPopupMenu() {
    if (catPopupListener == null) {

        //Create the popup menu.
        JPopupMenu popup = new JPopupMenu();

        JMenuItem menuItem = new JMenuItem("Search...");
        menuItem.addActionListener(this);
        popup.add(menuItem);

        //Add listener to the text area so the popup menu can come up.
        catPopupListener = new PopupListener(popup);
    }

    return (catPopupListener);
}

From source file:com.pironet.tda.TDA.java

/**
 * create a instance of this menu for a category
 */// www  .j av a2 s.c  o m
private PopupListener getMonitorsPopupMenu() {
    if (monitorsPopupListener == null) {
        final JPopupMenu popup = new JPopupMenu();
        JMenuItem menuItem = new JMenuItem("Search...");
        menuItem.addActionListener(this);
        popup.add(menuItem);
        popup.addSeparator();
        menuItem = new JMenuItem("Expand all nodes");
        menuItem.addActionListener(this);
        popup.add(menuItem);
        menuItem = new JMenuItem("Collapse all nodes");
        menuItem.addActionListener(this);
        popup.add(menuItem);
        popup.addSeparator();
        menuItem = new JMenuItem("Sort by thread count");
        menuItem.addActionListener(this);
        popup.add(menuItem);

        //Add listener to the text area so the popup menu can come up.
        monitorsPopupListener = new PopupListener(popup);
    }

    return (monitorsPopupListener);
}

From source file:corelyzer.ui.CorelyzerApp.java

public void createPluginMenuItems(final Vector pluginNames) {
    JMenuItem pluginMenuItem;
    for (int k = 0; k < pluginNames.size(); k++) {
        pluginMenuItem = new JMenuItem((String) pluginNames.elementAt(k));
        pluginMenuItem.addActionListener(controller);
        pluginMenu.add(pluginMenuItem);//www .  j  a v  a 2s .c o m
        pluginMenuItemVec.add(pluginMenuItem);

        if (k == getPluginUIIndex()) {
            pluginMenuItem.setEnabled(false);
        }
    }
}

From source file:net.sf.jabref.gui.JabRefFrame.java

private JPopupMenu tabPopupMenu() {
    JPopupMenu popupMenu = new JPopupMenu();

    // Close actions
    JMenuItem close = new JMenuItem(Localization.lang("Close"));
    JMenuItem closeOthers = new JMenuItem(Localization.lang("Close Others"));
    JMenuItem closeAll = new JMenuItem(Localization.lang("Close All"));
    close.addActionListener(closeDatabaseAction);
    closeOthers.addActionListener(closeOtherDatabasesAction);
    closeAll.addActionListener(closeAllDatabasesAction);
    popupMenu.add(close);// ww  w .j av a2 s  .c  om
    popupMenu.add(closeOthers);
    popupMenu.add(closeAll);

    popupMenu.addSeparator();

    JMenuItem databaseProperties = new JMenuItem(Localization.lang("Database properties"));
    databaseProperties.addActionListener(this.databaseProperties);
    popupMenu.add(databaseProperties);

    JMenuItem bibtexKeyPatternBtn = new JMenuItem(Localization.lang("BibTeX key patterns"));
    bibtexKeyPatternBtn.addActionListener(bibtexKeyPattern);
    popupMenu.add(bibtexKeyPatternBtn);

    JMenuItem manageSelectorsBtn = new JMenuItem(Localization.lang("Manage content selectors"));
    manageSelectorsBtn.addActionListener(manageSelectors);
    popupMenu.add(manageSelectorsBtn);

    return popupMenu;
}

From source file:corelyzer.ui.CorelyzerApp.java

private JPopupMenu sectionListPopupMenu(final int[] rows) {
    // section popup
    JPopupMenu menu = new JPopupMenu("Sections");

    // Section/Image property
    JMenuItem propertiesMenuItem = new JMenuItem("Properties...");
    propertiesMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, MENU_MASK));
    propertiesMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            controller.sectionProperties(rows);
        }//ww  w  . ja v  a 2s  .  c  o  m
    });

    JMenuItem splitMenuItem = new JMenuItem("Split...");
    if (rows.length > 1) {
        splitMenuItem.setEnabled(false);
    }
    splitMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            controller.sectionSplit();
        }
    });

    JMenuItem deleteMenuItem = new JMenuItem("Delete");
    deleteMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            onDeleteSelectedSections(rows);
        }
    });

    JMenuItem locateMenuItem = new JMenuItem("Locate");
    locateMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            onLocateSelectedSection();
        }
    });

    menu.add(locateMenuItem);
    menu.add(splitMenuItem);
    menu.add(propertiesMenuItem);
    menu.add(deleteMenuItem);

    return menu;
}

From source file:com.pironet.tda.TDA.java

public void createPopupMenu() {

    //Create the popup menu.
    JPopupMenu popup = new JPopupMenu();

    JMenuItem menuItem = new JMenuItem("Diff Selection");
    menuItem.addActionListener(this);
    popup.add(menuItem);/*  ww w  . ja va  2s. c o m*/
    menuItem = new JMenuItem("Find long running threads...");
    menuItem.addActionListener(this);
    popup.add(menuItem);

    showDumpMenuItem = new JMenuItem("Show selected Dump in logfile");
    showDumpMenuItem.addActionListener(this);
    showDumpMenuItem.setEnabled(false);
    if (!runningAsJConsolePlugin && !runningAsVisualVMPlugin) {
        popup.addSeparator();
        menuItem = new JMenuItem("Parse loggc-logfile...");
        menuItem.addActionListener(this);
        if (!PrefManager.get().getForceLoggcLoading()) {
            menuItem.setEnabled(!isFoundClassHistogram);
        }
        popup.add(menuItem);

        menuItem = new JMenuItem("Close logfile...");
        menuItem.addActionListener(this);
        popup.add(menuItem);
        popup.addSeparator();
        popup.add(showDumpMenuItem);
    } else {
        popup.addSeparator();
        if (!runningAsVisualVMPlugin) {
            menuItem = new JMenuItem("Request Thread Dump...");
            menuItem.addActionListener(this);
            popup.add(menuItem);
            popup.addSeparator();
            menuItem = new JMenuItem("Preferences");
            menuItem.addActionListener(this);
            popup.add(menuItem);
            menuItem = new JMenuItem("Filters");
            menuItem.addActionListener(this);
            popup.add(menuItem);
            popup.addSeparator();
            menuItem = new JMenuItem("Save Logfile...");
            menuItem.addActionListener(this);
            popup.add(menuItem);
            popup.addSeparator();
            menuItem = new JCheckBoxMenuItem("Show Toolbar", PrefManager.get().getShowToolbar());
            menuItem.addActionListener(this);
            popup.add(menuItem);
            popup.addSeparator();
            menuItem = new JMenuItem("Help");
            menuItem.addActionListener(this);
            popup.add(menuItem);
            popup.addSeparator();
        }
        menuItem = new JMenuItem("About TDA");
        menuItem.addActionListener(this);
        popup.add(menuItem);
    }

    //Add listener to the text area so the popup menu can come up.
    MouseListener popupListener = new PopupListener(popup);
    tree.addMouseListener(popupListener);
}

From source file:edu.harvard.i2b2.query.ui.ConceptTreePanel.java

private void createPopupMenu() {
    JMenuItem menuItem;

    // Create the popup menu.
    JPopupMenu popup = new JPopupMenu();
    /*// ww w.  jav  a 2 s .  co  m
     * menuItem = new JMenuItem("Constrain Item ...");
     * menuItem.setAccelerator
     * (javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C,
     * java.awt.event.InputEvent.CTRL_MASK));
     * menuItem.addActionListener(this); popup.add(menuItem);
     */

    menuItem = new JMenuItem("Delete Item");
    // menuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.
    // event.KeyEvent.VK_X,
    // java.awt.event.InputEvent.CTRL_MASK));
    menuItem.addActionListener(this);
    popup.add(menuItem);

    /*
     * popup.add(new javax.swing.JSeparator());
     * 
     * menuItem = new JMenuItem("Exclude All Items");
     * menuItem.setAccelerator
     * (javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A,
     * java.awt.event.InputEvent.CTRL_MASK));
     * menuItem.addActionListener(this); popup.add(menuItem);
     */

    popup.add(new javax.swing.JSeparator());

    menuItem = new JMenuItem("Set Value ...");
    menuItem.setEnabled(false);
    // menuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.
    // event.KeyEvent.VK_S,
    // java.awt.event.InputEvent.CTRL_MASK));
    menuItem.addActionListener(this);
    popup.add(menuItem);

    // Add listener to the tree
    MouseListener popupListener = new ConceptTreePopupListener(popup);
    jTree1.addMouseListener(popupListener);
}