Search in sources :

Example 41 with JMenuItem

use of javax.swing.JMenuItem in project processing by processing.

the class Toolkit method newJMenuItem.

/**
   * @param action: use an Action, which sets the title, reaction
   *                and enabled-ness all by itself.
   */
public static JMenuItem newJMenuItem(Action action, int what) {
    JMenuItem menuItem = new JMenuItem(action);
    int modifiers = awtToolkit.getMenuShortcutKeyMask();
    menuItem.setAccelerator(KeyStroke.getKeyStroke(what, modifiers));
    return menuItem;
}
Also used : JMenuItem(javax.swing.JMenuItem)

Example 42 with JMenuItem

use of javax.swing.JMenuItem in project processing by processing.

the class Toolkit method setMenuMnemonics.

/**
   * As setMenuMnemonics(JMenuItem...).
   */
public static void setMenuMnemonics(JPopupMenu menu) {
    ArrayList<JMenuItem> items = new ArrayList<JMenuItem>();
    for (Component c : menu.getComponents()) {
        if (c instanceof JMenuItem)
            items.add((JMenuItem) c);
    }
    setMenuMnemonics(items.toArray(new JMenuItem[items.size()]));
}
Also used : ArrayList(java.util.ArrayList) JMenuItem(javax.swing.JMenuItem) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Example 43 with JMenuItem

use of javax.swing.JMenuItem in project processing by processing.

the class Toolkit method newJMenuItemShift.

/**
   * Like newJMenuItem() but adds shift as a modifier for the shortcut.
   */
public static JMenuItem newJMenuItemShift(Action action, int what) {
    JMenuItem menuItem = new JMenuItem(action);
    int modifiers = awtToolkit.getMenuShortcutKeyMask();
    modifiers |= ActionEvent.SHIFT_MASK;
    menuItem.setAccelerator(KeyStroke.getKeyStroke(what, modifiers));
    return menuItem;
}
Also used : JMenuItem(javax.swing.JMenuItem)

Example 44 with JMenuItem

use of javax.swing.JMenuItem in project felix by apache.

the class ControlPoint method doMenuBar.

public void doMenuBar(JFrame frame) {
    JMenuBar menuBar = new JMenuBar();
    // ////////////// FILE
    JMenu file_menu = new JMenu("File");
    file_menu.setMnemonic(KeyEvent.VK_F);
    searchMenu = new JMenu("Search");
    final String ALL_DEVICE = "ssdp:all";
    final String ROOT_DEVICE = "upnp:rootdevice";
    searchMenu.setMnemonic(KeyEvent.VK_L);
    searchMenu.setEnabled(false);
    AbstractAction searchAction = new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            DriverProxy controller = Mediator.getDriverProxy();
            if (e.getActionCommand().equals(ALL_DEVICE))
                controller.doSearch(ALL_DEVICE);
            else if (e.getActionCommand().equals(ROOT_DEVICE))
                controller.doSearch(ROOT_DEVICE);
        }
    };
    JMenuItem rootDeviceItem = new JMenuItem("Root Devices");
    rootDeviceItem.setMnemonic(KeyEvent.VK_R);
    rootDeviceItem.addActionListener(searchAction);
    rootDeviceItem.setActionCommand(ROOT_DEVICE);
    searchMenu.add(rootDeviceItem);
    JMenuItem allDeviceItem = new JMenuItem("All Devices");
    allDeviceItem.setMnemonic(KeyEvent.VK_A);
    allDeviceItem.addActionListener(searchAction);
    allDeviceItem.setActionCommand(ALL_DEVICE);
    searchMenu.add(allDeviceItem);
    JMenuItem checkIncompleteItem = new JMenuItem("Print Pending Devices");
    checkIncompleteItem.setMnemonic(KeyEvent.VK_I);
    checkIncompleteItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Mediator.getRootDeviceListener().checkIncompleteDevice();
        }
    });
    JMenuItem checkErrataItem = new JMenuItem("Check Errata UPnPDevices");
    checkErrataItem.setMnemonic(KeyEvent.VK_E);
    checkErrataItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            RootDeviceListener.checkErrataDevice();
        }
    });
    loggerMenu = new JMenu("Felix Logger");
    final String NO_LOGGING = "No Logging";
    final String ERROR = "Error";
    final String WARNING = "Warning";
    final String INFO = "Info";
    final String DEBUG = "Debug";
    loggerMenu.getPopupMenu().addPopupMenuListener(this);
    loggerMenu.setMnemonic(KeyEvent.VK_L);
    loggerMenu.setEnabled(false);
    AbstractAction loggerAction = new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            DriverProxy controller = Mediator.getDriverProxy();
            if (e.getActionCommand().equals(NO_LOGGING))
                controller.setLogLevel(0);
            else if (e.getActionCommand().equals(ERROR))
                controller.setLogLevel(1);
            else if (e.getActionCommand().equals(WARNING))
                controller.setLogLevel(2);
            else if (e.getActionCommand().equals(INFO))
                controller.setLogLevel(3);
            else if (e.getActionCommand().equals(DEBUG))
                controller.setLogLevel(4);
        }
    };
    ButtonGroup group = new ButtonGroup();
    JRadioButtonMenuItem rbMenuItem = new JRadioButtonMenuItem(NO_LOGGING);
    rbMenuItem.setSelected(true);
    rbMenuItem.setMnemonic(KeyEvent.VK_N);
    rbMenuItem.setActionCommand(NO_LOGGING);
    rbMenuItem.addActionListener(loggerAction);
    group.add(rbMenuItem);
    loggerMenu.add(rbMenuItem);
    loggerMenu.addSeparator();
    rbMenuItem = new JRadioButtonMenuItem(ERROR);
    rbMenuItem.setMnemonic(KeyEvent.VK_E);
    rbMenuItem.setActionCommand(ERROR);
    rbMenuItem.addActionListener(loggerAction);
    group.add(rbMenuItem);
    loggerMenu.add(rbMenuItem);
    rbMenuItem = new JRadioButtonMenuItem(WARNING);
    rbMenuItem.setMnemonic(KeyEvent.VK_W);
    rbMenuItem.setActionCommand(WARNING);
    rbMenuItem.addActionListener(loggerAction);
    group.add(rbMenuItem);
    loggerMenu.add(rbMenuItem);
    rbMenuItem = new JRadioButtonMenuItem(INFO);
    rbMenuItem.setMnemonic(KeyEvent.VK_I);
    rbMenuItem.setActionCommand(INFO);
    rbMenuItem.addActionListener(loggerAction);
    group.add(rbMenuItem);
    loggerMenu.add(rbMenuItem);
    rbMenuItem = new JRadioButtonMenuItem(DEBUG);
    rbMenuItem.setMnemonic(KeyEvent.VK_D);
    rbMenuItem.setActionCommand(DEBUG);
    rbMenuItem.addActionListener(loggerAction);
    group.add(rbMenuItem);
    loggerMenu.add(rbMenuItem);
    final String ON = "On";
    final String OFF = "Off";
    cyberMenu = new JMenu("Cyber Debugger");
    cyberMenu.getPopupMenu().addPopupMenuListener(this);
    cyberMenu.setMnemonic(KeyEvent.VK_C);
    cyberMenu.setEnabled(false);
    AbstractAction cyberAction = new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            DriverProxy controller = Mediator.getDriverProxy();
            if (e.getActionCommand().equals(ON))
                controller.setCyberDebug(true);
            else if (e.getActionCommand().equals(OFF))
                controller.setCyberDebug(false);
        }
    };
    ButtonGroup cyberGroup = new ButtonGroup();
    rbMenuItem = new JRadioButtonMenuItem(ON);
    rbMenuItem.setSelected(true);
    rbMenuItem.setMnemonic(KeyEvent.VK_O);
    rbMenuItem.setActionCommand(ON);
    rbMenuItem.addActionListener(cyberAction);
    cyberGroup.add(rbMenuItem);
    cyberMenu.add(rbMenuItem);
    rbMenuItem = new JRadioButtonMenuItem(OFF);
    rbMenuItem.setMnemonic(KeyEvent.VK_F);
    rbMenuItem.setActionCommand(OFF);
    rbMenuItem.addActionListener(cyberAction);
    cyberGroup.add(rbMenuItem);
    cyberMenu.add(rbMenuItem);
    /*
        JMenuItem clearSubscriptionItem = new JMenuItem("Clear Subscriptions");
        clearSubscriptionItem.setMnemonic(KeyEvent.VK_S);
        clearSubscriptionItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
// to do
                    }
            });
        */
    JMenuItem exitItem = new JMenuItem("Exit");
    exitItem.setMnemonic(KeyEvent.VK_X);
    exitItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            try {
                Activator.context.getBundle().stop();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });
    file_menu.add(searchMenu);
    file_menu.addSeparator();
    file_menu.add(loggerMenu);
    file_menu.add(cyberMenu);
    file_menu.addSeparator();
    file_menu.add(checkIncompleteItem);
    file_menu.add(checkErrataItem);
    // file_menu.addSeparator();
    // file_menu.add(clearSubscriptionItem);
    file_menu.addSeparator();
    file_menu.add(exitItem);
    menuBar.add(file_menu);
    frame.setJMenuBar(menuBar);
}
Also used : ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) ActionEvent(java.awt.event.ActionEvent) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) DriverProxy(org.apache.felix.upnp.tester.discovery.DriverProxy) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu) BundleException(org.osgi.framework.BundleException)

Example 45 with JMenuItem

use of javax.swing.JMenuItem in project omegat by omegat-org.

the class RecentProjects method updateMenu.

public static void updateMenu() {
    IMainWindow window = Core.getMainWindow();
    if (window == null) {
        return;
    }
    JMenuItem recentMenu = window.getMainMenu().getProjectRecentMenuItem();
    if (recentMenu == null) {
        return;
    }
    recentMenu.removeAll();
    synchronized (RECENT_PROJECTS) {
        for (final String project : RECENT_PROJECTS) {
            JMenuItem recentProjectMenuItem = new JMenuItem(project);
            recentProjectMenuItem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent event) {
                    ProjectUICommands.projectOpen(new File(project), true);
                }
            });
            recentMenu.add(recentProjectMenuItem);
        }
        recentMenu.setEnabled(!RECENT_PROJECTS.isEmpty());
    }
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) IMainWindow(org.omegat.gui.main.IMainWindow) JMenuItem(javax.swing.JMenuItem) File(java.io.File)

Aggregations

JMenuItem (javax.swing.JMenuItem)1138 ActionEvent (java.awt.event.ActionEvent)559 ActionListener (java.awt.event.ActionListener)463 JMenu (javax.swing.JMenu)373 JPopupMenu (javax.swing.JPopupMenu)229 JMenuBar (javax.swing.JMenuBar)104 AbstractAction (javax.swing.AbstractAction)90 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)76 ArrayList (java.util.ArrayList)72 JPanel (javax.swing.JPanel)70 Point (java.awt.Point)65 JSeparator (javax.swing.JSeparator)63 File (java.io.File)61 JLabel (javax.swing.JLabel)61 BorderLayout (java.awt.BorderLayout)57 JButton (javax.swing.JButton)54 Component (java.awt.Component)53 ButtonGroup (javax.swing.ButtonGroup)50 Dimension (java.awt.Dimension)46 MouseEvent (java.awt.event.MouseEvent)45