コード例 #1
0
 /**
  * @param component component
  * @return whether the component in Swing tree or not. This method is more weak then {@link
  *     Component#isShowing() }
  */
 private boolean isInTree(final Component component) {
   if (component instanceof Window) {
     return component.isShowing();
   } else {
     Window windowAncestor = SwingUtilities.getWindowAncestor(component);
     return windowAncestor != null && windowAncestor.isShowing();
   }
 }
コード例 #2
0
  public boolean processAction(final InputEvent e, ActionProcessor processor) {
    ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
    final Project project = PlatformDataKeys.PROJECT.getData(myContext.getDataContext());
    final boolean dumb = project != null && DumbService.getInstance(project).isDumb();
    List<AnActionEvent> nonDumbAwareAction = new ArrayList<AnActionEvent>();
    for (final AnAction action : myContext.getActions()) {
      final Presentation presentation = myPresentationFactory.getPresentation(action);

      // Mouse modifiers are 0 because they have no any sense when action is invoked via keyboard
      final AnActionEvent actionEvent =
          processor.createEvent(
              e,
              myContext.getDataContext(),
              ActionPlaces.MAIN_MENU,
              presentation,
              ActionManager.getInstance());

      ActionUtil.performDumbAwareUpdate(action, actionEvent, true);

      if (dumb && !action.isDumbAware()) {
        if (Boolean.FALSE.equals(
            presentation.getClientProperty(ActionUtil.WOULD_BE_ENABLED_IF_NOT_DUMB_MODE))) {
          continue;
        }

        nonDumbAwareAction.add(actionEvent);
        continue;
      }

      if (!presentation.isEnabled()) {
        continue;
      }

      processor.onUpdatePassed(e, action, actionEvent);

      ((DataManagerImpl.MyDataContext) myContext.getDataContext())
          .setEventCount(IdeEventQueue.getInstance().getEventCount(), this);
      actionManager.fireBeforeActionPerformed(action, actionEvent.getDataContext(), actionEvent);
      Component component =
          PlatformDataKeys.CONTEXT_COMPONENT.getData(actionEvent.getDataContext());
      if (component != null && !component.isShowing()) {
        return true;
      }

      processor.performAction(e, action, actionEvent);
      actionManager.fireAfterActionPerformed(action, actionEvent.getDataContext(), actionEvent);
      return true;
    }

    if (!nonDumbAwareAction.isEmpty()) {
      showDumbModeWarningLaterIfNobodyConsumesEvent(
          e, nonDumbAwareAction.toArray(new AnActionEvent[nonDumbAwareAction.size()]));
    }

    return false;
  }
コード例 #3
0
ファイル: WizardPopup.java プロジェクト: ngoanhtan/consulo
    @Override
    public Dimension getPreferredSize() {
      final Component focusOwner =
          KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
      Point p = null;
      if (focusOwner != null && focusOwner.isShowing()) {
        p = focusOwner.getLocationOnScreen();
      }

      return computeNotBiggerDimension(super.getPreferredSize().getSize(), p);
    }
コード例 #4
0
  public static Point getRelLocation(Component c) {
    if (c == null || !c.isShowing()) {
      return new Point(0, 0);
    }

    Container parent = getRootContainer(c);
    if ((parent != null) && parent.isShowing()) {
      Point p1 = c.getLocationOnScreen();
      Point p2 = parent.getLocationOnScreen();
      return new Point(p1.x - p2.x, p1.y - p2.y);
    }

    return new Point(0, 0);
  }
コード例 #5
0
  public static Component findComponentUnderGlassPaneAt(Point point, Component top) {
    Component component = null;

    if (top.isShowing()) {
      if (top instanceof RootPaneContainer)
        component =
            ((RootPaneContainer) top)
                .getLayeredPane()
                .findComponentAt(
                    SwingUtilities.convertPoint(
                        top, point, ((RootPaneContainer) top).getLayeredPane()));
      else component = ((Container) top).findComponentAt(point);
    }

    return component;
  }
コード例 #6
0
 @Override
 public void invokePopup(final EditorMouseEvent event) {
   if (!event.isConsumed() && event.getArea() == EditorMouseEventArea.EDITING_AREA) {
     ActionGroup group =
         (ActionGroup)
             CustomActionsSchema.getInstance().getCorrectedAction(IdeActions.GROUP_EDITOR_POPUP);
     ActionPopupMenu popupMenu =
         ActionManager.getInstance().createActionPopupMenu(ActionPlaces.EDITOR_POPUP, group);
     MouseEvent e = event.getMouseEvent();
     final Component c = e.getComponent();
     if (c != null && c.isShowing()) {
       popupMenu.getComponent().show(c, e.getX(), e.getY());
     }
     e.consume();
   }
 }
コード例 #7
0
    public DialogPopupWrapper(Component owner, Component content, int x, int y) {
      if (!owner.isShowing()) {
        throw new IllegalArgumentException("Popup owner must be showing");
      }

      final Window wnd =
          owner instanceof Window ? (Window) owner : SwingUtilities.getWindowAncestor(owner);
      if (wnd instanceof Frame) {
        myDialog = new JDialog((Frame) wnd, false);
      } else {
        myDialog = new JDialog((Dialog) wnd, false);
      }

      myDialog.getContentPane().setLayout(new BorderLayout());
      myDialog.getContentPane().add(content, BorderLayout.CENTER);

      myDialog.setUndecorated(true);
      myDialog.pack();
      myDialog.setLocation(x, y);
    }
コード例 #8
0
  /**
   * @param parent parent component which is used to calculate heavy weight window ancestor. <code>
   *     parent</code> cannot be <code>null</code> and must be showing.
   */
  protected DialogWrapperPeerImpl(
      @NotNull DialogWrapper wrapper, @NotNull Component parent, boolean canBeParent) {
    myWrapper = wrapper;
    if (!parent.isShowing() && parent != JOptionPane.getRootFrame()) {
      throw new IllegalArgumentException("parent must be showing: " + parent);
    }
    myWindowManager = null;
    Application application = ApplicationManager.getApplication();
    if (application != null && application.hasComponent(WindowManager.class)) {
      myWindowManager = (WindowManagerEx) WindowManager.getInstance();
    }

    Window owner =
        parent instanceof Window
            ? (Window) parent
            : (Window) SwingUtilities.getAncestorOfClass(Window.class, parent);
    if (!(owner instanceof Dialog) && !(owner instanceof Frame)) {
      owner = JOptionPane.getRootFrame();
    }
    createDialog(owner, canBeParent);
  }
コード例 #9
0
  /**
   * @return <code>true</code> if and only if the passed event is already dispatched by the <code>
   *     IdeMouseEventDispatcher</code> and there is no need for any other processing of the event.
   *     If the method returns <code>false</code> then it means that the event should be delivered
   *     to normal event dispatching.
   */
  public boolean dispatchMouseEvent(MouseEvent e) {
    Component c = e.getComponent();

    // frame activation by mouse click
    if (e.getID() == MOUSE_PRESSED && c instanceof IdeFrame && !c.hasFocus()) {
      IdeFocusManager focusManager = IdeFocusManager.getGlobalInstance();
      if (focusManager instanceof FocusManagerImpl) {
        Component at = SwingUtilities.getDeepestComponentAt(c, e.getX(), e.getY());
        if (at != null && at.isFocusable()) {
          ((FocusManagerImpl) focusManager).setLastFocusedAtDeactivation((IdeFrame) c, at);
        }
      }
    }

    if (SystemInfo.isXWindow && e.isPopupTrigger() && e.getButton() != 3) {
      // we can do better than silly triggering popup on everything but left click
      resetPopupTrigger(e);
    }

    boolean ignore = false;
    if (!(e.getID() == MouseEvent.MOUSE_PRESSED
        || e.getID() == MouseEvent.MOUSE_RELEASED
        || e.getID() == MOUSE_CLICKED)) {
      ignore = true;
    }

    patchClickCount(e);

    if (e.isConsumed()
        || e.isPopupTrigger()
        || (e.getButton() > 3 ? e.getID() != MOUSE_PRESSED : e.getID() != MOUSE_RELEASED)
        || e.getClickCount() < 1
        || e.getButton() == MouseEvent.NOBUTTON) { // See #16995. It did happen
      ignore = true;
    }

    int modifiers = e.getModifiers();
    int modifiersEx = e.getModifiersEx();
    if (e.getID() == MOUSE_PRESSED) {
      myPressedModifiersStored = true;
      myModifiers = modifiers;
      myModifiersEx = modifiersEx;
    } else if (e.getID() == MOUSE_RELEASED) {
      if (myPressedModifiersStored) {
        myPressedModifiersStored = false;
        modifiers = myModifiers;
        modifiersEx = myModifiersEx;
      }
    }

    final JRootPane root = findRoot(e);
    if (root != null) {
      BlockState blockState = myRootPane2BlockedId.get(root);
      if (blockState != null) {
        if (SWING_EVENTS_PRIORITY.indexOf(blockState.currentEventId)
            < SWING_EVENTS_PRIORITY.indexOf(e.getID())) {
          blockState.currentEventId = e.getID();
          if (blockState.blockMode == IdeEventQueue.BlockMode.COMPLETE) {
            return true;
          } else {
            ignore = true;
          }
        } else {
          myRootPane2BlockedId.remove(root);
        }
      }
    }

    if (c == null) {
      throw new IllegalStateException("component cannot be null");
    }
    c = SwingUtilities.getDeepestComponentAt(c, e.getX(), e.getY());

    if (c instanceof IdeGlassPaneImpl) {
      c = ((IdeGlassPaneImpl) c).getTargetComponentFor(e);
    }

    if (c == null) { // do nothing if component doesn't contains specified point
      return false;
    }

    if (isHorizontalScrolling(c, e)) {
      boolean done = doHorizontalScrolling(c, (MouseWheelEvent) e);
      if (done) return true;
    }

    if (ignore) return false;

    // avoid "cyclic component initialization error" in case of dialogs shown because of component
    // initialization failure
    if (!KeymapManagerImpl.ourKeymapManagerInitialized) {
      return false;
    }

    final MouseShortcut shortcut = new MouseShortcut(e.getButton(), modifiersEx, e.getClickCount());
    fillActionsList(c, shortcut, IdeKeyEventDispatcher.isModalContext(c));
    ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
    if (actionManager != null) {
      AnAction[] actions = myActions.toArray(new AnAction[myActions.size()]);
      for (AnAction action : actions) {
        DataContext dataContext = DataManager.getInstance().getDataContext(c);
        Presentation presentation = myPresentationFactory.getPresentation(action);
        AnActionEvent actionEvent =
            new AnActionEvent(
                e,
                dataContext,
                ActionPlaces.MAIN_MENU,
                presentation,
                ActionManager.getInstance(),
                modifiers);
        action.beforeActionPerformedUpdate(actionEvent);

        if (presentation.isEnabled()) {
          actionManager.fireBeforeActionPerformed(action, dataContext, actionEvent);
          final Component context = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);

          if (context != null && !context.isShowing()) continue;

          action.actionPerformed(actionEvent);
          e.consume();
        }
      }
      if (actions.length > 0 && e.isConsumed()) return true;
    }
    return e.getButton() > 3;
  }
コード例 #10
0
ファイル: VTabbedToolPanel.java プロジェクト: timburrow/ovj3
  public void showPinObj(PushpinIF pobj, boolean on) {
    Component comp = (Component) pobj;
    if (comp == null) return;
    Container p = comp.getParent();
    if (!on) {
      pobj.setPopup(false, true);
      if (p != null && p != tabbedPane) {
        p.remove(comp);
        p.validate();
        p.repaint();
      }
      if (popupComp == comp) popupComp = null;
      return;
    }

    if (popupComp != null) {
      if (popupComp != comp) {
        ((PushpinIF) popupComp).setPopup(false, true);
        p = popupComp.getParent();
        if (p != null && p != tabbedPane) {
          p.remove(popupComp);
        }
      }
      popupComp = null;
    }
    /*
    if (!isShowing()) {
        return;
    }
     */
    if (comp.isShowing()) {
      return;
    }
    Container p2 = null;
    p = pinPanel.getParent();
    while (p != null) {
      if (p instanceof JLayeredPane) p2 = p;
      p = p.getParent();
    }
    if (p2 == null) return;
    if (!isShowing()) {
      VnmrjIF vif = Util.getVjIF();
      vif.raiseToolPanel(on);
      setVisible(true);
    }

    popupComp = comp;
    p = p2;
    pobj.setPopup(true, true);
    /*
    Point pt0 = p.getLocationOnScreen();
    Point pt1 = getLocationOnScreen();
     */
    Point pt1 = getLocation();
    Dimension dim = getSize();
    int y0 = (int) ((float) dim.height * pobj.getRefY());
    int h = (int) ((float) dim.height * pobj.getRefH());
    int x = pt1.x + 2;
    int y = pt1.y + y0;
    p.add(comp, JLayeredPane.MODAL_LAYER);
    comp.setBounds(x, y, dim.width, dim.height - y0);
    ((JComponent) p).validate();
    /*
    p.repaint();
     */
  }
コード例 #11
0
ファイル: InputHandler.java プロジェクト: jthunnissen/AOP
  /**
   * 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;
    }
  } // }}}
コード例 #12
0
 protected boolean violatesEDTRule(Component component) {
   return !SwingUtilities.isEventDispatchThread() && component.isShowing();
 }