Example usage for javax.swing InputMap put

List of usage examples for javax.swing InputMap put

Introduction

In this page you can find the example usage for javax.swing InputMap put.

Prototype

public void put(KeyStroke keyStroke, Object actionMapKey) 

Source Link

Document

Adds a binding for keyStroke to actionMapKey .

Usage

From source file:org.alex73.skarynka.scan.ui.scan.ScanDialogController.java

void addAction(int keyCode, Action action) {
    InputMap im = dialog.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    im.put(KeyStroke.getKeyStroke(keyCode, 0), action.getValue(Action.NAME));
    dialog.getRootPane().getActionMap().put(action.getValue(Action.NAME), action);
}

From source file:org.apache.jmeter.gui.action.SearchTreeDialog.java

@Override
protected JRootPane createRootPane() {
    JRootPane rootPane = new JRootPane();
    // Hide Window on ESC
    Action escapeAction = new AbstractAction("ESCAPE") {

        private static final long serialVersionUID = -6543764044868772971L;

        @Override//from www. j  av  a  2  s.c om
        public void actionPerformed(ActionEvent actionEvent) {
            setVisible(false);
        }
    };
    // Do search on Enter
    Action enterAction = new AbstractAction("ENTER") {

        private static final long serialVersionUID = -3661361497864527363L;

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            doSearch(actionEvent);
        }
    };
    ActionMap actionMap = rootPane.getActionMap();
    actionMap.put(escapeAction.getValue(Action.NAME), escapeAction);
    actionMap.put(enterAction.getValue(Action.NAME), enterAction);
    InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStrokes.ESC, escapeAction.getValue(Action.NAME));
    inputMap.put(KeyStrokes.ENTER, enterAction.getValue(Action.NAME));

    return rootPane;
}

From source file:org.apache.jmeter.gui.MainFrame.java

private void addQuickComponentHotkeys(JTree treevar) {
    Action quickComponent = new AbstractAction("Quick Component") {
        private static final long serialVersionUID = 1L;

        @Override/*w  ww  .  j a v  a2 s. c  o  m*/
        public void actionPerformed(ActionEvent actionEvent) {
            String propname = "gui.quick_" + actionEvent.getActionCommand();
            String comp = JMeterUtils.getProperty(propname);
            log.debug("Event " + propname + ": " + comp);

            if (comp == null) {
                log.warn("No component set through property: " + propname);
                return;
            }

            GuiPackage guiPackage = GuiPackage.getInstance();
            try {
                guiPackage.updateCurrentNode();
                TestElement testElement = guiPackage.createTestElement(SaveService.aliasToClass(comp));
                JMeterTreeNode parentNode = guiPackage.getCurrentNode();
                while (!MenuFactory.canAddTo(parentNode, testElement)) {
                    parentNode = (JMeterTreeNode) parentNode.getParent();
                }
                if (parentNode.getParent() == null) {
                    log.debug("Cannot add element on very top level");
                } else {
                    JMeterTreeNode node = guiPackage.getTreeModel().addComponent(testElement, parentNode);
                    guiPackage.getMainFrame().getTree().setSelectionPath(new TreePath(node.getPath()));
                }
            } catch (Exception err) {
                log.warn("Failed to perform quick component add: " + comp, err); // $NON-NLS-1$
            }
        }
    };

    InputMap inputMap = treevar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    KeyStroke[] keyStrokes = new KeyStroke[] { KeyStrokes.CTRL_0, KeyStrokes.CTRL_1, KeyStrokes.CTRL_2,
            KeyStrokes.CTRL_3, KeyStrokes.CTRL_4, KeyStrokes.CTRL_5, KeyStrokes.CTRL_6, KeyStrokes.CTRL_7,
            KeyStrokes.CTRL_8, KeyStrokes.CTRL_9, };
    for (int n = 0; n < keyStrokes.length; n++) {
        treevar.getActionMap().put(ActionNames.QUICK_COMPONENT + String.valueOf(n), quickComponent);
        inputMap.put(keyStrokes[n], ActionNames.QUICK_COMPONENT + String.valueOf(n));
    }
}

From source file:org.docx4all.swing.text.WordMLEditorKit.java

private void initKeyBindings(JEditorPane editor) {
    ActionMap myActionMap = new ActionMap();
    InputMap myInputMap = new InputMap();

    KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_MASK);
    myActionMap.put(insertSoftBreakAction, new InsertSoftBreakAction(insertSoftBreakAction));
    myInputMap.put(ks, insertSoftBreakAction);

    ks = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    myActionMap.put(enterKeyTypedAction, new EnterKeyTypedAction(enterKeyTypedAction));
    myInputMap.put(ks, enterKeyTypedAction);

    ks = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0);
    myActionMap.put(deleteNextCharAction, new DeleteNextCharAction(deleteNextCharAction));
    myInputMap.put(ks, deleteNextCharAction);

    ks = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0);
    myActionMap.put(deletePrevCharAction, new DeletePrevCharAction(deletePrevCharAction));
    myInputMap.put(ks, deletePrevCharAction);

    myActionMap.setParent(editor.getActionMap());
    myInputMap.setParent(editor.getInputMap());
    editor.setActionMap(myActionMap);//from  ww w .  j a  v  a  2s .c o  m
    editor.setInputMap(JComponent.WHEN_FOCUSED, myInputMap);
}

From source file:org.domainmath.gui.FileTreePanel.java

/**
 * Handle key events like F5,DELETE etc.
 * @param e // w  w w.j a v  a 2s .  c o m
 */
private void addGlobalAction(MouseEvent e) {
    TreePath path2 = fileTree.getPathForLocation(e.getX(), e.getY());
    Rectangle pathBounds2 = fileTree.getUI().getPathBounds(fileTree, path2);
    if (pathBounds2 != null && pathBounds2.contains(e.getX(), e.getY())) {
        TreePath[] selectionPaths = fileTree.getSelectionModel().getSelectionPaths();
        openAction = new OpenAction((File) fileTree.getLastSelectedPathComponent());
        refreshAction = new RefreshAction((File) fileTree.getLastSelectedPathComponent());
        deleteAction = new DeleteAction(selectionPaths);

        InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
        ActionMap actionMap = getRootPane().getActionMap();

        inputMap.put(keyDeleteItem, "DeleteAction");
        actionMap.put("DeleteAction", deleteAction);
        inputMap.put(keyOpenItem, "OpenAction");
        actionMap.put("OpenAction", openAction);
        inputMap.put(keyRefreshItem, "RefreshAction");
        actionMap.put("RefreshAction", refreshAction);
    }
}

From source file:org.executequery.gui.editor.autocomplete.QueryEditorAutoCompletePopupProvider.java

private void addFocusActions() {

    JTextComponent textComponent = queryEditorTextComponent();

    ActionMap actionMap = textComponent.getActionMap();
    actionMap.put(LIST_FOCUS_ACTION_KEY, listFocusAction);
    actionMap.put(LIST_SCROLL_ACTION_KEY_DOWN, listScrollActionDown);
    actionMap.put(LIST_SCROLL_ACTION_KEY_UP, listScrollActionUp);
    actionMap.put(LIST_SELECTION_ACTION_KEY, listSelectionAction);
    actionMap.put(LIST_SCROLL_ACTION_KEY_PAGE_DOWN, listScrollActionPageDown);
    actionMap.put(LIST_SCROLL_ACTION_KEY_PAGE_UP, listScrollActionPageUp);

    InputMap inputMap = textComponent.getInputMap();
    saveExistingActions(inputMap);//w  w  w.  j a  v  a 2s  . c  o  m

    inputMap.put(KEY_STROKE_DOWN, LIST_SCROLL_ACTION_KEY_DOWN);
    inputMap.put(KEY_STROKE_UP, LIST_SCROLL_ACTION_KEY_UP);

    inputMap.put(KEY_STROKE_PAGE_DOWN, LIST_SCROLL_ACTION_KEY_PAGE_DOWN);
    inputMap.put(KEY_STROKE_PAGE_UP, LIST_SCROLL_ACTION_KEY_PAGE_UP);

    inputMap.put(KEY_STROKE_TAB, LIST_FOCUS_ACTION_KEY);
    inputMap.put(KEY_STROKE_ENTER, LIST_SELECTION_ACTION_KEY);

    textComponent.addCaretListener(this);
}

From source file:org.executequery.gui.editor.autocomplete.QueryEditorAutoCompletePopupProvider.java

private void resetEditorActions() {

    JTextComponent textComponent = queryEditorTextComponent();

    ActionMap actionMap = textComponent.getActionMap();
    actionMap.remove(LIST_FOCUS_ACTION_KEY);
    actionMap.remove(LIST_SELECTION_ACTION_KEY);
    actionMap.remove(LIST_SCROLL_ACTION_KEY_DOWN);
    actionMap.remove(LIST_SCROLL_ACTION_KEY_UP);

    InputMap inputMap = textComponent.getInputMap();
    inputMap.remove(KEY_STROKE_DOWN);/* w  w  w. j  a  v a 2  s. co  m*/
    inputMap.remove(KEY_STROKE_UP);
    inputMap.remove(KEY_STROKE_PAGE_DOWN);
    inputMap.remove(KEY_STROKE_PAGE_UP);
    inputMap.remove(KEY_STROKE_ENTER);
    inputMap.remove(KEY_STROKE_TAB);

    inputMap.put(KEY_STROKE_DOWN, existingKeyStrokeDownAction);
    inputMap.put(KEY_STROKE_UP, existingKeyStrokeUpAction);
    inputMap.put(KEY_STROKE_PAGE_DOWN, existingKeyStrokePageDownAction);
    inputMap.put(KEY_STROKE_PAGE_UP, existingKeyStrokePageUpAction);
    inputMap.put(KEY_STROKE_TAB, existingKeyStrokeTabAction);
    inputMap.put(KEY_STROKE_ENTER, existingKeyStrokeEnterAction);

    textComponent.removeCaretListener(this);
}

From source file:org.executequery.gui.editor.QueryEditor.java

private void addDeleteLineActionMapping() {

    Action action = new AbstractAction() {

        public void actionPerformed(ActionEvent e) {

            deleteLine();//from w w w .  ja  v  a2  s. c  o m
        }
    };

    KeyStroke keyStroke = KeyStroke.getKeyStroke("control D");

    ActionMap textPaneActionMap = editorPanel.getTextPaneActionMap();
    InputMap textPaneInputMap = editorPanel.getTextPaneInputMap();

    String actionMapKey = "editor-delete-line";

    textPaneActionMap.put(actionMapKey, action);
    textPaneInputMap.put(keyStroke, actionMapKey);
}

From source file:org.executequery.gui.ExportResultSetPanel.java

private void init() throws Exception {

    fileNameField = WidgetFactory.createTextField();
    connectionsCombo = WidgetFactory.createComboBox();

    String[] delims = { "|", ",", ";", "#" };
    delimiterCombo = WidgetFactory.createComboBox(delims);
    delimiterCombo.setEditable(true);// ww  w.ja va2  s .  com

    combosGroup = new TableSelectionCombosGroup(connectionsCombo);

    includeColumNamesCheck = new JCheckBox("Include column names as first row");

    sqlText = new SimpleSqlTextPanel();
    //        sqlText.getTextPane().setBackground(Color.WHITE);
    sqlText.setBorder(null);
    sqlText.setScrollPaneBorder(BorderFactory.createMatteBorder(1, 1, 0, 1, UIUtils.getDefaultBorderColour()));

    statusBar = new SqlTextPaneStatusBar();
    JPanel sqlPanel = new JPanel(new BorderLayout());
    sqlPanel.add(sqlText, BorderLayout.CENTER);
    sqlPanel.add(statusBar, BorderLayout.SOUTH);
    statusBar.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 1));

    outputPanel = new LoggingOutputPanel();
    FlatSplitPane splitPane = new FlatSplitPane(JSplitPane.VERTICAL_SPLIT, sqlPanel, outputPanel);
    splitPane.setResizeWeight(0.5);
    splitPane.setDividerLocation(0.8);
    splitPane.setDividerSize(5);

    JButton button = WidgetFactory.createInlineFieldButton("Browse");
    button.setActionCommand("browse");
    button.addActionListener(this);
    button.setMnemonic('r');

    JPanel mainPanel = new JPanel(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridy = 0;
    gbc.gridx = 0;
    gbc.gridheight = 1;
    gbc.insets.top = 5;
    gbc.insets.bottom = 5;
    gbc.insets.right = 5;
    gbc.insets.left = 5;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    mainPanel.add(new JLabel("Connection:"), gbc);
    gbc.gridx = 1;
    gbc.weightx = 1.0;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(connectionsCombo, gbc);
    gbc.insets.left = 5;
    gbc.gridy++;
    gbc.gridx = 0;
    gbc.weightx = 0;
    gbc.gridwidth = 1;
    gbc.insets.top = 0;
    mainPanel.add(new JLabel("Data Delimiter:"), gbc);
    gbc.gridx = 1;
    gbc.weightx = 1.0;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(delimiterCombo, gbc);
    gbc.gridy++;
    gbc.gridx = 0;
    gbc.weightx = 0;
    gbc.gridwidth = 1;
    gbc.insets.top = 2;
    mainPanel.add(new JLabel("Output File:"), gbc);
    gbc.gridx = 1;
    gbc.weightx = 1.0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(fileNameField, gbc);
    gbc.gridx = 2;
    gbc.weightx = 0;
    gbc.insets.left = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(button, gbc);
    gbc.gridy++;
    gbc.gridx = 0;
    gbc.weightx = 0;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.insets.top = 2;
    gbc.insets.left = 5;
    mainPanel.add(includeColumNamesCheck, gbc);
    gbc.gridy++;
    gbc.insets.bottom = 10;
    mainPanel.add(new JLabel(instructionNote()), gbc);

    gbc.gridy++;
    gbc.gridx = 0;
    gbc.weighty = 1.0;
    gbc.weightx = 1.0;
    gbc.insets.top = 0;
    gbc.insets.left = 5;
    gbc.insets.bottom = 5;
    gbc.fill = GridBagConstraints.BOTH;
    mainPanel.add(splitPane, gbc);

    mainPanel.setBorder(BorderFactory.createEtchedBorder());

    int minimumButtonWidth = 85;
    executeButton = new MinimumWidthActionButton(minimumButtonWidth, this, "Execute", "executeAndExport");
    stopButton = new MinimumWidthActionButton(minimumButtonWidth, this, "Stop", "stop");
    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 2, 5));
    buttonPanel.add(executeButton);
    buttonPanel.add(stopButton);

    stopButton.setEnabled(false);

    add(mainPanel, BorderLayout.CENTER);
    add(buttonPanel, BorderLayout.SOUTH);
    setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));

    // register as a keyword and connection listener
    EventMediator.registerListener(this);

    JTextPane textPane = sqlText.getTextPane();
    ActionMap actionMap = textPane.getActionMap();

    String actionKey = "executeQueryAction";
    actionMap.put(actionKey, executeQueryAction);

    InputMap inputMap = textPane.getInputMap();
    inputMap.put(EXECUTE_KEYSTROKE, actionKey);

    JPopupMenu popupMenu = sqlText.getPopup();
    popupMenu.addSeparator();
    popupMenu.add(executeQueryAction);
}

From source file:org.executequery.util.LookAndFeelLoader.java

private void applyMacSettings() {

    if (UIUtils.isMac()) {

        String[] textComponents = { "TextField", "TextPane", "TextArea", "EditorPane", "PasswordField" };
        for (String textComponent : textComponents) {

            InputMap im = (InputMap) UIManager.get(textComponent + ".focusInputMap");
            im.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.META_DOWN_MASK), DefaultEditorKit.copyAction);
            im.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.META_DOWN_MASK),
                    DefaultEditorKit.pasteAction);
            im.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.META_DOWN_MASK), DefaultEditorKit.cutAction);
        }/*w  w w  .  j a  v a2s . c o m*/

        if (UIUtils.isNativeMacLookAndFeel()) {

            UIManager.put("Table.gridColor", UIUtils.getDefaultBorderColour());
        }

    }

}