当前位置: 首页>>代码示例>>Java>>正文


Java KeyEvent.getID方法代码示例

本文整理汇总了Java中java.awt.event.KeyEvent.getID方法的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent.getID方法的具体用法?Java KeyEvent.getID怎么用?Java KeyEvent.getID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.event.KeyEvent的用法示例。


在下文中一共展示了KeyEvent.getID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processKeyEvent

import java.awt.event.KeyEvent; //导入方法依赖的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: postProcessKeyEvent

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
public boolean postProcessKeyEvent(KeyEvent ev) {
    if(ev.isConsumed() && ev.getKeyCode() != KeyEvent.VK_ALT) {
        // mnemonic combination, it's consumed, but we need
        // set altKeyPressed to false, otherwise after selection
        // component by mnemonic combination a menu will be open
        altKeyPressed = false;
        return false;
    }
    if (ev.getKeyCode() == KeyEvent.VK_ALT) {
        root = SwingUtilities.getRootPane(ev.getComponent());
        winAncestor = (root == null ? null :
                SwingUtilities.getWindowAncestor(root));

        if (ev.getID() == KeyEvent.KEY_PRESSED) {
            if (!altKeyPressed) {
                altPressed(ev);
            }
            altKeyPressed = true;
            return true;
        } else if (ev.getID() == KeyEvent.KEY_RELEASED) {
            if (altKeyPressed) {
                altReleased(ev);
            } else {
                MenuSelectionManager msm =
                    MenuSelectionManager.defaultManager();
                MenuElement[] path = msm.getSelectedPath();
                if (path.length <= 0) {
                    WindowsLookAndFeel.setMnemonicHidden(true);
                    WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
                }
            }
            altKeyPressed = false;
        }
        root = null;
        winAncestor = null;
    } else {
        altKeyPressed = false;
    }
    return false;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:41,代码来源:WindowsRootPaneUI.java

示例3: getAWTKeyStrokeForEvent

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
/**
 * Returns an <code>AWTKeyStroke</code> which represents the
 * stroke which generated a given <code>KeyEvent</code>.
 * <p>
 * This method obtains the keyChar from a <code>KeyTyped</code>
 * event, and the keyCode from a <code>KeyPressed</code> or
 * <code>KeyReleased</code> event. The <code>KeyEvent</code> modifiers are
 * obtained for all three types of <code>KeyEvent</code>.
 *
 * @param anEvent the <code>KeyEvent</code> from which to
 *      obtain the <code>AWTKeyStroke</code>
 * @throws NullPointerException if <code>anEvent</code> is null
 * @return the <code>AWTKeyStroke</code> that precipitated the event
 */
public static AWTKeyStroke getAWTKeyStrokeForEvent(KeyEvent anEvent) {
    int id = anEvent.getID();
    switch(id) {
      case KeyEvent.KEY_PRESSED:
      case KeyEvent.KEY_RELEASED:
        return getCachedStroke(KeyEvent.CHAR_UNDEFINED,
                               anEvent.getKeyCode(),
                               anEvent.getModifiers(),
                               (id == KeyEvent.KEY_RELEASED));
      case KeyEvent.KEY_TYPED:
        return getCachedStroke(anEvent.getKeyChar(),
                               KeyEvent.VK_UNDEFINED,
                               anEvent.getModifiers(),
                               false);
      default:
        // Invalid ID for this KeyEvent
        return null;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:34,代码来源:AWTKeyStroke.java

示例4: processKeyEvent

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
protected void processKeyEvent(KeyEvent event) {
    if (event.getID() == KeyEvent.KEY_RELEASED) {
        int row = getSelectedRow();
        
        if (row != -1) {
            if (event.getKeyCode() == KeyEvent.VK_LEFT) {
                if (treeRenderer.isExpanded(row)) {
                    treeRenderer.collapseRow(row);
                } else {
                    int parentRow = treeRenderer.getRowForPath(treeRenderer.getPathForRow(row).getParentPath());
                    
                    treeRenderer.collapseRow(parentRow);
                    getSelectionModel().setSelectionInterval(parentRow, parentRow);
                }
                event.consume();
                return;
            }
            if (event.getKeyCode() == KeyEvent.VK_RIGHT) {
                if (treeRenderer.isCollapsed(row)) {
                    treeRenderer.expandRow(row);
                }
                event.consume();
                return;
            }
        }
    }
    
    super.processKeyEvent(event);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:NbiTreeTable.java

示例5: processKeyEvent

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
@Override
public void processKeyEvent(KeyEvent evt) {
    if (evt.getID() == KeyEvent.KEY_TYPED) {
        if(evt.getKeyChar() == '.') { // NOI18N
            Completion.get().hideDocumentation();
            JTextComponent component = (JTextComponent)evt.getSource();
            int caretOffset = component.getSelectionEnd();
            int len = caretOffset - substitutionOffset;
            if (len >= 0) {
                substituteText(component, substitutionOffset, len, Character.toString(evt.getKeyChar()));
                Completion.get().showCompletion();
                evt.consume();
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:SpringXMLConfigCompletionItem.java

示例6: postProcessKeyEvent

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
public boolean postProcessKeyEvent(final KeyEvent ev) {
    if (ev.getKeyCode() != KeyEvent.VK_ALT) {
        return false;
    }

    final JRootPane root = SwingUtilities.getRootPane(ev.getComponent());
    final Window winAncestor = (root == null ? null : SwingUtilities.getWindowAncestor(root));

    switch(ev.getID()) {
        case KeyEvent.KEY_PRESSED:
            setMnemonicHidden(false);
            break;
        case KeyEvent.KEY_RELEASED:
            setMnemonicHidden(true);
            break;
    }

    repaintMnemonicsInWindow(winAncestor);

    return false;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:AquaMnemonicHandler.java

示例7: processKeyEvent

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
public void processKeyEvent (KeyEvent evt) {
    if (evt.getID() == KeyEvent.KEY_TYPED) {
        char c = evt.getKeyChar();
        JTextComponent component = (JTextComponent)evt.getSource();
        if (confirmChars == null) {
            confirmChars = getConfirmChars(component);
        }
        if (confirmChars.indexOf(c) != -1) {
            if (c != '.') {
                Completion.get().hideDocumentation();
                Completion.get().hideCompletion();
            }
            NbEditorDocument doc = (NbEditorDocument) component.getDocument ();
            try {
                defaultAction(component);
                doc.insertString(processKeyEventOffset, Character.toString(c), null);
            } catch (BadLocationException e) {
            }
            if (c == '.')
                Completion.get().showCompletion();
            evt.consume();
        } // if
    } // if
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:CompletionSupport.java

示例8: processKeyEvent

import java.awt.event.KeyEvent; //导入方法依赖的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

示例9: processInterruption

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
/**
 * Prevents showing a popup if a user releases the <code>releaseKey</code>
 * in time specified by <code>invokerTimer</code> (which is 200ms by
 * default).
 */
private static void processInterruption(KeyEvent kev) {
    int keyCode = kev.getKeyCode();
    if (keyCode == releaseKey && kev.getID() == KeyEvent.KEY_RELEASED) {
        // if an user releases Ctrl-Tab before the time to show
        // popup expires, don't show the popup at all and switch to
        // the last used document immediately
        cleanupInterrupter();
        hits = 0;
        AbstractAction rva = new ThreadsHistoryAction();
        rva.actionPerformed(new ActionEvent(kev.getSource(),
                ActionEvent.ACTION_PERFORMED,
                "immediately", kev.getModifiers())); // NOI18N
        kev.consume();
    // #88931: Need to react to KEY_PRESSED, not KEY_RELEASED, to not miss the hit    
    } else if (keyCode == triggerKey
            && kev.getModifiers() == InputEvent.CTRL_MASK
            && kev.getID() == KeyEvent.KEY_PRESSED) {
        // count number of trigger key hits before popup is shown
        hits++;
        kev.consume();
        cleanupInterrupter();
        instance = new KeyboardPopupSwitcher(hits + 1, true);
        instance.showPopup();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:KeyboardPopupSwitcher.java

示例10: keyReleased

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
public void keyReleased(KeyEvent e) {
    int id = e.getID();
    if(id == e.KEY_RELEASED && e.getKeyChar() == e.VK_BACK_SPACE)
    {
        /*
        if(getSelectedRow() != -1)
            ((GeometricLayerModel)dataModel).removeSelection(getSelectedRow());
        this.repaint();
        ((GeometricLayerModel)dataModel).changeSelection(getSelectedRow());
        */
    }
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:13,代码来源:GeometricInteractiveLayerPanel.java

示例11: consumeProcessedKeyEvent

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
private boolean consumeProcessedKeyEvent(KeyEvent e) {
    if ((e.getID() == KeyEvent.KEY_TYPED) && consumeNextKeyTyped) {
        e.consume();
        consumeNextKeyTyped = false;
        return true;
    }
    return false;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:DefaultKeyboardFocusManager.java

示例12: handleJavaKeyEvent

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
void handleJavaKeyEvent(KeyEvent e) {
    int id = e.getID();
    switch (id) {
      case KeyEvent.KEY_PRESSED:
          if (e.getKeyCode() == KeyEvent.VK_SPACE)
          {
              pressed=true;
              armed=true;
              repaint();
              action(e.getWhen(),e.getModifiers());
          }

          break;

      case KeyEvent.KEY_RELEASED:
          if (e.getKeyCode() == KeyEvent.VK_SPACE)
          {
              pressed = false;
              armed = false;
              repaint();
          }

          break;


    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:XButtonPeer.java

示例13: startScreen

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
public static void startScreen(){
	//controller.addNetworkHost(ip:"132.252.250.93");
	writeMode();
	controller.updateLedStripe();
	while (startScreen = true){
		KeyEvent event = buffer.pop();
		if (event != null){
			if (event.getID() == java.awt.event.KeyEvent.KEY_PRESSED){
				switch (event.getKeyCode()){
					case java.awt.event.KeyEvent.VK_1:
						controller.resetColors();
						controller.updateLedStripe();
						controller.sleep(500);
						screenOne();
						controller.updateLedStripe();
						startScreen = false;
						screen = 1;
						break;
					case java.awt.event.KeyEvent.VK_2:
						controller.resetColors();
						controller.updateLedStripe();
						controller.sleep(500);
						screenTwo();
						controller.updateLedStripe();
						startScreen = false;
						screen = 2;
						break;
					default:
				}
			}
		}
	}
}
 
开发者ID:JonathanTheZero,项目名称:LEDBoard-Game-Collection,代码行数:34,代码来源:Board.java

示例14: dispatchKeyEvent

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
/**
 * Dispatches a key event.
 *
 * @param e the key event
 * @return the status of the key event
 */
@Override
public boolean dispatchKeyEvent(KeyEvent e) {
    if (e.getID() == KEY_PRESSED) {
        onKeyEvent(e, true);
    } else if (e.getID() == KEY_RELEASED) {
        onKeyEvent(e, false);
    }

    return false;
}
 
开发者ID:Ordina-JTech,项目名称:hack-a-drone,代码行数:17,代码来源:Keyboard.java

示例15: dispatchKeyGeneral

import java.awt.event.KeyEvent; //导入方法依赖的package包/类
/**
 * Handles the keys which have to be enabled all the time in the frame.
 */
private void dispatchKeyGeneral(KeyEvent e) {
    int eventId = e.getID();
    int key = e.getKeyCode();

    if (eventId == KeyEvent.KEY_PRESSED) {

        switch (key) {

            case KeyEvent.VK_ESCAPE:
                cancelWindow();
                break;

            case KeyEvent.VK_ENTER:
                // if the textfield id the focus owner, do not save the object
                if (jFTFObjAlphaVal.isFocusOwner() || jFTFDPIValue.isFocusOwner()) {
                    break;
                }

                savePreferences();
                break;

            default:
                // do nothing
                break;
        }
    }
}
 
开发者ID:buni-rock,项目名称:Pixie,代码行数:31,代码来源:UserConfigs.java


注:本文中的java.awt.event.KeyEvent.getID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。