Example usage for javax.swing JMenuItem setAccelerator

List of usage examples for javax.swing JMenuItem setAccelerator

Introduction

In this page you can find the example usage for javax.swing JMenuItem setAccelerator.

Prototype

@BeanProperty(preferred = true, description = "The keystroke combination which will invoke the JMenuItem's actionlisteners without navigating the menu hierarchy")
public void setAccelerator(KeyStroke keyStroke) 

Source Link

Document

Sets the key combination which invokes the menu item's action listeners without navigating the menu hierarchy.

Usage

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

public void init(String[] args) {

    // copy ARGs//from   w ww  .  j  a v 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:br.org.acessobrasil.ases.ferramentas_de_reparo.vista.label.PainelLabel.java

/**
 * Cria o menu editar do Frame Principal
 * //from   w w  w  . java 2  s . c o m
 * @param menu
 */
private JMenu criaMenuEditar() {
    JMenu menu = new JMenu(GERAL.EDITAR);
    menu.setBackground(parentFrame.corDefault);
    menu.setMnemonic('E');
    menu.setMnemonic(KeyEvent.VK_E);

    JMenuItem btnContraste = new JMenuItem(GERAL.ALTERAR_CONTRASTE);
    btnContraste.addActionListener(this);
    btnContraste.setActionCommand("Contraste");
    // btnAumenta.setMnemonic('F');
    // btnAumenta.setMnemonic(KeyEvent.VK_F);
    // btnAumenta.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ADD,
    // ActionEvent.CTRL_MASK));
    btnContraste.setToolTipText(GERAL.DICA_CONTRASTE);
    btnContraste.getAccessibleContext().setAccessibleDescription(GERAL.DICA_CONTRASTE);
    menu.add(btnContraste);

    JMenuItem btnAumenta = new JMenuItem(GERAL.AUMENTA_FONTE);
    btnAumenta.addActionListener(this);
    btnAumenta.setActionCommand("AumentaFonte");
    // btnAumenta.setMnemonic('F');
    // btnAumenta.setMnemonic(KeyEvent.VK_F);
    btnAumenta.setAccelerator(
            javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ADD, ActionEvent.CTRL_MASK));
    btnAumenta.setToolTipText(GERAL.DICA_AUMENTA_FONTE);
    btnAumenta.getAccessibleContext().setAccessibleDescription(GERAL.DICA_AUMENTA_FONTE);
    menu.add(btnAumenta);

    JMenuItem btnDiminui = new JMenuItem(GERAL.DIMINUI_FONTE);
    btnDiminui.addActionListener(this);
    btnDiminui.setActionCommand("DiminuiFonte");
    // btnDiminui.setMnemonic('F');
    // btnDiminui.setMnemonic(KeyEvent.VK_F);
    btnDiminui.setAccelerator(
            javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_SUBTRACT, ActionEvent.CTRL_MASK));
    btnDiminui.setToolTipText(GERAL.DICA_DIMINUI_FONTE);
    btnDiminui.getAccessibleContext().setAccessibleDescription(GERAL.DICA_DIMINUI_FONTE);
    menu.add(btnDiminui);

    menu.add(new JSeparator());

    JMenuItem btnProcurar = new JMenuItem(GERAL.PROCURAR);
    btnProcurar.addActionListener(this);
    btnProcurar.setActionCommand("Procurar");
    btnProcurar.setMnemonic('P');
    btnProcurar.setMnemonic(KeyEvent.VK_P);
    btnProcurar.setAccelerator(
            javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, ActionEvent.CTRL_MASK));
    btnProcurar.setToolTipText(GERAL.DICA_PROCURAR);
    btnProcurar.getAccessibleContext().setAccessibleDescription(GERAL.DICA_PROCURAR);
    menu.add(btnProcurar);

    JMenuItem btnSelecionarTudo = new JMenuItem(GERAL.SELECIONAR_TUDO);
    btnSelecionarTudo.addActionListener(this);
    btnSelecionarTudo.setActionCommand("SelecionarTudo");
    btnSelecionarTudo.setMnemonic('T');
    btnSelecionarTudo.setMnemonic(KeyEvent.VK_T);
    btnSelecionarTudo.setAccelerator(
            javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, ActionEvent.CTRL_MASK));
    btnSelecionarTudo.setToolTipText(GERAL.DICA_SELECIONAR_TODO_CSS);
    btnSelecionarTudo.getAccessibleContext().setAccessibleDescription(GERAL.DICA_SELECIONAR_TODO_CSS);
    menu.add(btnSelecionarTudo);

    JMenuItem btnDesfazer = new JMenuItem(GERAL.DESFAZER);
    btnDesfazer.addActionListener(this);
    btnDesfazer.setActionCommand("Desfazer");
    btnDesfazer.setMnemonic('z');
    btnDesfazer.setMnemonic(KeyEvent.VK_Z);
    btnDesfazer.getAccessibleContext().setAccessibleDescription(GERAL.DICA_DESFAZER);
    btnDesfazer.setAccelerator(
            javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Z, ActionEvent.CTRL_MASK));
    menu.add(btnDesfazer);
    menu.setEnabled(true);
    return menu;
}

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  ww .  j  av  a 2 s .  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: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);
        }/*from w  w  w .  j a v  a2 s .  c  om*/
    });

    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:edu.ku.brc.ui.UIHelper.java

/**
 * Creates a JMenu./* w ww.jav  a2s.  c o  m*/
 * @param resKey the resource key for localization
 * @param virtualKeyCode the virtual key code i.e. KeyEvent.VK_N
 * @param mneu thee mneumonic
 * @return the JMenuItem
 */
protected static JMenuItem createMenu(final String resKey, final int virtualKeyCode, final String mneu) {
    JMenuItem jmi = new JMenuItem(getResourceString(resKey));
    if (oSType != OSTYPE.MacOSX) {
        jmi.setMnemonic(mneu.charAt(0));
    }
    jmi.setAccelerator(
            KeyStroke.getKeyStroke(virtualKeyCode, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    return jmi;
}

From source file:uk.ac.lkl.cram.ui.ModuleFrame.java

/**
 * Creates new form ModuleFrame//from   www .j  a v a 2  s  .  c  o  m
 * @param module the module that this window displays
 * @param file  
 */
public ModuleFrame(final Module module, File file) {
    this.module = module;
    this.moduleFile = file;
    this.setTitle(module.getModuleName());
    initComponents();
    //Add undo mechanism
    undoHandler = new UndoHandler();
    JMenuItem undoMI = editMenu.add(undoHandler.getUndoAction());
    JMenuItem redoMI = editMenu.add(undoHandler.getRedoAction());
    //Listen to the undo handler for when there is something to undo
    undoHandler.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            //We're assuming there's only one property
            //If the new value is true, then there's something to undo
            //And thus the save menu item should be enabled
            Boolean newValue = (Boolean) evt.getNewValue();
            if (moduleFile != null) {
                saveMI.setEnabled(newValue);
            }
        }
    });
    editMenu.addSeparator();
    //Add cut, copy & paste menu items
    JMenuItem cutMI = editMenu.add(new JMenuItem(new DefaultEditorKit.CutAction()));
    cutMI.setText("Cut");
    JMenuItem copyMI = editMenu.add(new JMenuItem(new DefaultEditorKit.CopyAction()));
    copyMI.setText("Copy");
    JMenuItem pasteMI = editMenu.add(new JMenuItem(new DefaultEditorKit.PasteAction()));
    pasteMI.setText("Paste");

    //Listen for changes to the shared selection model
    sharedSelectionModel.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            //Update the menu items
            modifyLineItemMI.setEnabled(evt.getNewValue() != null);
            removeLineItemMI.setEnabled(evt.getNewValue() != null);
        }
    });

    doubleClickListener = new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            //If the user double clicks, then treat this as a shortcut to modify the selected line item
            if (e.getClickCount() == 2) {
                modifySelectedLineItem();
            }
        }
    };

    //Set Accelerator keys
    undoMI.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    redoMI.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_Y, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    cutMI.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    copyMI.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    pasteMI.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    newMI.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    openMI.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    saveMI.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    quitMI.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_Q, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    //Remove quit menu item and separator from file menu on Mac
    if (Utilities.isMac()) {
        fileMenu.remove(quitSeparator);
        fileMenu.remove(quitMI);
    }

    leftTaskPaneContainer.add(createCourseDataPane());
    leftTaskPaneContainer.add(createLineItemPane());
    leftTaskPaneContainer.add(createTutorHoursPane());
    leftTaskPaneContainer.add(createTutorCostPane());
    rightTaskPaneContainer.add(createLearningTypeChartPane());
    rightTaskPaneContainer.add(createLearningExperienceChartPane());
    rightTaskPaneContainer.add(createLearnerFeedbackChartPane());
    rightTaskPaneContainer.add(createHoursChartPane());
    rightTaskPaneContainer.add(createTotalCostsPane());
}

From source file:corelyzer.ui.CorelyzerApp.java

private void setupMenuStuff() {
    menuBar = new JMenuBar();

    // Create File Menu
    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);

    JMenuItem createSessionMenuItem = new JMenuItem("Create a Session", KeyEvent.VK_N);
    createSessionMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, MENU_MASK));
    createSessionMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.createSession();//from  ww  w . j a  v a  2s  . co m
        }
    });
    createSessionMenuItem.setEnabled(true);
    fileMenu.add(createSessionMenuItem);

    createTrackMenuItem = new JMenuItem("Create a Track", KeyEvent.VK_T);
    createTrackMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, MENU_MASK));
    createTrackMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.createTrack();
        }
    });
    createTrackMenuItem.setEnabled(false);
    fileMenu.add(createTrackMenuItem);

    fileMenu.addSeparator();

    // Images
    JMenu loadImageMenu = new JMenu("Load Images");
    loadImageMenuItem = new JMenuItem("Open Local Image Files...", KeyEvent.VK_M);
    loadImageMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, MENU_MASK));
    loadImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.loadImageAction();
        }
    });
    loadImageMenu.add(loadImageMenuItem);

    // "Auto-load" 4/25/2012 brg
    JMenuItem autoLoadImageMenuItem = new JMenuItem("Open Image Listing...");
    autoLoadImageMenuItem.setEnabled(true);
    autoLoadImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.loadImageListingAction();
        }
    });
    loadImageMenu.add(autoLoadImageMenuItem);

    // online image services
    JMenuItem chronosMenuItem = new JMenuItem("Online Image Services...");
    loadImageMenu.add(chronosMenuItem);
    chronosMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            IODPListsDialog d = new IODPListsDialog(getMainFrame());
            d.pack();
            d.setSize(800, 600);
            d.setLocationRelativeTo(getMainFrame());
            d.setVisibleTab(1);
            d.setVisible(true);
        }
    });

    fileMenu.add(loadImageMenu);

    // Numbercal data (plots)
    JMenu loadDataMenu = new JMenu("Load Data");

    loadDataMenuItem = new JMenuItem("Open Local Dataset Files", KeyEvent.VK_D);
    loadDataMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, MENU_MASK));
    loadDataMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            Runnable r = new Runnable() {
                public void run() {
                    controller.loadData();
                }
            };

            new Thread(r).start();
        }
    });
    loadDataMenu.add(loadDataMenuItem);
    fileMenu.add(loadDataMenu);

    JMenuItem quickDataImportMenuItem = new JMenuItem("Quick Data Import...");
    quickDataImportMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.quickDataImport();
        }
    });
    loadDataMenu.add(quickDataImportMenuItem);

    JMenuItem importDataMenuItem = new JMenuItem("Custom Data Import...");
    importDataMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.importData();
        }
    });
    loadDataMenu.add(importDataMenuItem);

    // LoggingDB
    JMenuItem loggingDBMenuItem = new JMenuItem("LDEO logging DB...");
    loggingDBMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            IODPListsDialog d = new IODPListsDialog(getMainFrame());
            d.pack();
            d.setSize(800, 600);
            d.setLocationRelativeTo(getMainFrame());
            d.setVisibleTab(2);
            d.setVisible(true);
        }
    });
    loadDataMenu.add(loggingDBMenuItem);

    fileMenu.addSeparator();

    loadStateFileMenuItem = new JMenuItem("Open a Session File", KeyEvent.VK_O);
    loadStateFileMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, MENU_MASK));
    loadStateFileMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.loadStateFile();
        }
    });
    loadStateFileMenuItem.setEnabled(false);
    fileMenu.add(loadStateFileMenuItem);

    JMenuItem saveMenuItem = new JMenuItem("Save Session", KeyEvent.VK_S);
    saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, MENU_MASK));
    saveMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            controller.saveCurrentSession();
        }
    });
    fileMenu.add(saveMenuItem);

    JMenuItem saveStateToFileMenuItem = new JMenuItem("Save Session As...", KeyEvent.VK_S);
    saveStateToFileMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, MENU_MASK));
    saveStateToFileMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.saveStateToFile();
        }
    });
    fileMenu.add(saveStateToFileMenuItem);

    // Session History
    recentSessionsMenu = new JMenu("Recent Sessions");
    controller.refreshSessionHistoryMenu();
    fileMenu.add(recentSessionsMenu);

    fileMenu.addSeparator();

    JMenu packageMenu = new JMenu("Core Archive");
    JMenuItem importMenuItem = new JMenuItem("Import...");
    importMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.importPackage();
        }
    });
    packageMenu.add(importMenuItem);

    JMenuItem exportMenuItem = new JMenuItem("Export...");
    exportMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.exportTheWholeScene();
        }
    });
    packageMenu.add(exportMenuItem);
    fileMenu.add(packageMenu);

    JMenu limsMenu = new JMenu("IODP");

    JMenuItem allIODPLists = new JMenuItem("All IODP lists...");
    allIODPLists.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            IODPListsDialog d = new IODPListsDialog(getMainFrame());
            d.pack();
            d.setSize(800, 600);
            d.setLocationRelativeTo(getMainFrame());
            d.setVisible(true);
        }
    });
    limsMenu.add(allIODPLists);

    JMenuItem loadLIMSTables = new JMenuItem("Load a section list...");
    loadLIMSTables.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            IODPListsDialog d = new IODPListsDialog(getMainFrame());
            d.loadLIMSTables(getMainFrame());

            d.pack();
            d.setSize(800, 600);
            d.setLocationRelativeTo(getMainFrame());
            d.setVisibleTab(0);
            d.setVisible(true);
        }
    });
    limsMenu.add(loadLIMSTables);

    JMenuItem loadAffineTable = new JMenuItem("Load an affine table...");
    loadAffineTable.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            IODPListsDialog d = new IODPListsDialog(getMainFrame());
            d.loadAAffineTable(getMainFrame());

            d.pack();
            d.setSize(800, 600);
            d.setLocationRelativeTo(getMainFrame());
            d.setVisibleTab(3);
            d.setVisible(true);
        }
    });
    limsMenu.add(loadAffineTable);

    JMenuItem loadSpliceTable = new JMenuItem("Load a splice table...");
    loadSpliceTable.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            IODPListsDialog d = new IODPListsDialog(getMainFrame());
            d.loadASpliceTable(getMainFrame());

            d.pack();
            d.setSize(800, 600);
            d.setLocationRelativeTo(getMainFrame());
            d.setVisibleTab(4);
            d.setVisible(true);
        }
    });
    limsMenu.add(loadSpliceTable);

    fileMenu.add(limsMenu);

    JMenu disMenu = new JMenu("DIS");

    JMenuItem disListMenuItem = new JMenuItem("Accessing DIS...");
    disListMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            DISListsDialog d = new DISListsDialog(getMainFrame());
            d.pack();
            d.setSize(800, 600);
            d.setLocationRelativeTo(getMainFrame());
            d.setVisible(true);
        }
    });

    JMenuItem disImport = new JMenuItem("Import...");
    disImport.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.disImport();
        }
    });
    JMenuItem disExport = new JMenuItem("Export...");
    disExport.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.disExport();
        }
    });

    JMenuItem disBatchDataLoad = new JMenuItem("Load Tab Delimited Data File...");
    disBatchDataLoad.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.disBatchDataLoad();
        }
    });

    disMenu.add(disListMenuItem);
    disMenu.add(disImport);
    disMenu.add(disExport);
    disMenu.add(disBatchDataLoad);
    fileMenu.add(disMenu);

    JMenuItem saveOutputToFileMenuItem = new JMenuItem("Export Sheets...", KeyEvent.VK_A);
    saveOutputToFileMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.saveOutputToFile();
        }
    });
    fileMenu.add(saveOutputToFileMenuItem);

    fileMenu.addSeparator();

    JMenuItem quitMenuItem = new JMenuItem("Quit");
    fileMenu.add(quitMenuItem);
    quitMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, MENU_MASK));
    quitMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.quit();
        }
    });

    menuBar.add(fileMenu);

    // Create Edit Menu
    JMenu editMenu = new JMenu("Edit");
    editMenu.setMnemonic(KeyEvent.VK_E);

    JMenuItem clearImageCacheMenuItem = new JMenuItem("Clear Image Cache...", KeyEvent.VK_I);
    clearImageCacheMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.clearImageCache();
        }
    });
    editMenu.add(clearImageCacheMenuItem);

    editMenu.addSeparator();
    JMenuItem depthDirection = new JMenuItem("Switch Depth Direction", KeyEvent.VK_K);
    depthDirection.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_K, MENU_MASK));
    depthDirection.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            boolean b = SceneGraph.getDepthOrientation();
            SceneGraph.setDepthOrientation(!b);

            CorelyzerApp.getApp().updateGLWindows();
        }
    });
    editMenu.add(depthDirection);

    JMenuItem tour = new JMenuItem("Tour...");
    tour.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            CRNavigationSetupDialog dlg = new CRNavigationSetupDialog();
            dlg.pack();
            dlg.setLocationRelativeTo(getApp().getMainFrame());

            dlg.setAlwaysOnTop(true);
            dlg.setVisible(true);
        }
    });

    editMenu.add(tour);

    editMenu.addSeparator();
    JMenuItem preferencesMenuItem = new JMenuItem("Preferences...");
    editMenu.add(preferencesMenuItem);
    preferencesMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.doPreferences();
        }
    });

    menuBar.add(editMenu);

    // Create Share Menu
    JMenu shareMenu = new JMenu("Share");

    JMenuItem publishMenuItem = new JMenuItem("Publish...");
    publishMenuItem.setEnabled(true);
    publishMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            controller.publishASession();
        }
    });
    shareMenu.add(publishMenuItem);

    JMenuItem listMenuItem = new JMenuItem("List...");
    listMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            controller.listSessions();
        }
    });
    shareMenu.add(listMenuItem);

    shareMenu.addSeparator();

    friendsMenu = new JMenu("Friends");
    shareMenu.add(friendsMenu);

    menuBar.add(shareMenu);

    // Create Debug Menu
    JMenu debugMenu = new JMenu("Debug");
    debugMenu.setMnemonic(KeyEvent.VK_D);

    JMenuItem matchTestMenuItem = new JMenuItem("Match-Test", KeyEvent.VK_B);
    matchTestMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent event) {
            controller.testAndMatch();
        }
    });

    debugMenu.add(matchTestMenuItem);

    if ((System.getenv("DEBUG") != null) && System.getenv("DEBUG").equals("YES")) {
        menuBar.add(shareMenu);
    }

    // Create the Plugin Menu
    pluginMenu = new JMenu("Plugins");
    menuBar.add(pluginMenu);
    pluginMenuItemVec = new Vector<JMenuItem>();

    // Lists
    JMenu listsMenu = new JMenu("Lists");

    JMenuItem iodpLists = new JMenuItem("IODP lists...");
    iodpLists.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            IODPListsDialog d = new IODPListsDialog(getMainFrame());
            d.pack();
            d.setSize(800, 600);
            d.setLocationRelativeTo(getMainFrame());
            d.setVisible(true);
        }
    });
    listsMenu.add(iodpLists);

    JMenuItem disLists = new JMenuItem("DIS lists...");
    disLists.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            DISListsDialog d = new DISListsDialog(getMainFrame());
            d.pack();
            d.setSize(800, 600);
            d.setLocationRelativeTo(getMainFrame());
            d.setVisible(true);
        }
    });
    listsMenu.add(disLists);

    JMenu annotLists = new JMenu("Annotation");

    JMenuItem freeformsItem = new JMenuItem("Default");
    freeformsItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            FreeformAnnotationListDialog dlg = new FreeformAnnotationListDialog(getApp().getMainFrame());
            dlg.pack();
            dlg.setLocationRelativeTo(getApp().getMainFrame());
            dlg.onRefresh();

            dlg.setAlwaysOnTop(true);
            dlg.setVisible(true);
        }
    });
    annotLists.add(freeformsItem);

    JMenuItem clastListItem = new JMenuItem("Clast");
    clastListItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            ClastStatisticsDialog dlg = new ClastStatisticsDialog(getApp().getMainFrame());
            dlg.pack();
            dlg.setLocationRelativeTo(getApp().getMainFrame());
            dlg.onRefresh();

            dlg.setAlwaysOnTop(true);
            dlg.setVisible(true);
        }
    });
    annotLists.add(clastListItem);

    JMenuItem sampleReqsItem = new JMenuItem("Sample");
    sampleReqsItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            SampleRequestListDialog dlg = new SampleRequestListDialog(getApp().getMainFrame());
            dlg.pack();
            dlg.setLocationRelativeTo(getApp().getMainFrame());
            dlg.onRefresh();

            dlg.setAlwaysOnTop(true);
            dlg.setVisible(true);
        }
    });
    annotLists.add(sampleReqsItem);
    listsMenu.add(annotLists);

    menuBar.add(listsMenu);

    // Create Tools Menu
    JMenu toolsMenu = new JMenu("Tools");
    JMenuItem wholeCoreViewerMenuItem = new JMenuItem("Get 3D Whole Core Imagery Viewer...");
    wholeCoreViewerMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            try {
                String app;
                String url = "http://www.evl.uic.edu/cavern/corewall/SciVizCore/";

                if (System.getProperty("os.name").toLowerCase().contains("windows")) {
                    app = "cmd.exe /c explorer " + url;
                    Runtime.getRuntime().exec(app);
                } else {
                    app = "open";
                    String[] cmd = { app, url };
                    Runtime.getRuntime().exec(cmd);
                }
            } catch (IOException ex) {
                System.err.println("IOException in opening SciVizCore link");
            }
        }
    });

    toolsMenu.add(wholeCoreViewerMenuItem);

    // DEBUG
    String debug = System.getProperty("DEBUG");
    if ((debug != null) && System.getProperty("DEBUG").equals("true")) {
        JMenuItem gcItem = new JMenuItem("GC");
        gcItem.addActionListener(new ActionListener() {
            public void actionPerformed(final ActionEvent event) {
                long mem0 = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
                System.out.println("- B4 mem:\t" + mem0 / 1000000.0f);

                int trials = 10000;
                for (int i = 0; i < trials; i++) {
                    updateGLWindows();
                }

                long mem1 = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
                System.out.println("- " + trials + " mem:\t" + mem1 / 1000000.0f);

                System.gc();
                System.gc();
                System.gc();

                long mem2 = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
                System.out.println("- AferGC mem:\t" + mem2 / 1000000.0f);
            }
        });
        toolsMenu.add(gcItem);
    }

    menuBar.add(toolsMenu);

    // Create Help Menu
    // Create JavaHelp hooks
    File helpSet = new File("help/jhelpset.hs");
    HelpSet hs = null;
    try {
        URL hsURL = helpSet.toURI().toURL();
        hs = new HelpSet(null, hsURL);
    } catch (HelpSetException e) {
        JOptionPane.showMessageDialog(getMainFrame(), "Cannot find help: format error.");
        e.printStackTrace();
    } catch (MalformedURLException e) {
        JOptionPane.showMessageDialog(getMainFrame(), "Cannot find help: malformed URL.");
        e.printStackTrace();
    }

    // Help UI
    JMenu helpMenu = new JMenu("Help");
    JMenuItem helpMenuItem = new JMenuItem("Help", KeyEvent.VK_H);

    if (hs != null) {
        HelpBroker hb = hs.createHelpBroker();
        helpActionListener = new CSH.DisplayHelpFromSource(hb);
        helpMenuItem.addActionListener(helpActionListener);
    } else {
        helpMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(final ActionEvent event) {
                controller.helpAction();
            }
        });
    }
    helpMenu.add(helpMenuItem);

    helpMenu.addSeparator();
    JMenuItem aboutMenuItem = new JMenuItem("About Corelyzer");
    helpMenu.add(aboutMenuItem);
    aboutMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent event) {
            controller.about();
        }
    });

    menuBar.add(helpMenu);

    mainFrame.setJMenuBar(menuBar);
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopAbstractTable.java

protected JPopupMenu createPopupMenu() {
    JPopupMenu popup = new JPopupMenu();
    JMenuItem menuItem;
    for (final Action action : actionList) {
        if (StringUtils.isNotBlank(action.getCaption()) && action.isVisible()) {
            menuItem = new JMenuItem(action.getCaption());
            if (action.getIcon() != null) {
                menuItem.setIcon(AppBeans.get(IconResolver.class).getIconResource(action.getIcon()));
            }//from  w ww  .ja v a  2  s .c om
            if (action.getShortcutCombination() != null) {
                menuItem.setAccelerator(convertKeyCombination(action.getShortcutCombination()));
            }
            menuItem.setEnabled(action.isEnabled());
            menuItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    action.actionPerform(DesktopAbstractTable.this);
                }
            });
            popup.add(menuItem);
        }
    }
    return popup;
}

From source file:com.diversityarrays.kdxplore.curate.TrialDataEditor.java

@Override
public JMenuBar getJMenuBar() {

    if (menuBar == null) {

        JMenuItem menuItem;
        //        JMenu windowsMenu = new JMenu("Graphs & Plots");
        showAll.setEnabled(false);//from   ww  w .j ava  2s .c o m
        menuItem = windowsMenu.add(showAll);
        menuItem.setMnemonic('B');
        menuItem.setAccelerator(
                KeyStroke.getKeyStroke('B', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

        closeAll.setEnabled(false);
        windowsMenu.add(closeAll);
        windowsMenu.addSeparator();

        JMenu fileMenu = new JMenu(Msg.MENU_FILE());
        menuItem = fileMenu.add(saveChangesAction);
        menuItem.setMnemonic('S');
        menuItem.setAccelerator(
                KeyStroke.getKeyStroke('S', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

        menuItem = fileMenu.add(exportCuratedData);
        // menuItem.setMnemonic('T');
        // menuItem.setAccelerator(KeyStroke.getKeyStroke('T',
        // Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask()));
        fileMenu.addSeparator();

        fileMenu.add(importCuratedData);

        importCuratedData.setEnabled(true);

        JMenu editMenu = new JMenu(Msg.MENU_EDIT());
        menuItem = editMenu.add(undoAction);
        menuItem.setMnemonic('Z');
        menuItem.setAccelerator(
                KeyStroke.getKeyStroke('Z', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

        menuItem = editMenu.add(redoAction);
        menuItem.setMnemonic('Y');
        menuItem.setAccelerator(
                KeyStroke.getKeyStroke('Y', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

        // undockMenuItem = viewMenu.add(undockViewAction);

        showWarnings.setEnabled(false);
        JMenu viewMenu = new JMenu(Msg.MENU_VIEW());
        viewMenu.add(showWarnings);

        problemMenu.add(new ReportIssueAction(this));

        menuBar = new JMenuBar();
        menuBar.add(fileMenu);
        menuBar.add(editMenu);
        menuBar.add(viewMenu);
        menuBar.add(windowsMenu);
        menuBar.add(problemMenu);
    }

    return menuBar;
}

From source file:javazoom.jlgui.player.amp.PlayerUI.java

public void loadSkin() {
    log.info("Load PlayerUI (EDT=" + SwingUtilities.isEventDispatchThread() + ")");
    removeAll();//from w  w  w  . j  a  v  a  2s . co m
    // Load skin specified in args
    if (ui.getPath() != null) {
        log.info("Load default skin from " + ui.getPath());
        ui.loadSkin(ui.getPath());
        config.setDefaultSkin(ui.getPath());
    }
    // Load skin specified in jlgui.ini
    else if ((config.getDefaultSkin() != null) && (!config.getDefaultSkin().trim().equals(""))) {
        log.info("Load default skin from " + config.getDefaultSkin());
        ui.loadSkin(config.getDefaultSkin());
    }
    // Default included skin
    else {
        ClassLoader cl = getClass().getClassLoader();
        InputStream sis = cl.getResourceAsStream("javazoom/jlgui/player/amp/metrix.wsz");
        log.info("Load default skin for JAR");
        ui.loadSkin(sis);
    }
    // Background
    ImageBorder border = new ImageBorder();
    border.setImage(ui.getMainImage());
    setBorder(border);
    // Buttons        
    add(ui.getAcPrevious(), ui.getAcPrevious().getConstraints());
    ui.getAcPrevious().removeActionListener(this);
    ui.getAcPrevious().addActionListener(this);
    add(ui.getAcPlay(), ui.getAcPlay().getConstraints());
    ui.getAcPlay().removeActionListener(this);
    ui.getAcPlay().addActionListener(this);
    add(ui.getAcPause(), ui.getAcPause().getConstraints());
    ui.getAcPause().removeActionListener(this);
    ui.getAcPause().addActionListener(this);
    add(ui.getAcStop(), ui.getAcStop().getConstraints());
    ui.getAcStop().removeActionListener(this);
    ui.getAcStop().addActionListener(this);
    add(ui.getAcNext(), ui.getAcNext().getConstraints());
    ui.getAcNext().removeActionListener(this);
    ui.getAcNext().addActionListener(this);
    add(ui.getAcEject(), ui.getAcEject().getConstraints());
    ui.getAcEject().removeActionListener(this);
    ui.getAcEject().addActionListener(this);
    // EqualizerUI toggle
    add(ui.getAcEqualizer(), ui.getAcEqualizer().getConstraints());
    ui.getAcEqualizer().removeActionListener(this);
    ui.getAcEqualizer().addActionListener(this);
    // Playlist toggle
    add(ui.getAcPlaylist(), ui.getAcPlaylist().getConstraints());
    ui.getAcPlaylist().removeActionListener(this);
    ui.getAcPlaylist().addActionListener(this);
    // Shuffle toggle
    add(ui.getAcShuffle(), ui.getAcShuffle().getConstraints());
    ui.getAcShuffle().removeActionListener(this);
    ui.getAcShuffle().addActionListener(this);
    // Repeat toggle
    add(ui.getAcRepeat(), ui.getAcRepeat().getConstraints());
    ui.getAcRepeat().removeActionListener(this);
    ui.getAcRepeat().addActionListener(this);
    // Volume
    add(ui.getAcVolume(), ui.getAcVolume().getConstraints());
    ui.getAcVolume().removeChangeListener(this);
    ui.getAcVolume().addChangeListener(this);
    // Balance
    add(ui.getAcBalance(), ui.getAcBalance().getConstraints());
    ui.getAcBalance().removeChangeListener(this);
    ui.getAcBalance().addChangeListener(this);
    // Seek bar
    add(ui.getAcPosBar(), ui.getAcPosBar().getConstraints());
    ui.getAcPosBar().removeChangeListener(this);
    ui.getAcPosBar().addChangeListener(this);
    // Mono
    add(ui.getAcMonoIcon(), ui.getAcMonoIcon().getConstraints());
    // Stereo
    add(ui.getAcStereoIcon(), ui.getAcStereoIcon().getConstraints());
    // Title label
    add(ui.getAcTitleLabel(), ui.getAcTitleLabel().getConstraints());
    // Sample rate label
    add(ui.getAcSampleRateLabel(), ui.getAcSampleRateLabel().getConstraints());
    // Bit rate label
    add(ui.getAcBitRateLabel(), ui.getAcBitRateLabel().getConstraints());
    // Play icon
    add(ui.getAcPlayIcon(), ui.getAcPlayIcon().getConstraints());
    // Time icon
    add(ui.getAcTimeIcon(), ui.getAcTimeIcon().getConstraints());
    // MinuteH number
    add(ui.getAcMinuteH(), ui.getAcMinuteH().getConstraints());
    // MinuteL number
    add(ui.getAcMinuteL(), ui.getAcMinuteL().getConstraints());
    // SecondH number
    add(ui.getAcSecondH(), ui.getAcSecondH().getConstraints());
    // SecondL number
    add(ui.getAcSecondL(), ui.getAcSecondL().getConstraints());
    // TitleBar
    add(ui.getAcTitleBar(), ui.getAcTitleBar().getConstraints());
    add(ui.getAcMinimize(), ui.getAcMinimize().getConstraints());
    ui.getAcMinimize().removeActionListener(this);
    ui.getAcMinimize().addActionListener(this);
    add(ui.getAcExit(), ui.getAcExit().getConstraints());
    ui.getAcExit().removeActionListener(this);
    ui.getAcExit().addActionListener(this);
    // DSP
    if (ui.getAcAnalyzer() != null) {
        add(ui.getAcAnalyzer(), ui.getAcAnalyzer().getConstraints());
    }
    // Popup menu
    mainpopup = new JPopupMenu(ui.getResource("popup.title"));
    JMenuItem mi = new JMenuItem(Skin.TITLETEXT + "- JavaZOOM");
    //mi.removeActionListener(this);
    //mi.addActionListener(this);
    mainpopup.add(mi);
    mainpopup.addSeparator();
    JMenu playSubMenu = new JMenu(ui.getResource("popup.play"));
    miPlayFile = new JMenuItem(ui.getResource("popup.play.file"));
    miPlayFile.setActionCommand(PlayerActionEvent.MIPLAYFILE);
    miPlayFile.removeActionListener(this);
    miPlayFile.addActionListener(this);
    miPlayLocation = new JMenuItem(ui.getResource("popup.play.location"));
    miPlayLocation.setActionCommand(PlayerActionEvent.MIPLAYLOCATION);
    miPlayLocation.removeActionListener(this);
    miPlayLocation.addActionListener(this);
    playSubMenu.add(miPlayFile);
    playSubMenu.add(miPlayLocation);
    mainpopup.add(playSubMenu);
    mainpopup.addSeparator();
    miPlaylist = new JCheckBoxMenuItem(ui.getResource("popup.playlist"));
    miPlaylist.setActionCommand(PlayerActionEvent.MIPLAYLIST);
    if (config.isPlaylistEnabled())
        miPlaylist.setState(true);
    miPlaylist.removeActionListener(this);
    miPlaylist.addActionListener(this);
    mainpopup.add(miPlaylist);
    miEqualizer = new JCheckBoxMenuItem(ui.getResource("popup.equalizer"));
    miEqualizer.setActionCommand(PlayerActionEvent.MIEQUALIZER);
    if (config.isEqualizerEnabled())
        miEqualizer.setState(true);
    miEqualizer.removeActionListener(this);
    miEqualizer.addActionListener(this);
    mainpopup.add(miEqualizer);
    mainpopup.addSeparator();
    mi = new JMenuItem(ui.getResource("popup.preferences"));
    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK, false));
    mi.setActionCommand(PlayerActionEvent.MIPREFERENCES);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    mainpopup.add(mi);
    JMenu skinsSubMenu = new JMenu(ui.getResource("popup.skins"));
    mi = new JMenuItem(ui.getResource("popup.skins.browser"));
    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.ALT_MASK, false));
    mi.setActionCommand(PlayerActionEvent.MISKINBROWSER);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    skinsSubMenu.add(mi);
    mi = new JMenuItem(ui.getResource("popup.skins.load"));
    mi.setActionCommand(PlayerActionEvent.MILOADSKIN);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    skinsSubMenu.add(mi);
    mainpopup.add(skinsSubMenu);
    JMenu playbackSubMenu = new JMenu(ui.getResource("popup.playback"));
    mi = new JMenuItem(ui.getResource("popup.playback.jump"));
    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J, 0, false));
    mi.setActionCommand(PlayerActionEvent.MIJUMPFILE);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    playbackSubMenu.add(mi);
    mi = new JMenuItem(ui.getResource("popup.playback.stop"));
    mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, 0, false));
    mi.setActionCommand(PlayerActionEvent.MISTOP);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    playbackSubMenu.add(mi);
    mainpopup.add(playbackSubMenu);
    mainpopup.addSeparator();
    mi = new JMenuItem(ui.getResource("popup.exit"));
    mi.setActionCommand(PlayerActionEvent.ACEXIT);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    mainpopup.add(mi);
    // Popup menu on TitleBar
    ui.getAcTitleBar().removeMouseListener(popupAdapter);
    popupAdapter = new PopupAdapter(mainpopup);
    ui.getAcTitleBar().addMouseListener(popupAdapter);
    // Popup menu on Eject button
    ejectpopup = new JPopupMenu();
    mi = new JMenuItem(ui.getResource("popup.eject.openfile"));
    mi.setActionCommand(PlayerActionEvent.MIPLAYFILE);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    ejectpopup.add(mi);
    mi = new JMenuItem(ui.getResource("popup.eject.openlocation"));
    mi.setActionCommand(PlayerActionEvent.MIPLAYLOCATION);
    mi.removeActionListener(this);
    mi.addActionListener(this);
    ejectpopup.add(mi);
    ui.getAcEject().removeMouseListener(ejectpopupAdapter);
    ejectpopupAdapter = new PopupAdapter(ejectpopup);
    ui.getAcEject().addMouseListener(ejectpopupAdapter);
    // EqualizerUI
    if (equalizerUI != null)
        equalizerUI.loadUI();
    if (playlistUI != null)
        playlistUI.loadUI();
    validate();
    loader.loaded();
}