當前位置: 首頁>>代碼示例>>Java>>正文


Java KeyStroke.getKeyStrokeForEvent方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:34,代碼來源:WatchesColumnModels.java

示例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 );
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:KeySequenceInputPanel.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:StayOpenPopupMenu.java

示例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();
//
            }
        }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:TextRegionManager.java

示例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();
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:28,代碼來源:PopupManager.java

示例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();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:12,代碼來源:ToggleProfilingPointAction.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:39,代碼來源:ShortcutAndMenuKeyEventProcessor.java

示例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);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:11,代碼來源:ImportClassPanel.java

示例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());
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:29,代碼來源:TopComponentTest.java

示例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);
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:37,代碼來源:PopupManager.java

示例11: keyPressed

import javax.swing.KeyStroke; //導入方法依賴的package包/類
public void keyPressed(KeyEvent e) {
    tableKeyStroke = KeyStroke.getKeyStrokeForEvent(e);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:4,代碼來源:DetailsPanel.java

示例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();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:7,代碼來源:RemoveSurroundingCodePanel.java

示例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());
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:67,代碼來源:MacroDialogSupport.java

示例14: getKeyStrokeForEvent

import javax.swing.KeyStroke; //導入方法依賴的package包/類
public static NamedKeyStroke getKeyStrokeForEvent(KeyEvent e) {
  return new NamedKeyStroke(KeyStroke.getKeyStrokeForEvent(e));
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:4,代碼來源:NamedKeyStroke.java

示例15: keyPressed

import javax.swing.KeyStroke; //導入方法依賴的package包/類
public void keyPressed(KeyEvent e) {
  stroke = KeyStroke.getKeyStrokeForEvent(e);
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:4,代碼來源:HotkeySpecifier.java


注:本文中的javax.swing.KeyStroke.getKeyStrokeForEvent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。