本文整理汇总了Java中javax.swing.KeyStroke.getKeyStrokeForEvent方法的典型用法代码示例。如果您正苦于以下问题:Java KeyStroke.getKeyStrokeForEvent方法的具体用法?Java KeyStroke.getKeyStrokeForEvent怎么用?Java KeyStroke.getKeyStrokeForEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.KeyStroke
的用法示例。
在下文中一共展示了KeyStroke.getKeyStrokeForEvent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processKeyEvent
import javax.swing.KeyStroke; //导入方法依赖的package包/类
@Override
protected void processKeyEvent(KeyEvent e) {
KeyStroke ks = KeyStroke.getKeyStrokeForEvent(e);
if (enter.equals(ks)) {
// Prevent JComponent.processKeyBindings() to be called (it is called from
// JComponent.processKeyEvent() ), notify only registered key listeners
int id = e.getID();
for (KeyListener keyListener : getKeyListeners()) {
switch(id) {
case KeyEvent.KEY_TYPED:
keyListener.keyTyped(e);
break;
case KeyEvent.KEY_PRESSED:
keyListener.keyPressed(e);
break;
case KeyEvent.KEY_RELEASED:
keyListener.keyReleased(e);
break;
}
}
if (!e.isConsumed() && id == KeyEvent.KEY_PRESSED) {
synchronized(listeners) {
List<CellEditorListener> list = new ArrayList<CellEditorListener>(listeners);
for (CellEditorListener listener : list) {
listener.editingStopped(new ChangeEvent(this));
}
}
}
e.consume();
} else {
super.processKeyEvent(e);
}
}
示例2: keySequenceInputFieldKeyPressed
import javax.swing.KeyStroke; //导入方法依赖的package包/类
private void keySequenceInputFieldKeyPressed (java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keySequenceInputFieldKeyPressed
String inputText = keySequenceInputField.getText();
if (evt.getModifiers() == 0 &&
KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0).equals(KeyStroke.getKeyStrokeForEvent( evt )) &&
inputText!=null && inputText.length()>0){
keySequenceInputField.transferFocus();
return;
}
evt.consume();
String modif = KeyEvent.getKeyModifiersText( evt.getModifiers() );
if( isModifier( evt.getKeyCode() ) ) {
keySequenceInputField.setText( text.toString() + modif + '+' ); //NOI18N
} else {
KeyStroke stroke = KeyStroke.getKeyStrokeForEvent( evt );
strokes.add( stroke );
text.append( Utilities.keyStrokeToString( stroke ) );
text.append( ' ' );
keySequenceInputField.setText( text.toString() );
firePropertyChange( PROP_KEYSEQUENCE, null, null );
}
}
示例3: processKeyEvent
import javax.swing.KeyStroke; //导入方法依赖的package包/类
public void processKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager manager) {
if (isReturnAction(e)) { // Handle SPACE and ENTER
MenuElement[] p = manager.getSelectedPath();
MenuElement m = p != null && p.length > 0 ? p[p.length - 1] : null;
if (m instanceof StayOpen) {
e.consume();
if (e.getID() == KeyEvent.KEY_PRESSED)
performAction((StayOpen)m, e.getModifiers());
return;
}
} else for (Component component : getComponents()) { // Handle mnemonics and accelerators
if (component instanceof StayOpen) {
StayOpen item = (StayOpen)component;
JMenuItem i = item.getItem();
KeyStroke k = KeyStroke.getKeyStrokeForEvent(e);
if (k.equals(mnemonic(i)) || k.equals(i.getAccelerator())) {
e.consume();
manager.setSelectedPath(new MenuElement[] { this, i });
performAction(item, e.getModifiers());
return;
}
}
}
super.processKeyEvent(e, path, manager);
}
示例4: keyPressed
import javax.swing.KeyStroke; //导入方法依赖的package包/类
public void keyPressed(KeyEvent evt) {
TextRegionManager manager = textRegionManager(evt);
if (manager == null || !manager.isActive() || evt.isConsumed())
return;
KeyStroke evtKeyStroke = KeyStroke.getKeyStrokeForEvent(evt);
if (KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0) == evtKeyStroke) {
manager.escapeAction();
evt.consume();
// } else if (KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0) == evtKeyStroke) {
// if (editing.enterAction())
// evt.consume();
//
// } else if (KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0) == evtKeyStroke) {
// if (editing.tabAction())
// evt.consume();
//
// } else if (KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_MASK) == evtKeyStroke) {
// if (editing.shiftTabAction())
// evt.consume();
//
}
}
示例5: consumeIfKeyPressInActionMap
import javax.swing.KeyStroke; //导入方法依赖的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();
}
}
}
示例6: eventDispatched
import javax.swing.KeyStroke; //导入方法依赖的package包/类
public void eventDispatched(AWTEvent event) {
if (!(event instanceof KeyEvent)) return;
KeyStroke eventKeyStroke = KeyStroke.getKeyStrokeForEvent((KeyEvent)event);
if (acceleratorKeyStroke == null || eventKeyStroke == null) return;
int acceleratorModifiers = acceleratorKeyStroke.getModifiers();
if (acceleratorModifiers == 0) return;
if (acceleratorModifiers != eventKeyStroke.getModifiers()) modifierKeyStateChanged();
}
示例7: processShortcut
import javax.swing.KeyStroke; //导入方法依赖的package包/类
private boolean processShortcut(KeyEvent ev) {
//ignore shortcut keys when the IDE is shutting down
if (NbLifecycleManager.isExiting()) {
ev.consume();
return true;
}
KeyStroke ks = KeyStroke.getKeyStrokeForEvent(ev);
Window w = SwingUtilities.windowForComponent(ev.getComponent());
// don't process shortcuts if this is a help frame
if ((w instanceof JFrame) && ((JFrame)w).getRootPane().getClientProperty("netbeans.helpframe") != null) // NOI18N
return true;
// don't let action keystrokes to propagate from both
// modal and nonmodal dialogs, but propagate from separate floating windows,
// even if they are backed by JDialog
if ((w instanceof Dialog) &&
!WindowManagerImpl.isSeparateWindow(w) &&
!isTransmodalAction(ks)) {
return false;
}
// Provide a reasonably useful action event that identifies what was focused
// when the key was pressed, as well as what keystroke ran the action.
ActionEvent aev = new ActionEvent(
ev.getSource(), ActionEvent.ACTION_PERFORMED, Utilities.keyToString(ks));
Keymap root = Lookup.getDefault().lookup(Keymap.class);
Action a = root.getAction (ks);
if (a != null && a.isEnabled()) {
ActionManager am = Lookup.getDefault().lookup(ActionManager.class);
am.invokeAction(a, aev);
ev.consume();
return true;
}
return false;
}
示例8: listKeyReleased
import javax.swing.KeyStroke; //导入方法依赖的package包/类
private void listKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_listKeyReleased
KeyStroke ks = KeyStroke.getKeyStrokeForEvent(evt);
if ( ks.getKeyCode() == KeyEvent.VK_ENTER ||
ks.getKeyCode() == KeyEvent.VK_SPACE ) {
importClass(
getSelected(),
(evt.getModifiers() & (org.openide.util.Utilities.isMac() ? InputEvent.META_MASK : InputEvent.ALT_MASK)) > 0,
(evt.getModifiers() & InputEvent.SHIFT_MASK) > 0);
}
}
示例9: testToStringOfDelegateContainsNameOfOriginalAction
import javax.swing.KeyStroke; //导入方法依赖的package包/类
public void testToStringOfDelegateContainsNameOfOriginalAction() throws Exception {
SaveAction sa = SaveAction.get(SaveAction.class);
Action a = sa.createContextAwareInstance(Lookup.EMPTY);
if (a.toString().indexOf("SaveAction") == -1) {
fail("We need name of the original action:\n" + a.toString());
}
SaveAction.cnt = 0;
CharSequence log = Log.enable("org.netbeans.ui", Level.FINER);
final TopComponent tc = new TopComponent();
final KeyEvent ke = new KeyEvent(tc, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), KeyEvent.CTRL_MASK, 0, 'S');
final KeyStroke ks = KeyStroke.getKeyStrokeForEvent(ke);
MockServices.setServices(MyKM.class);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
tc.setActivatedNodes( new Node[0] );
tc.processKeyBinding(ks, ke, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, true);
}
});
if (log.toString().indexOf("SaveAction") == -1
&& SaveAction.cnt == 1 ) { //make sure the action was actually invoked
fail(log.toString());
}
}
示例10: keyPressed
import javax.swing.KeyStroke; //导入方法依赖的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);
}
}
}
示例11: keyPressed
import javax.swing.KeyStroke; //导入方法依赖的package包/类
public void keyPressed(KeyEvent e) {
tableKeyStroke = KeyStroke.getKeyStrokeForEvent(e);
}
示例12: listKeyReleased
import javax.swing.KeyStroke; //导入方法依赖的package包/类
private void listKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_listKeyReleased
KeyStroke ks = KeyStroke.getKeyStrokeForEvent(evt);
if (ks.getKeyCode() == KeyEvent.VK_ENTER || ks.getKeyCode() == KeyEvent.VK_SPACE) {
invokeSelected();
}
}
示例13: actionPerformed
import javax.swing.KeyStroke; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt, JTextComponent target) {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("actionCommand='" + evt.getActionCommand() //NOI18N
+ "', modifiers=" + evt.getModifiers() //NOI18N
+ ", when=" + evt.getWhen() //NOI18N
+ ", paramString='" + evt.paramString() + "'"); //NOI18N
}
if (target == null) {
return;
}
BaseKit kit = Utilities.getKit(target);
if (kit == null) {
return;
}
BaseDocument doc = Utilities.getDocument(target);
if (doc == null) {
return;
}
// changed as reponse to #250157: other events may get fired during
// the course of key binding processing and if an event is processed
// as nested (i.e. hierarchy change resulting from a component retracting from the screen),
// thie following test would fail.
AWTEvent maybeKeyEvent = EventQueue.getCurrentEvent();
KeyStroke keyStroke = null;
if (maybeKeyEvent instanceof KeyEvent) {
keyStroke = KeyStroke.getKeyStrokeForEvent((KeyEvent) maybeKeyEvent);
}
// try simple keystorkes first
MimePath mimeType = MimePath.parse(NbEditorUtilities.getMimeType(target));
MacroDescription macro = null;
if (keyStroke != null) {
macro = findMacro(mimeType, keyStroke);
} else {
LOG.warning("KeyStroke could not be created for event " + maybeKeyEvent);
}
if (macro == null) {
// if not found, try action command, which should contain complete multi keystroke
KeyStroke[] shortcut = KeyStrokeUtils.getKeyStrokes(evt.getActionCommand());
if (shortcut != null) {
macro = findMacro(mimeType, shortcut);
} else {
LOG.warning("KeyStroke could not be created for action command " + evt.getActionCommand());
}
}
if (macro == null) {
error(target, "macro-not-found", KeyStrokeUtils.getKeyStrokeAsText(keyStroke)); // NOI18N
return;
}
if (!runningActions.add(macro.getName())) { // this macro is already running, beware of loops
error(target, "macro-loop", macro.getName()); // NOI18N
return;
}
try {
runMacro(target, doc, kit, macro);
} finally {
runningActions.remove(macro.getName());
}
}
示例14: getKeyStrokeForEvent
import javax.swing.KeyStroke; //导入方法依赖的package包/类
public static NamedKeyStroke getKeyStrokeForEvent(KeyEvent e) {
return new NamedKeyStroke(KeyStroke.getKeyStrokeForEvent(e));
}
示例15: keyPressed
import javax.swing.KeyStroke; //导入方法依赖的package包/类
public void keyPressed(KeyEvent e) {
stroke = KeyStroke.getKeyStrokeForEvent(e);
}