本文整理匯總了Java中javax.swing.InputMap.get方法的典型用法代碼示例。如果您正苦於以下問題:Java InputMap.get方法的具體用法?Java InputMap.get怎麽用?Java InputMap.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.InputMap
的用法示例。
在下文中一共展示了InputMap.get方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getOSKey
import javax.swing.InputMap; //導入方法依賴的package包/類
private JavaAgentKeys getOSKey() {
KeyStroke selectall = null;
InputMap inputMap = new JTextField().getInputMap();
KeyStroke[] allKeys = inputMap.allKeys();
for (KeyStroke keyStroke : allKeys) {
Object object = inputMap.get(keyStroke);
if (object.equals("select-all")) {
selectall = keyStroke;
break;
}
}
if ((selectall.getModifiers() & InputEvent.CTRL_DOWN_MASK) == InputEvent.CTRL_DOWN_MASK) {
return JavaAgentKeys.CONTROL;
}
if ((selectall.getModifiers() & InputEvent.META_DOWN_MASK) == InputEvent.META_DOWN_MASK) {
return JavaAgentKeys.META;
}
throw new RuntimeException("Which key?");
}
示例2: checkKeystrokesForActions
import javax.swing.InputMap; //導入方法依賴的package包/類
public void checkKeystrokesForActions() throws Throwable {
StringBuilder sb = new StringBuilder();
driver = new JavaDriver();
WebElement textField = driver.findElement(By.cssSelector("text-field"));
JTextField f = new JTextField();
InputMap inputMap = f.getInputMap();
KeyStroke[] allKeys = inputMap.allKeys();
for (KeyStroke keyStroke : allKeys) {
Object object = inputMap.get(keyStroke);
try {
OSUtils.getKeysFor(textField, object.toString());
} catch (Throwable t) {
sb.append("failed for(" + object + "): " + keyStroke);
}
}
AssertJUnit.assertEquals("", sb.toString());
}
示例3: consumeIfKeyPressInActionMap
import javax.swing.InputMap; //導入方法依賴的package包/類
private void consumeIfKeyPressInActionMap(KeyEvent e) {
// get popup's registered keyboard actions
ActionMap am = popup.getActionMap();
InputMap im = popup.getInputMap();
// check whether popup registers keystroke
// If we consumed key pressed, we need to consume other key events as well:
KeyStroke ks = KeyStroke.getKeyStrokeForEvent(
new KeyEvent((Component) e.getSource(),
KeyEvent.KEY_PRESSED,
e.getWhen(),
e.getModifiers(),
KeyEvent.getExtendedKeyCodeForChar(e.getKeyChar()),
e.getKeyChar(),
e.getKeyLocation())
);
Object obj = im.get(ks);
if (obj != null && !obj.equals("tooltip-no-action") //NOI18N ignore ToolTipSupport installed actions
) {
// if yes, if there is a popup's action, consume key event
Action action = am.get(obj);
if (action != null && action.isEnabled()) {
// actionPerformed on key press only.
e.consume();
}
}
}
示例4: getCopyActionDelegate
import javax.swing.InputMap; //導入方法依賴的package包/類
private Action getCopyActionDelegate(InputMap map, KeyStroke ks) {
ActionMap am = getActionMap();
if(map != null && am != null && isEnabled()) {
Object binding = map.get(ks);
final Action action = (binding == null) ? null : am.get(binding);
if (action != null) {
return new CopyToClipboardAction(action);
}
}
return null;
}
示例5: actionPerformed
import javax.swing.InputMap; //導入方法依賴的package包/類
@Override
public void actionPerformed(ActionEvent e) {
if (isEditing() || editorComp != null) {
removeEditor();
return;
} else {
Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
InputMap imp = getRootPane().getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
ActionMap am = getRootPane().getActionMap();
KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
Object key = imp.get(escape);
if (key == null) {
//Default for NbDialog
key = "Cancel";
}
if (key != null) {
Action a = am.get(key);
if (a != null) {
String commandKey = (String)a.getValue(Action.ACTION_COMMAND_KEY);
if (commandKey == null) {
commandKey = key.toString();
}
a.actionPerformed(new ActionEvent(this,
ActionEvent.ACTION_PERFORMED, commandKey)); //NOI18N
}
}
}
}
示例6: listActionFor
import javax.swing.InputMap; //導入方法依賴的package包/類
@CheckForNull
private Pair<String,JComponent> listActionFor(KeyEvent ev) {
InputMap map = matchesList.getInputMap();
Object o = map.get(KeyStroke.getKeyStrokeForEvent(ev));
if (o instanceof String) {
return Pair.<String,JComponent>of((String)o, matchesList);
}
map = matchesScrollPane1.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
o = map.get(KeyStroke.getKeyStrokeForEvent(ev));
if (o instanceof String) {
return Pair.<String,JComponent>of((String)o, matchesScrollPane1);
}
return null;
}
示例7: listActionFor
import javax.swing.InputMap; //導入方法依賴的package包/類
@CheckForNull
private Pair<String,JComponent> listActionFor(KeyEvent ev) {
InputMap map = resultList.getInputMap();
Object o = map.get(KeyStroke.getKeyStrokeForEvent(ev));
if (o instanceof String) {
return Pair.<String,JComponent>of((String)o, resultList);
}
map = resultScrollPane.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
o = map.get(KeyStroke.getKeyStrokeForEvent(ev));
if (o instanceof String) {
return Pair.<String,JComponent>of((String)o, resultScrollPane);
}
return null;
}
示例8: keyPressed
import javax.swing.InputMap; //導入方法依賴的package包/類
public @Override void keyPressed(KeyEvent e){
if (e != null && popup != null && popup.isShowing()) {
// get popup's registered keyboard actions
ActionMap am = popup.getActionMap();
InputMap im = popup.getInputMap();
// check whether popup registers keystroke
KeyStroke ks = KeyStroke.getKeyStrokeForEvent(e);
Object obj = im.get(ks);
LOG.log(Level.FINE, "Keystroke for event {0}: {1}; action-map-key={2}", new Object [] { e, ks, obj }); //NOI18N
if (obj != null && !obj.equals("tooltip-no-action") //NOI18N ignore ToolTipSupport installed actions
) {
// if yes, gets the popup's action for this keystroke, perform it
// and consume key event
Action action = am.get(obj);
LOG.log(Level.FINE, "Popup component''s action: {0}, {1}", new Object [] { action, action != null ? action.getValue(Action.NAME) : null }); //NOI18N
if (action != null && action.isEnabled()) {
action.actionPerformed(null);
e.consume();
return;
}
}
if (e.getKeyCode() != KeyEvent.VK_CONTROL &&
e.getKeyCode() != KeyEvent.VK_SHIFT &&
e.getKeyCode() != KeyEvent.VK_ALT &&
e.getKeyCode() != KeyEvent.VK_ALT_GRAPH &&
e.getKeyCode() != KeyEvent.VK_META
) {
// hide tooltip if any was shown
Utilities.getEditorUI(textComponent).getToolTipSupport().setToolTipVisible(false);
}
}
}
示例9: trySendEscToDialog
import javax.swing.InputMap; //導入方法依賴的package包/類
/** Transmits escape sequence to dialog */
private void trySendEscToDialog() {
if (isTableUI()) {
//let the table decide, don't be preemptive
return;
}
// System.err.println("SendEscToDialog");
EventObject ev = EventQueue.getCurrentEvent();
if (ev instanceof KeyEvent && (((KeyEvent) ev).getKeyCode() == KeyEvent.VK_ESCAPE)) {
if (ev.getSource() instanceof JComboBox && ((JComboBox) ev.getSource()).isPopupVisible()) {
return;
}
if (
ev.getSource() instanceof JTextComponent &&
((JTextComponent) ev.getSource()).getParent() instanceof JComboBox &&
((JComboBox) ((JTextComponent) ev.getSource()).getParent()).isPopupVisible()
) {
return;
}
InputMap imp = getRootPane().getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
ActionMap am = getRootPane().getActionMap();
KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
Object key = imp.get(escape);
if (key != null) {
Action a = am.get(key);
if (a != null) {
if (Boolean.getBoolean("netbeans.proppanel.logDialogActions")) { //NOI18N
System.err.println("Action bound to escape key is " + a); //NOI18N
}
String commandKey = (String) a.getValue(Action.ACTION_COMMAND_KEY);
if (commandKey == null) {
commandKey = "cancel"; //NOI18N
}
a.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, commandKey)); //NOI18N
}
}
}
}
示例10: trySendEscToDialog
import javax.swing.InputMap; //導入方法依賴的package包/類
private void trySendEscToDialog(JTable jt) {
// System.err.println("SendEscToDialog");
EventObject ev = EventQueue.getCurrentEvent();
if (ev instanceof KeyEvent && (((KeyEvent) ev).getKeyCode() == KeyEvent.VK_ESCAPE)) {
if (ev.getSource() instanceof JComboBox && ((JComboBox) ev.getSource()).isPopupVisible()) {
return;
}
if (
ev.getSource() instanceof JTextComponent &&
((JTextComponent) ev.getSource()).getParent() instanceof JComboBox &&
((JComboBox) ((JTextComponent) ev.getSource()).getParent()).isPopupVisible()
) {
return;
}
InputMap imp = jt.getRootPane().getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
ActionMap am = jt.getRootPane().getActionMap();
KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
Object key = imp.get(escape);
if (key != null) {
Action a = am.get(key);
if (a != null) {
if (Boolean.getBoolean("netbeans.proppanel.logDialogActions")) { //NOI18N
System.err.println("Action bound to escape key is " + a); //NOI18N
}
//Actions registered with deprecated registerKeyboardAction will
//need this lookup of the action command
String commandKey = (String) a.getValue(Action.ACTION_COMMAND_KEY);
if (commandKey == null) {
commandKey = "cancel"; //NOI18N
}
a.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, commandKey)); //NOI18N
}
}
}
}
示例11: installKeyBindings
import javax.swing.InputMap; //導入方法依賴的package包/類
/**
* Registers keyboard actions to listen for in the text component and
* intercept.
*
* @see #uninstallKeyBindings()
*/
private void installKeyBindings() {
if (AutoCompletion.getDebug()) {
System.out.println("PopupWindow: Installing keybindings");
}
if (keyBindingsInstalled) {
System.err.println("Error: key bindings were already installed");
Thread.dumpStack();
return;
}
if (escapeKap==null) { // Lazily create actions.
createKeyActionPairs();
}
JTextComponent comp = ac.getTextComponent();
InputMap im = comp.getInputMap();
ActionMap am = comp.getActionMap();
replaceAction(im, am, KeyEvent.VK_ESCAPE, escapeKap, oldEscape);
if (AutoCompletion.getDebug() && oldEscape.action==escapeKap.action) {
Thread.dumpStack();
}
replaceAction(im, am, KeyEvent.VK_UP, upKap, oldUp);
replaceAction(im, am, KeyEvent.VK_LEFT, leftKap, oldLeft);
replaceAction(im, am, KeyEvent.VK_DOWN, downKap, oldDown);
replaceAction(im, am, KeyEvent.VK_RIGHT, rightKap, oldRight);
replaceAction(im, am, KeyEvent.VK_ENTER, enterKap, oldEnter);
replaceAction(im, am, KeyEvent.VK_TAB, tabKap, oldTab);
replaceAction(im, am, KeyEvent.VK_HOME, homeKap, oldHome);
replaceAction(im, am, KeyEvent.VK_END, endKap, oldEnd);
replaceAction(im, am, KeyEvent.VK_PAGE_UP, pageUpKap, oldPageUp);
replaceAction(im, am, KeyEvent.VK_PAGE_DOWN, pageDownKap, oldPageDown);
// Make Ctrl+C copy from description window. This isn't done
// automagically because the desc. window is not focusable, and copying
// from text components can only be done from focused components.
KeyStroke ks = getCopyKeyStroke();
oldCtrlC.key = im.get(ks);
im.put(ks, ctrlCKap.key);
oldCtrlC.action = am.get(ctrlCKap.key);
am.put(ctrlCKap.key, ctrlCKap.action);
comp.addCaretListener(this);
keyBindingsInstalled = true;
}
示例12: installKeyBindings
import javax.swing.InputMap; //導入方法依賴的package包/類
/**
* Installs key bindings on the text component that facilitate the user
* editing this completion's parameters.
*
* @see #uninstallKeyBindings()
*/
private void installKeyBindings() {
if (AutoCompletion.getDebug()) {
System.out.println("CompletionContext: Installing keybindings");
}
JTextComponent tc = ac.getTextComponent();
InputMap im = tc.getInputMap();
ActionMap am = tc.getActionMap();
KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
oldTabKey = im.get(ks);
im.put(ks, IM_KEY_TAB);
oldTabAction = am.get(IM_KEY_TAB);
am.put(IM_KEY_TAB, new NextParamAction());
ks = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK);
oldShiftTabKey = im.get(ks);
im.put(ks, IM_KEY_SHIFT_TAB);
oldShiftTabAction = am.get(IM_KEY_SHIFT_TAB);
am.put(IM_KEY_SHIFT_TAB, new PrevParamAction());
ks = KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0);
oldUpKey = im.get(ks);
im.put(ks, IM_KEY_UP);
oldUpAction = am.get(IM_KEY_UP);
am.put(IM_KEY_UP, new NextChoiceAction(-1, oldUpAction));
ks = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0);
oldDownKey = im.get(ks);
im.put(ks, IM_KEY_DOWN);
oldDownAction = am.get(IM_KEY_DOWN);
am.put(IM_KEY_DOWN, new NextChoiceAction(1, oldDownAction));
ks = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
oldEnterKey = im.get(ks);
im.put(ks, IM_KEY_ENTER);
oldEnterAction = am.get(IM_KEY_ENTER);
am.put(IM_KEY_ENTER, new GotoEndAction());
ks = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
oldEscapeKey = im.get(ks);
im.put(ks, IM_KEY_ESCAPE);
oldEscapeAction = am.get(IM_KEY_ESCAPE);
am.put(IM_KEY_ESCAPE, new HideAction());
char end = pc.getProvider().getParameterListEnd();
ks = KeyStroke.getKeyStroke(end);
oldClosingKey = im.get(ks);
im.put(ks, IM_KEY_CLOSING);
oldClosingAction = am.get(IM_KEY_CLOSING);
am.put(IM_KEY_CLOSING, new ClosingAction());
}
示例13: replaceAction
import javax.swing.InputMap; //導入方法依賴的package包/類
/**
* Replaces a key/Action pair in an InputMap and ActionMap with a new
* pair.
*
* @param im The input map.
* @param am The action map.
* @param key The keystroke whose information to replace.
* @param kap The new key/Action pair for <code>key</code>.
* @param old A buffer in which to place the old key/Action pair.
* @see #putBackAction(InputMap, ActionMap, int, KeyActionPair)
*/
private void replaceAction(InputMap im, ActionMap am, int key,
KeyActionPair kap, KeyActionPair old) {
KeyStroke ks = KeyStroke.getKeyStroke(key, 0);
old.key = im.get(ks);
im.put(ks, kap.key);
old.action = am.get(kap.key);
am.put(kap.key, kap.action);
}