Search in sources :

Example 46 with KeyStroke

use of javax.swing.KeyStroke in project java-jotasync by trixon.

the class TabHolder method initActions.

void initActions() {
    InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    ActionMap actionMap = getRootPane().getActionMap();
    int commandMask = SystemHelper.getCommandMask();
    mCloseAction = mActionManager.getAction(ActionManager.CLOSE_TAB);
    mSaveAction = mActionManager.getAction(ActionManager.SAVE_TAB);
    for (int i = 0; i < 10; i++) {
        KeyStroke keyStroke = KeyStroke.getKeyStroke(0x31 + i, commandMask);
        String key = "key_" + i;
        final int tabIndex = i;
        AbstractAction action = new AbstractAction("Tab") {

            @Override
            public void actionPerformed(ActionEvent e) {
                displayTab(tabIndex);
            }
        };
        inputMap.put(keyStroke, key);
        actionMap.put(key, action);
    }
    AbstractAction action = new AbstractAction("TabNext") {

        @Override
        public void actionPerformed(ActionEvent e) {
            displayTab(getSelectedIndex() + 1);
        }
    };
    KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, commandMask);
    String key = "nextTab";
    inputMap.put(keyStroke, key);
    actionMap.put(key, action);
    action = new AbstractAction("TabPrev") {

        @Override
        public void actionPerformed(ActionEvent e) {
            displayTab(Math.max(getSelectedIndex() - 1, 0));
        }
    };
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, commandMask + InputEvent.SHIFT_MASK);
    key = "prevTab";
    inputMap.put(keyStroke, key);
    actionMap.put(key, action);
    mActionManager.addAppListener(new ActionManager.AppAdapter() {

        @Override
        public void onCancel(ActionEvent actionEvent) {
            if (getSelectedComponent() instanceof TabItem) {
                TabItem tabItem = (TabItem) getSelectedComponent();
                if (tabItem.isCancelable()) {
                    tabItem.cancel();
                }
            }
        }

        @Override
        public void onMenu(ActionEvent actionEvent) {
            mMenuMouseAdapter.mousePressed(null);
        }
    });
}
Also used : ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) KeyStroke(javax.swing.KeyStroke) InputMap(javax.swing.InputMap) AbstractAction(javax.swing.AbstractAction)

Example 47 with KeyStroke

use of javax.swing.KeyStroke in project java-jotasync by trixon.

the class TabHolder method init.

private void init() {
    setFocusTraversalKeysEnabled(false);
    mSpeedDialPanel = new SpeedDialPanel();
    IconColor iconColor = mAlmondOptions.getIconColor();
    add(mSpeedDialPanel, MaterialIcon._Action.HOME.get(AlmondUI.ICON_SIZE_NORMAL, iconColor));
    setIconAt(0, MaterialIcon._Action.HOME.get(AlmondUI.ICON_SIZE_NORMAL, iconColor));
    HistoryPanel historyPanel = new HistoryPanel();
    add(historyPanel, MaterialIcon._Action.HISTORY.get(AlmondUI.ICON_SIZE_NORMAL, iconColor));
    setIconAt(1, MaterialIcon._Action.HISTORY.get(AlmondUI.ICON_SIZE_NORMAL, iconColor));
    mJobMap.values().stream().forEach((tabItem) -> {
        tabItem.updateIcons(iconColor);
    });
    mManager.addConnectionListeners(this);
    mManager.getClient().addServerEventListener(this);
    mMenuMouseAdapter = new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (e == null || e.getButton() == MouseEvent.BUTTON1) {
                Component component = ((TabListener) getSelectedComponent()).getMenuButton();
                JPopupMenu popupMenu = MainFrame.getPopupMenu();
                InputMap inputMap = popupMenu.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
                ActionMap actionMap = popupMenu.getActionMap();
                Action action = new AbstractAction("HideMenu") {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        popupMenu.setVisible(false);
                    }
                };
                String key = "HideMenu";
                actionMap.put(key, action);
                KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
                inputMap.put(keyStroke, key);
                if (popupMenu.isVisible()) {
                    popupMenu.setVisible(false);
                } else {
                    popupMenu.show(component, component.getWidth() - popupMenu.getWidth(), component.getHeight());
                    int x = component.getLocationOnScreen().x + component.getWidth() - popupMenu.getWidth();
                    int y = component.getLocationOnScreen().y + component.getHeight();
                    popupMenu.setLocation(x, y);
                }
            }
        }
    };
    mSpeedDialPanel.getMenuButton().addMouseListener(mMenuMouseAdapter);
    // FIXME Why is this necessary?
    setTabLayoutPolicy(SCROLL_TAB_LAYOUT);
    setTabLayoutPolicy(WRAP_TAB_LAYOUT);
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) MouseEvent(java.awt.event.MouseEvent) ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) MouseAdapter(java.awt.event.MouseAdapter) JPopupMenu(javax.swing.JPopupMenu) IconColor(se.trixon.almond.util.icons.IconColor) KeyStroke(javax.swing.KeyStroke) InputMap(javax.swing.InputMap) JComponent(javax.swing.JComponent) Component(java.awt.Component) AbstractAction(javax.swing.AbstractAction)

Example 48 with KeyStroke

use of javax.swing.KeyStroke in project triplea by triplea-game.

the class JDialogBuilder method build.

/**
 * Constructs a Swing JDialog using current builder values.
 * Values that must be set: title, contents
 */
public JDialog build() {
    checkNotNull(title);
    checkNotNull(contents);
    final JDialog dialog = new JDialog(parentFrame, title, true);
    dialog.getContentPane().add(contents);
    final Action closeAction = SwingAction.of("", e -> dialog.setVisible(false));
    final KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    final String key = "dialog.close";
    dialog.getRootPane().getActionMap().put(key, closeAction);
    dialog.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, key);
    return dialog;
}
Also used : Action(javax.swing.Action) SwingAction(games.strategy.ui.SwingAction) KeyStroke(javax.swing.KeyStroke) JDialog(javax.swing.JDialog)

Example 49 with KeyStroke

use of javax.swing.KeyStroke in project logisim-evolution by reds-heig.

the class KeyboardToolSelection method register.

public static void register(Toolbar toolbar) {
    ActionMap amap = toolbar.getActionMap();
    InputMap imap = toolbar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    int mask = toolbar.getToolkit().getMenuShortcutKeyMask();
    for (int i = 0; i < 10; i++) {
        KeyStroke keyStroke = KeyStroke.getKeyStroke((char) ('0' + i), mask);
        int j = (i == 0 ? 10 : i - 1);
        KeyboardToolSelection action = new KeyboardToolSelection(toolbar, j);
        String key = "ToolSelect" + i;
        amap.put(key, action);
        imap.put(keyStroke, key);
    }
}
Also used : ActionMap(javax.swing.ActionMap) KeyStroke(javax.swing.KeyStroke) InputMap(javax.swing.InputMap)

Example 50 with KeyStroke

use of javax.swing.KeyStroke in project artisynth_core by artisynth.

the class ReadlinePanel method initializeKeyMap.

private void initializeKeyMap() {
    addKeyListener(new MyKeyListener());
    InputMap map = getInputMap();
    KeyStroke[] keys = map.allKeys();
    for (int i = 0; i < keys.length; i++) {
        // disable this key binding
        map.put(keys[i], "none");
    }
}
Also used : KeyStroke(javax.swing.KeyStroke) InputMap(javax.swing.InputMap)

Aggregations

KeyStroke (javax.swing.KeyStroke)194 ActionEvent (java.awt.event.ActionEvent)77 AbstractAction (javax.swing.AbstractAction)56 InputMap (javax.swing.InputMap)46 Action (javax.swing.Action)44 JRootPane (javax.swing.JRootPane)36 ActionListener (java.awt.event.ActionListener)27 JPanel (javax.swing.JPanel)20 ActionMap (javax.swing.ActionMap)17 JComponent (javax.swing.JComponent)16 KeyEvent (java.awt.event.KeyEvent)15 JMenuItem (javax.swing.JMenuItem)14 JScrollPane (javax.swing.JScrollPane)14 Point (java.awt.Point)13 JFrame (javax.swing.JFrame)12 JPopupMenu (javax.swing.JPopupMenu)12 WindowEvent (java.awt.event.WindowEvent)10 Dimension (java.awt.Dimension)9 MouseAdapter (java.awt.event.MouseAdapter)9 MouseEvent (java.awt.event.MouseEvent)9