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:edu.harvard.mcz.imagecapture.BulkMediaFrame.java

private void init() {
    thisFrame = this;
    setTitle("BulkMedia Preparation");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 902, 174);/* w  w w .ja  v  a 2s  .c  om*/

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu mnFile = new JMenu("File");
    mnFile.setMnemonic(KeyEvent.VK_F);
    menuBar.add(mnFile);

    JMenuItem mntmPrepareDirectory = new JMenuItem("Prepare Directory");
    mntmPrepareDirectory.setMnemonic(KeyEvent.VK_D);
    mntmPrepareDirectory.addActionListener(new PrepareDirectoryAction());
    mnFile.add(mntmPrepareDirectory);

    JMenuItem mntmNewMenuItem = new JMenuItem("Exit");
    mntmNewMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            done();
        }
    });

    JMenuItem mntmNewMenuItem_1 = new JMenuItem("Edit Properties");
    mntmNewMenuItem_1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            PropertiesEditor p = new PropertiesEditor();
            p.pack();
            p.setVisible(true);
        }
    });
    mnFile.add(mntmNewMenuItem_1);
    mntmNewMenuItem.setMnemonic(KeyEvent.VK_X);
    mntmNewMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));
    mnFile.add(mntmNewMenuItem);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(new BorderLayout(0, 0));

    JPanel panel = new JPanel();
    contentPane.add(panel, BorderLayout.CENTER);
    panel.setLayout(new GridLayout(3, 2, 0, 0));

    JLabel lblBaseUri = new JLabel("Base URI (first part of path to images on the web)");
    lblBaseUri.setHorizontalAlignment(SwingConstants.TRAILING);
    panel.add(lblBaseUri, "2, 2");

    textField = new JTextField();
    textField.setEditable(false);
    textField.setText(Singleton.getSingletonInstance().getProperties().getProperties()
            .getProperty(ImageCaptureProperties.KEY_IMAGEBASEURI));
    panel.add(textField);
    textField.setColumns(10);

    JLabel lblNewLabel = new JLabel("Local Path To Base (local mount path that maps to base URI)");
    lblNewLabel.setHorizontalAlignment(SwingConstants.TRAILING);
    panel.add(lblNewLabel);

    textField_1 = new JTextField();
    textField_1.setEditable(false);
    textField_1.setText(Singleton.getSingletonInstance().getProperties().getProperties()
            .getProperty(ImageCaptureProperties.KEY_IMAGEBASE));
    panel.add(textField_1);
    textField_1.setColumns(10);

    JLabel lblBeforeExitingWait = new JLabel(
            "Before exiting wait for both the Done and Thumbnails Built messages.");
    panel.add(lblBeforeExitingWait);

    JLabel lblThumbnailGenerationIs = new JLabel("Thumbnail generation is not reported on the progress bar.");
    panel.add(lblThumbnailGenerationIs);

    progressBar = new JProgressBar();
    progressBar.setStringPainted(false);
    contentPane.add(progressBar, BorderLayout.NORTH);

    JPanel panel_1 = new JPanel();
    contentPane.add(panel_1, BorderLayout.SOUTH);

    JButton btnPrepareDirectory = new JButton("Run");
    btnPrepareDirectory.setToolTipText("Select a directory and prepare a bulk media file for images therein.");
    panel_1.add(btnPrepareDirectory);
    btnPrepareDirectory.addActionListener(new PrepareDirectoryAction());
    btnPrepareDirectory.setPreferredSize(new Dimension(80, 25));

    JButton btnExit = new JButton("Exit");
    btnExit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            done();
        }
    });
    panel_1.add(btnExit);
}

From source file:burlov.ultracipher.swing.SwingGuiApplication.java

private JMenuBar createMenuBar() {
    JMenuBar bar = new JMenuBar();
    JMenu menu = null;//from  w  w w  .  j  a  va 2  s .  co m
    /*
     * 'File' Menue
     */
    menu = new JMenu("File");
    menu.setMnemonic(KeyEvent.VK_F);
    bar.add(menu);

    JMenuItem item = new JMenuItem("Save database");
    item.setAccelerator(KeyStroke.getKeyStroke("control S"));
    item.setMnemonic(KeyEvent.VK_S);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            saveDatabase();
        }
    });
    menu.add(item);

    item = new JMenuItem("Download database");
    item.setMnemonic(KeyEvent.VK_L);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            downloadAndMergeData();
        }
    });
    menu.add(item);

    item = new JMenuItem("Edit sync account");
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            editSyncAccount();
        }
    });
    menu.add(item);
    menu.add(new JSeparator());

    JMenu submenu = new JMenu("Import");
    menu.add(submenu);

    item = new JMenuItem("From CSV");
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            importCSV();
        }
    });
    submenu.add(item);

    submenu = new JMenu("Export");
    menu.add(submenu);

    item = new JMenuItem("As CSV");
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            exportCSV();
        }
    });
    submenu.add(item);
    item = new JMenuItem("Change passphrase");
    menu.add(item);
    item.addActionListener(new ActionListener() {

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

    /*
     * 'Edit' Menue
     */
    menu = new JMenu("Edit");
    menu.setMnemonic(KeyEvent.VK_E);
    bar.add(menu);
    item = menu.add(mainPanel.getNewEntryAction());
    item.setMnemonic(KeyEvent.VK_N);
    item = menu.add(mainPanel.getDeleteEntryAction());
    item.setMnemonic(KeyEvent.VK_D);

    menu.add(new JSeparator());

    menu = new JMenu("Tools");
    // item = new JMenuItem("Passwort generator");
    // menu.add(item);
    // item.addActionListener(new ActionListener() {
    //
    // @Override
    // public void actionPerformed(ActionEvent e) {
    // passGenerator.setVisible(false);
    // passGenerator.setLocationRelativeTo(getMainFrame());
    // passGenerator.setVisible(true);
    // }
    // });
    item = new JMenuItem("Screen keyboard");
    menu.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            screenKeyboard.setLocationRelativeTo(getMainFrame());
            screenKeyboard.setVisible(true);

        }
    });
    item = new JMenuItem("File digester");
    menu.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            digester.setLocationRelativeTo(getMainFrame());
            digester.setVisible(true);

        }
    });
    bar.add(menu);
    /*
     * 'Help' Menue
     */
    menu = new JMenu("Help");
    menu.setMnemonic(KeyEvent.VK_H);
    bar.add(menu);

    item = new JMenuItem("Performance test");
    menu.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            measurePerformance();
        }
    });
    item = new JMenuItem("System info");
    menu.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            showSystemInfo();
        }
    });
    item = new JMenuItem("About");
    menu.add(item);
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            String text = "<html>Ultracipher 6.1<br>(C) Copyright 2015 Paul Burlov<br><br>"
                    + "Encryption strength: 768Bit (6 x 128Bit keys)<br>Cipher cascade: AES/Twofish/Serpent/CAST6/SEED/Camellia"
                    + "<br>Encryption mode: Two pass CBC"
                    + "<br>Key derivation algorithm: SCrypt with N=2^14,P=8,R=1<br><br> "
                    + "This product includes software developed by the<br>"
                    + "<ul><li>Apache Software Foundation "
                    + "<a href='http://www.apache.org'>http://www.apache.org</a>"
                    + "<li>Legion of the Bouncy Castle <a href='http://bouncycastle.org/'>http://bouncycastle.org</a>"
                    + "<li>Project SwingX" + "<li>Bytecode Pty Ltd." + "</ul></html>";
            JOptionPane.showMessageDialog(getMainFrame(), text, "", JOptionPane.INFORMATION_MESSAGE,
                    getAppIcon());
        }
    });
    bar.add(Box.createHorizontalGlue());
    menu = new JMenu("Keyboard");
    ButtonGroup group = new ButtonGroup();
    JRadioButtonMenuItem radioitem = new JRadioButtonMenuItem("System");
    radioitem.setSelected(true);
    group.add(radioitem);
    radioitem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            translator.resetMapping();
        }
    });
    menu.add(radioitem);
    radioitem = new JRadioButtonMenuItem("Futhark runes");
    group.add(radioitem);
    radioitem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            translator.initForFuthark();
        }
    });
    menu.add(radioitem);
    radioitem = new JRadioButtonMenuItem("Anglo-Saxon runes");
    group.add(radioitem);
    radioitem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            translator.initForAngloSaxon();
        }
    });
    menu.add(radioitem);
    bar.add(menu);
    // bar.add(Box.createHorizontalGlue());
    // bar.add(new PassGeneratorPanel());
    return bar;
}

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

protected JPopupMenu createPopupMenu() {
    JPopupMenu popup = new JPopupMenu();
    JMenuItem menuItem;
    for (final com.haulmont.cuba.gui.components.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()));
            }//ww  w  . jav  a2s .c  o m
            if (action.getShortcutCombination() != null) {
                menuItem.setAccelerator(
                        DesktopComponentsHelper.convertKeyCombination(action.getShortcutCombination()));
            }
            menuItem.setEnabled(action.isEnabled());
            menuItem.addActionListener(e -> action.actionPerform(DesktopTree.this));
            popup.add(menuItem);
        }
    }
    return popup;
}

From source file:com.isencia.passerelle.hmi.generic.GenericHMI.java

public void addPrefsMenu(final JMenuBar menuBar) {
    final JMenu prefsMenu = new JMenu(HMIMessages.getString(HMIMessages.MENU_PREFS));
    prefsMenu.setMnemonic(HMIMessages.getString(HMIMessages.MENU_PREFS + HMIMessages.KEY).charAt(0));
    final JMenuItem layoutMenuItem = new JMenuItem(HMIMessages.getString(HMIMessages.MENU_LAYOUT),
            HMIMessages.getString(HMIMessages.MENU_LAYOUT + HMIMessages.KEY).charAt(0));
    layoutMenuItem.addActionListener(new ColumnCountDialogOpener());
    prefsMenu.add(layoutMenuItem);//from  w ww .  j  a v  a  2  s  .  c o m
    final JMenuItem actorOrderMenuItem = new JMenuItem(HMIMessages.getString(HMIMessages.MENU_ACTOR_ORDER),
            HMIMessages.getString(HMIMessages.MENU_ACTOR_ORDER + HMIMessages.KEY).charAt(0));
    actorOrderMenuItem.addActionListener(new ActorOrderOpener());
    prefsMenu.add(actorOrderMenuItem);
    final JMenuItem paramFilterMenuItem = new JMenuItem(
            HMIMessages.getString(HMIMessages.MENU_PARAM_VISIBILITY),
            HMIMessages.getString(HMIMessages.MENU_PARAM_VISIBILITY + HMIMessages.KEY).charAt(0));
    paramFilterMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_MASK));
    paramFilterMenuItem.addActionListener(new ParameterFilterOpener());
    prefsMenu.add(paramFilterMenuItem);
    menuBar.add(prefsMenu);

    StateMachine.getInstance().registerActionForState(StateMachine.MODEL_OPEN, HMIMessages.MENU_PREFS,
            prefsMenu);
}

From source file:edu.brown.gui.CatalogViewer.java

/**
 * /*from  ww w.j  av  a2  s  . c o m*/
 */
protected void viewerInit() {
    // ----------------------------------------------
    // MENU
    // ----------------------------------------------
    JMenu menu;
    JMenuItem menuItem;

    // 
    // File Menu
    //
    menu = new JMenu("File");
    menu.getPopupMenu().setLightWeightPopupEnabled(false);
    menu.setMnemonic(KeyEvent.VK_F);
    menu.getAccessibleContext().setAccessibleDescription("File Menu");
    menuBar.add(menu);

    menuItem = new JMenuItem("Open Catalog From File");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Open Catalog From File");
    menuItem.addActionListener(this.menuHandler);
    menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.CATALOG_OPEN_FILE);
    menu.add(menuItem);

    menuItem = new JMenuItem("Open Catalog From Jar");
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Open Catalog From Project Jar");
    menuItem.addActionListener(this.menuHandler);
    menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.CATALOG_OPEN_JAR);
    menu.add(menuItem);

    menu.addSeparator();

    menuItem = new JMenuItem("Quit", KeyEvent.VK_Q);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Quit Program");
    menuItem.addActionListener(this.menuHandler);
    menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.QUIT);
    menu.add(menuItem);

    // ----------------------------------------------
    // CATALOG TREE PANEL
    // ----------------------------------------------
    this.catalogTree = new JTree();
    this.catalogTree.setEditable(false);
    this.catalogTree.setCellRenderer(new CatalogViewer.CatalogTreeRenderer());
    this.catalogTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    this.catalogTree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) CatalogViewer.this.catalogTree
                    .getLastSelectedPathComponent();
            if (node == null)
                return;

            Object user_obj = node.getUserObject();
            String new_text = ""; // <html>";
            boolean text_mode = true;
            if (user_obj instanceof WrapperNode) {
                CatalogType catalog_obj = ((WrapperNode) user_obj).getCatalogType();
                new_text += CatalogViewer.this.getAttributesText(catalog_obj);
            } else if (user_obj instanceof AttributesNode) {
                AttributesNode wrapper = (AttributesNode) user_obj;
                new_text += wrapper.getAttributes();

            } else if (user_obj instanceof PlanTreeCatalogNode) {
                final PlanTreeCatalogNode wrapper = (PlanTreeCatalogNode) user_obj;
                text_mode = false;

                CatalogViewer.this.mainPanel.remove(0);
                CatalogViewer.this.mainPanel.add(wrapper.getPanel(), BorderLayout.CENTER);
                CatalogViewer.this.mainPanel.validate();
                CatalogViewer.this.mainPanel.repaint();

                if (SwingUtilities.isEventDispatchThread() == false) {
                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            wrapper.centerOnRoot();
                        }
                    });
                } else {
                    wrapper.centerOnRoot();
                }

            } else {
                new_text += CatalogViewer.this.getSummaryText();
            }

            // Text Mode
            if (text_mode) {
                if (CatalogViewer.this.text_mode == false) {
                    CatalogViewer.this.mainPanel.remove(0);
                    CatalogViewer.this.mainPanel.add(CatalogViewer.this.textInfoPanel);
                }
                CatalogViewer.this.textInfoTextArea.setText(new_text);

                // Scroll to top
                CatalogViewer.this.textInfoTextArea.grabFocus();
            }

            CatalogViewer.this.text_mode = text_mode;
        }
    });
    this.generateCatalogTree(this.catalog, this.catalog_file_path.getName());

    //
    // Text Information Panel
    //
    this.textInfoPanel = new JPanel();
    this.textInfoPanel.setLayout(new BorderLayout());
    this.textInfoTextArea = new JTextArea();
    this.textInfoTextArea.setEditable(false);
    this.textInfoTextArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
    this.textInfoTextArea.setText(this.getSummaryText());
    this.textInfoTextArea.addFocusListener(new FocusListener() {
        @Override
        public void focusLost(FocusEvent e) {
            // TODO Auto-generated method stub
        }

        @Override
        public void focusGained(FocusEvent e) {
            CatalogViewer.this.scrollTextInfoToTop();
        }
    });
    this.textInfoScroller = new JScrollPane(this.textInfoTextArea);
    this.textInfoPanel.add(this.textInfoScroller, BorderLayout.CENTER);
    this.mainPanel = new JPanel(new BorderLayout());
    this.mainPanel.add(textInfoPanel, BorderLayout.CENTER);

    //
    // Search Toolbar
    //
    JPanel searchPanel = new JPanel();
    searchPanel.setLayout(new BorderLayout());
    JPanel innerSearchPanel = new JPanel();
    innerSearchPanel.setLayout(new BoxLayout(innerSearchPanel, BoxLayout.X_AXIS));
    innerSearchPanel.add(new JLabel("Search: "));
    this.searchField = new JTextField(30);
    innerSearchPanel.add(this.searchField);
    searchPanel.add(innerSearchPanel, BorderLayout.EAST);

    this.searchField.addKeyListener(new KeyListener() {
        private String last = null;

        @Override
        public void keyReleased(KeyEvent e) {
            String value = CatalogViewer.this.searchField.getText().toLowerCase().trim();
            if (!value.isEmpty() && (this.last == null || !this.last.equals(value))) {
                CatalogViewer.this.search(value);
            }
            this.last = value;
        }

        @Override
        public void keyTyped(KeyEvent e) {
            // Do nothing...
        }

        @Override
        public void keyPressed(KeyEvent e) {
            // Do nothing...
        }
    });

    // Putting it all together
    JScrollPane scrollPane = new JScrollPane(this.catalogTree);
    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BorderLayout());
    topPanel.add(searchPanel, BorderLayout.NORTH);
    topPanel.add(scrollPane, BorderLayout.CENTER);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, topPanel, this.mainPanel);
    splitPane.setDividerLocation(400);

    this.add(splitPane, BorderLayout.CENTER);
}

From source file:ch.fork.AdHocRailway.ui.AdHocRailway.java

/**
 *
 *///  w  w  w.j a  v  a  2s . c  o  m
private void assignAccelerator(final JMenuItem item, final String actionName) {
    final Set<KeyStroke> strokes = preferences.getKeyBoardLayout().getKeys(actionName);
    if (strokes != null && strokes.size() > 0) {
        item.setAccelerator(strokes.iterator().next());
    }
}

From source file:ch.fork.AdHocRailway.ui.AdHocRailway.java

private void initMenu() {
    menuBar = new JMenuBar();
    /* FILE *///from  w ww .java  2 s  . c o  m
    final JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);

    final JMenuItem newItem = new JMenuItem(new NewFileAction());
    newItem.setMnemonic(KeyEvent.VK_N);
    newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));

    final JMenuItem openItem = new JMenuItem(new OpenFileAction());
    openItem.setMnemonic(KeyEvent.VK_O);
    openItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));

    final JMenuItem openDatabaseItem = new JMenuItem(new OpenDatabaseAction());

    saveItem = new JMenuItem(new SaveAction());
    saveItem.setMnemonic(KeyEvent.VK_S);
    saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));

    saveAsItem = new JMenuItem(new SaveAsAction());
    saveAsItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));

    final JMenuItem importAllItem = new JMenuItem(new ImportAllAction());
    final JMenuItem importLocomotivesItem = new JMenuItem(new ImportLocomotivesAction());
    final JMenuItem exportLocomotivesItem = new JMenuItem(new ExportLocomotivesAction());
    final JMenuItem exportAllItem = new JMenuItem(new ExportAllAction());

    final JMenu importMenu = new JMenu("Import");
    importMenu.add(importAllItem);
    importMenu.add(importLocomotivesItem);
    final JMenu exportMenu = new JMenu("Export");
    exportMenu.add(exportLocomotivesItem);
    exportMenu.add(exportAllItem);

    final JMenuItem clearLocomotivesItem = new JMenuItem(new ClearLocomotivesAction());
    final JMenuItem clearTurnoutsRoutesItem = new JMenuItem(new ClearTurnoutsAndRoutesAction());

    final JMenu clearMenu = new JMenu("Clear");
    clearMenu.add(clearLocomotivesItem);
    clearMenu.add(clearTurnoutsRoutesItem);

    final JMenuItem exitItem = new JMenuItem(new ExitAction());
    exitItem.setMnemonic(KeyEvent.VK_X);
    exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));

    fileMenu.add(newItem);
    fileMenu.add(openItem);
    fileMenu.add(openDatabaseItem);
    fileMenu.add(saveItem);
    fileMenu.add(saveAsItem);
    fileMenu.add(new JSeparator());
    fileMenu.add(importMenu);
    fileMenu.add(exportMenu);
    fileMenu.add(clearMenu);
    fileMenu.add(new JSeparator());
    fileMenu.add(exitItem);

    /* EDIT */
    final JMenu editMenu = new JMenu("Edit");
    enableEditing = new JCheckBoxMenuItem(new EnableEditingAction());

    switchesItem = new JMenuItem(new TurnoutAction());
    routesItem = new JMenuItem(new RoutesAction());
    locomotivesItem = new JMenuItem(new LocomotivesAction());
    preferencesItem = new JMenuItem(new PreferencesAction());
    enableEditing.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.ALT_MASK));

    switchesItem.setMnemonic(KeyEvent.VK_T);
    switchesItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.ALT_MASK));
    routesItem.setMnemonic(KeyEvent.VK_R);
    routesItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.ALT_MASK));
    locomotivesItem.setMnemonic(KeyEvent.VK_L);
    locomotivesItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, ActionEvent.ALT_MASK));
    preferencesItem.setMnemonic(KeyEvent.VK_P);
    preferencesItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.ALT_MASK));
    editMenu.add(enableEditing);
    editMenu.add(new JSeparator());
    editMenu.add(switchesItem);
    editMenu.add(routesItem);
    editMenu.add(locomotivesItem);
    editMenu.add(new JSeparator());
    editMenu.add(preferencesItem);

    /* DAEMON */
    final JMenu daemonMenu = new JMenu("Device");
    daemonConnectItem = new JMenuItem(new ConnectAction());
    daemonConnectItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
    daemonDisconnectItem = new JMenuItem(new DisconnectAction());
    daemonPowerOnItem = new JMenuItem(new PowerOnAction());
    assignAccelerator(daemonPowerOnItem, "PowerOn");
    daemonPowerOnItem.setEnabled(true);
    daemonPowerOffItem = new JMenuItem(new PowerOffAction());
    assignAccelerator(daemonPowerOffItem, "PowerOff");
    daemonPowerOffItem.setEnabled(true);
    daemonDisconnectItem.setEnabled(false);
    daemonMenu.add(daemonConnectItem);
    daemonMenu.add(daemonDisconnectItem);
    daemonMenu.add(new JSeparator());
    daemonMenu.add(daemonPowerOnItem);
    daemonMenu.add(daemonPowerOffItem);

    /* VIEW */
    final JMenu viewMenu = new JMenu("View");
    final JMenuItem refreshItem = new JMenuItem(new RefreshAction());
    final JMenuItem fullscreenItem = new JMenuItem(new ToggleFullscreenAction());

    viewMenu.add(refreshItem);
    viewMenu.add(fullscreenItem);

    /* HELP */
    // JMenu helpMenu = new JMenu("Help");
    addMenu(fileMenu);
    addMenu(editMenu);
    addMenu(daemonMenu);
    addMenu(viewMenu);
    // addMenu(helpMenu);
    setJMenuBar(menuBar);
}

From source file:com.digitalgeneralists.assurance.ui.MainWindow.java

private void initializeComponent() {
    if (!this.initialized) {
        logger.info("Initializing the main window.");

        if (AssuranceUtils.getPlatform() == Platform.MAC) {

            System.setProperty("apple.laf.useScreenMenuBar", "true");
            com.apple.eawt.Application macApplication = com.apple.eawt.Application.getApplication();
            MacApplicationAdapter macAdapter = new MacApplicationAdapter(this);
            macApplication.addApplicationListener(macAdapter);
            macApplication.setEnabledPreferencesMenu(true);
        }// w w w  . j a v  a2  s  .  c  om

        this.setTitle(Application.applicationShortName);

        this.setDefaultCloseOperation(EXIT_ON_CLOSE);

        GridBagLayout gridbag = new GridBagLayout();
        this.setLayout(gridbag);

        this.topArea = new JTabbedPane();

        this.scanLaunchPanel.setPreferredSize(new Dimension(600, 150));

        this.scanHistoryPanel.setPreferredSize(new Dimension(600, 150));

        this.topArea.addTab("Scan", this.scanLaunchPanel);

        this.topArea.addTab("History", this.scanHistoryPanel);

        this.resultsPanel.setPreferredSize(new Dimension(600, 400));

        this.topArea.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                resultsPanel.resetPanel();
                // NOTE:  This isn't ideal.  It feels brittle.
                if (topArea.getSelectedIndex() == viewHistoryMenuItemIndex) {
                    viewHistoryMenuItem.setSelected(true);
                } else {
                    viewScanMenuItem.setSelected(true);
                }
            }
        });

        GridBagConstraints topPanelConstraints = new GridBagConstraints();
        topPanelConstraints.anchor = GridBagConstraints.NORTH;
        topPanelConstraints.fill = GridBagConstraints.BOTH;
        topPanelConstraints.gridx = 0;
        topPanelConstraints.gridy = 0;
        topPanelConstraints.weightx = 1.0;
        topPanelConstraints.weighty = 0.33;
        topPanelConstraints.gridheight = 1;
        topPanelConstraints.gridwidth = 1;
        topPanelConstraints.insets = new Insets(0, 0, 0, 0);

        this.getContentPane().add(this.topArea, topPanelConstraints);

        GridBagConstraints resultsPanelConstraints = new GridBagConstraints();
        resultsPanelConstraints.anchor = GridBagConstraints.SOUTH;
        resultsPanelConstraints.fill = GridBagConstraints.BOTH;
        resultsPanelConstraints.gridx = 0;
        resultsPanelConstraints.gridy = 1;
        resultsPanelConstraints.weightx = 1.0;
        resultsPanelConstraints.weighty = 0.67;
        resultsPanelConstraints.gridheight = 1;
        resultsPanelConstraints.gridwidth = 1;
        resultsPanelConstraints.insets = new Insets(0, 0, 0, 0);

        this.getContentPane().add(this.resultsPanel, resultsPanelConstraints);

        this.applicationDelegate.addEventObserver(ScanStartedEvent.class, this);
        this.applicationDelegate.addEventObserver(ScanCompletedEvent.class, this);
        this.applicationDelegate.addEventObserver(SetScanDefinitionMenuStateEvent.class, this);
        this.applicationDelegate.addEventObserver(SetScanResultsMenuStateEvent.class, this);
        this.applicationDelegate.addEventObserver(ApplicationConfigurationLoadedEvent.class, this);

        JMenu menu;
        JMenuItem menuItem;

        menuBar = new JMenuBar();

        StringBuilder accessiblityLabel = new StringBuilder(128);
        if (AssuranceUtils.getPlatform() != Platform.MAC) {
            menu = new JMenu(Application.applicationShortName);
            menu.getAccessibleContext().setAccessibleDescription(accessiblityLabel.append("Actions for ")
                    .append(Application.applicationShortName).append(" application").toString());
            accessiblityLabel.setLength(0);
            menuBar.add(menu);

            menuItem = new JMenuItem(MainWindow.quitApplicationMenuLabel, KeyEvent.VK_Q);
            menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
            menuItem.getAccessibleContext().setAccessibleDescription(accessiblityLabel.append("Close the ")
                    .append(Application.applicationShortName).append(" application").toString());
            accessiblityLabel.setLength(0);
            menuItem.addActionListener(this);
            menuItem.setActionCommand(AssuranceActions.quitApplicationAction);
            menu.add(menuItem);

            menu.addSeparator();

            menuItem = new JMenuItem(MainWindow.aboutApplicationMenuLabel);
            menuItem.getAccessibleContext().setAccessibleDescription(
                    accessiblityLabel.append("Display information about this version of ")
                            .append(Application.applicationShortName).append(".").toString());
            accessiblityLabel.setLength(0);
            menuItem.addActionListener(this);
            menuItem.setActionCommand(AssuranceActions.aboutApplicationAction);
            menu.add(menuItem);
        }

        menu = new JMenu("Scan");
        menu.setMnemonic(KeyEvent.VK_S);
        menu.getAccessibleContext().setAccessibleDescription("Actions for file scans");
        menuBar.add(menu);

        menuItem = new JMenuItem(MainWindow.newScanDefinitonMenuLabel, KeyEvent.VK_N);
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
        menuItem.getAccessibleContext().setAccessibleDescription("Create a new scan definition");
        menuItem.addActionListener(this.scanLaunchPanel);
        menuItem.setActionCommand(AssuranceActions.newScanDefinitonAction);
        menu.add(menuItem);

        menuItem = new JMenuItem(MainWindow.deleteScanDefinitonMenuLabel, KeyEvent.VK_D);
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, ActionEvent.CTRL_MASK));
        menuItem.getAccessibleContext().setAccessibleDescription("Delete the selected scan definition");
        menuItem.addActionListener(this.scanLaunchPanel);
        menuItem.setActionCommand(AssuranceActions.deleteScanDefinitonAction);
        menu.add(menuItem);

        menu.addSeparator();

        menuItem = new JMenuItem(MainWindow.scanMenuLabel, KeyEvent.VK_S);
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
        menuItem.getAccessibleContext()
                .setAccessibleDescription("Launch a scan using the selected scan definition");
        menuItem.addActionListener(this.scanLaunchPanel);
        menuItem.setActionCommand(AssuranceActions.scanAction);
        menu.add(menuItem);

        menuItem = new JMenuItem(MainWindow.scanAndMergeMenuLabel, KeyEvent.VK_M);
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.CTRL_MASK));
        menuItem.getAccessibleContext().setAccessibleDescription(
                "Launch a scan using the selected scan definition and merge the results");
        menuItem.addActionListener(this.scanLaunchPanel);
        menuItem.setActionCommand(AssuranceActions.scanAndMergeAction);
        menu.add(menuItem);

        menu = new JMenu("Results");
        menu.setMnemonic(KeyEvent.VK_R);
        menu.getAccessibleContext().setAccessibleDescription("Actions for scan results");
        menuBar.add(menu);

        menuItem = new JMenuItem(MainWindow.replaceSourceMenuLabel, KeyEvent.VK_O);
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
        menuItem.getAccessibleContext()
                .setAccessibleDescription("Replace the source file with the target file");
        menuItem.addActionListener(this.resultsPanel.getResultMenuListener());
        menuItem.setActionCommand(AssuranceActions.replaceSourceAction);
        menu.add(menuItem);

        menuItem = new JMenuItem(MainWindow.replaceTargetMenuLabel, KeyEvent.VK_T);
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK));
        menuItem.getAccessibleContext()
                .setAccessibleDescription("Replace the target file with the source file");
        menuItem.addActionListener(this.resultsPanel.getResultMenuListener());
        menuItem.setActionCommand(AssuranceActions.replaceTargetAction);
        menu.add(menuItem);

        menu.addSeparator();

        menuItem = new JMenuItem(MainWindow.sourceAttributesMenuLabel);
        menuItem.getAccessibleContext().setAccessibleDescription("View the source file attributes");
        menuItem.addActionListener(this.resultsPanel.getResultMenuListener());
        menuItem.setActionCommand(AssuranceActions.sourceAttributesAction);
        menu.add(menuItem);

        menuItem = new JMenuItem(MainWindow.targetAttributesMenuLabel);
        menuItem.getAccessibleContext().setAccessibleDescription("View the target file attributes");
        menuItem.addActionListener(this.resultsPanel.getResultMenuListener());
        menuItem.setActionCommand(AssuranceActions.targetAttributesAction);
        menu.add(menuItem);

        menu = new JMenu("View");
        menu.setMnemonic(KeyEvent.VK_V);
        menu.getAccessibleContext().setAccessibleDescription(
                accessiblityLabel.append("Views within ").append(Application.applicationShortName).toString());
        accessiblityLabel.setLength(0);
        menuBar.add(menu);

        ButtonGroup group = new ButtonGroup();

        this.viewScanMenuItem = new JRadioButtonMenuItem(MainWindow.viewScanMenuLabel);
        this.viewScanMenuItem.addActionListener(this);
        this.viewScanMenuItem.setActionCommand(AssuranceActions.viewScanAction);
        this.viewScanMenuItem.setSelected(true);
        group.add(this.viewScanMenuItem);
        menu.add(this.viewScanMenuItem);

        this.viewHistoryMenuItem = new JRadioButtonMenuItem(MainWindow.viewHistoryMenuLabel);
        this.viewHistoryMenuItem.addActionListener(this);
        this.viewHistoryMenuItem.setActionCommand(AssuranceActions.viewHistoryAction);
        this.viewHistoryMenuItem.setSelected(true);
        group.add(this.viewHistoryMenuItem);
        menu.add(this.viewHistoryMenuItem);

        if (AssuranceUtils.getPlatform() != Platform.MAC) {
            menu = new JMenu("Tools");
            menu.getAccessibleContext()
                    .setAccessibleDescription(accessiblityLabel.append("Additional actions for ")
                            .append(Application.applicationShortName).append(" application").toString());
            accessiblityLabel.setLength(0);
            menuBar.add(menu);

            menuItem = new JMenuItem(MainWindow.settingsMenuLabel, KeyEvent.VK_COMMA);
            menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_COMMA, ActionEvent.CTRL_MASK));
            menuItem.getAccessibleContext()
                    .setAccessibleDescription(accessiblityLabel.append("Change settings for the ")
                            .append(Application.applicationShortName).append(" application").toString());
            accessiblityLabel.setLength(0);
            menuItem.addActionListener(this);
            menuItem.setActionCommand(AssuranceActions.displaySettingsAction);
            menu.add(menuItem);
        }

        this.setJMenuBar(menuBar);

        this.initialized = true;
    }
}

From source file:edu.harvard.i2b2.previousquery.QueryPreviousRunsPanel.java

private void createPopupMenu() {
    JMenuItem menuItem;

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

    menuItem = new JMenuItem("Rename ...");
    menuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R,
            java.awt.event.InputEvent.CTRL_MASK));
    menuItem.addActionListener(this);
    popup.add(menuItem);/* w w w.  j  a  v a 2  s .  c o  m*/

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

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

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

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

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

From source file:edu.harvard.i2b2.query.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);//w  ww.j av a  2s.c o m
    popup.add(menuItem);*/

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

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

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