List of usage examples for javax.swing JComponent getActionMap
public final ActionMap getActionMap()
ActionMap
used to determine what Action
to fire for particular KeyStroke
binding. From source file:com.moneydance.modules.features.importlist.table.AbstractEditor.java
public final void registerKeyboardShortcut(final JComponent jComponent) { Validate.notNull(jComponent, "jComponent must not be null"); if (this.getKeyStroke() == null) { return;//from www . j a v a2s . c o m } final Action action = new AbstractAction() { private static final long serialVersionUID = 1L; @Override public void actionPerformed(final ActionEvent actionEvent) { ActionListener actionListener = AbstractEditor.this.getActionListener(0); actionListener.actionPerformed(actionEvent); } }; final String actionMapKey = this.getClass().getName(); // unique jComponent.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(this.getKeyStroke(), actionMapKey); jComponent.getActionMap().put(actionMapKey, action); }
From source file:ch.epfl.lis.gnwgui.NetworkGraph.java
/** * Add a key listener to print the content of the JPanel in which the graph is drawn. * @param jp JPanel that contains the network graph. *///from w w w. j a va 2 s . c o m @SuppressWarnings("serial") public void addPrintAction(JComponent jp) { KeyStroke k = KeyStroke.getKeyStroke("alt P"); jp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(k, "printscreen"); jp.getActionMap().put("printscreen", new AbstractAction() { public void actionPerformed(ActionEvent arg0) { item_.getNetworkViewer().getControl().printGraph(); } }); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopLookupField.java
protected void initClearShortcut() { JComponent editor = (JComponent) comboBox.getEditor().getEditorComponent(); KeyStroke clearKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, InputEvent.SHIFT_DOWN_MASK, false); editor.getInputMap(JComponent.WHEN_FOCUSED).put(clearKeyStroke, "clearShortcut"); editor.getActionMap().put("clearShortcut", new AbstractAction() { @Override//w ww. java 2 s . c o m public void actionPerformed(ActionEvent e) { if (!isRequired() && isEditable() && isEnabled()) { setValue(null); fireUserSelectionListeners(); } } }); }
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:com.t3.client.ui.T3Frame.java
private void updateKeyStrokes(JComponent c) { c.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).clear(); Map<KeyStroke, MacroButton> keyStrokeMap = MacroButtonHotKeyManager.getKeyStrokeMap(); if (c.getActionMap().keys() != null) { for (Object o : c.getActionMap().keys()) { // We're looking for MacroButton here, but we're adding AbstractActions below... Is this right? XXX if (o instanceof MacroButton) { if (log.isInfoEnabled()) log.info("Removing MacroButton " + ((MacroButton) o).getButtonText()); c.getActionMap().remove(o); }/*w w w . j av a 2 s . co m*/ } } for (KeyStroke keyStroke : keyStrokeMap.keySet()) { final MacroButton button = keyStrokeMap.get(keyStroke); if (button != null) { c.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, button); c.getActionMap().put(button, new MTButtonHotKeyAction(button)); } else { // This shouldn't be possible... log.error("No MacroButton found for keyStroke " + keyStroke.toString()); } } }
From source file:edu.ku.brc.ui.UIHelper.java
/** * Helper for adding KeyBindings.//from ww w . ja v a2 s.c o m * @param comp the component (usually a JButton) * @param action the action to be invoked * @param actionName the name to put into the map for the action * @param keyCode the key code * @param modifier the modifer */ public static void addKeyBinding(final JComponent comp, final Action action, final String actionName, final int keyCode, final int modifier) { KeyStroke ctrlS = KeyStroke.getKeyStroke(keyCode, modifier); InputMap inputMap = comp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(ctrlS, actionName); ActionMap actionMap = comp.getActionMap(); actionMap.put(actionName, action); }
From source file:com.osparking.attendant.AttListForm.java
private void attachEnterHandler(JComponent compo) { Action handleEnter = new AbstractAction() { public void actionPerformed(ActionEvent e) { searchButtonActionPerformed(null); }/* ww w.j ava2 s.co m*/ }; compo.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "handleEnter"); compo.getActionMap().put("handleEnter", handleEnter); }
From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java
/** * Adds a Key mappings.//from ww w .ja v a 2 s. co m * @param comp comp * @param keyCode keyCode * @param actionName actionName * @param action action * @return the action */ public Action addRecordKeyMappings(final JComponent comp, final int keyCode, final String actionName, final Action action, int modifiers) { InputMap inputMap = comp.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); ActionMap actionMap = comp.getActionMap(); inputMap.put(KeyStroke.getKeyStroke(keyCode, modifiers), actionName); actionMap.put(actionName, action); //UIRegistry.registerAction(actionName, action); return action; }
From source file:org.bitbucket.mlopatkin.android.logviewer.widgets.UiHelper.java
public static void bindKeyFocused(JComponent component, String key, String actionKey, Action action) { component.getInputMap().put(KeyStroke.getKeyStroke(key), actionKey); component.getActionMap().put(actionKey, action); }
From source file:org.bitbucket.mlopatkin.android.logviewer.widgets.UiHelper.java
/** * Creates a wrapper around an existing action of the component to be used * in menus./*from w w w. j a v a2 s .c om*/ * * @param c * base component * @param actionKey * key in the component's ActionMap * @param caption * caption of the action wrapper * @param acceleratorKey * accelerator key of the action wrapper * @return action that translates its * {@link Action#actionPerformed(ActionEvent)} to the underlaying * existing action. */ public static Action createActionWrapper(final JComponent c, final String actionKey, String caption, final String acceleratorKey) { final Action baseAction = c.getActionMap().get(actionKey); Action result = new AbstractAction(caption) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(acceleratorKey)); } @Override public void actionPerformed(ActionEvent e) { ActionEvent newEvent = new ActionEvent(c, e.getID(), actionKey, e.getWhen(), e.getModifiers()); baseAction.actionPerformed(newEvent); } @Override public void setEnabled(boolean newValue) { super.setEnabled(newValue); baseAction.setEnabled(newValue); } }; return result; }