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:ee.ioc.cs.vsle.editor.Editor.java

/**
 * Creates Action objects and initializes Input and Action mappings
 *//*from   w w  w  .j  a v  a  2s  .  c  o m*/
private void initActions() {
    JRootPane rp = getRootPane();

    ActionMap am = rp.getActionMap();
    InputMap im = rp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

    am.put(DeleteAction.class, deleteAction);
    am.put(CloneAction.class, cloneAction);

    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), DeleteAction.class);
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK), CloneAction.class);
}

From source file:edu.ku.brc.ui.tmanfe.SearchReplacePanel.java

/**
 * sets up the keystroke mappings for "Ctrl-F" firing the find/replace panel
 * Escape making it disappear, and enter key firing a search
 */// ww w. j  a v  a 2  s .  co  m
private void setupKeyStrokeMappings() {
    //table.getActionMap().clear();

    //override the "Ctrl-F" function for launching the find dialog shipped with JXTable
    table.getInputMap().put(
            KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
            UIRegistry.getResourceString(FIND));
    table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK),
            UIRegistry.getResourceString(FIND));

    //create action that will display the find/replace dialog
    launchFindAction = new LaunchFindAction();
    table.getActionMap().put(FIND, launchFindAction);

    //Allow ESC buttun to call DisablePanelAction   
    String CANCEL_KEY = "CANCELKEY"; // i18n
    //Allow ENTER button to SearchAction
    String ENTER_KEY = "ENTERKEY"; // i18n
    String REPLACE_KEY = "REPLACEKEY"; // i18n

    KeyStroke enterKey = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false);
    KeyStroke escapeKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);

    InputMap textFieldInputMap = findField.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    textFieldInputMap.put(enterKey, ENTER_KEY);
    textFieldInputMap.put(escapeKey, CANCEL_KEY);

    ActionMap textFieldActionMap = findField.getActionMap();
    textFieldActionMap.put(ENTER_KEY, searchAction);
    textFieldActionMap.put(CANCEL_KEY, hideFindPanelAction);

    if (!table.isReadOnly()) {
        InputMap replaceFieldInputMap = replaceField.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
        replaceFieldInputMap.put(enterKey, REPLACE_KEY);
        replaceFieldInputMap.put(escapeKey, CANCEL_KEY);

        ActionMap replaceFieldActionMap = replaceField.getActionMap();
        replaceFieldActionMap.put(REPLACE_KEY, replaceAction);
        replaceFieldActionMap.put(CANCEL_KEY, hideFindPanelAction);
    }
}

From source file:fll.subjective.SubjectiveFrame.java

/**
 * Set the tab and return behavior for a table.
 *//*w w w. j  av a  2s.c om*/
private void setupTabReturnBehavior(final JTable table) {
    final InputMap im = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    // Have the enter key work the same as the tab key
    final KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
    final KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    im.put(enter, im.get(tab));

    // Override the default tab behavior
    // Tab to the next editable cell. When no editable cells goto next cell.
    final Action oldTabAction = table.getActionMap().get(im.get(tab));
    final Action tabAction = new AbstractAction() {
        public void actionPerformed(final ActionEvent e) {
            if (null != oldTabAction) {
                oldTabAction.actionPerformed(e);
            }

            final JTable table = (JTable) e.getSource();
            final int rowCount = table.getRowCount();
            final int columnCount = table.getColumnCount();
            int row = table.getSelectedRow();
            int column = table.getSelectedColumn();

            // skip the no show when tabbing
            while (!table.isCellEditable(row, column) || table.getColumnClass(column) == Boolean.class) {
                column += 1;

                if (column == columnCount) {
                    column = 0;
                    row += 1;
                }

                if (row == rowCount) {
                    row = 0;
                }

                // Back to where we started, get out.
                if (row == table.getSelectedRow() && column == table.getSelectedColumn()) {
                    break;
                }
            }

            table.changeSelection(row, column, false, false);
        }
    };
    table.getActionMap().put(im.get(tab), tabAction);
}

From source file:com.all.login.view.NewAccountFormPanel.java

JTextField getEmailTextField() {
    if (emailTextField == null) {
        emailTextField = new JTextField();
        emailTextField.setBounds(EMAIL_TEXTFIELD_BOUNDS);
        emailTextField.setSelectionColor(COLOR_SELECTION_TEXTFIELDS);
        emailTextField.setName(EMAIL_TEXT_FIELD_NAME);
        final LowercaseFocusListener emailListener = new LowercaseFocusListener(emailTextField,
                EMAIL_FIELD_NAME);/*from w w  w  .ja va  2  s . c  om*/
        emailTextField.addFocusListener(emailListener);
        emailTextField.addKeyListener(new KeyAdapter() {
            @Override
            public void keyReleased(KeyEvent e) {
                int caretPosition = emailTextField.getCaretPosition();
                if (emailTextField.getName().startsWith(INVALID_FIELD_NAME)) {
                    emailListener.focusLost(null);
                }
                validateAllUserData();
                emailTextField.setCaretPosition(caretPosition);
            }
        });
        InputMap map = emailTextField.getInputMap(JTextField.WHEN_FOCUSED);
        map.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.VK_CONTROL), null);
        emailTextField.addKeyListener(new CopyPasteKeyAdapterForMac());
    }
    return emailTextField;
}

From source file:edu.ku.brc.af.ui.forms.ResultSetController.java

/**
 * //  w  w  w .  j  a va  2 s.  co m
 */
public void setupGotoListener() {
    KeyStroke gotoKS = KeyStroke.getKeyStroke(KeyEvent.VK_L,
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    String ACTION_KEY = "GOTO";
    InputMap inputMap = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    ActionMap actionMap = panel.getActionMap();

    inputMap.put(gotoKS, ACTION_KEY);
    actionMap.put(ACTION_KEY, new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            showGotoRecDlg();
        }
    });
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopPickerField.java

protected void updateOrderedShortcuts() {
    InputMap inputMap = getImpl().getInputField().getInputMap(JComponent.WHEN_FOCUSED);
    for (int i = 0; i < 9; i++) {
        KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_1 + i, modifiersMask, false);
        inputMap.remove(keyStroke);//from  w w  w.  ja  v  a 2  s . c  o m
    }

    int index = 0;
    for (Action action : actionsOrder) {
        KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_1 + index, modifiersMask, false);
        List<KeyStroke> keyStrokes = new LinkedList<>();
        keyStrokes.add(keyStroke);
        keyStrokesMap.put(action, keyStrokes);

        inputMap.put(keyStroke, action.getId());

        index++;
    }
}

From source file:net.sf.jabref.EntryEditor.java

/**
 * Create toolbar for entry editor.//from   www . j av  a 2 s  .  c  o  m
 */
private void setupToolBar() {
    JToolBar tlb = new JToolBar(JToolBar.VERTICAL);
    CloseAction closeAction = new CloseAction();
    ;
    StoreFieldAction storeFieldAction = new StoreFieldAction();
    DeleteAction deleteAction = new DeleteAction();
    UndoAction undoAction = new UndoAction();
    RedoAction redoAction = new RedoAction();

    tlb.setBorder(null);
    tlb.setRollover(true);
    tlb.setMargin(new Insets(0, 0, 0, 2));
    tlb.setFloatable(false);
    tlb.addSeparator();
    tlb.add(deleteAction);
    tlb.addSeparator();
    tlb.add(prevEntryAction);
    tlb.add(nextEntryAction);
    tlb.addSeparator();
    tlb.add(helpAction);
    for (Component comp : tlb.getComponents()) {
        ((JComponent) comp).setOpaque(false);
    }

    // The toolbar carries all the key bindings that are valid for the whole window.
    ActionMap am = tlb.getActionMap();
    InputMap im = tlb.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(prefs.getKey("Close entry editor"), "close");
    am.put("close", closeAction);
    im.put(prefs.getKey("Entry editor, store field"), "store");
    am.put("store", storeFieldAction);
    im.put(prefs.getKey("Entry editor, previous entry"), "prev");
    am.put("prev", prevEntryAction);
    im.put(prefs.getKey("Entry editor, next entry"), "next");
    am.put("next", nextEntryAction);
    im.put(prefs.getKey("Undo"), "undo");
    am.put("undo", undoAction);
    im.put(prefs.getKey("Redo"), "redo");
    am.put("redo", redoAction);
    im.put(prefs.getKey("Help"), "help");
    am.put("help", helpAction);

    // Add actions (and thus buttons)
    JButton closeBut = new JButton(closeAction);
    closeBut.setText(null);
    closeBut.setBorder(null);

    // Create type-label
    TypeLabel typeLabel = new TypeLabel(entry.getType().getName());

    JPanel leftPan = new JPanel();
    leftPan.setLayout(new BorderLayout());
    leftPan.add(closeBut, BorderLayout.NORTH);
    leftPan.add(typeLabel, BorderLayout.CENTER);
    leftPan.add(tlb, BorderLayout.SOUTH);

    add(leftPan, BorderLayout.WEST);
}

From source file:net.sf.jabref.EntryEditor.java

protected void setupSwingComponentKeyBindings(JComponent component) {
    // Set up key bindings and focus listener for the FieldEditor.
    InputMap im = component.getInputMap(JComponent.WHEN_FOCUSED);
    ActionMap am = component.getActionMap();

    im.put(prefs.getKey("Entry editor, store field"), "store");
    am.put("store", storeFieldAction);

    im.put(prefs.getKey("Entry editor, next panel"), "right");
    im.put(prefs.getKey("Entry editor, next panel 2"), "right");
    am.put("right", switchRightAction);

    im.put(prefs.getKey("Entry editor, previous panel"), "left");
    im.put(prefs.getKey("Entry editor, previous panel 2"), "left");
    am.put("left", switchLeftAction);

    im.put(prefs.getKey("Help"), "help");
    am.put("help", helpAction);

    im.put(prefs.getKey("Save database"), "save");
    am.put("save", saveDatabaseAction);

    im.put(Globals.prefs.getKey("Next tab"), "nexttab");
    am.put("nexttab", frame.nextTab);

    im.put(Globals.prefs.getKey("Previous tab"), "prevtab");
    am.put("prevtab", frame.prevTab);
}

From source file:ca.phon.app.project.ProjectWindow.java

private MultiActionButton createCorpusButton() {
    MultiActionButton retVal = new MultiActionButton();

    ImageIcon newIcn = IconManager.getInstance().getIcon("places/folder", IconSize.SMALL);

    String s1 = "Corpus";
    String s2 = "Enter corpus name and press enter.  Press escape to cancel.";

    retVal.getTopLabel().setText(WorkspaceTextStyler.toHeaderText(s1));
    retVal.getTopLabel().setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
    retVal.getTopLabel().setFont(FontPreferences.getTitleFont());
    retVal.getTopLabel().setIcon(newIcn);
    retVal.setAlwaysDisplayActions(true);

    retVal.setOpaque(false);/*from  w ww .j a v a2s .c om*/

    ImageIcon cancelIcn = IconManager.getInstance().getIcon("actions/button_cancel", IconSize.SMALL);
    ImageIcon cancelIcnL = cancelIcn;

    PhonUIAction btnSwapAct = new PhonUIAction(this, "onSwapNewAndCreateCorpus", retVal);
    btnSwapAct.putValue(Action.ACTION_COMMAND_KEY, "CANCEL_CREATE_ITEM");
    btnSwapAct.putValue(Action.NAME, "Cancel create");
    btnSwapAct.putValue(Action.SHORT_DESCRIPTION, "Cancel create");
    btnSwapAct.putValue(Action.SMALL_ICON, cancelIcn);
    btnSwapAct.putValue(Action.LARGE_ICON_KEY, cancelIcnL);
    retVal.addAction(btnSwapAct);

    JPanel corpusNamePanel = new JPanel(new BorderLayout());
    corpusNamePanel.setOpaque(false);

    final JTextField corpusNameField = new JTextField();
    corpusNameField.setDocument(new NameDocument());
    corpusNameField.setText("Corpus Name");
    corpusNamePanel.add(corpusNameField, BorderLayout.CENTER);

    ActionMap actionMap = retVal.getActionMap();
    actionMap.put(btnSwapAct.getValue(Action.ACTION_COMMAND_KEY), btnSwapAct);
    InputMap inputMap = retVal.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);

    inputMap.put(ks, btnSwapAct.getValue(Action.ACTION_COMMAND_KEY));

    retVal.setActionMap(actionMap);
    retVal.setInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);

    PhonUIAction createNewCorpusAct = new PhonUIAction(this, "onCreateCorpus", corpusNameField);
    createNewCorpusAct.putValue(Action.SHORT_DESCRIPTION, "Create new corpus folder");
    createNewCorpusAct.putValue(Action.SMALL_ICON,
            IconManager.getInstance().getIcon("actions/list-add", IconSize.SMALL));

    JButton createBtn = new JButton(createNewCorpusAct);
    corpusNamePanel.add(createBtn, BorderLayout.EAST);

    corpusNameField.setAction(createNewCorpusAct);

    // swap bottom component in new project button
    retVal.setBottomLabelText(WorkspaceTextStyler.toDescText(s2));
    retVal.add(corpusNamePanel, BorderLayout.CENTER);

    retVal.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
        }

        @Override
        public void focusGained(FocusEvent e) {
            corpusNameField.requestFocus();
        }
    });

    return retVal;
}

From source file:ca.phon.app.project.ProjectWindow.java

private MultiActionButton createSessionButton() {
    MultiActionButton retVal = new MultiActionButton();

    ImageIcon newIcn = IconManager.getInstance().getIcon("mimetypes/text-xml", IconSize.SMALL);

    String s1 = "Session";
    String s2 = "Enter session name and press enter.  Press escape to cancel.";

    retVal.getTopLabel().setText(WorkspaceTextStyler.toHeaderText(s1));
    retVal.getTopLabel().setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
    retVal.getTopLabel().setFont(FontPreferences.getTitleFont());
    retVal.getTopLabel().setIcon(newIcn);
    retVal.setAlwaysDisplayActions(true);

    retVal.setOpaque(false);/*from  w  ww .  j  av a  2 s . c  om*/

    ImageIcon cancelIcn = IconManager.getInstance().getIcon("actions/button_cancel", IconSize.SMALL);
    ImageIcon cancelIcnL = cancelIcn;

    PhonUIAction btnSwapAct = new PhonUIAction(this, "onSwapNewAndCreateSession", retVal);
    btnSwapAct.putValue(Action.ACTION_COMMAND_KEY, "CANCEL_CREATE_ITEM");
    btnSwapAct.putValue(Action.NAME, "Cancel create");
    btnSwapAct.putValue(Action.SHORT_DESCRIPTION, "Cancel create");
    btnSwapAct.putValue(Action.SMALL_ICON, cancelIcn);
    btnSwapAct.putValue(Action.LARGE_ICON_KEY, cancelIcnL);
    retVal.addAction(btnSwapAct);

    JPanel sessionNamePanel = new JPanel(new BorderLayout());
    sessionNamePanel.setOpaque(false);

    final JTextField sessionNameField = new JTextField();
    sessionNameField.setDocument(new NameDocument());
    sessionNameField.setText("Session Name");
    sessionNamePanel.add(sessionNameField, BorderLayout.CENTER);

    ActionMap actionMap = retVal.getActionMap();
    actionMap.put(btnSwapAct.getValue(Action.ACTION_COMMAND_KEY), btnSwapAct);
    InputMap inputMap = retVal.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);

    inputMap.put(ks, btnSwapAct.getValue(Action.ACTION_COMMAND_KEY));

    retVal.setActionMap(actionMap);
    retVal.setInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);

    PhonUIAction createNewSessionAct = new PhonUIAction(this, "onCreateSession", sessionNameField);
    createNewSessionAct.putValue(Action.SHORT_DESCRIPTION, "Create new session in selected corpus");
    createNewSessionAct.putValue(Action.SMALL_ICON,
            IconManager.getInstance().getIcon("actions/list-add", IconSize.SMALL));

    JButton createBtn = new JButton(createNewSessionAct);
    sessionNamePanel.add(createBtn, BorderLayout.EAST);

    sessionNameField.setAction(createNewSessionAct);

    // swap bottom component in new project button
    retVal.setBottomLabelText(WorkspaceTextStyler.toDescText(s2));
    retVal.add(sessionNamePanel, BorderLayout.CENTER);

    retVal.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {

        }

        @Override
        public void focusGained(FocusEvent e) {
            sessionNameField.requestFocus();
        }
    });

    return retVal;
}