Example usage for javax.swing ActionMap allKeys

List of usage examples for javax.swing ActionMap allKeys

Introduction

In this page you can find the example usage for javax.swing ActionMap allKeys.

Prototype

public Object[] allKeys() 

Source Link

Document

Returns an array of the keys defined in this ActionMap and its parent.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JButton component = new JButton("button");
    ActionMap map = component.getActionMap();
    list(map, map.keys());//ww  w  . j a v  a2 s  . co  m
    list(map, map.allKeys());
}

From source file:Main.java

public static void main(String args[]) {
    String ACTION_KEY = "The Action";

    JFrame frame = new JFrame("KeyStroke Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JButton buttonA = new JButton("FOCUSED (control alt 7)");
    JButton buttonB = new JButton("FOCUS/RELEASE (VK_ENTER)");
    JButton buttonC = new JButton("ANCESTOR  (VK_F4+SHIFT_MASK)");
    JButton buttonD = new JButton("WINDOW (' ')");

    Action actionListener = new AbstractAction() {
        public void actionPerformed(ActionEvent actionEvent) {
            JButton source = (JButton) actionEvent.getSource();
            System.out.println("Activated: " + source.getText());
        }/*from   ww  w .  j  av  a2 s  . c o m*/
    };

    KeyStroke controlAlt7 = KeyStroke.getKeyStroke("control alt 7");
    InputMap inputMap = buttonA.getInputMap();
    inputMap.put(controlAlt7, ACTION_KEY);
    ActionMap actionMap = buttonA.getActionMap();
    Object[] keys = actionMap.allKeys();
    actionMap.put(ACTION_KEY, actionListener);

    KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true);
    inputMap = buttonB.getInputMap();
    inputMap.put(enter, ACTION_KEY);
    buttonB.setActionMap(actionMap);

    KeyStroke shiftF4 = KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.SHIFT_MASK);
    inputMap = buttonC.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    inputMap.put(shiftF4, ACTION_KEY);
    buttonC.setActionMap(actionMap);

    KeyStroke space = KeyStroke.getKeyStroke(' ');
    inputMap = buttonD.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(space, ACTION_KEY);
    buttonD.setActionMap(actionMap);

    frame.setLayout(new GridLayout(2, 2));
    frame.add(buttonA);
    frame.add(buttonB);
    frame.add(buttonC);
    frame.add(buttonD);

    frame.setSize(400, 200);
    frame.setVisible(true);
}

From source file:se.trixon.jota.client.ui.MainFrame.java

private void loadClientOption(ClientOptionsEvent clientOptionEvent) {
    switch (clientOptionEvent) {
    case LOOK_AND_FEEL:
        if (mOptions.isForceLookAndFeel()) {
            SwingUtilities.invokeLater(() -> {
                try {
                    UIManager.setLookAndFeel(SwingHelper.getLookAndFeelClassName(mOptions.getLookAndFeel()));
                    SwingUtilities.updateComponentTreeUI(MainFrame.this);
                    SwingUtilities.updateComponentTreeUI(sPopupMenu);

                    if (mOptions.getLookAndFeel().equalsIgnoreCase("Darcula")) {
                        int iconSize = 32;
                        UIDefaults uiDefaults = UIManager.getLookAndFeelDefaults();
                        uiDefaults.put("OptionPane.informationIcon",
                                MaterialIcon.Action.INFO_OUTLINE.get(iconSize, IconColor.WHITE));
                        uiDefaults.put("OptionPane.errorIcon",
                                MaterialIcon.Alert.ERROR_OUTLINE.get(iconSize, IconColor.WHITE));
                        uiDefaults.put("OptionPane.questionIcon",
                                MaterialIcon.Action.HELP_OUTLINE.get(iconSize, IconColor.WHITE));
                        uiDefaults.put("OptionPane.warningIcon",
                                MaterialIcon.Alert.WARNING.get(iconSize, IconColor.WHITE));
                    }/*from  w  w  w  . j  ava  2 s . com*/
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                        | UnsupportedLookAndFeelException ex) {
                    //Xlog.timedErr(ex.getMessage());
                }
            });
        }
        break;

    case MENU_ICONS:
        ActionMap actionMap = getRootPane().getActionMap();
        for (Object allKey : actionMap.allKeys()) {
            Action action = actionMap.get(allKey);
            Icon icon = null;
            if (mOptions.isDisplayMenuIcons()) {
                icon = (Icon) action.getValue(ActionManager.JOTA_SMALL_ICON_KEY);
            }
            action.putValue(Action.SMALL_ICON, icon);
        }
        break;

    default:
        throw new AssertionError();
    }

}