예제 #1
0
 private void lastEventTime(InputEvent event) {
   lastEventTime = event.getWhen();
 }
  private int getMask(final InputEvent e) {
    final int modifiers = e.getModifiers();
    final int modifiersEx = e.getModifiersEx();
    int mask = modifiersEx;

    /*
     * For scrolling AWT uses the SHIFT_DOWN_MASK to indicate horizontal scrolling.
     * We keep track of whether the SHIFT key was actually pressed for disambiguation.
     */
    if (shiftPressed) mask |= InputEvent.SHIFT_DOWN_MASK;
    else mask &= ~InputEvent.SHIFT_DOWN_MASK;

    /*
     * On OS X AWT sets the META_DOWN_MASK to for right clicks. We keep
     * track of whether the META key was actually pressed for
     * disambiguation.
     */
    if (metaPressed) mask |= InputEvent.META_DOWN_MASK;
    else mask &= ~InputEvent.META_DOWN_MASK;

    /*
     * We add the button modifiers to modifiersEx such that the
     * XXX_DOWN_MASK can be used as the canonical flag. E.g. we adapt
     * modifiersEx such that BUTTON1_DOWN_MASK is also present in
     * mouseClicked() when BUTTON1 was clicked (although the button is no
     * longer down at this point).
     *
     * ...but only if its not a MouseWheelEvent because OS X sets button
     * modifiers if ALT or META modifiers are pressed.
     */
    if (!(e instanceof MouseWheelEvent)) {
      if ((modifiers & InputEvent.BUTTON1_MASK) != 0) mask |= InputEvent.BUTTON1_DOWN_MASK;
      if ((modifiers & InputEvent.BUTTON2_MASK) != 0) mask |= InputEvent.BUTTON2_DOWN_MASK;
      if ((modifiers & InputEvent.BUTTON3_MASK) != 0) mask |= InputEvent.BUTTON3_DOWN_MASK;
    }

    /*
     * On OS X AWT sets the BUTTON3_DOWN_MASK for meta+left clicks. Fix
     * that.
     */
    if (modifiers == OSX_META_LEFT_CLICK) mask &= ~InputEvent.BUTTON3_DOWN_MASK;

    /*
     * On OS X AWT sets the BUTTON2_DOWN_MASK for alt+left clicks. Fix
     * that.
     */
    if (modifiers == OSX_ALT_LEFT_CLICK) mask &= ~InputEvent.BUTTON2_DOWN_MASK;

    /*
     * On OS X AWT sets the BUTTON2_DOWN_MASK for alt+right clicks. Fix
     * that.
     */
    if (modifiers == OSX_ALT_RIGHT_CLICK) mask &= ~InputEvent.BUTTON2_DOWN_MASK;

    /*
     * Deal with double-clicks.
     */

    if (e instanceof MouseEvent && ((MouseEvent) e).getClickCount() > 1)
      mask |= InputTrigger.DOUBLE_CLICK_MASK; // mouse
    else if (e instanceof KeyEvent) {
      // double-click on keys.
      if ((e.getWhen() - timeKeyDown) < DOUBLE_CLICK_INTERVAL)
        mask |= InputTrigger.DOUBLE_CLICK_MASK;
      else timeKeyDown = e.getWhen();
    }

    if (e instanceof MouseWheelEvent) mask |= InputTrigger.SCROLL_MASK;

    return mask;
  }
예제 #3
0
 private boolean isOld(InputEvent event) {
   return event.getWhen() < lastEventTime();
 }