Search in sources :

Example 36 with MenuItem

use of java.awt.MenuItem in project voltdb by VoltDB.

the class Transfer method addMenuItems.

/**
     * Method declaration
     *
     *
     * @param f
     * @param m
     */
private void addMenuItems(Menu f, String[] m) {
    for (int i = 0; i < m.length; i++) {
        if (m[i].equals("-")) {
            f.addSeparator();
        } else {
            MenuItem item = new MenuItem(m[i]);
            item.addActionListener(this);
            f.add(item);
        }
    }
}
Also used : MenuItem(java.awt.MenuItem)

Example 37 with MenuItem

use of java.awt.MenuItem in project jdk8u_jdk by JetBrains.

the class AWTInputMethodPopupMenu method addMenuItem.

void addMenuItem(Object targetMenu, String label, String command, String currentSelection) {
    MenuItem menuItem;
    if (isSelected(command, currentSelection)) {
        menuItem = new CheckboxMenuItem(label, true);
    } else {
        menuItem = new MenuItem(label);
    }
    menuItem.setActionCommand(command);
    menuItem.addActionListener(this);
    menuItem.setEnabled(command != null);
    ((Menu) targetMenu).add(menuItem);
}
Also used : CheckboxMenuItem(java.awt.CheckboxMenuItem) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) MenuItem(java.awt.MenuItem) JMenuItem(javax.swing.JMenuItem) CheckboxMenuItem(java.awt.CheckboxMenuItem) JPopupMenu(javax.swing.JPopupMenu) JMenu(javax.swing.JMenu) Menu(java.awt.Menu) PopupMenu(java.awt.PopupMenu)

Example 38 with MenuItem

use of java.awt.MenuItem in project jdk8u_jdk by JetBrains.

the class CMenuItem method setLabel.

public void setLabel(String label, char keyChar, int keyCode, int modifiers) {
    int keyMask = modifiers;
    if (keyCode == KeyEvent.VK_UNDEFINED) {
        MenuShortcut shortcut = ((MenuItem) getTarget()).getShortcut();
        if (shortcut != null) {
            keyCode = shortcut.getKey();
            keyMask |= InputEvent.META_MASK;
            if (shortcut.usesShiftModifier()) {
                keyMask |= InputEvent.SHIFT_MASK;
            }
        }
    }
    if (label == null) {
        label = "";
    }
    // CHAR_UNDEFINED into 0.
    if (keyChar == KeyEvent.CHAR_UNDEFINED) {
        keyChar = 0;
    }
    final String finalLabel = label;
    final char finalKeyChar = keyChar;
    final int finalKeyCode = keyCode;
    final int finalKeyMask = keyMask;
    execute(ptr -> nativeSetLabel(ptr, finalLabel, finalKeyChar, finalKeyCode, finalKeyMask));
}
Also used : MenuItem(java.awt.MenuItem) MenuShortcut(java.awt.MenuShortcut)

Example 39 with MenuItem

use of java.awt.MenuItem in project litiengine by gurkenlabs.

the class Program method initViewMenu.

private static Menu initViewMenu() {
    Menu mnView = new Menu(Resources.get("menu_view"));
    CheckboxMenuItem snapToGrid = new CheckboxMenuItem(Resources.get("menu_snapGrid"));
    snapToGrid.setState(userPreferences.isSnapGrid());
    EditorScreen.instance().getMapComponent().setSnapToGrid(snapToGrid.getState());
    snapToGrid.addItemListener(e -> {
        EditorScreen.instance().getMapComponent().setSnapToGrid(snapToGrid.getState());
        userPreferences.setSnapGrid(snapToGrid.getState());
    });
    CheckboxMenuItem renderGrid = new CheckboxMenuItem(Resources.get("menu_renderGrid"));
    renderGrid.setState(userPreferences.isShowGrid());
    EditorScreen.instance().getMapComponent().setRenderGrid(renderGrid.getState());
    renderGrid.setShortcut(new MenuShortcut(KeyEvent.VK_G));
    renderGrid.addItemListener(e -> {
        EditorScreen.instance().getMapComponent().setRenderGrid(renderGrid.getState());
        userPreferences.setShowGrid(renderGrid.getState());
    });
    CheckboxMenuItem renderCollision = new CheckboxMenuItem(Resources.get("menu_renderCollisionBoxes"));
    renderCollision.setState(userPreferences.isRenderBoundingBoxes());
    EditorScreen.instance().getMapComponent().setRenderCollisionBoxes(renderCollision.getState());
    renderCollision.setShortcut(new MenuShortcut(KeyEvent.VK_H));
    renderCollision.addItemListener(e -> {
        EditorScreen.instance().getMapComponent().setRenderCollisionBoxes(renderCollision.getState());
        userPreferences.setRenderBoundingBoxes(renderCollision.getState());
    });
    MenuItem setGrid = new MenuItem(Resources.get("menu_gridSize"));
    setGrid.addActionListener(a -> {
        GridEditPanel panel = new GridEditPanel(EditorScreen.instance().getMapComponent().getGridSize());
        int option = JOptionPane.showConfirmDialog(Game.getScreenManager().getRenderComponent(), panel, Resources.get("menu_gridSettings"), JOptionPane.DEFAULT_OPTION);
        if (option == JOptionPane.OK_OPTION) {
            EditorScreen.instance().getMapComponent().setGridSize(panel.getGridSize());
        }
    });
    MenuItem zoomIn = new MenuItem(Resources.get("menu_zoomIn"));
    zoomIn.setShortcut(new MenuShortcut(KeyEvent.VK_PLUS));
    zoomIn.addActionListener(a -> EditorScreen.instance().getMapComponent().zoomIn());
    MenuItem zoomOut = new MenuItem(Resources.get("menu_zoomOut"));
    zoomOut.setShortcut(new MenuShortcut(KeyEvent.VK_MINUS));
    zoomOut.addActionListener(a -> EditorScreen.instance().getMapComponent().zoomOut());
    mnView.add(snapToGrid);
    mnView.add(renderGrid);
    mnView.add(renderCollision);
    mnView.add(setGrid);
    mnView.addSeparator();
    mnView.add(zoomIn);
    mnView.add(zoomOut);
    return mnView;
}
Also used : CheckboxMenuItem(java.awt.CheckboxMenuItem) GridEditPanel(de.gurkenlabs.utiliti.swing.dialogs.GridEditPanel) CheckboxMenuItem(java.awt.CheckboxMenuItem) MenuItem(java.awt.MenuItem) JMenuItem(javax.swing.JMenuItem) PopupMenu(java.awt.PopupMenu) Menu(java.awt.Menu) JPopupMenu(javax.swing.JPopupMenu) MenuShortcut(java.awt.MenuShortcut)

Example 40 with MenuItem

use of java.awt.MenuItem in project litiengine by gurkenlabs.

the class Program method initSystemTray.

private static void initSystemTray() {
    // add system tray icon with popup menu
    if (SystemTray.isSupported()) {
        SystemTray tray = SystemTray.getSystemTray();
        PopupMenu menu = new PopupMenu();
        MenuItem exitItem = new MenuItem(Resources.get("menu_exit"));
        exitItem.addActionListener(a -> Game.terminate());
        menu.add(exitItem);
        trayIcon = new TrayIcon(Resources.getImage("pixel-icon-utility.png"), Game.getInfo().toString(), menu);
        trayIcon.setImageAutoSize(true);
        try {
            tray.add(trayIcon);
        } catch (AWTException e) {
            log.log(Level.SEVERE, e.getLocalizedMessage(), e);
        }
    }
}
Also used : TrayIcon(java.awt.TrayIcon) SystemTray(java.awt.SystemTray) CheckboxMenuItem(java.awt.CheckboxMenuItem) MenuItem(java.awt.MenuItem) JMenuItem(javax.swing.JMenuItem) PopupMenu(java.awt.PopupMenu) JPopupMenu(javax.swing.JPopupMenu) AWTException(java.awt.AWTException)

Aggregations

MenuItem (java.awt.MenuItem)53 PopupMenu (java.awt.PopupMenu)24 Menu (java.awt.Menu)15 JMenuItem (javax.swing.JMenuItem)15 JPopupMenu (javax.swing.JPopupMenu)13 TrayIcon (java.awt.TrayIcon)12 AWTException (java.awt.AWTException)9 MenuShortcut (java.awt.MenuShortcut)9 ActionEvent (java.awt.event.ActionEvent)9 ActionListener (java.awt.event.ActionListener)9 CheckboxMenuItem (java.awt.CheckboxMenuItem)8 Image (java.awt.Image)8 SystemTray (java.awt.SystemTray)8 IOException (java.io.IOException)6 Dimension (java.awt.Dimension)5 File (java.io.File)4 BorderLayout (java.awt.BorderLayout)3 FileDialog (java.awt.FileDialog)3 URL (java.net.URL)3 SQLException (java.sql.SQLException)3