Example usage for javax.swing JRadioButtonMenuItem addActionListener

List of usage examples for javax.swing JRadioButtonMenuItem addActionListener

Introduction

In this page you can find the example usage for javax.swing JRadioButtonMenuItem addActionListener.

Prototype

public void addActionListener(ActionListener l) 

Source Link

Document

Adds an ActionListener to the button.

Usage

From source file:com.haskins.cloudtrailviewer.sidebar.EventsChart.java

@Override
public void addCustomMenu() {

    JRadioButtonMenuItem mnuEventName = new JRadioButtonMenuItem("Event Name");
    JRadioButtonMenuItem mnuAwsRegion = new JRadioButtonMenuItem("AWS Region");
    JRadioButtonMenuItem mnuSourceIpAddress = new JRadioButtonMenuItem("Source IP Address");
    JRadioButtonMenuItem mnuUserAgent = new JRadioButtonMenuItem("User Agent");
    JRadioButtonMenuItem mnuEventSource = new JRadioButtonMenuItem("Event Source");
    JRadioButtonMenuItem mnuErrorCode = new JRadioButtonMenuItem("Error Code");
    JRadioButtonMenuItem mnuRecipientAccountId = new JRadioButtonMenuItem("Recipient Account Id");

    mnuEventName.setActionCommand("EventName");
    mnuEventName.addActionListener(this);
    mnuEventName.setSelected(true);/*from  w ww. java2 s .com*/

    mnuAwsRegion.setActionCommand("AwsRegion");
    mnuAwsRegion.addActionListener(this);

    mnuSourceIpAddress.setActionCommand("SourceIPAddress");
    mnuSourceIpAddress.addActionListener(this);

    mnuUserAgent.setActionCommand("UserAgent");
    mnuUserAgent.addActionListener(this);

    mnuEventSource.setActionCommand("EventSource");
    mnuEventSource.addActionListener(this);

    mnuErrorCode.setActionCommand("ErrorCode");
    mnuErrorCode.addActionListener(this);

    mnuRecipientAccountId.setActionCommand("RecipientAccountId");
    mnuRecipientAccountId.addActionListener(this);

    customGroup.add(mnuEventName);
    customGroup.add(mnuAwsRegion);
    customGroup.add(mnuSourceIpAddress);
    customGroup.add(mnuUserAgent);
    customGroup.add(mnuEventSource);
    customGroup.add(mnuErrorCode);
    customGroup.add(mnuRecipientAccountId);

    JMenu sourceMenu = new JMenu("Event");
    sourceMenu.add(mnuEventName);
    sourceMenu.add(mnuAwsRegion);
    sourceMenu.add(mnuSourceIpAddress);
    sourceMenu.add(mnuUserAgent);
    sourceMenu.add(mnuEventSource);
    sourceMenu.add(mnuErrorCode);
    sourceMenu.add(mnuRecipientAccountId);
    sourceMenu.add(getUserIdentityMenu(customGroup));

    menu.add(sourceMenu);
}

From source file:JDAC.JDAC.java

public JDAC() {
    setTitle("JDAC");

    ImageIcon img = new ImageIcon("logo.png");
    setIconImage(img.getImage());//w  w  w.  j a va  2  s . co  m

    //setLayout(new FlowLayout());

    mDataset = createDataset("A");

    mChart = ChartFactory.createXYLineChart("Preview", "Time (ms)", "Value", mDataset, PlotOrientation.VERTICAL,
            false, true, false);

    mLastChart = ChartFactory.createXYLineChart("Last n values", "Time (ms)", "Value", createLastDataset("B"),
            PlotOrientation.VERTICAL, false, true, false);
    mChart.getXYPlot().getDomainAxis().setLowerMargin(0);
    mChart.getXYPlot().getDomainAxis().setUpperMargin(0);
    mLastChart.getXYPlot().getDomainAxis().setLowerMargin(0);
    mLastChart.getXYPlot().getDomainAxis().setUpperMargin(0);

    ChartPanel chartPanel = new ChartPanel(mChart);
    ChartPanel chartLastPanel = new ChartPanel(mLastChart);
    //chartPanel.setPreferredSize( new java.awt.Dimension( 560 , 367 ) );

    XYPlot plot = mChart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.GREEN);
    renderer.setSeriesStroke(0, new BasicStroke(1.0f));
    plot.setRenderer(renderer);

    XYPlot lastPlot = mLastChart.getXYPlot();
    XYLineAndShapeRenderer lastRenderer = new XYLineAndShapeRenderer();
    lastRenderer.setSeriesPaint(0, Color.RED);
    lastRenderer.setSeriesStroke(0, new BasicStroke(1.0f));
    lastPlot.setRenderer(lastRenderer);

    resetChartButton = new JButton("Reset");
    resetChartButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            resetChart();
        }
    });

    mMenuBar = new JMenuBar();
    JMenu fileMenu = new JMenu("File");
    JMenu sensorMenu = new JMenu("Sensor");
    JMenu deviceMenu = new JMenu("Device");
    portSubMenu = new JMenu("Port");
    JMenu helpMenu = new JMenu("Help");

    serialStatusLabel = new JLabel("Disconnected");
    statusLabel = new JLabel("Ready");
    clearStatus = new LabelClear(statusLabel);
    clearStatus.resetTime();

    connectButton = new JMenuItem("Connect");
    disconnectButton = new JMenuItem("Disconnect");
    startButton = new JButton("Start");
    stopButton = new JButton("Stop");
    scanButton = new JMenuItem("Refresh port list");
    exportCSVButton = new JMenuItem("Export data to CSV");
    exportCSVButton.setAccelerator(KeyStroke.getKeyStroke("control S"));
    exportCSVButton.setMnemonic(KeyEvent.VK_S);
    exportPNGButton = new JMenuItem("Export chart to PNG");

    JPanel optionsPanel = new JPanel(new BorderLayout());

    JMenuItem exitItem = new JMenuItem("Exit");
    exitItem.setAccelerator(KeyStroke.getKeyStroke("control X"));
    exitItem.setMnemonic(KeyEvent.VK_X);

    JMenuItem aboutItem = new JMenuItem("About");
    JMenuItem helpItem = new JMenuItem("Help");
    JMenuItem quickStartItem = new JMenuItem("Quick start");

    lastSpinner = new JSpinner(new SpinnerNumberModel(10, 0, 1000, 1));

    ActionListener mSensorListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setSensor(e.getActionCommand());
        }
    };
    ButtonGroup sensorGroup = new ButtonGroup();
    JRadioButtonMenuItem tmpRadioButton = new JRadioButtonMenuItem("Temperature");
    sensorGroup.add(tmpRadioButton);
    sensorMenu.add(tmpRadioButton);
    tmpRadioButton.addActionListener(mSensorListener);
    tmpRadioButton = new JRadioButtonMenuItem("Distance");
    sensorGroup.add(tmpRadioButton);
    sensorMenu.add(tmpRadioButton);
    tmpRadioButton.addActionListener(mSensorListener);
    tmpRadioButton = new JRadioButtonMenuItem("Voltage");
    sensorGroup.add(tmpRadioButton);
    sensorMenu.add(tmpRadioButton);
    tmpRadioButton.addActionListener(mSensorListener);
    tmpRadioButton = new JRadioButtonMenuItem("Generic");
    tmpRadioButton.setSelected(true);
    setSensor("Generic");
    sensorGroup.add(tmpRadioButton);
    sensorMenu.add(tmpRadioButton);
    tmpRadioButton.addActionListener(mSensorListener);

    connectButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (selectedPortName == null) {
                setStatus("No port selected");
                return;
            }
            connect(selectedPortName);
        }
    });
    disconnectButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            serialStatusLabel.setText("Disconnecting...");
            if (serialPort == null) {
                serialStatusLabel.setText("Disconnected");
                serialConnected = false;
                return;
            }

            stopCollect();
            disconnect();
        }
    });
    scanButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            searchForPorts();
        }
    });
    exportCSVButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            saveData();
        }
    });
    exportPNGButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            exportPNG();
        }
    });
    startButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            startCollect();
        }
    });
    stopButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            stopCollect();
        }
    });
    lastSpinner.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            numLastValues = (Integer) lastSpinner.getValue();
            updateLastTitle();
        }
    });
    updateLastTitle();
    exitItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    helpItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new HelpFrame();
        }
    });
    aboutItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new AboutFrame();
        }
    });
    quickStartItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new StartFrame();
        }
    });

    fileMenu.add(exportCSVButton);
    fileMenu.add(exportPNGButton);
    fileMenu.addSeparator();
    fileMenu.add(exitItem);
    deviceMenu.add(connectButton);
    deviceMenu.add(disconnectButton);
    deviceMenu.addSeparator();
    deviceMenu.add(portSubMenu);
    deviceMenu.add(scanButton);
    helpMenu.add(quickStartItem);
    helpMenu.add(helpItem);
    helpMenu.add(aboutItem);

    mMenuBar.add(fileMenu);
    mMenuBar.add(sensorMenu);
    mMenuBar.add(deviceMenu);
    mMenuBar.add(helpMenu);

    JPanel controlsPanel = new JPanel();
    controlsPanel.add(startButton);
    controlsPanel.add(stopButton);
    controlsPanel.add(resetChartButton);
    optionsPanel.add(controlsPanel, BorderLayout.LINE_START);

    JPanel lastPanel = new JPanel(new FlowLayout());
    lastPanel.add(new JLabel("Shown values: "));
    lastPanel.add(lastSpinner);
    optionsPanel.add(lastPanel);

    JPanel serialPanel = new JPanel(new FlowLayout());
    serialPanel.add(serialStatusLabel);
    optionsPanel.add(serialPanel, BorderLayout.LINE_END);

    add(optionsPanel, BorderLayout.PAGE_START);

    JPanel mainPanel = new JPanel(new GridLayout(0, 2));
    mainPanel.add(chartPanel);
    mainPanel.add(chartLastPanel);
    add(mainPanel);

    add(statusLabel, BorderLayout.PAGE_END);
    setJMenuBar(mMenuBar);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent we) {
            dispose();
        }
    });

    setSize(800, 800);
    pack();
    new StartFrame();

    //center on screen
    Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (int) ((dimension.getWidth() - getWidth()) / 2);
    int y = (int) ((dimension.getHeight() - getHeight()) / 2);
    setLocation(x, y);

    setVisible(true);
}

From source file:com.haskins.cloudtrailviewer.sidebar.EventsStats.java

private void addSourceMenu() {

    JRadioButtonMenuItem mnuEventName = new JRadioButtonMenuItem("Event Name");
    JRadioButtonMenuItem mnuAwsRegion = new JRadioButtonMenuItem("AWS Region");
    JRadioButtonMenuItem mnuSourceIpAddress = new JRadioButtonMenuItem("Source IP Address");
    JRadioButtonMenuItem mnuUserAgent = new JRadioButtonMenuItem("User Agent");
    JRadioButtonMenuItem mnuEventSource = new JRadioButtonMenuItem("Event Source");
    JRadioButtonMenuItem mnuErrorCode = new JRadioButtonMenuItem("Error Code");
    JRadioButtonMenuItem mnuRecipientAccountId = new JRadioButtonMenuItem("Recipient Account Id");

    mnuEventName.setActionCommand("EventName");
    mnuEventName.addActionListener(this);
    mnuEventName.setSelected(true);/*ww  w  .j  ava 2s  .com*/

    mnuAwsRegion.setActionCommand("AwsRegion");
    mnuAwsRegion.addActionListener(this);

    mnuSourceIpAddress.setActionCommand("SourceIPAddress");
    mnuSourceIpAddress.addActionListener(this);

    mnuUserAgent.setActionCommand("UserAgent");
    mnuUserAgent.addActionListener(this);

    mnuEventSource.setActionCommand("EventSource");
    mnuEventSource.addActionListener(this);

    mnuErrorCode.setActionCommand("ErrorCode");
    mnuErrorCode.addActionListener(this);

    mnuRecipientAccountId.setActionCommand("RecipientAccountId");
    mnuRecipientAccountId.addActionListener(this);

    sourceGroup.add(mnuEventName);
    sourceGroup.add(mnuAwsRegion);
    sourceGroup.add(mnuSourceIpAddress);
    sourceGroup.add(mnuUserAgent);
    sourceGroup.add(mnuEventSource);
    sourceGroup.add(mnuErrorCode);
    sourceGroup.add(mnuRecipientAccountId);

    JMenu sourceMenu = new JMenu("Source");
    sourceMenu.add(mnuEventName);
    sourceMenu.add(mnuAwsRegion);
    sourceMenu.add(mnuSourceIpAddress);
    sourceMenu.add(mnuUserAgent);
    sourceMenu.add(mnuEventSource);
    sourceMenu.add(mnuErrorCode);
    sourceMenu.add(mnuRecipientAccountId);
    sourceMenu.add(getUserIdentityMenu(sourceGroup));

    menu.add(sourceMenu);
}

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

private JMenuBar createMenuBar() {
    JMenuBar bar = new JMenuBar();
    JMenu menu = null;/*from  w w  w. j a  v  a2 s.  c  om*/
    /*
     * '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:net.sf.jabref.gui.openoffice.OpenOfficePanel.java

private void showSettingsPopup() {
    JPopupMenu menu = new JPopupMenu();
    final JCheckBoxMenuItem autoSync = new JCheckBoxMenuItem(
            Localization.lang("Automatically sync bibliography when inserting citations"),
            preferences.syncWhenCiting());
    final JRadioButtonMenuItem useActiveBase = new JRadioButtonMenuItem(
            Localization.lang("Look up BibTeX entries in the active tab only"));
    final JRadioButtonMenuItem useAllBases = new JRadioButtonMenuItem(
            Localization.lang("Look up BibTeX entries in all open databases"));
    final JMenuItem clearConnectionSettings = new JMenuItem(Localization.lang("Clear connection settings"));
    ButtonGroup bg = new ButtonGroup();
    bg.add(useActiveBase);//from ww w . j a  v a  2  s. c o  m
    bg.add(useAllBases);
    if (preferences.useAllDatabases()) {
        useAllBases.setSelected(true);
    } else {
        useActiveBase.setSelected(true);
    }

    autoSync.addActionListener(e -> preferences.setSyncWhenCiting(autoSync.isSelected()));

    useAllBases.addActionListener(e -> preferences.setUseAllDatabases(useAllBases.isSelected()));

    useActiveBase.addActionListener(e -> preferences.setUseAllDatabases(!useActiveBase.isSelected()));

    clearConnectionSettings.addActionListener(e -> frame.output(preferences.clearConnectionSettings()));

    menu.add(autoSync);
    menu.addSeparator();
    menu.add(useActiveBase);
    menu.add(useAllBases);
    menu.addSeparator();
    menu.add(clearConnectionSettings);
    menu.show(settingsB, 0, settingsB.getHeight());
}

From source file:com.igormaznitsa.sciareto.ui.MainFrame.java

public MainFrame(@Nonnull @MustNotContainNull final String... args) {
    super();//from   w w  w  .  ja v a 2  s .c  o m
    initComponents();

    this.stackPanel = new JPanel();
    this.stackPanel.setFocusable(false);
    this.stackPanel.setOpaque(false);
    this.stackPanel.setBorder(BorderFactory.createEmptyBorder(32, 32, 16, 32));
    this.stackPanel.setLayout(new BoxLayout(this.stackPanel, BoxLayout.Y_AXIS));

    final JPanel glassPanel = (JPanel) this.getGlassPane();
    glassPanel.setOpaque(false);

    this.setGlassPane(glassPanel);

    glassPanel.setLayout(new BorderLayout(8, 8));
    glassPanel.add(Box.createGlue(), BorderLayout.CENTER);

    final JPanel ppanel = new JPanel(new BorderLayout(0, 0));
    ppanel.setFocusable(false);
    ppanel.setOpaque(false);
    ppanel.setCursor(null);
    ppanel.add(this.stackPanel, BorderLayout.SOUTH);

    glassPanel.add(ppanel, BorderLayout.EAST);

    this.stackPanel.add(Box.createGlue());

    glassPanel.setVisible(false);

    this.setTitle("Scia Reto");

    setIconImage(UiUtils.loadImage("logo256x256.png"));

    this.stateless = args.length > 0;

    final MainFrame theInstance = this;

    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(@Nonnull final WindowEvent e) {
            if (doClosing()) {
                dispose();
            }
        }
    });

    this.tabPane = new EditorTabPane(this);

    this.explorerTree = new ExplorerTree(this);

    final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.setOneTouchExpandable(true);
    splitPane.setDividerLocation(250);
    splitPane.setResizeWeight(0.0d);
    splitPane.setLeftComponent(this.explorerTree);
    splitPane.setRightComponent(this.tabPane);

    add(splitPane, BorderLayout.CENTER);

    this.menuOpenRecentProject.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            final File[] lastOpenedProjects = FileHistoryManager.getInstance().getLastOpenedProjects();
            if (lastOpenedProjects.length > 0) {
                for (final File folder : lastOpenedProjects) {
                    final JMenuItem item = new JMenuItem(folder.getName());
                    item.setToolTipText(folder.getAbsolutePath());
                    item.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            openProject(folder, false);
                        }
                    });
                    menuOpenRecentProject.add(item);
                }
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            menuOpenRecentProject.removeAll();
        }

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

    this.menuOpenRecentFile.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            final File[] lastOpenedFiles = FileHistoryManager.getInstance().getLastOpenedFiles();
            if (lastOpenedFiles.length > 0) {
                for (final File file : lastOpenedFiles) {
                    final JMenuItem item = new JMenuItem(file.getName());
                    item.setToolTipText(file.getAbsolutePath());
                    item.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            openFileAsTab(file);
                        }
                    });
                    menuOpenRecentFile.add(item);
                }
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            menuOpenRecentFile.removeAll();
        }

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

    if (!this.stateless) {
        restoreState();
    } else {
        boolean openedProject = false;
        for (final String filePath : args) {
            final File file = new File(filePath);
            if (file.isDirectory()) {
                openedProject = true;
                openProject(file, true);
            } else if (file.isFile()) {
                openFileAsTab(file);
            }
        }
        if (!openedProject) {
            //TODO try to hide project panel!
        }
    }

    final LookAndFeel current = UIManager.getLookAndFeel();
    final ButtonGroup lfGroup = new ButtonGroup();
    final String currentLFClassName = current.getClass().getName();
    for (final UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(info.getName());
        lfGroup.add(menuItem);
        if (currentLFClassName.equals(info.getClassName())) {
            menuItem.setSelected(true);
        }
        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(@Nonnull final ActionEvent e) {
                try {
                    UIManager.setLookAndFeel(info.getClassName());
                    SwingUtilities.updateComponentTreeUI(theInstance);
                    PreferencesManager.getInstance().getPreferences().put(Main.PROPERTY_LOOKANDFEEL,
                            info.getClassName());
                    PreferencesManager.getInstance().flush();
                } catch (Exception ex) {
                    LOGGER.error("Can't change LF", ex);
                }
            }
        });
        this.menuLookAndFeel.add(menuItem);
    }
}

From source file:net.sf.jabref.openoffice.OpenOfficePanel.java

private void showSettingsPopup() {
    JPopupMenu menu = new JPopupMenu();
    final JCheckBoxMenuItem autoSync = new JCheckBoxMenuItem(
            Localization.lang("Automatically sync bibliography when inserting citations"),
            Globals.prefs.getBoolean(JabRefPreferences.SYNC_OO_WHEN_CITING));
    final JRadioButtonMenuItem useActiveBase = new JRadioButtonMenuItem(
            Localization.lang("Look up BibTeX entries in the active tab only"));
    final JRadioButtonMenuItem useAllBases = new JRadioButtonMenuItem(
            Localization.lang("Look up BibTeX entries in all open databases"));
    final JMenuItem clearConnectionSettings = new JMenuItem(Localization.lang("Clear connection settings"));
    ButtonGroup bg = new ButtonGroup();
    bg.add(useActiveBase);/*  w  ww.  j  a va 2 s.  c  o  m*/
    bg.add(useAllBases);
    if (Globals.prefs.getBoolean(JabRefPreferences.USE_ALL_OPEN_BASES)) {
        useAllBases.setSelected(true);
    } else {
        useActiveBase.setSelected(true);
    }

    autoSync.addActionListener(
            e -> Globals.prefs.putBoolean(JabRefPreferences.SYNC_OO_WHEN_CITING, autoSync.isSelected()));

    useAllBases.addActionListener(
            e -> Globals.prefs.putBoolean(JabRefPreferences.USE_ALL_OPEN_BASES, useAllBases.isSelected()));

    useActiveBase.addActionListener(
            e -> Globals.prefs.putBoolean(JabRefPreferences.USE_ALL_OPEN_BASES, !useActiveBase.isSelected()));

    clearConnectionSettings.addActionListener(e -> {

        Globals.prefs.clear(JabRefPreferences.OO_PATH);
        Globals.prefs.clear(JabRefPreferences.OO_EXECUTABLE_PATH);
        Globals.prefs.clear(JabRefPreferences.OO_JARS_PATH);
        frame.output(Localization.lang("Cleared connection settings."));

    });

    menu.add(autoSync);
    menu.addSeparator();
    menu.add(useActiveBase);
    menu.add(useAllBases);
    menu.addSeparator();
    menu.add(clearConnectionSettings);
    menu.show(settingsB, 0, settingsB.getHeight());
}

From source file:components.MenuDemo.java

public JMenuBar createMenuBar() {
    JMenuBar menuBar;// ww  w .  ja va  2 s.c o m
    JMenu menu, submenu;
    JMenuItem menuItem;
    JRadioButtonMenuItem rbMenuItem;
    JCheckBoxMenuItem cbMenuItem;

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

    //Build the first menu.
    menu = new JMenu("A Menu");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items");
    menuBar.add(menu);

    //a group of JMenuItems
    menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T);
    //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    ImageIcon icon = createImageIcon("images/middle.gif");
    menuItem = new JMenuItem("Both text and icon", icon);
    menuItem.setMnemonic(KeyEvent.VK_B);
    menuItem.addActionListener(this);
    menu.add(menuItem);

    menuItem = new JMenuItem(icon);
    menuItem.setMnemonic(KeyEvent.VK_D);
    menuItem.addActionListener(this);
    menu.add(menuItem);

    //a group of radio button menu items
    menu.addSeparator();
    ButtonGroup group = new ButtonGroup();

    rbMenuItem = new JRadioButtonMenuItem("A radio button menu item");
    rbMenuItem.setSelected(true);
    rbMenuItem.setMnemonic(KeyEvent.VK_R);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);

    rbMenuItem = new JRadioButtonMenuItem("Another one");
    rbMenuItem.setMnemonic(KeyEvent.VK_O);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);

    //a group of check box menu items
    menu.addSeparator();
    cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
    cbMenuItem.setMnemonic(KeyEvent.VK_C);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);

    cbMenuItem = new JCheckBoxMenuItem("Another one");
    cbMenuItem.setMnemonic(KeyEvent.VK_H);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);

    //a submenu
    menu.addSeparator();
    submenu = new JMenu("A submenu");
    submenu.setMnemonic(KeyEvent.VK_S);

    menuItem = new JMenuItem("An item in the submenu");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
    menuItem.addActionListener(this);
    submenu.add(menuItem);

    menuItem = new JMenuItem("Another item");
    menuItem.addActionListener(this);
    submenu.add(menuItem);
    menu.add(submenu);

    //Build second menu in the menu bar.
    menu = new JMenu("Another Menu");
    menu.setMnemonic(KeyEvent.VK_N);
    menu.getAccessibleContext().setAccessibleDescription("This menu does nothing");
    menuBar.add(menu);

    return menuBar;
}

From source file:MenuDemo.java

public JMenuBar createMenuBar() {
    JMenuBar menuBar;//  w w w.  j  av  a2  s.  c o  m
    JMenu menu, submenu;
    JMenuItem menuItem;
    JRadioButtonMenuItem rbMenuItem;
    JCheckBoxMenuItem cbMenuItem;

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

    //Build the first menu.
    menu = new JMenu("A Menu");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items");
    menuBar.add(menu);

    //a group of JMenuItems
    menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T);
    //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    ImageIcon icon = createImageIcon("images/1.gif");
    menuItem = new JMenuItem("Both text and icon", icon);
    menuItem.setMnemonic(KeyEvent.VK_B);
    menuItem.addActionListener(this);
    menu.add(menuItem);

    menuItem = new JMenuItem(icon);
    menuItem.setMnemonic(KeyEvent.VK_D);
    menuItem.addActionListener(this);
    menu.add(menuItem);

    //a group of radio button menu items
    menu.addSeparator();
    ButtonGroup group = new ButtonGroup();

    rbMenuItem = new JRadioButtonMenuItem("A radio button menu item");
    rbMenuItem.setSelected(true);
    rbMenuItem.setMnemonic(KeyEvent.VK_R);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);

    rbMenuItem = new JRadioButtonMenuItem("Another one");
    rbMenuItem.setMnemonic(KeyEvent.VK_O);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);

    //a group of check box menu items
    menu.addSeparator();
    cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
    cbMenuItem.setMnemonic(KeyEvent.VK_C);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);

    cbMenuItem = new JCheckBoxMenuItem("Another one");
    cbMenuItem.setMnemonic(KeyEvent.VK_H);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);

    //a submenu
    menu.addSeparator();
    submenu = new JMenu("A submenu");
    submenu.setMnemonic(KeyEvent.VK_S);

    menuItem = new JMenuItem("An item in the submenu");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
    menuItem.addActionListener(this);
    submenu.add(menuItem);

    menuItem = new JMenuItem("Another item");
    menuItem.addActionListener(this);
    submenu.add(menuItem);
    menu.add(submenu);

    //Build second menu in the menu bar.
    menu = new JMenu("Another Menu");
    menu.setMnemonic(KeyEvent.VK_N);
    menu.getAccessibleContext().setAccessibleDescription("This menu does nothing");
    menuBar.add(menu);

    return menuBar;
}

From source file:components.MenuSelectionManagerDemo.java

public JMenuBar createMenuBar() {
    JMenuBar menuBar;/*from ww w.  j a  va2 s. c om*/
    JMenu menu, submenu;
    JMenuItem menuItem;
    JRadioButtonMenuItem rbMenuItem;
    JCheckBoxMenuItem cbMenuItem;

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

    //Build the first menu.
    menu = new JMenu("A Menu");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items");
    menuBar.add(menu);

    //a group of JMenuItems
    menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T);
    //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    ImageIcon icon = createImageIcon("images/middle.gif");
    menuItem = new JMenuItem("Both text and icon", icon);
    menuItem.setMnemonic(KeyEvent.VK_B);
    menuItem.addActionListener(this);
    menu.add(menuItem);

    menuItem = new JMenuItem(icon);
    menuItem.setMnemonic(KeyEvent.VK_D);
    menuItem.addActionListener(this);
    menu.add(menuItem);

    //a group of radio button menu items
    menu.addSeparator();
    ButtonGroup group = new ButtonGroup();

    rbMenuItem = new JRadioButtonMenuItem("A radio button menu item");
    rbMenuItem.setSelected(true);
    rbMenuItem.setMnemonic(KeyEvent.VK_R);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);

    rbMenuItem = new JRadioButtonMenuItem("Another one");
    rbMenuItem.setMnemonic(KeyEvent.VK_O);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);

    //a group of check box menu items
    menu.addSeparator();
    cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
    cbMenuItem.setMnemonic(KeyEvent.VK_C);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);

    cbMenuItem = new JCheckBoxMenuItem("Another one");
    cbMenuItem.setMnemonic(KeyEvent.VK_H);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);

    //a submenu
    menu.addSeparator();
    submenu = new JMenu("A submenu");
    submenu.setMnemonic(KeyEvent.VK_S);

    menuItem = new JMenuItem("An item in the submenu");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
    menuItem.addActionListener(this);
    submenu.add(menuItem);

    menuItem = new JMenuItem("Another item");
    menuItem.addActionListener(this);
    submenu.add(menuItem);
    menu.add(submenu);

    //Build second menu in the menu bar.
    menu = new JMenu("Another Menu");
    menu.setMnemonic(KeyEvent.VK_N);
    menu.getAccessibleContext().setAccessibleDescription("This menu does nothing");
    menuBar.add(menu);

    Timer timer = new Timer(ONE_SECOND, new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            MenuElement[] path = MenuSelectionManager.defaultManager().getSelectedPath();
            for (int i = 0; i < path.length; i++) {
                if (path[i].getComponent() instanceof javax.swing.JMenuItem) {
                    JMenuItem mi = (JMenuItem) path[i].getComponent();
                    if ("".equals(mi.getText())) {
                        output.append("ICON-ONLY MENU ITEM > ");
                    } else {
                        output.append(mi.getText() + " > ");
                    }
                }
            }
            if (path.length > 0)
                output.append(newline);
        }
    });
    timer.start();
    return menuBar;
}