Java Code Examples for java.awt.event.KeyEvent#getID()

The following examples show how to use java.awt.event.KeyEvent#getID() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AquaMnemonicHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: AquaMnemonicHandler.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: PinPadPanelImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public void eventDispatched(AWTEvent event) {
   if (event instanceof KeyEvent) {
      KeyEvent key = (KeyEvent)event;
      if (key.getID() == 401) {
         if (key.getKeyCode() == 8) {
            PinPadPanelImpl.this.processBackspace();
         } else if (key.getKeyCode() == 10) {
            PinPadPanelImpl.this.validateGoButton();
            if (PinPadPanelImpl.this.btnGo.isEnabled()) {
               ActionEvent action = new ActionEvent(PinPadPanelImpl.this.btnGo, 1001, PinPadPanelImpl.this.btnGo.getActionCommand(), System.currentTimeMillis(), 16);
               PinPadPanelImpl.this.actionListenerGoButton.actionPerformed(action);
            }
         } else {
            PinPadPanelImpl.this.processContent(Character.toString(key.getKeyChar()));
         }
      }
   }

}
 
Example 4
Source File: MenuBar.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
boolean handleShortcut(KeyEvent e) {
    // Is it a key event?
    int id = e.getID();
    if (id != KeyEvent.KEY_PRESSED && id != KeyEvent.KEY_RELEASED) {
        return false;
    }

    // Is the accelerator modifier key pressed?
    int accelKey = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    if ((e.getModifiers() & accelKey) == 0) {
        return false;
    }

    // Pass MenuShortcut on to child menus.
    int nmenus = getMenuCount();
    for (int i = 0 ; i < nmenus ; i++) {
        Menu m = getMenu(i);
        if (m.handleShortcut(e)) {
            return true;
        }
    }
    return false;
}
 
Example 5
Source File: PinPadPanelImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public void eventDispatched(AWTEvent event) {
   if (event instanceof KeyEvent) {
      KeyEvent key = (KeyEvent)event;
      if (key.getID() == 401) {
         if (key.getKeyCode() == 8) {
            PinPadPanelImpl.this.processBackspace();
         } else if (key.getKeyCode() == 10) {
            PinPadPanelImpl.this.validateGoButton();
            if (PinPadPanelImpl.this.btnGo.isEnabled()) {
               ActionEvent action = new ActionEvent(PinPadPanelImpl.this.btnGo, 1001, PinPadPanelImpl.this.btnGo.getActionCommand(), System.currentTimeMillis(), 16);
               PinPadPanelImpl.this.actionListenerGoButton.actionPerformed(action);
            }
         } else {
            PinPadPanelImpl.this.processContent(Character.toString(key.getKeyChar()));
         }
      }
   }

}
 
Example 6
Source File: AWTKeyStroke.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
    }
}
 
Example 7
Source File: DefaultKeyboardFocusManager.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private boolean consumeProcessedKeyEvent(KeyEvent e) {
    if ((e.getID() == KeyEvent.KEY_TYPED) && consumeNextKeyTyped) {
        e.consume();
        consumeNextKeyTyped = false;
        return true;
    }
    return false;
}
 
Example 8
Source File: WindowsRootPaneUI.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 9
Source File: XButtonPeer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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;


    }
}
 
Example 10
Source File: BeansCompletionItem.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void processKeyEvent(KeyEvent evt) {
    if (evt.getID() == KeyEvent.KEY_TYPED) {
        Completion completion = Completion.get();
        switch (evt.getKeyChar()) {
            case ' ':
                if (evt.getModifiers() == 0) {
                    completion.hideCompletion();
                    completion.hideDocumentation();
                }
                break;
        }
    }
}
 
Example 11
Source File: KeyboardTabSwitcher.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean postProcessKeyEvent(KeyEvent e) {
  if (e.getID() == KeyEvent.KEY_PRESSED && e.getModifiers() == InputEvent.CTRL_MASK) {
    if (e.getKeyCode() == KeyEvent.VK_PAGE_DOWN || e.getKeyCode() == KeyEvent.VK_LEFT) {
      goPrevPane();
      return true;
    } else if (e.getKeyCode() == KeyEvent.VK_PAGE_UP || e.getKeyCode() == KeyEvent.VK_RIGHT) {
      goNextPane();
      return true;
    }

  }
  return false;
}
 
Example 12
Source File: WatchesColumnModels.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 13
Source File: MnemonicsSearch.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void processKeyEvent(@Nonnull KeyEvent e) {
  if (e.isConsumed()) return;
  if (e.getID() != KeyEvent.KEY_TYPED) return;
  if (!StringUtil.isEmptyOrSpaces(myPopup.getSpeedSearch().getFilter())) return;

  if (Character.isLetterOrDigit(e.getKeyChar())) {
    final String s = Character.toString(e.getKeyChar());
    final T toSelect = myChar2ValueMap.get(s);
    if (toSelect != null) {
      select(toSelect);
      e.consume();
    }
  }
}
 
Example 14
Source File: WTextFieldPeer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean handleJavaKeyEvent(KeyEvent e) {
    switch (e.getID()) {
       case KeyEvent.KEY_TYPED:
           if ((e.getKeyChar() == '\n') && !e.isAltDown() && !e.isControlDown()) {
                postEvent(new ActionEvent(target, ActionEvent.ACTION_PERFORMED,
                                          getText(), e.getWhen(), e.getModifiers()));
                return true;
           }
       break;
    }
    return false;
}
 
Example 15
Source File: WTextFieldPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public boolean handleJavaKeyEvent(KeyEvent e) {
    switch (e.getID()) {
       case KeyEvent.KEY_TYPED:
           if ((e.getKeyChar() == '\n') && !e.isAltDown() && !e.isControlDown()) {
                postEvent(new ActionEvent(target, ActionEvent.ACTION_PERFORMED,
                                          getText(), e.getWhen(), e.getModifiers()));
                return true;
           }
       break;
    }
    return false;
}
 
Example 16
Source File: ProfilerPopup.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public boolean dispatchKeyEvent(KeyEvent e) {
    if (skippingEvents || e.isConsumed()) return false;
    
    if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_ESCAPE)
        if (SwingUtilities.getRootPane(this) != e.getSource()) { // Closing JPopupMenu using the ESC key
            e.consume();
            if (DEBUG) System.err.println(">>> Closed by ESC"); // NOI18N
            ProfilerPopup.this.hide();
            return true;
        }
    
    return false;
}
 
Example 17
Source File: IdeKeyEventDispatcher.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean inProcessedState() {
  KeyEvent e = myContext.getInputEvent();

  // ignore typed events which come after processed pressed event
  if (KeyEvent.KEY_TYPED == e.getID() && isPressedWasProcessed()) {
    return true;
  }
  if (KeyEvent.KEY_RELEASED == e.getID() && KeyEvent.VK_ALT == e.getKeyCode() && isPressedWasProcessed()) {
    //see IDEADEV-8615
    return true;
  }
  setState(KeyState.STATE_INIT);
  setPressedWasProcessed(false);
  return inInitState();
}
 
Example 18
Source File: DefaultKeyboardFocusManager.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private boolean consumeProcessedKeyEvent(KeyEvent e) {
    if ((e.getID() == KeyEvent.KEY_TYPED) && consumeNextKeyTyped) {
        e.consume();
        consumeNextKeyTyped = false;
        return true;
    }
    return false;
}
 
Example 19
Source File: DefaultKeyboardFocusManager.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
private void consumeTraversalKey(KeyEvent e) {
    e.consume();
    consumeNextKeyTyped = (e.getID() == KeyEvent.KEY_PRESSED) &&
                          !e.isActionKey();
}
 
Example 20
Source File: DefaultKeyboardFocusManager.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void consumeTraversalKey(KeyEvent e) {
    e.consume();
    consumeNextKeyTyped = (e.getID() == KeyEvent.KEY_PRESSED) &&
                          !e.isActionKey();
}