public boolean isEnabled(@NotNull final Project project, final AnActionEvent event) {
      if (!myHandler.isEnabled(project)) return false;

      Editor editor = event.getData(PlatformDataKeys.EDITOR);
      if (editor == null) return false;

      InputEvent inputEvent = event.getInputEvent();
      if (inputEvent instanceof MouseEvent && inputEvent.isAltDown()) {
        MouseEvent mouseEvent = (MouseEvent) inputEvent;
        Component component =
            SwingUtilities.getDeepestComponentAt(
                mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
        if (SwingUtilities.isDescendingFrom(component, editor.getComponent())) {
          MouseEvent convertedEvent =
              SwingUtilities.convertMouseEvent(mouseEvent.getComponent(), mouseEvent, component);
          EditorMouseEventArea area = editor.getMouseEventArea(convertedEvent);
          if (area != EditorMouseEventArea.EDITING_AREA) {
            return false;
          }
        }
      } else {
        if (StringUtil.isEmptyOrSpaces(editor.getSelectionModel().getSelectedText())) {
          return false;
        }
      }

      return true;
    }
 public static void showPopup(AnActionEvent e, JBPopup popup) {
   final InputEvent event = e.getInputEvent();
   if (event instanceof MouseEvent) {
     popup.showUnderneathOf(event.getComponent());
   } else {
     popup.showInBestPositionFor(e.getDataContext());
   }
 }
Esempio n. 3
0
 private DefaultView2d getDefaultView2d(InputEvent e) {
   Object source = e.getSource();
   if (source instanceof DefaultView2d) {
     return (DefaultView2d) source;
   }
   return null;
 }
Esempio n. 4
0
 /** {@inheritDoc} */
 public int getModifiersEx() {
   int tmpModifiers = modifiers;
   if (shouldExcludeButtonFromExtModifiers) {
     tmpModifiers &= ~(InputEvent.getMaskForButton(getButton()));
   }
   return tmpModifiers & ~JDK_1_3_MODIFIERS;
 }
 @Override
 public void onUpdatePassed(
     final InputEvent inputEvent,
     @NotNull final AnAction action,
     @NotNull final AnActionEvent actionEvent) {
   setState(KeyState.STATE_PROCESSED);
   setPressedWasProcessed(inputEvent.getID() == KeyEvent.KEY_PRESSED);
 }
Esempio n. 6
0
  /**
   * Returns a <code>String</code> instance describing the modifier keys and mouse buttons that were
   * down during the event, such as "Shift", or "Ctrl+Shift". These strings can be localized by
   * changing the <code>awt.properties</code> file.
   *
   * <p>Note that the <code>InputEvent.ALT_MASK</code> and <code>InputEvent.BUTTON2_MASK</code> have
   * equal values, so the "Alt" string is returned for both modifiers. Likewise, the <code>
   * InputEvent.META_MASK</code> and <code>InputEvent.BUTTON3_MASK</code> have equal values, so the
   * "Meta" string is returned for both modifiers.
   *
   * <p>Note that passing negative parameter is incorrect, and will cause the returning an
   * unspecified string. Zero parameter means that no modifiers were passed and will cause the
   * returning an empty string.
   *
   * <p>
   *
   * @param modifiers A modifier mask describing the modifier keys and mouse buttons that were down
   *     during the event
   * @return string string text description of the combination of modifier keys and mouse buttons
   *     that were down during the event
   * @see InputEvent#getModifiersExText(int)
   * @since 1.4
   */
  public static String getMouseModifiersText(int modifiers) {
    StringBuilder buf = new StringBuilder();
    if ((modifiers & InputEvent.ALT_MASK) != 0) {
      buf.append(Toolkit.getProperty("AWT.alt", "Alt"));
      buf.append("+");
    }
    if ((modifiers & InputEvent.META_MASK) != 0) {
      buf.append(Toolkit.getProperty("AWT.meta", "Meta"));
      buf.append("+");
    }
    if ((modifiers & InputEvent.CTRL_MASK) != 0) {
      buf.append(Toolkit.getProperty("AWT.control", "Ctrl"));
      buf.append("+");
    }
    if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
      buf.append(Toolkit.getProperty("AWT.shift", "Shift"));
      buf.append("+");
    }
    if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
      buf.append(Toolkit.getProperty("AWT.altGraph", "Alt Graph"));
      buf.append("+");
    }
    if ((modifiers & InputEvent.BUTTON1_MASK) != 0) {
      buf.append(Toolkit.getProperty("AWT.button1", "Button1"));
      buf.append("+");
    }
    if ((modifiers & InputEvent.BUTTON2_MASK) != 0) {
      buf.append(Toolkit.getProperty("AWT.button2", "Button2"));
      buf.append("+");
    }
    if ((modifiers & InputEvent.BUTTON3_MASK) != 0) {
      buf.append(Toolkit.getProperty("AWT.button3", "Button3"));
      buf.append("+");
    }

    int mask;

    // TODO: add a toolkit field that holds a number of button on the mouse.
    // As the method getMouseModifiersText() is static and obtain
    // an integer as a parameter then we may not restrict this with the number
    // of buttons installed on the mouse.
    // It's a temporary solution. We need to somehow hold the number of buttons somewhere else.
    for (int i = 1; i <= cachedNumberOfButtons; i++) {
      mask = InputEvent.getMaskForButton(i);
      if ((modifiers & mask) != 0
          && buf.indexOf(Toolkit.getProperty("AWT.button" + i, "Button" + i))
              == -1) // 1,2,3 buttons may already be there; so don't duplicate it.
      {
        buf.append(Toolkit.getProperty("AWT.button" + i, "Button" + i));
        buf.append("+");
      }
    }

    if (buf.length() > 0) {
      buf.setLength(buf.length() - 1); // remove trailing '+'
    }
    return buf.toString();
  }
 private void setmods(InputEvent ev) {
   int mod = ev.getModifiersEx();
   modshift = (mod & InputEvent.SHIFT_DOWN_MASK) != 0;
   modctrl = (mod & InputEvent.CTRL_DOWN_MASK) != 0;
   modmeta = (mod & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_GRAPH_DOWN_MASK)) != 0;
   /*
   	modsuper = (mod & InputEvent.SUPER_DOWN_MASK) != 0;
   */
 }
 public void performAction(
     final InputEvent e, final AnAction action, final AnActionEvent actionEvent) {
   e.consume();
   action.actionPerformed(actionEvent);
   if (Registry.is("actionSystem.fixLostTyping")) {
     IdeEventQueue.getInstance()
         .doWhenReady(
             new Runnable() {
               @Override
               public void run() {
                 IdeEventQueue.getInstance().getKeyEventDispatcher().resetState();
               }
             });
   }
 }
  private int getMask(int button) {
    return InputEvent.getMaskForButton(button);

    /*
        //this only works for standard buttons and for old JDK builds
    int mask = 0;
    switch (button){
    case 1: {
        mask = InputEvent.BUTTON1_MASK;
        break;
    }
    case 2: {
        mask = InputEvent.BUTTON2_MASK;
        break;
    }
    case 3: {
        mask = InputEvent.BUTTON3_MASK;
        break;
    }
    }
    return mask;
    */
  }
  void execute(@NotNull AnActionEvent e, @NotNull ExecutionEnvironment environment) {
    MyRunProfile profile = getRunProfile(environment);
    if (profile == null) {
      return;
    }

    final ExecutionEnvironmentBuilder environmentBuilder =
        new ExecutionEnvironmentBuilder(environment).runProfile(profile);

    final InputEvent event = e.getInputEvent();
    if (!(event instanceof MouseEvent) || !event.isShiftDown()) {
      performAction(environmentBuilder);
      return;
    }

    final LinkedHashMap<Executor, ProgramRunner> availableRunners = new LinkedHashMap<>();
    for (Executor ex :
        new Executor[] {
          DefaultRunExecutor.getRunExecutorInstance(),
          DefaultDebugExecutor.getDebugExecutorInstance()
        }) {
      final ProgramRunner runner = RunnerRegistry.getInstance().getRunner(ex.getId(), profile);
      if (runner != null) {
        availableRunners.put(ex, runner);
      }
    }

    if (availableRunners.isEmpty()) {
      LOG.error(environment.getExecutor().getActionName() + " is not available now");
    } else if (availableRunners.size() == 1) {
      //noinspection ConstantConditions
      performAction(environmentBuilder.runner(availableRunners.get(environment.getExecutor())));
    } else {
      final JBList list = new JBList(availableRunners.keySet());
      list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
      list.setSelectedValue(environment.getExecutor(), true);
      list.setCellRenderer(
          new DefaultListCellRenderer() {
            @NotNull
            @Override
            public Component getListCellRendererComponent(
                @NotNull JList list,
                Object value,
                int index,
                boolean isSelected,
                boolean cellHasFocus) {
              final Component component =
                  super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
              if (value instanceof Executor) {
                setText(UIUtil.removeMnemonic(((Executor) value).getStartActionText()));
                setIcon(((Executor) value).getIcon());
              }
              return component;
            }
          });
      //noinspection ConstantConditions
      JBPopupFactory.getInstance()
          .createListPopupBuilder(list)
          .setTitle("Restart Failed Tests")
          .setMovable(false)
          .setResizable(false)
          .setRequestFocus(true)
          .setItemChoosenCallback(
              () -> {
                final Object value = list.getSelectedValue();
                if (value instanceof Executor) {
                  //noinspection ConstantConditions
                  performAction(
                      environmentBuilder
                          .runner(availableRunners.get(value))
                          .executor((Executor) value));
                }
              })
          .createPopup()
          .showUnderneathOf(event.getComponent());
    }
  }
Esempio n. 11
0
 /**
  * Returns true if the system's shortcut key was pressed.
  *
  * @param e input event
  * @return result of check
  */
 public static boolean sc(final InputEvent e) {
   return (SC & e.getModifiers()) == SC;
 }
  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;
  }
Esempio n. 13
0
 /**
  * Indicates if a given mouse button is being pressed.
  *
  * @param e the InputEvent to check
  * @param button the mouse button to look for
  * @return true if the button is being pressed, false otherwise
  * @see prefuse.controls.Control
  */
 public static boolean isButtonPressed(InputEvent e, int button) {
   return (e.getModifiers() & button) == button;
 }
Esempio n. 14
0
 private void lastEventTime(InputEvent event) {
   lastEventTime = event.getWhen();
 }
Esempio n. 15
0
 private boolean isOld(InputEvent event) {
   return event.getWhen() < lastEventTime();
 }