Exemple #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;
      }
    }
Exemple #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);
  } // }}}
Exemple #3
0
  /**
   * Forwards key events directly to the input handler. This is slightly faster than using a
   * KeyListener because some Swing overhead is avoided.
   *
   * @since 4.3pre7
   */
  @Override
  public void processKeyEvent(KeyEvent evt, int from, boolean global) {
    if (Debug.DUMP_KEY_EVENTS) {
      Log.log(
          Log.DEBUG,
          this,
          "Key event                 : " + AbstractInputHandler.toString(evt) + " from " + from);
      Log.log(Log.DEBUG, this, view + ".isFocused()=" + view.isFocused() + '.', new Exception());
    }

    if (view.getTextArea().hasFocus() && from == View.VIEW) return;

    evt = _preprocessKeyEvent(evt);
    if (evt == null) return;

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

    Component prefixFocusOwner = view.getPrefixFocusOwner();
    boolean focusOnTextArea = false;
    switch (evt.getID()) {
      case KeyEvent.KEY_TYPED:
        // if the user pressed eg C+e n n in the
        // search bar we want focus to go back there
        // after the prefix is done
        if (prefixFocusOwner != null) {
          if (prefixFocusOwner.isShowing()) {
            prefixFocusOwner.requestFocus();
            focusOnTextArea = true;
          }
        }

        if (keyEventInterceptor != null) keyEventInterceptor.keyTyped(evt);
        else if (from == View.ACTION_BAR || isPrefixActive() || view.getTextArea().hasFocus()) {
          processKeyEventKeyStrokeHandling(evt, from, "type ", global);
        }

        processKeyEventSub(focusOnTextArea);

        break;
      case KeyEvent.KEY_PRESSED:
        if (keyEventInterceptor != null) keyEventInterceptor.keyPressed(evt);
        else if (KeyEventWorkaround.isBindable(evt.getKeyCode())) {
          if (prefixFocusOwner != null) {
            if (prefixFocusOwner.isShowing()) {
              prefixFocusOwner.requestFocus();
              focusOnTextArea = true;
            }
            view.setPrefixFocusOwner(null);
          }

          processKeyEventKeyStrokeHandling(evt, from, "press", global);

          processKeyEventSub(focusOnTextArea);
        }
        break;
      case KeyEvent.KEY_RELEASED:
        if (keyEventInterceptor != null) keyEventInterceptor.keyReleased(evt);
        break;
    }
  } // }}}