/**
   * Return a String representation of the keyboard event for debugging purpose.
   *
   * @param evt the keyboard event
   * @return a String representation for this keyboard event
   * @since jEdit 4.3pre15
   */
  public static String toString(KeyEvent evt) {
    String id;
    switch (evt.getID()) {
      case KeyEvent.KEY_PRESSED:
        id = "KEY_PRESSED";
        break;
      case KeyEvent.KEY_RELEASED:
        id = "KEY_RELEASED";
        break;
      case KeyEvent.KEY_TYPED:
        id = "KEY_TYPED";
        break;
      default:
        id = "unknown type";
        break;
    }

    StringBuilder b = new StringBuilder(50);

    b.append(id);
    b.append(",keyCode=0x").append(Integer.toString(evt.getKeyCode(), 16));
    b.append(",keyChar=0x").append(Integer.toString(evt.getKeyChar(), 16));
    b.append(",modifiers=0x").append(Integer.toString(evt.getModifiers(), 16));

    b.append(",consumed=");
    b.append(evt.isConsumed() ? '1' : '0');

    return b.toString();
  } // }}}
示例#2
0
 /**
  * Processes key stroke events such as mnemonics and accelerators.
  *
  * @param evt the key event to be processed
  */
 protected void processKeyEvent(KeyEvent evt) {
   MenuSelectionManager.defaultManager().processKeyEvent(evt);
   if (evt.isConsumed()) {
     return;
   }
   super.processKeyEvent(evt);
 }
示例#3
0
    @Override
    public void keyPressed(KeyEvent e, Point2D imagePoint, IcyCanvas canvas) {
      if (!isActiveFor(canvas)) return;

      if (!e.isConsumed()) {
        switch (e.getKeyCode()) {
          case KeyEvent.VK_ESCAPE:
            // shape selected ? --> unselect the ROI
            if (ROI2D.this.selected) {
              ROI2D.this.setSelected(false, false);
              e.consume();
            }
            break;

          case KeyEvent.VK_DELETE:
          case KeyEvent.VK_BACK_SPACE:
            // roi selected ?
            if (ROI2D.this.selected) {
              // remove selected control point if there is one
              if (removeSelectedPoint(canvas, imagePoint)) e.consume();
              else {
                // else simply delete ROI
                ROI2D.this.delete();
                e.consume();
              }
            }
            // roi focused ? --> delete ROI
            else if (ROI2D.this.focused) {
              ROI2D.this.delete();
              e.consume();
            }
            break;
        }
      }
    }
示例#4
0
    @Override
    public void keyPressed(KeyEvent evt) {
      if (evt.isConsumed()) return;
      Component comp = getFocusOwner();
      if (evt.getKeyCode() == KeyEvent.VK_ENTER && enterEnabled) {
        while (comp != null) {
          if (comp instanceof JComboBox) {
            JComboBox<?> combo = (JComboBox<?>) comp;
            if (combo.isEditable()) {
              Object selected = combo.getEditor().getItem();
              if (selected != null) combo.setSelectedItem(selected);
            }

            if (combo.isPopupVisible()) {
              evt.consume();
              combo.setPopupVisible(false);
            }
            return;
          }
          // TODO: add other classes that need custom key handling here.
          comp = comp.getParent();
        }
        evt.consume();
        ok();
      } else if (evt.getKeyCode() == KeyEvent.VK_ESCAPE || isCloseBufferShortcut(evt)) {
        evt.consume();
        if (comp instanceof JComboBox) {
          JComboBox<?> combo = (JComboBox<?>) comp;
          if (combo.isPopupVisible()) combo.setPopupVisible(false);
          else cancel();
        } else cancel();
      }
    }
  @Override
  public void eventDispatched(AWTEvent event) {
    assert event instanceof KeyEvent
        : "Shall only listen to KeyEvents, so no other events shall come here";
    assert assertEDT(); // REMEMBER THAT THIS IS SINGLE THREADED, so no need for synch.

    // ?: Is this one of our synthetic RELEASED events?
    if (event instanceof Reposted) {
      // -> Yes, so we shalln't process it again.
      return;
    }

    // ?: KEY_TYPED event? (We're only interested in KEY_PRESSED and KEY_RELEASED).
    if (event.getID() == KeyEvent.KEY_TYPED) {
      // -> Yes, TYPED, don't process.
      return;
    }

    final KeyEvent keyEvent = (KeyEvent) event;

    // ?: Is this already consumed?
    // (Note how events are passed on to all AWTEventListeners even though a previous one consumed
    // it)
    if (keyEvent.isConsumed()) {
      return;
    }

    // ?: Is this RELEASED? (the problem we're trying to fix!)
    if (keyEvent.getID() == KeyEvent.KEY_RELEASED) {
      // -> Yes, so stick in wait
      /**
       * Really just wait until "immediately", as the point is that the subsequent PRESSED shall
       * already have been posted on the event queue, and shall thus be the direct next event no
       * matter which events are posted afterwards. The code with the ReleasedAction handles if the
       * Timer thread actually fires the action due to lags, by cancelling the action itself upon
       * the PRESSED.
       */
      final Timer timer = new Timer(2, null);
      ReleasedAction action = new ReleasedAction(keyEvent, timer);
      timer.addActionListener(action);
      timer.start();

      _map.put(Integer.valueOf(keyEvent.getKeyCode()), action);

      // Consume the original
      keyEvent.consume();
    } else if (keyEvent.getID() == KeyEvent.KEY_PRESSED) {
      // Remember that this is single threaded (EDT), so we can't have races.
      ReleasedAction action = _map.remove(Integer.valueOf(keyEvent.getKeyCode()));
      // ?: Do we have a corresponding RELEASED waiting?
      if (action != null) {
        // -> Yes, so dump it
        action.cancel();
      }
      // System.out.println("PRESSED: [" + keyEvent + "]");
    } else {
      throw new AssertionError("All IDs should be covered.");
    }
  }
  public static boolean processKeyBindings(final KeyEvent event) {
    if (event == null || event.isConsumed()) {
      return false;
    }

    Component source = event.getComponent();
    return JComponent.processKeyBindings(event, source);
  }
  /**
   * When a MenuElement receives an event from a KeyListener, it should never process the event
   * directly. Instead all MenuElements should call this method with the event.
   *
   * @param e a KeyEvent object
   */
  public void processKeyEvent(KeyEvent e) {
    MenuElement[] sel2 = new MenuElement[0];
    sel2 = selection.toArray(sel2);
    int selSize = sel2.length;
    MenuElement[] path;

    if (selSize < 1) {
      return;
    }

    for (int i = selSize - 1; i >= 0; i--) {
      MenuElement elem = sel2[i];
      MenuElement[] subs = elem.getSubElements();
      path = null;

      for (int j = 0; j < subs.length; j++) {
        if (subs[j] == null
            || !subs[j].getComponent().isShowing()
            || !subs[j].getComponent().isEnabled()) {
          continue;
        }

        if (path == null) {
          path = new MenuElement[i + 2];
          System.arraycopy(sel2, 0, path, 0, i + 1);
        }
        path[i + 1] = subs[j];
        subs[j].processKeyEvent(e, path, this);
        if (e.isConsumed()) {
          return;
        }
      }
    }

    // finally dispatch event to the first component in path
    path = new MenuElement[1];
    path[0] = sel2[0];
    path[0].processKeyEvent(e, path, this);
    if (e.isConsumed()) {
      return;
    }
  }
示例#8
0
    public void keyPressed(KeyEvent e) {
      if (e.isConsumed()) {
        return;
      }

      if (!_list.isCheckBoxEnabled()) {
        return;
      }

      if (e.getModifiers() == 0 && e.getKeyChar() == KeyEvent.VK_SPACE) toggleSelections();
    }
  public void keyReleased(final KeyEvent e) {
    if (e.isConsumed()) {
      return;
    }

    if (e.getKeyCode() != KeyEvent.VK_ENTER) {
      return;
    }

    RequestThread.runInParallel(action);
    e.consume();
  }
 @Override
 public void keyPressed(KeyEvent e) {
   if (!e.isConsumed()) {
     if (e.getKeyCode() == 38) { // UP
       parentForm.focusPreviousColumnPanel(DatasetRecordEditorColumnForm.this);
       e.consume();
     } else if (e.getKeyCode() == 40) { // DOWN
       parentForm.focusNextColumnPanel(DatasetRecordEditorColumnForm.this);
       e.consume();
     }
   }
 }
  @Override
  public void keyPressed(KeyEvent evt) {
    multicaster.keyPressed(evt);
    if (!evt.isConsumed()) {
      super.keyPressed(evt);

      // Forward key presses to the handler
      if (dragLocation != null) {
        multicaster.trackStep(anchor, dragLocation, evt.getModifiersEx(), getView());
      }
    }
  }
  public void process(KeyEvent e) {
    if (e.isConsumed() || !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();
      }
    }
  }
示例#13
0
  @Override
  public void keyPressed(KeyEvent e) {
    if (e.isConsumed()) return;
    if (ren.VisibleActorCount() == 0) return;

    vtkActorCollection ac;
    vtkActor anActor;
    int i;

    switch (e.getKeyChar()) {
      case 'r': // reset camera
        resetCamera();
        repaint();
        // consume event
        e.consume();
        break;

      case 'w': // wireframe mode
        lock();
        try {
          ac = ren.GetActors();
          ac.InitTraversal();
          for (i = 0; i < ac.GetNumberOfItems(); i++) {
            anActor = ac.GetNextActor();
            anActor.GetProperty().SetRepresentationToWireframe();
          }
        } finally {
          unlock();
        }
        repaint();
        // consume event
        e.consume();
        break;

      case 's':
        lock();
        try {
          ac = ren.GetActors();
          ac.InitTraversal();
          for (i = 0; i < ac.GetNumberOfItems(); i++) {
            anActor = ac.GetNextActor();
            anActor.GetProperty().SetRepresentationToSurface();
          }
        } finally {
          unlock();
        }
        repaint();
        // consume event
        e.consume();
        break;
    }
  }
示例#14
0
 public void keyEvent(KeyEvent e) {
   if (!isOpen()) return;
   if (e.getID() == KeyEvent.KEY_TYPED) {
     ArrayList temp = (ArrayList) items.clone();
     Collections.sort(temp, visComp);
     for (int i = 0; i < temp.size(); i++) {
       if (!e.isConsumed()) {
         RadialMenuItem item = (RadialMenuItem) temp.get(i);
         item.keyHintEvent(e);
       }
     }
   }
   e.consume();
 }
示例#15
0
    public void keyPressed(KeyEvent e) {
      TreePath selectionPath = mainTree.getSelectionPath();
      if (selectionPath == null || mainTree.getSelectionCount() == 0) {
        return;
      }

      if (mainTree.getSelectionCount() == 1) {
        SoapUITreeNode lastPathComponent = (SoapUITreeNode) selectionPath.getLastPathComponent();
        ActionList actions = lastPathComponent.getActions();
        if (actions != null) {
          actions.dispatchKeyEvent(e);
        }

        if (!e.isConsumed()) {
          KeyStroke ks = KeyStroke.getKeyStrokeForEvent(e);
          if (ks.equals(UISupport.getKeyStroke("alt C"))) {
            mainTree.collapsePath(selectionPath);
            e.consume();
          } else if (ks.equals(UISupport.getKeyStroke("alt E"))) {
            mainTree.collapsePath(selectionPath);
            int row = mainTree.getSelectionRows()[0];
            TreePath nextPath = mainTree.getPathForRow(row + 1);

            TreePath path = mainTree.getPathForRow(row);
            while (path != null && !path.equals(nextPath)) {
              mainTree.expandRow(row);
              path = mainTree.getPathForRow(++row);
            }

            e.consume();
          }
        }
      } else {
        TreePath[] selectionPaths = mainTree.getSelectionPaths();
        List<ModelItem> targets = new ArrayList<ModelItem>();
        for (TreePath treePath : selectionPaths) {
          SoapUITreeNode node = (SoapUITreeNode) treePath.getLastPathComponent();
          targets.add(node.getModelItem());
        }

        if (targets.size() > 0) {
          ActionList actions =
              ActionListBuilder.buildMultiActions(targets.toArray(new ModelItem[targets.size()]));
          if (actions.getActionCount() > 0) {
            actions.dispatchKeyEvent(e);
          }
        }
      }
    }
示例#16
0
  public final boolean dispatch(KeyEvent event) {
    if (event.getID() != KeyEvent.KEY_PRESSED && event.getID() != KeyEvent.KEY_RELEASED) {
      return false;
    }

    if (event.getID() == KeyEvent.KEY_PRESSED) {
      final KeyStroke stroke =
          KeyStroke.getKeyStroke(event.getKeyCode(), event.getModifiers(), false);
      if (proceedKeyEvent(event, stroke)) return false;
    }

    if (event.getID() == KeyEvent.KEY_RELEASED) {
      final KeyStroke stroke =
          KeyStroke.getKeyStroke(event.getKeyCode(), event.getModifiers(), true);
      return proceedKeyEvent(event, stroke);
    }

    myMnemonicsSearch.process(event);
    mySpeedSearch.process(event);

    if (event.isConsumed()) return true;
    process(event);
    return event.isConsumed();
  }
 public void processKeyEvent(KeyEvent e) {
   mySearchField.processKeyEvent(e);
   if (e.isConsumed()) {
     int keyCode = e.getKeyCode();
     String s = mySearchField.getText();
     Object element;
     if (isUpDownHomeEnd(keyCode)) {
       element = findTargetElement(keyCode, s);
       if (myClearSearchOnNavigateNoMatch && element == null) {
         manageSearchPopup(null);
         element = findTargetElement(keyCode, "");
       }
     } else {
       element = findElement(s);
     }
     updateSelection(element);
   }
 }
示例#18
0
  public void processKeyEvent(KeyEvent evt) {

    // this had to be added because the menu key events weren't making it up to the frame.

    switch (evt.getID()) {
      case KeyEvent.KEY_TYPED:
        if (editorListener != null) editorListener.keyTyped(evt);
        break;
      case KeyEvent.KEY_PRESSED:
        if (editorListener != null) editorListener.keyPressed(evt);
        break;
      case KeyEvent.KEY_RELEASED:
        // inputHandler.keyReleased(evt);
        break;
    }

    if (!evt.isConsumed()) {
      super.processKeyEvent(evt);
    }
  }
示例#19
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);
  } // }}}
示例#20
0
文件: FigComment.java 项目: kopl/misc
  /*
   * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
   */
  @Override
  public void keyTyped(KeyEvent ke) {
    if (Character.isISOControl(ke.getKeyChar())) {
      return;
    }
    if (!readyToEdit) {
      Object owner = getOwner();
      if (Model.getFacade().isAModelElement(owner)
          && !Model.getModelManagementHelper().isReadOnly(owner)) {
        storeBody("");
        readyToEdit = true;
      } else {

        return;
      }
    }
    if (ke.isConsumed()) {
      return;
    }
    if (getOwner() == null) {
      return;
    }
    bodyTextFig.keyTyped(ke);
  }
示例#21
0
  /**
   * Need this method to detect when the focus may have chance to leave the focus cycle root which
   * is EmbeddedFrame. Mostly, the code here is copied from
   * DefaultKeyboardFocusManager.processKeyEvent with some minor modifications.
   */
  public boolean dispatchKeyEvent(KeyEvent e) {

    // We can't guarantee that this is called on the same AppContext as EmbeddedFrame
    // belongs to. That's why we can't use public methods to find current focus cycle
    // root. Instead, we access KFM's private field directly.
    if (currentCycleRoot == null) {
      currentCycleRoot =
          (Field)
              AccessController.doPrivileged(
                  new PrivilegedAction() {
                    public Object run() {
                      try {
                        Field unaccessibleRoot =
                            KeyboardFocusManager.class.getDeclaredField("currentFocusCycleRoot");
                        if (unaccessibleRoot != null) {
                          unaccessibleRoot.setAccessible(true);
                        }
                        return unaccessibleRoot;
                      } catch (NoSuchFieldException e1) {
                        assert false;
                      } catch (SecurityException e2) {
                        assert false;
                      }
                      return null;
                    }
                  });
    }

    Container currentRoot = null;
    if (currentCycleRoot != null) {
      try {
        // The field is static, so we can pass null to Field.get() as the argument.
        currentRoot = (Container) currentCycleRoot.get(null);
      } catch (IllegalAccessException e3) {
        // This is impossible: currentCycleRoot would be null if setAccessible failed.
        assert false;
      }
    }

    // if we are not in EmbeddedFrame's cycle, we should not try to leave.
    if (this != currentRoot) {
      return false;
    }

    // KEY_TYPED events cannot be focus traversal keys
    if (e.getID() == KeyEvent.KEY_TYPED) {
      return false;
    }

    if (!getFocusTraversalKeysEnabled() || e.isConsumed()) {
      return false;
    }

    AWTKeyStroke stroke = AWTKeyStroke.getAWTKeyStrokeForEvent(e);
    Set toTest;
    Component currentFocused = e.getComponent();

    Component last = getFocusTraversalPolicy().getLastComponent(this);
    toTest = getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
    if (toTest.contains(stroke) && (currentFocused == last || last == null)) {
      if (traverseOut(FORWARD)) {
        e.consume();
        return true;
      }
    }

    Component first = getFocusTraversalPolicy().getFirstComponent(this);
    toTest = getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
    if (toTest.contains(stroke) && (currentFocused == first || first == null)) {
      if (traverseOut(BACKWARD)) {
        e.consume();
        return true;
      }
    }
    return false;
  }
示例#22
0
  /**
   * This method is called when the focused component (and none of its ancestors) want the key
   * event. This will look up the keystroke to see if any chidren (or subchildren) of the specified
   * container want a crack at the event. If one of them wants it, then it will "DO-THE-RIGHT-THING"
   */
  public boolean fireKeyboardAction(KeyEvent e, boolean pressed, Container topAncestor) {

    if (e.isConsumed()) {
      System.out.println("Acquired pre-used event!");
      Thread.dumpStack();
    }

    // There may be two keystrokes associated with a low-level key event;
    // in this case a keystroke made of an extended key code has a priority.
    KeyStroke ks;
    KeyStroke ksE = null;

    if (e.getID() == KeyEvent.KEY_TYPED) {
      ks = KeyStroke.getKeyStroke(e.getKeyChar());
    } else {
      if (e.getKeyCode() != e.getExtendedKeyCode()) {
        ksE = KeyStroke.getKeyStroke(e.getExtendedKeyCode(), e.getModifiers(), !pressed);
      }
      ks = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers(), !pressed);
    }

    Hashtable keyMap = containerMap.get(topAncestor);
    if (keyMap != null) { // this container isn't registered, so bail

      Object tmp = null;
      // extended code has priority
      if (ksE != null) {
        tmp = keyMap.get(ksE);
        if (tmp != null) {
          ks = ksE;
        }
      }
      if (tmp == null) {
        tmp = keyMap.get(ks);
      }

      if (tmp == null) {
        // don't do anything
      } else if (tmp instanceof JComponent) {
        JComponent c = (JComponent) tmp;
        if (c.isShowing() && c.isEnabled()) { // only give it out if enabled and visible
          fireBinding(c, ks, e, pressed);
        }
      } else if (tmp instanceof Vector) { // more than one comp registered for this
        Vector v = (Vector) tmp;
        // There is no well defined order for WHEN_IN_FOCUSED_WINDOW
        // bindings, but we give precedence to those bindings just
        // added. This is done so that JMenus WHEN_IN_FOCUSED_WINDOW
        // bindings are accessed before those of the JRootPane (they
        // both have a WHEN_IN_FOCUSED_WINDOW binding for enter).
        for (int counter = v.size() - 1; counter >= 0; counter--) {
          JComponent c = (JComponent) v.elementAt(counter);
          // System.out.println("Trying collision: " + c + " vector = "+ v.size());
          if (c.isShowing() && c.isEnabled()) { // don't want to give these out
            fireBinding(c, ks, e, pressed);
            if (e.isConsumed()) return true;
          }
        }
      } else {
        System.out.println("Unexpected condition in fireKeyboardAction " + tmp);
        // This means that tmp wasn't null, a JComponent, or a Vector.  What is it?
        Thread.dumpStack();
      }
    }

    if (e.isConsumed()) {
      return true;
    }
    // if no one else handled it, then give the menus a crack
    // The're handled differently.  The key is to let any JMenuBars
    // process the event
    if (keyMap != null) {
      Vector v = (Vector) keyMap.get(JMenuBar.class);
      if (v != null) {
        Enumeration iter = v.elements();
        while (iter.hasMoreElements()) {
          JMenuBar mb = (JMenuBar) iter.nextElement();
          if (mb.isShowing() && mb.isEnabled()) { // don't want to give these out
            boolean extended = (ksE != null) && !ksE.equals(ks);
            if (extended) {
              fireBinding(mb, ksE, e, pressed);
            }
            if (!extended || !e.isConsumed()) {
              fireBinding(mb, ks, e, pressed);
            }
            if (e.isConsumed()) {
              return true;
            }
          }
        }
      }
    }

    return e.isConsumed();
  }
 /** @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent) */
 public void keyTyped(KeyEvent ke) {
   if (ke.isConsumed()) return;
   if (nameFig != null && canEdit(nameFig)) nameFig.keyTyped(ke);
 }
  /**
   * @return <code>true</code> if and only if the passed event is already dispatched by the <code>
   *     IdeKeyEventDispatcher</code> and there is no need for any other processing of the event.
   */
  public boolean dispatchKeyEvent(final KeyEvent e) {
    if (myDisposed) return false;

    if (e.isConsumed()) {
      return false;
    }

    // http://www.jetbrains.net/jira/browse/IDEADEV-12372
    if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
      if (e.getID() == KeyEvent.KEY_PRESSED) {
        myLeftCtrlPressed = e.getKeyLocation() == KeyEvent.KEY_LOCATION_LEFT;
      } else if (e.getID() == KeyEvent.KEY_RELEASED) {
        myLeftCtrlPressed = false;
      }
    } else if (e.getKeyCode() == KeyEvent.VK_ALT) {
      if (e.getID() == KeyEvent.KEY_PRESSED) {
        myRightAltPressed = e.getKeyLocation() == KeyEvent.KEY_LOCATION_RIGHT;
      } else if (e.getID() == KeyEvent.KEY_RELEASED) {
        myRightAltPressed = false;
      }
    }

    KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    Component focusOwner = focusManager.getFocusOwner();

    // shortcuts should not work in shortcut setup fields
    if (focusOwner instanceof ShortcutTextField) {
      return false;
    }
    if (focusOwner instanceof JTextComponent && ((JTextComponent) focusOwner).isEditable()) {
      if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED && e.getKeyChar() != KeyEvent.VK_ESCAPE) {
        MacUIUtil.hideCursor();
      }
    }

    MenuSelectionManager menuSelectionManager = MenuSelectionManager.defaultManager();
    MenuElement[] selectedPath = menuSelectionManager.getSelectedPath();
    if (selectedPath.length > 0) {
      if (!(selectedPath[0] instanceof ComboPopup)) {
        // The following couple of lines of code is a PATCH!!!
        // It is needed to ignore ENTER KEY_TYPED events which sometimes can reach editor when an
        // action
        // is invoked from main menu via Enter key.
        setState(KeyState.STATE_PROCESSED);
        setPressedWasProcessed(true);
        return false;
      }
    }

    // Keymap shortcuts (i.e. not local shortcuts) should work only in:
    // - main frame
    // - floating focusedWindow
    // - when there's an editor in contexts
    Window focusedWindow = focusManager.getFocusedWindow();
    boolean isModalContext = focusedWindow != null && isModalContext(focusedWindow);

    final DataManager dataManager = DataManager.getInstance();
    if (dataManager == null) return false;

    DataContext dataContext = dataManager.getDataContext();

    myContext.setDataContext(dataContext);
    myContext.setFocusOwner(focusOwner);
    myContext.setModalContext(isModalContext);
    myContext.setInputEvent(e);

    try {
      if (getState() == KeyState.STATE_INIT) {
        return inInitState();
      } else if (getState() == KeyState.STATE_PROCESSED) {
        return inProcessedState();
      } else if (getState() == KeyState.STATE_WAIT_FOR_SECOND_KEYSTROKE) {
        return inWaitForSecondStrokeState();
      } else if (getState() == KeyState.STATE_SECOND_STROKE_IN_PROGRESS) {
        return inSecondStrokeInProgressState();
      } else if (getState() == KeyState.STATE_KEY_GESTURE_PROCESSOR) {
        return myKeyGestureProcessor.process();
      } else {
        throw new IllegalStateException("state = " + getState());
      }
    } finally {
      myContext.clear();
    }
  }
示例#25
0
 @Override
 public void keyReleased(KeyEvent e) {
   if (e.isConsumed()) return;
 }
示例#26
0
 @Override
 protected void processKeyEvent(KeyEvent evt) {
   if (evt.getID() == KeyEvent.KEY_PRESSED) {
     ActionContext ac = VFSBrowser.getActionContext();
     int row = parentDirectories.getSelectedIndex();
     switch (evt.getKeyCode()) {
       case KeyEvent.VK_DOWN:
         evt.consume();
         if (row < parentDirectories.getSize().height - 1)
           parentDirectories.setSelectedIndex(++row);
         break;
       case KeyEvent.VK_LEFT:
         if ((evt.getModifiers() & InputEvent.ALT_MASK) > 0) {
           evt.consume();
           browser.previousDirectory();
         } else super.processEvent(evt);
         break;
       case KeyEvent.VK_RIGHT:
         if ((evt.getModifiers() & InputEvent.ALT_MASK) > 0) {
           evt.consume();
           browser.nextDirectory();
         } else super.processEvent(evt);
         break;
       case KeyEvent.VK_TAB:
         evt.consume();
         if ((evt.getModifiers() & InputEvent.SHIFT_MASK) > 0) browser.focusOnDefaultComponent();
         else table.requestFocus();
         break;
       case KeyEvent.VK_UP:
         evt.consume();
         if (row > 0) {
           parentDirectories.setSelectedIndex(--row);
         }
         break;
       case KeyEvent.VK_BACK_SPACE:
         evt.consume();
         EditAction up = ac.getAction("vfs.browser.up");
         ac.invokeAction(evt, up);
         break;
       case KeyEvent.VK_F5:
         evt.consume();
         EditAction reload = ac.getAction("vfs.browser.reload");
         ac.invokeAction(evt, reload);
         break;
       case KeyEvent.VK_ENTER:
         evt.consume();
         if (row != -1) {
           // basically the same handling as in ParentMouseHandler#mouseReleased
           Object obj = parentDirectories.getModel().getElementAt(row);
           if (obj instanceof VFSFile) {
             VFSFile dirEntry = (VFSFile) obj;
             browser.setDirectory(dirEntry.getPath());
             if (browser.getMode() == VFSBrowser.BROWSER) focusOnFileView();
           }
         }
         break;
         /* These actions don't work because they look at the EntryTable for the current selected
         * 	item. We need actions that look at the parentDirectoryList item instead.
         *
         			case KeyEvent.VK_DELETE:
         				evt.consume();
         				ea = ac.getAction("vfs.browser.delete");
         				ac.invokeAction(evt, ea);
         				break;
         			case KeyEvent.CTRL_MASK | KeyEvent.VK_N:
         				evt.consume();
         				ea = ac.getAction("vfs.browser.new-file");
         				ac.invokeAction(evt, ea);
         				break;
         			case KeyEvent.VK_INSERT:
         				evt.consume();
         				ea = ac.getAction("vfs.browser.new-directory");
         				ac.invokeAction(evt, ea);
         				break; */
     }
   } else if (evt.getID() == KeyEvent.KEY_TYPED) {
     if (evt.isControlDown() || evt.isAltDown() || evt.isMetaDown()) {
       evt.consume();
       return;
     }
     switch (evt.getKeyChar()) {
       case '~':
         evt.consume();
         if (browser.getMode() == VFSBrowser.BROWSER)
           browser.setDirectory(System.getProperty("user.home"));
         break;
       case '/':
         evt.consume();
         if (browser.getMode() == VFSBrowser.BROWSER) browser.rootDirectory();
         break;
       case '-':
         evt.consume();
         if (browser.getMode() == VFSBrowser.BROWSER) {
           browser.setDirectory(browser.getView().getBuffer().getDirectory());
         }
         break;
     }
   }
   if (!evt.isConsumed()) super.processKeyEvent(evt);
 }