Example usage for javax.swing JMenuItem setMnemonic

List of usage examples for javax.swing JMenuItem setMnemonic

Introduction

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

Prototype

@BeanProperty(visualUpdate = true, description = "the keyboard character mnemonic")
public void setMnemonic(int mnemonic) 

Source Link

Document

Sets the keyboard mnemonic on the current model.

Usage

From source file:net.sourceforge.pmd.cpd.GUI.java

public GUI() {
    frame = new JFrame("PMD Duplicate Code Detector (v " + PMDVersion.VERSION + ')');

    timeField.setEditable(false);//  w ww . ja  v  a 2  s . c  o  m

    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic('f');

    addSaveOptionsTo(fileMenu);

    JMenuItem exitItem = new JMenuItem("Exit");
    exitItem.setMnemonic('x');
    exitItem.addActionListener(new CancelListener());
    fileMenu.add(exitItem);
    JMenu viewMenu = new JMenu("View");
    fileMenu.setMnemonic('v');
    JMenuItem trimItem = new JCheckBoxMenuItem("Trim leading whitespace");
    trimItem.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            AbstractButton button = (AbstractButton) e.getItem();
            GUI.this.trimLeadingWhitespace = button.isSelected();
        }
    });
    viewMenu.add(trimItem);
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(fileMenu);
    menuBar.add(viewMenu);
    frame.setJMenuBar(menuBar);

    // first make all the buttons
    JButton browseButton = new JButton("Browse");
    browseButton.setMnemonic('b');
    browseButton.addActionListener(new BrowseListener());
    goButton = new JButton("Go");
    goButton.setMnemonic('g');
    goButton.addActionListener(new GoListener());
    cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new CancelListener());

    JPanel settingsPanel = makeSettingsPanel(browseButton, goButton, cancelButton);
    progressPanel = makeProgressPanel();
    JPanel resultsPanel = makeResultsPanel();

    adjustLanguageControlsFor((LanguageConfig) LANGUAGE_SETS[0][1]);

    frame.getContentPane().setLayout(new BorderLayout());
    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BorderLayout());
    topPanel.add(settingsPanel, BorderLayout.NORTH);
    topPanel.add(progressPanel, BorderLayout.CENTER);
    setProgressControls(false); // not running now
    frame.getContentPane().add(topPanel, BorderLayout.NORTH);
    frame.getContentPane().add(resultsPanel, BorderLayout.CENTER);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
}

From source file:org.apache.jackrabbit.oak.explorer.Explorer.java

private void createAndShowGUI(final File path, boolean skipSizeCheck) throws IOException {
    JTextArea log = new JTextArea(5, 20);
    log.setMargin(new Insets(5, 5, 5, 5));
    log.setLineWrap(true);/*from   w  ww  .  j  av  a 2  s.  com*/
    log.setEditable(false);

    final NodeStoreTree treePanel = new NodeStoreTree(backend, log, skipSizeCheck);

    final JFrame frame = new JFrame("Explore " + path + " @head");
    frame.addWindowListener(new java.awt.event.WindowAdapter() {
        @Override
        public void windowClosing(java.awt.event.WindowEvent windowEvent) {
            IOUtils.closeQuietly(treePanel);
            System.exit(0);
        }
    });

    JPanel content = new JPanel(new GridBagLayout());

    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1;
    c.weighty = 1;

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(treePanel),
            new JScrollPane(log));
    splitPane.setDividerLocation(0.3);
    content.add(new JScrollPane(splitPane), c);
    frame.getContentPane().add(content);

    JMenuBar menuBar = new JMenuBar();
    menuBar.setMargin(new Insets(2, 2, 2, 2));

    JMenuItem menuReopen = new JMenuItem("Reopen");
    menuReopen.setMnemonic(KeyEvent.VK_R);
    menuReopen.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            try {
                treePanel.reopen();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    });

    JMenuItem menuCompaction = new JMenuItem("Time Machine");
    menuCompaction.setMnemonic(KeyEvent.VK_T);
    menuCompaction.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            List<String> revs = backend.readRevisions();
            String s = (String) JOptionPane.showInputDialog(frame, "Revert to a specified revision",
                    "Time Machine", JOptionPane.PLAIN_MESSAGE, null, revs.toArray(), revs.get(0));
            if (s != null && treePanel.revert(s)) {
                frame.setTitle("Explore " + path + " @" + s);
            }
        }
    });

    JMenuItem menuRefs = new JMenuItem("Tar File Info");
    menuRefs.setMnemonic(KeyEvent.VK_I);
    menuRefs.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            List<String> tarFiles = new ArrayList<String>();
            for (File f : path.listFiles()) {
                if (f.getName().endsWith(".tar")) {
                    tarFiles.add(f.getName());
                }
            }

            String s = (String) JOptionPane.showInputDialog(frame, "Choose a tar file", "Tar File Info",
                    JOptionPane.PLAIN_MESSAGE, null, tarFiles.toArray(), tarFiles.get(0));
            if (s != null) {
                treePanel.printTarInfo(s);
            }
        }
    });

    JMenuItem menuSCR = new JMenuItem("Segment Refs");
    menuSCR.setMnemonic(KeyEvent.VK_R);
    menuSCR.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            String s = JOptionPane.showInputDialog(frame, "Segment References\nUsage: <segmentId>",
                    "Segment References", JOptionPane.PLAIN_MESSAGE);
            if (s != null) {
                treePanel.printSegmentReferences(s);
            }
        }
    });

    JMenuItem menuDiff = new JMenuItem("SegmentNodeState diff");
    menuDiff.setMnemonic(KeyEvent.VK_D);
    menuDiff.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            String s = JOptionPane.showInputDialog(frame,
                    "SegmentNodeState diff\nUsage: <recordId> <recordId> [<path>]", "SegmentNodeState diff",
                    JOptionPane.PLAIN_MESSAGE);
            if (s != null) {
                treePanel.printDiff(s);
            }
        }
    });

    JMenuItem menuPCM = new JMenuItem("Persisted Compaction Maps");
    menuPCM.setMnemonic(KeyEvent.VK_P);
    menuPCM.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            treePanel.printPCMInfo();
        }
    });

    menuBar.add(menuReopen);
    menuBar.add(new JSeparator(JSeparator.VERTICAL));
    menuBar.add(menuCompaction);
    menuBar.add(new JSeparator(JSeparator.VERTICAL));
    menuBar.add(menuRefs);
    menuBar.add(new JSeparator(JSeparator.VERTICAL));
    menuBar.add(menuSCR);
    menuBar.add(new JSeparator(JSeparator.VERTICAL));
    menuBar.add(menuDiff);
    menuBar.add(new JSeparator(JSeparator.VERTICAL));
    menuBar.add(menuPCM);
    menuBar.add(new JSeparator(JSeparator.VERTICAL));

    frame.setJMenuBar(menuBar);
    frame.pack();
    frame.setSize(960, 720);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

}

From source file:org.ayound.js.debug.ui.DebugMainFrame.java

protected JMenuBar createMenuBar() {
    final JMenuBar menuBar = new JMenuBar();

    JMenu fileMenu = new JMenu(Messages.getString("DebugMainFrame.File")); //$NON-NLS-1$
    fileMenu.setMnemonic('f');
    JMenuItem item = null;

    item = fileMenu.add(actionOpen);//from   ww  w  .ja v a  2s  .c o  m
    fileMenu.add(item);

    item = fileMenu.add(actionClose);
    fileMenu.add(item);

    fileMenu.addSeparator();

    item = fileMenu.add(actionExit);
    item.setMnemonic('x');
    menuBar.add(fileMenu);

    JMenu debugMenu = new JMenu(Messages.getString("DebugMainFrame.Debug")); //$NON-NLS-1$
    debugMenu.setMnemonic('d');

    item = debugMenu.add(actionDebugStart);
    debugMenu.add(item);

    menuBar.add(debugMenu);

    item = debugMenu.add(actionDebugEnd);
    debugMenu.add(item);

    JMenu helpMenu = new JMenu(Messages.getString("DebugMainFrame.Help")); //$NON-NLS-1$
    helpMenu.setMnemonic('d');

    item = helpMenu.add(actionHelp);
    helpMenu.add(item);

    item = helpMenu.add(actionAbout);
    helpMenu.add(item);

    JMenu languageMenu = new JMenu("lauguage");

    item = languageMenu.add(actionLanguageChinese);
    languageMenu.add(item);

    item = languageMenu.add(actionLanguageEnglish);
    languageMenu.add(item);

    menuBar.add(languageMenu);

    menuBar.add(helpMenu);

    return menuBar;
}

From source file:org.f2o.absurdum.puck.gui.PuckFrame.java

/**
 * Instances and shows Puck's main frame.
 *//*  ww  w. ja  v  a  2s . com*/
public PuckFrame() {

    super();

    setLookAndFeel(PuckConfiguration.getInstance().getProperty("look"));

    /*
    LookAndFeelInfo[] lfs = UIManager.getInstalledLookAndFeels();
    for ( int i = 0 ; i < lfs.length ; i++ )
    {
       if ( lfs[i].getName().toLowerCase().contains("nimbus") )
       {
    try 
    {
       UIManager.setLookAndFeel(lfs[i].getClassName());
    } 
    catch (Exception e) //class not found, instantiation exception, etc. (shouldn't happen)
    {
       e.printStackTrace();
    }
            
       }
    }
    */

    setSize(PuckConfiguration.getInstance().getIntegerProperty("windowWidth"),
            PuckConfiguration.getInstance().getIntegerProperty("windowHeight"));
    setLocation(PuckConfiguration.getInstance().getIntegerProperty("windowLocationX"),
            PuckConfiguration.getInstance().getIntegerProperty("windowLocationY"));
    //setSize(600,600);
    if (PuckConfiguration.getInstance().getBooleanProperty("windowMaximized"))
        maximizeIfPossible();
    //setTitle(Messages.getInstance().getMessage("frame.title"));
    refreshTitle();
    left = new JPanel();
    right = new JPanel();
    JScrollPane rightScroll = new JScrollPane(right);
    rightScroll.getVerticalScrollBar().setUnitIncrement(16); //faster scrollbar (by default it was very slow, maybe because component inside is not text component!)
    split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, rightScroll) {
        //dynamic resizing of right panel
        /*
        public void setDividerLocation ( int pixels )
        {
              if ( propPanel != null )
              {
          double rightPartSize = getContentPane().getWidth() - pixels - 15;
          System.out.println("rps=" + rightPartSize);
          System.out.println("mnw=" + this.getMinimumSize().getWidth());
          Dimension propPanSize = propPanel.getSize();
          int propPanHeight = 0;
          if (propPanSize != null) propPanHeight = (int) propPanSize.getHeight();
          //propPanel.revalidate();
          System.out.println("h " + propPanHeight);
          //if ( rightPartSize >= propPanel.getMinimumSize().getWidth() )
             propPanel.setPreferredSize(new Dimension((int)rightPartSize,propPanHeight));
             //propPanel.setMinimumSize(new Dimension((int)rightPartSize,propPanHeight));
             //propPanel.setMaximumSize(new Dimension((int)rightPartSize,propPanHeight));
             //propPanel.setSize(new Dimension((int)rightPartSize,propPanHeight));
             propPanel.revalidate();
              }
              super.setDividerLocation(pixels);
        }
        */

    };
    split.setContinuousLayout(true);
    split.setResizeWeight(0.60);
    final int dividerLoc = PuckConfiguration.getInstance().getIntegerProperty("dividerLocation", 0);

    /*
    SwingUtilities.invokeLater(new Runnable(){
    public void run()
    {
    */

    /*   
    }
    });
    */
    split.setOneTouchExpandable(true);
    getContentPane().add(split);

    System.out.println(Toolkit.getDefaultToolkit().getBestCursorSize(20, 20));
    //it's 32x32. Will have to do it.

    //Image img = Toolkit.getDefaultToolkit().createImage( getClass().getResource("addCursor32.png") );

    //Image img = Toolkit.getDefaultToolkit().createImage("addCursor32.png");

    left.setLayout(new BorderLayout());

    //right.setLayout(new BoxLayout(right,BoxLayout.LINE_AXIS));
    if (PuckConfiguration.getInstance().getBooleanProperty("dynamicFormResizing"))
        right.setLayout(new BorderLayout());
    else
        right.setLayout(new FlowLayout());

    propPanel = new PropertiesPanel();
    right.add(propPanel);

    graphPanel = new GraphEditingPanel(propPanel);
    graphPanel.setGrid(Boolean.valueOf(PuckConfiguration.getInstance().getProperty("showGrid")).booleanValue());
    graphPanel.setSnapToGrid(
            Boolean.valueOf(PuckConfiguration.getInstance().getProperty("snapToGrid")).booleanValue());
    propPanel.setGraphEditingPanel(graphPanel);
    tools = new PuckToolBar(graphPanel, propPanel, this);
    left.add(tools, BorderLayout.WEST);
    left.add(graphPanel, BorderLayout.CENTER);

    /*
    Action testAction = 
    new AbstractAction()
    {
       public void actionPerformed ( ActionEvent evt )
       {
          System.out.println("Puck!");
       }
    }
    ;
    testAction.putValue(Action.NAME,"Print Puck");
            
    tools.add(testAction);
    */

    /*
    public void saveChanges ( )
    {
       if ( editingFileName == null )
       {
    //save as... code
       }
       else
       {
    File f = new File(editingFileName);
    try
    {
       Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
       d.appendChild(graphPanel.getWorldNode().getAssociatedPanel().getXML(d));
       Transformer t = TransformerFactory.newInstance().newTransformer();
       Source s = new DOMSource(d);
       Result r = new StreamResult(f);
       t.transform(s,r);
       editingFileName = f.toString();
       refreshTitle();
    }
    catch ( Exception e )
    {
       JOptionPane.showMessageDialog(PuckFrame.this,e,"Whoops!",JOptionPane.ERROR_MESSAGE);
       e.printStackTrace();
    }
       }
    }
    */

    JMenuBar mainMenuBar = new JMenuBar();
    JMenu fileMenu = new JMenu(UIMessages.getInstance().getMessage("menu.file"));
    fileMenu.setMnemonic(KeyEvent.VK_F);
    saveMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.save"));
    saveMenuItem.setMnemonic(KeyEvent.VK_S);
    saveMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if (editingFileName == null)
                JOptionPane.showMessageDialog(PuckFrame.this, "File has no name!", "Whoops!",
                        JOptionPane.ERROR_MESSAGE);
            /*
            File f = new File(editingFileName);
            try
            {
             Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
             d.appendChild(graphPanel.getWorldNode().getAssociatedPanel().getXML(d));
             Transformer t = TransformerFactory.newInstance().newTransformer();
             Source s = new DOMSource(d);
             Result r = new StreamResult(f);
             t.transform(s,r);
             editingFileName = f.toString();
             refreshTitle();
            }
            catch ( Exception e )
            {
             JOptionPane.showMessageDialog(PuckFrame.this,e,"Whoops!",JOptionPane.ERROR_MESSAGE);
             e.printStackTrace();
            }
            */
            try {
                saveChangesInCurrentFile();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(PuckFrame.this, e.getLocalizedMessage(), "Whoops!",
                        JOptionPane.ERROR_MESSAGE);
                e.printStackTrace();
            }
        }
    });
    JMenu newMenu = new JMenu(UIMessages.getInstance().getMessage("menu.file.new"));
    JMenuItem newBlankMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.new.blank"));
    //newBlankMenuItem.setMnemonic(KeyEvent.VK_N);
    newBlankMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            GraphElementPanel.emptyQueue(); //stop deferred loads
            graphPanel.clear();
            propPanel.clear();
            JSyntaxBSHCodeFrame.closeAllInstances();
            WorldPanel wp = new WorldPanel(graphPanel);
            WorldNode wn = new WorldNode(wp);
            graphPanel.setWorldNode(wn);
            propPanel.show(graphPanel.getWorldNode());
            resetCurrentlyEditingFile();
            refreshTitle();
            //revalidate(); //only since java 1.7
            //invalidate();
            //validate();
            split.revalidate(); //JComponents do have it before java 1.7 (not JFrame)
        }
    });
    newMenu.add(newBlankMenuItem);
    JMenu templateMenus = new WorldTemplateMenuBuilder(this).getMenu();
    if (templateMenus != null) {
        for (int i = 0; i < templateMenus.getItemCount(); i++) {
            if (i == 0)
                newMenu.add(new JSeparator());
            newMenu.add(templateMenus.getItem(i));
        }
    }
    JMenuItem saveAsMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.saveas"));
    saveAsMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            /*
            JFileChooser jfc = new JFileChooser(".");
            int opt = jfc.showSaveDialog(PuckFrame.this);
            if ( opt == JFileChooser.APPROVE_OPTION )
            {
             File f = jfc.getSelectedFile();
             try
             {
                Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
                d.appendChild(graphPanel.getWorldNode().getAssociatedPanel().getXML(d));
                Transformer t = TransformerFactory.newInstance().newTransformer();
                Source s = new DOMSource(d);
                Result r = new StreamResult(f);
                t.transform(s,r);
                editingFileName = f.toString();
                saveMenuItem.setEnabled(true);
                refreshTitle();
             }
             catch ( Exception e )
             {
                JOptionPane.showMessageDialog(PuckFrame.this,e,"Whoops!",JOptionPane.ERROR_MESSAGE);
                e.printStackTrace();
             }
            }
            */
            try {
                saveAs();
                saveMenuItem.setEnabled(true);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(PuckFrame.this, e.getLocalizedMessage(), "Whoops!",
                        JOptionPane.ERROR_MESSAGE);
                e.printStackTrace();
            }
            //saveAs(saveMenuItem);
        }
    });
    JMenuItem openMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.open"));
    openMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            //graphPanel.setVisible(false);
            //propPanel.setVisible(false);

            JFileChooser jfc = new JFileChooser(".");
            jfc.setFileFilter(new FiltroFicheroMundo());
            int opt = jfc.showOpenDialog(PuckFrame.this);
            if (opt == JFileChooser.APPROVE_OPTION) {
                File f = jfc.getSelectedFile();
                openFileOrShowError(f);
            }

            //graphPanel.setVisible(true);
            //propPanel.setVisible(true);
        }
    });
    openRecentMenu = new JMenu(UIMessages.getInstance().getMessage("menu.file.recent"));
    JMenuItem exitMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.exit"));
    exitMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {

            /*
            int opt = JOptionPane.showConfirmDialog(PuckFrame.this,Messages.getInstance().getMessage("exit.sure.text"),Messages.getInstance().getMessage("exit.sure.title"),JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
                    
            if ( opt == JOptionPane.YES_OPTION )
             System.exit(0);
            */
            userExit();

        }
    });
    JMenu exportMenu = new JMenu(UIMessages.getInstance().getMessage("menu.file.export"));
    JMenuItem exportAppletMenuItem = new JMenuItem(
            UIMessages.getInstance().getMessage("menu.file.export.applet"));
    exportAppletMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            ExportAppletDialog dial = new ExportAppletDialog(PuckFrame.this);
            dial.setVisible(true);
        }
    });
    exportMenu.add(exportAppletMenuItem);

    fileMenu.add(newMenu);
    fileMenu.add(openMenuItem);
    fileMenu.add(openRecentMenu);
    updateRecentMenu();
    fileMenu.add(new JSeparator());
    saveMenuItem.setEnabled(false);
    fileMenu.add(saveMenuItem);
    fileMenu.add(saveAsMenuItem);
    fileMenu.add(exportMenu);
    fileMenu.add(new JSeparator());
    fileMenu.add(exitMenuItem);

    mainMenuBar.add(fileMenu);

    /**
     * Create an Edit menu to support cut/copy/paste.
     */

    JMenu editMenu = new JMenu(UIMessages.getInstance().getMessage("menu.edit"));
    editMenu.setMnemonic(KeyEvent.VK_E);

    JMenuItem findMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.find.entity"));
    findMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            showFindEntityDialog();
        }
    });
    editMenu.add(findMenuItem);
    editMenu.add(new JSeparator());

    JMenuItem aMenuItem = new JMenuItem(new CutAction());
    aMenuItem.setText(UIMessages.getInstance().getMessage("menuaction.cut"));
    aMenuItem.setMnemonic(KeyEvent.VK_T);
    editMenu.add(aMenuItem);

    aMenuItem = new JMenuItem(new CopyAction());
    aMenuItem.setText(UIMessages.getInstance().getMessage("menuaction.copy"));
    aMenuItem.setMnemonic(KeyEvent.VK_C);
    editMenu.add(aMenuItem);

    aMenuItem = new JMenuItem(new PasteAction());
    aMenuItem.setText(UIMessages.getInstance().getMessage("menuaction.paste"));
    aMenuItem.setMnemonic(KeyEvent.VK_P);
    editMenu.add(aMenuItem);

    mainMenuBar.add(editMenu);

    JMenu optionsMenu = new JMenu(UIMessages.getInstance().getMessage("menu.options"));
    JMenu gridMenu = new JMenu(UIMessages.getInstance().getMessage("menu.options.grid"));
    optionsMenu.add(gridMenu);
    final JCheckBoxMenuItem showGridItem = new JCheckBoxMenuItem(
            UIMessages.getInstance().getMessage("menu.options.grid.show"));
    showGridItem.setSelected(
            Boolean.valueOf(PuckConfiguration.getInstance().getProperty("showGrid")).booleanValue());
    gridMenu.add(showGridItem);
    showGridItem.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                graphPanel.setGrid(true);
                PuckConfiguration.getInstance().setProperty("showGrid", "true");
            } else if (e.getStateChange() == ItemEvent.DESELECTED) {
                graphPanel.setGrid(false);
                PuckConfiguration.getInstance().setProperty("showGrid", "false");
            }
            graphPanel.repaint();
        }
    });
    final JCheckBoxMenuItem snapToGridItem = new JCheckBoxMenuItem(
            UIMessages.getInstance().getMessage("menu.options.grid.snap"));
    snapToGridItem.setSelected(
            Boolean.valueOf(PuckConfiguration.getInstance().getProperty("snapToGrid")).booleanValue());
    gridMenu.add(snapToGridItem);
    snapToGridItem.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                graphPanel.setSnapToGrid(true);
                PuckConfiguration.getInstance().setProperty("snapToGrid", "true");
            } else if (e.getStateChange() == ItemEvent.DESELECTED) {
                graphPanel.setSnapToGrid(false);
                PuckConfiguration.getInstance().setProperty("snapToGrid", "false");
            }
            graphPanel.repaint();
        }
    });

    JMenuItem translationModeMenu = new JMenu(UIMessages.getInstance().getMessage("menu.options.translation"));
    ButtonGroup translationGroup = new ButtonGroup();
    final JRadioButtonMenuItem holdMenuItem = new JRadioButtonMenuItem(
            UIMessages.getInstance().getMessage("menu.options.translation.hold"));
    final JRadioButtonMenuItem pushMenuItem = new JRadioButtonMenuItem(
            UIMessages.getInstance().getMessage("menu.options.translation.push"));
    pushMenuItem.setSelected("push".equals(PuckConfiguration.getInstance().getProperty("translateMode")));
    if (!pushMenuItem.isSelected())
        holdMenuItem.setSelected(true);
    translationGroup.add(holdMenuItem);
    translationGroup.add(pushMenuItem);
    holdMenuItem.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent arg0) {
            if (holdMenuItem.isSelected())
                PuckConfiguration.getInstance().setProperty("translateMode", "hold");
            else
                PuckConfiguration.getInstance().setProperty("translateMode", "push");
        }
    });
    translationModeMenu.add(holdMenuItem);
    translationModeMenu.add(pushMenuItem);
    optionsMenu.add(translationModeMenu);

    JMenuItem toolSelectionModeMenu = new JMenu(
            UIMessages.getInstance().getMessage("menu.options.toolselection"));
    ButtonGroup toolSelectionGroup = new ButtonGroup();
    final JRadioButtonMenuItem oneUseMenuItem = new JRadioButtonMenuItem(
            UIMessages.getInstance().getMessage("menu.options.toolselection.oneuse"));
    final JRadioButtonMenuItem multipleUseMenuItem = new JRadioButtonMenuItem(
            UIMessages.getInstance().getMessage("menu.options.toolselection.multipleuse"));
    multipleUseMenuItem.setSelected(
            "multipleUse".equalsIgnoreCase(PuckConfiguration.getInstance().getProperty("toolSelectionMode")));
    if (!multipleUseMenuItem.isSelected())
        oneUseMenuItem.setSelected(true);
    toolSelectionGroup.add(oneUseMenuItem);
    toolSelectionGroup.add(multipleUseMenuItem);
    oneUseMenuItem.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent arg0) {
            if (oneUseMenuItem.isSelected())
                PuckConfiguration.getInstance().setProperty("toolSelectionMode", "oneUse");
            else
                PuckConfiguration.getInstance().setProperty("toolSelectionMode", "multipleUse");
        }
    });
    toolSelectionModeMenu.add(oneUseMenuItem);
    toolSelectionModeMenu.add(multipleUseMenuItem);
    optionsMenu.add(toolSelectionModeMenu);

    JMenuItem sizesMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.options.iconsizes"));
    sizesMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            IconSizesDialog dial = new IconSizesDialog(PuckFrame.this, true);
            dial.setVisible(true);
        }
    });
    optionsMenu.add(sizesMenuItem);

    JMenuItem showHideMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.options.showhide"));
    showHideMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ShowHideDialog dial = new ShowHideDialog(PuckFrame.this, true);
            dial.setVisible(true);
        }
    });
    optionsMenu.add(showHideMenuItem);

    JMenuItem mapColorsMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.options.mapcolors"));
    mapColorsMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            MapColorsDialog dial = new MapColorsDialog(PuckFrame.this, true);
            dial.setVisible(true);
        }
    });
    optionsMenu.add(mapColorsMenuItem);

    String skinList = PuckConfiguration.getInstance().getProperty("availableSkins");
    if (skinList != null && skinList.trim().length() > 0) {
        JMenu skinsMenu = new JMenu(UIMessages.getInstance().getMessage("menu.skins"));
        StringTokenizer st = new StringTokenizer(skinList, ", ");
        ButtonGroup skinButtons = new ButtonGroup();
        while (st.hasMoreTokens()) {
            final String nextSkin = st.nextToken();
            final JRadioButtonMenuItem skinMenuItem = new JRadioButtonMenuItem(nextSkin);
            skinMenuItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    setSkin(nextSkin);
                    skinMenuItem.setSelected(true);
                }
            });
            if (nextSkin.equals(PuckConfiguration.getInstance().getProperty("skin")))
                skinMenuItem.setSelected(true);
            skinsMenu.add(skinMenuItem);
            skinButtons.add(skinMenuItem);
        }
        optionsMenu.add(skinsMenu);
    }

    JMenu lookFeelMenu = new JMenu(UIMessages.getInstance().getMessage("menu.looks"));
    ButtonGroup lookButtons = new ButtonGroup();
    final JRadioButtonMenuItem defaultLookMenuItem = new JRadioButtonMenuItem(
            UIMessages.getInstance().getMessage("menu.looks.default"));
    if ("default".equals(PuckConfiguration.getInstance().getProperty("look"))) {
        defaultLookMenuItem.setSelected(true);
    }
    lookFeelMenu.add(defaultLookMenuItem);
    lookButtons.add(defaultLookMenuItem);
    defaultLookMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setLookAndFeel("default");
            defaultLookMenuItem.setSelected(true);
        }
    });
    final JRadioButtonMenuItem systemLookMenuItem = new JRadioButtonMenuItem(
            UIMessages.getInstance().getMessage("menu.looks.system"));
    if ("system".equals(PuckConfiguration.getInstance().getProperty("look"))) {
        systemLookMenuItem.setSelected(true);
    }
    lookFeelMenu.add(systemLookMenuItem);
    lookButtons.add(systemLookMenuItem);
    systemLookMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setLookAndFeel("system");
            systemLookMenuItem.setSelected(true);
        }
    });
    String additionalLookList = PuckConfiguration.getInstance().getProperty("additionalLooks");
    if (additionalLookList != null && additionalLookList.trim().length() > 0) {
        StringTokenizer st = new StringTokenizer(additionalLookList, ", ");
        while (st.hasMoreTokens()) {
            final String nextLook = st.nextToken();
            final JRadioButtonMenuItem lookMenuItem = new JRadioButtonMenuItem(nextLook);
            lookMenuItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    setLookAndFeel(nextLook);
                    lookMenuItem.setSelected(true);
                }
            });
            if (nextLook.equals(PuckConfiguration.getInstance().getProperty("look"))) {
                lookMenuItem.setSelected(true);
            }
            lookFeelMenu.add(lookMenuItem);
            lookButtons.add(lookMenuItem);
        }
    }
    optionsMenu.add(lookFeelMenu);

    optionsMenu.add(new UILanguageSelectionMenu(this));

    mainMenuBar.add(optionsMenu);

    JMenu toolsMenu = new JMenu(UIMessages.getInstance().getMessage("menu.tools"));

    final JMenuItem verbListMenuItem = new JMenuItem(
            UIMessages.getInstance().getMessage("menu.tools.verblist"));
    verbListMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            WorldPanel wp = (WorldPanel) graphPanel.getWorldNode().getAssociatedPanel();
            VerbListFrame vlf = VerbListFrame.getInstance(wp.getSelectedLanguageCode());
            vlf.setVisible(true);
        }
    });
    toolsMenu.add(verbListMenuItem);

    final JMenuItem validateMenuItem = new JMenuItem(
            UIMessages.getInstance().getMessage("menu.tools.validatebsh"));
    validateMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            BeanShellCodeValidator bscv = new BeanShellCodeValidator(graphPanel);
            if (!bscv.validate()) {
                BeanShellErrorsDialog bsed = new BeanShellErrorsDialog(PuckFrame.this, bscv.getErrorText());
                bsed.setVisible(true);
                //JOptionPane.showMessageDialog(PuckFrame.this, bscv.getErrorText());
            } else {
                JOptionPane.showMessageDialog(PuckFrame.this,
                        UIMessages.getInstance().getMessage("bsh.code.ok"), "OK!",
                        JOptionPane.INFORMATION_MESSAGE);
                //JOptionPane.showMessageDialog(PuckFrame.this, bscv.getErrorText());
            }
        }
    });
    toolsMenu.add(validateMenuItem);

    mainMenuBar.add(toolsMenu);

    JMenu helpMenu = new JMenu(UIMessages.getInstance().getMessage("menu.help"));
    //JHelpAction.startHelpWorker("help/PUCKHelp.hs");
    //JHelpAction helpTocAction = JHelpAction.getShowHelpInstance(Messages.getInstance().getMessage("menu.help.toc"));
    //JHelpAction helpContextSensitiveAction = JHelpAction.getTrackInstance(Messages.getInstance().getMessage("menu.help.context"));
    //final JMenuItem helpTocMenuItem = new JMenuItem(helpTocAction);
    //final JMenuItem helpContextSensitiveMenuItem = new JMenuItem(helpContextSensitiveAction);
    //helpMenu.add(helpTocMenuItem);
    //helpMenu.add(helpContextSensitiveMenuItem);

    final JMenuItem helpMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.help.toc"));
    helpMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DocumentationLinkDialog dial = new DocumentationLinkDialog(PuckFrame.this, true);
            dial.setVisible(true);
        }
    });
    helpMenu.add(helpMenuItem);

    mainMenuBar.add(helpMenu);

    MenuMnemonicOnTheFly.setMnemonics(mainMenuBar);

    this.setJMenuBar(mainMenuBar);

    //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            userExit();
        }
    });

    propPanel.show(graphPanel.getWorldNode());

    setVisible(true);

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            if (dividerLoc > 0)
                split.setDividerLocation(dividerLoc);
            else
                split.setDividerLocation(0.60);
        }
    });

}

From source file:org.jcurl.demo.editor.EditorApp.java

private JMenuItem newMI(final char mnemonic, final int ctrlAccel, final Action action) {
    final JMenuItem item = new JMenuItem(action);
    item.setMnemonic(mnemonic);
    if (ctrlAccel >= 0)
        item.setAccelerator(KeyStroke.getKeyStroke(ctrlAccel, InputEvent.CTRL_MASK));
    return item;//from  w  w  w .j a va2  s  .c o  m
}

From source file:org.jcurl.demo.tactics.old.ActionRegistry.java

private void addMenuItem(final Object controller, final JMenu ret, final Method m) {
    final JCAction a = m.getAnnotation(JCAction.class);
    if (a.separated())
        ret.addSeparator();/*from  ww w.j a  va  2 s  .c  o  m*/
    final JMenuItem mi = new JMenuItem();
    mi.setAction(findAction(controller, m));
    {
        // TODO move to createAction
        final Character mne = findMnemonic(a.title());
        if (mne != null)
            mi.setMnemonic(mne);
    }
    ret.add(mi);
}

From source file:org.kepler.gui.MenuMapper.java

public static JMenuItem addMenuFor(String key, Action action, JComponent topLvlContainer,
        Map<String, JMenuItem> keplerMenuMap) {

    if (topLvlContainer == null) {
        if (isDebugging) {
            log.debug("NULL container received (eg JMenuBar) - returning NULL");
        }//from   w  ww. j  a va2s .c o  m
        return null;
    }
    if (key == null) {
        if (isDebugging) {
            log.debug("NULL key received");
        }
        return null;
    }
    key = key.trim();

    if (key.length() < 1) {
        if (isDebugging) {
            log.debug("BLANK key received");
        }
        return null;
    }
    if (action == null && key.indexOf(MENU_SEPARATOR_KEY) < 0) {
        if (isDebugging) {
            log.debug("NULL action received, but was not a separator: " + key);
        }
        return null;
    }

    if (keplerMenuMap.containsKey(key)) {
        if (isDebugging) {
            log.debug("Menu already added; skipping: " + key);
        }
        return null;
    }

    // split delimited parts and ensure menus all exist
    String[] menuLevel = key.split(MENU_PATH_DELIMITER);

    int totLevels = menuLevel.length;

    // create a menu for each "menuLevel" if it doesn't already exist
    final StringBuffer nextLevelBuff = new StringBuffer();
    String prevLevelStr = null;
    JMenuItem leafMenuItem = null;

    for (int levelIdx = 0; levelIdx < totLevels; levelIdx++) {

        // save previous value
        prevLevelStr = nextLevelBuff.toString();

        String nextLevelStr = menuLevel[levelIdx];
        // get the index of the first MNEMONIC_SYMBOL
        int mnemonicIdx = nextLevelStr.indexOf(MNEMONIC_SYMBOL);
        char mnemonicChar = 0;

        // if an MNEMONIC_SYMBOL exists, remove all underscores. Then, idx
        // of
        // first underscore becomes idx of letter it used to precede - this
        // is the mnemonic letter
        if (mnemonicIdx > -1) {
            nextLevelStr = nextLevelStr.replaceAll(MNEMONIC_SYMBOL, "");
            mnemonicChar = nextLevelStr.charAt(mnemonicIdx);
        }
        if (levelIdx != 0) {
            nextLevelBuff.append(MENU_PATH_DELIMITER);
        }
        nextLevelBuff.append(nextLevelStr);

        // don't add multiple separators together...
        if (nextLevelStr.indexOf(MENU_SEPARATOR_KEY) > -1) {
            if (separatorJustAdded == false) {

                // Check if we're at the top level, since this makes sense
                // only for
                // context menu - we can't add a separator to a JMenuBar
                if (levelIdx == 0) {
                    if (topLvlContainer instanceof JContextMenu) {
                        ((JContextMenu) topLvlContainer).addSeparator();
                    }
                } else {
                    JMenu parent = (JMenu) keplerMenuMap.get(prevLevelStr);

                    if (parent != null) {
                        if (parent.getMenuComponentCount() < 1) {
                            if (isDebugging) {
                                log.debug("------ NOT adding separator to parent " + parent.getText()
                                        + ", since it does not contain any menu items");
                            }
                        } else {
                            if (isDebugging) {
                                log.debug("------ adding separator to parent " + parent.getText());
                            }
                            // add separator to parent
                            parent.addSeparator();
                            separatorJustAdded = true;
                        }
                    }
                }
            }
        } else if (!keplerMenuMap.containsKey(nextLevelBuff.toString())) {
            // If menu has not already been created, we need
            // to create it and then add it to the parent level...

            JMenuItem menuItem = null;

            // if we're at a "leaf node" - need to create a JMenuItem
            if (levelIdx == totLevels - 1) {

                // save old display name to use as actionCommand on
                // menuitem,
                // since some parts of PTII still
                // use "if (actionCommand.equals("SaveAs")) {..." etc
                String oldDisplayName = (String) action.getValue(Action.NAME);

                // action.putValue(Action.NAME, nextLevelStr);

                if (mnemonicChar > 0) {
                    action.putValue(GUIUtilities.MNEMONIC_KEY, new Integer(mnemonicChar));
                }

                // Now we look to see if it's a checkbox
                // menu item, or just a regular one
                String menuItemType = (String) (action.getValue(MENUITEM_TYPE));

                if (menuItemType != null && menuItemType == CHECKBOX_MENUITEM_TYPE) {
                    menuItem = new JCheckBoxMenuItem(action);
                } else {
                    menuItem = new JMenuItem(action);
                }

                // --------------------------------------------------------------
                /** @todo - setting menu names - TEMPORARY FIX - FIXME */
                // Currently, if we use the "proper" way of setting menu
                // names -
                // ie by using action.putValue(Action.NAME, "somename");,
                // then
                // the name appears on the port buttons on the toolbar,
                // making
                // them huge. As a temporary stop-gap, I am just setting the
                // new
                // display name using setText() instead of
                // action.putValue(..,
                // but this needs to be fixed elsewhere - we want to be able
                // to
                // use action.putValue(Action.NAME (ie uncomment the line
                // above
                // that reads:
                // action.putValue(Action.NAME, nextLevelStr);
                // and delete the line below that reads:
                // menuItem.setText(nextLevelStr);
                // otherwise this may bite us in future...
                menuItem.setText(nextLevelStr);
                // --------------------------------------------------------------

                // set old display name as actionCommand on
                // menuitem, for ptii backward-compatibility
                menuItem.setActionCommand(oldDisplayName);

                // add JMenuItem to the Action, so it can be accessed by
                // Action code
                action.putValue(NEW_JMENUITEM_KEY, menuItem);
                leafMenuItem = menuItem;
            } else {
                // if we're *not* at a "leaf node" - need to create a JMenu
                menuItem = new JMenu(nextLevelStr);
                if (mnemonicChar > 0) {
                    menuItem.setMnemonic(mnemonicChar);
                }
            }
            // level 0 is a special case, since the container (JMenuBar or
            // JContextMenu) is not a JMenu or a JMenuItem, so we can't
            // use the same code to add child to parent...
            if (levelIdx == 0) {
                if (topLvlContainer instanceof JMenuBar) {
                    // this handles JMenuBar menus
                    ((JMenuBar) topLvlContainer).add(menuItem);
                } else if (topLvlContainer instanceof JContextMenu) {
                    // this handles popup context menus
                    ((JContextMenu) topLvlContainer).add(menuItem);
                }
                // add to Map
                keplerMenuMap.put(nextLevelBuff.toString(), menuItem);
                separatorJustAdded = false;
            } else {
                JMenu parent = (JMenu) keplerMenuMap.get(prevLevelStr);
                if (parent != null) {
                    // add to parent
                    parent.add(menuItem);
                    // add to Map
                    keplerMenuMap.put(nextLevelBuff.toString(), menuItem);
                    separatorJustAdded = false;
                } else {
                    if (isDebugging) {
                        log.debug("Parent menu is NULL" + prevLevelStr);
                    }
                }
            }
        }
    }
    return leafMenuItem;
}

From source file:org.kuali.test.creator.TestCreator.java

private void createMenuBar() {
    JMenuBar mainMenu = new JMenuBar();

    JMenuItem menu = new JMenu();
    menu.setMnemonic('f');
    menu.setText("File");

    JMenuItem m = new JMenuItem("Reload Configuration");
    m.addActionListener(new ActionListener() {
        @Override//from   www.j  av  a  2  s.co m
        public void actionPerformed(ActionEvent evt) {
            handleReloadConfiguation(evt);
        }
    });

    menu.add(m);

    m = new JMenuItem("Schedule Tests...");
    m.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            handleScheduleTests(evt);
        }
    });

    menu.add(m);

    menu.add(new JSeparator());

    saveConfigurationMenuItem = new JMenuItem("Save Repository Configuration");
    saveConfigurationMenuItem.setEnabled(false);

    saveConfigurationMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            testRepositoryTree.saveConfiguration();
            saveConfigurationButton.setEnabled(false);
            saveConfigurationMenuItem.setEnabled(false);
        }
    });

    menu.add(saveConfigurationMenuItem);

    JMenuItem backupRepositoryMenuItem = new JMenuItem("Backup Repository");

    backupRepositoryMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            handleBackupRepository();
        }
    });

    menu.add(backupRepositoryMenuItem);

    menu.add(new JSeparator());

    createTestMenuItem = new JMenuItem("Create Test");

    createTestMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            handleCreateTest(null);
        }
    });

    menu.add(createTestMenuItem);

    menu.add(new JSeparator());

    JMenuItem setup = new JMenu("Setup");

    m = new JMenuItem("Add Platform");
    m.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            handleAddPlatform(evt);
        }
    });
    setup.add(m);

    m = new JMenuItem("Add Database Connection");
    m.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            handleAddDatabaseConnection(evt);
        }
    });
    setup.add(m);

    m = new JMenuItem("Add Web Service");

    m.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            handleAddWebService(evt);
        }
    });

    setup.add(m);

    m = new JMenuItem("Add JMX Connection");

    m.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            handleAddJmxConnection(evt);
        }
    });

    setup.add(m);

    setup.add(new JSeparator());

    m = new JMenuItem("Parameters requiring encryption");
    m.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            handleParametersRequiringEncryptionSetup();
        }
    });

    setup.add(m);

    m = new JMenuItem("Auto replace parameters");
    m.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            handleAutoReplaceParameterSetup();
        }
    });

    setup.add(m);

    setup.add(new JSeparator());

    m = new JMenuItem("Email Setup");
    m.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            handleEmailSetup(evt);
        }
    });

    setup.add(m);

    menu.add(setup);

    menu.add(new JSeparator());

    m = new JMenuItem("Exit");
    m.setMnemonic('x');
    m.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            exitApplication.doClick();
        }
    });

    menu.add(m);

    mainMenu.add(menu);

    menu = new JMenu("Help");
    menu.setMnemonic('h');

    m = new JMenuItem("Contents");
    m.setMnemonic('c');
    menu.add(m);
    m.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            showHelp(evt);
        }
    });

    m = new JMenuItem("About");
    m.setMnemonic('a');
    menu.add(m);

    m.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            showHelpAbout();
        }
    });

    mainMenu.add(menu);

    setJMenuBar(mainMenu);
}

From source file:org.nebulaframework.ui.swing.node.NodeMainUI.java

/**
 * Setup Menu Bar//from w  w  w  . j a v  a  2  s.c om
 * @return JMenu Bar
 */
private JMenuBar setupMenu() {
    JMenuBar menuBar = new JMenuBar();

    /* -- GridNode Menu -- */

    JMenu gridNodeMenu = new JMenu("GridNode");
    gridNodeMenu.setMnemonic(KeyEvent.VK_N);
    menuBar.add(gridNodeMenu);

    // Discover 
    JMenuItem clusterDiscoverItem = new JMenuItem("Disover and Connect Clusters");
    clusterDiscoverItem.setMnemonic(KeyEvent.VK_D);
    clusterDiscoverItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0));
    gridNodeMenu.add(clusterDiscoverItem);
    clusterDiscoverItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            doDiscover(false);
            ((JCheckBoxMenuItem) getUIElement("menu.node.autodiscover")).setSelected(false);
        }
    });
    addUIElement("menu.node.discover", clusterDiscoverItem); // Add to components map

    // Auto-Discovery
    final JCheckBoxMenuItem autodiscoveryItem = new JCheckBoxMenuItem("Auto Discover");
    autodiscoveryItem.setMnemonic(KeyEvent.VK_A);
    autodiscoveryItem.setSelected(true);
    gridNodeMenu.add(autodiscoveryItem);
    autodiscoveryItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            autodiscover = autodiscoveryItem.isSelected();
        }
    });
    addUIElement("menu.node.autodiscover", autodiscoveryItem); // Add to components map

    gridNodeMenu.addSeparator();

    // Cluster-> Shutdown
    JMenuItem nodeShutdownItem = new JMenuItem("Shutdown", 'u');
    nodeShutdownItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0));
    nodeShutdownItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            doShutdownNode();
        }
    });
    gridNodeMenu.add(nodeShutdownItem);
    addUIElement("menu.node.shutdown", nodeShutdownItem); // Add to components map

    /* -- Options Menu -- */
    JMenu optionsMenu = new JMenu("Options");
    optionsMenu.setMnemonic(KeyEvent.VK_O);
    menuBar.add(optionsMenu);

    // Configuration
    JMenuItem optionsConfigItem = new JMenuItem("Configuration...", 'C');
    optionsConfigItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            showConfiguration();
        }
    });
    optionsMenu.add(optionsConfigItem);
    optionsConfigItem.setEnabled(false); // TODO Create Configuration Options

    /* -- Help Menu -- */
    JMenu helpMenu = new JMenu("Help");
    helpMenu.setMnemonic(KeyEvent.VK_H);
    menuBar.add(helpMenu);

    // Help Contents
    JMenuItem helpContentsItem = new JMenuItem("Help Contents", 'H');
    helpContentsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
    helpContentsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            showHelp();
        }
    });
    helpMenu.add(helpContentsItem);

    helpMenu.addSeparator();

    JMenuItem helpAboutItem = new JMenuItem("About", 'A');
    helpAboutItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            showAbout();
        }
    });
    helpMenu.add(helpAboutItem);

    return menuBar;
}

From source file:org.stanwood.nwn2.gui.MainWindow.java

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

    JMenu mnuFile = new JMenu("File");
    mnuFile.setMnemonic('F');
    JMenuItem newAction = new JMenuItem("Add GUI file");
    newAction.setMnemonic('A');
    newAction.setIcon(IconManager.getInstance().getIcon(IconManager.SIZE_16, IconManager.ICON_LIST_ADD));
    newAction.addActionListener(new ActionListener() {
        @Override//from   ww  w.  ja  v a 2s .  com
        public void actionPerformed(ActionEvent e) {
            addNewGUIFile();
        }
    });
    mnuFile.add(newAction);

    Action exitAction = StandardActions.getApplicationExit(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            closeWindow();
        }
    });
    mnuFile.add(exitAction);

    JMenu mnuPrefences = new JMenu("Prefences");
    mnuPrefences.setMnemonic('P');

    JMenuItem pref = new JMenuItem("Options");
    pref.setMnemonic('O');
    pref.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            showOptionsDialog();
        }

    });
    mnuPrefences.add(pref);

    JMenu mnuHelp = new JMenu("Help");
    mnuHelp.setMnemonic('H');
    Action helpAction = StandardActions.getAboutAction(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            AboutDialog ad = new AboutDialog(MainWindow.this, APP_TITLE, APP_VERSION);

            ad.setApplicationWebLink("http://code.google.com/p/nwn2gui/");
            ad.setMessage("A NWN2 GUI XML viewer.\n\n (C) 2010, The NWN2 GUI developers");
            ad.addAuthor(new Author("John-Paul Stanford", "dev@stanwood.org.uk",
                    "Lead developer and project creator"));
            ad.setIcon(new ImageIcon(MainWindow.class.getResource("nwn2gui48.png")));
            ad.init();
            ad.setVisible(true);
        }
    });
    mnuHelp.add(helpAction);

    menuBar.add(mnuFile);
    menuBar.add(mnuPrefences);
    menuBar.add(mnuHelp);

    setJMenuBar(menuBar);
}