Beispiel #1
0
    public void processKeyEvent(KeyEvent evt) {
      evt = KeyEventWorkaround.processKeyEvent(evt);
      if (evt == null) return;

      switch (evt.getID()) {
        case KeyEvent.KEY_TYPED:
          char ch = evt.getKeyChar();
          if (!nonDigit && Character.isDigit(ch)) {
            super.processKeyEvent(evt);
            repeat = true;
            repeatCount = Integer.parseInt(action.getText());
          } else {
            nonDigit = true;
            if (repeat) {
              passToView(evt);
            } else super.processKeyEvent(evt);
          }
          break;
        case KeyEvent.KEY_PRESSED:
          int keyCode = evt.getKeyCode();
          if (evt.isActionKey()
              || evt.isControlDown()
              || evt.isAltDown()
              || evt.isMetaDown()
              || keyCode == KeyEvent.VK_BACK_SPACE
              || keyCode == KeyEvent.VK_DELETE
              || keyCode == KeyEvent.VK_ENTER
              || keyCode == KeyEvent.VK_TAB
              || keyCode == KeyEvent.VK_ESCAPE) {
            nonDigit = true;
            if (repeat) {
              passToView(evt);
              break;
            } else if (keyCode == KeyEvent.VK_TAB) {
              complete(true);
              evt.consume();
            } else if (keyCode == KeyEvent.VK_ESCAPE) {
              evt.consume();
              if (popup != null) {
                popup.dispose();
                popup = null;
                action.requestFocus();
              } else {
                if (temp) view.removeToolBar(ActionBar.this);
                view.getEditPane().focusOnTextArea();
              }
              break;
            } else if ((keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_DOWN)
                && popup != null) {
              popup.list.processKeyEvent(evt);
              break;
            }
          }
          super.processKeyEvent(evt);
          break;
      }
    }
Beispiel #2
0
  // {{{ _preprocessKeyEvent() method
  private KeyEvent _preprocessKeyEvent(KeyEvent evt) {
    if (view.isClosed()) return null;
    Component focusOwner = view.getFocusOwner();
    if (focusOwner instanceof JComponent) {
      JComponent comp = (JComponent) focusOwner;
      InputMap map = comp.getInputMap();
      ActionMap am = comp.getActionMap();

      if (map != null && am != null && comp.isEnabled()) {
        KeyStroke keyStroke = KeyStroke.getKeyStrokeForEvent(evt);
        Object binding = map.get(keyStroke);
        if (binding != null && am.get(binding) != null) {
          return null;
        }
      }
    }

    if (focusOwner instanceof JTextComponent) {
      // fix for the bug where key events in JTextComponents
      // inside views are also handled by the input handler
      if (evt.getID() == KeyEvent.KEY_PRESSED) {
        switch (evt.getKeyCode()) {
          case KeyEvent.VK_ENTER:
          case KeyEvent.VK_TAB:
          case KeyEvent.VK_BACK_SPACE:
          case KeyEvent.VK_SPACE:
            return null;
        }
      }
    }

    if (evt.isConsumed()) return null;

    if (Debug.DUMP_KEY_EVENTS) {
      Log.log(Log.DEBUG, this, "Key event (preprocessing) : " + AbstractInputHandler.toString(evt));
    }

    return KeyEventWorkaround.processKeyEvent(evt);
  } // }}}