@Override
  public void mouseDragged(MouseEvent arg0) {
    if (dragging) {
      setDragTileLocation(new Point(arg0.getXOnScreen(), arg0.getYOnScreen()));

      // find drop target on world
      Point os = new Point(arg0.getXOnScreen(), arg0.getYOnScreen());
      SwingUtilities.convertPointFromScreen(os, parent.world);

      Component component =
          SwingUtilities.getDeepestComponentAt(parent.world, (int) os.getX(), (int) os.getY());

      if (component instanceof TileView) {
        // available drop target reached
        draggedOverTile = ((TileView) component);

        // change cursor symbol to drop target symbol
        Cursor cursor = DragSource.DefaultCopyDrop;
        draggedTile.setCursor(cursor);
      } else {
        draggedOverTile = null;

        // reset cursor symbol
        draggedTile.setCursor(null);
      }
    }
  }
 public boolean shouldSelectCell(EventObject anEvent) {
   if (editorComponent != null
       && anEvent instanceof MouseEvent
       && ((MouseEvent) anEvent).getID() == MouseEvent.MOUSE_PRESSED) {
     Component dispatchComponent = SwingUtilities.getDeepestComponentAt(editorComponent, 3, 3);
     MouseEvent e = (MouseEvent) anEvent;
     MouseEvent e2 =
         new MouseEvent(
             dispatchComponent,
             MouseEvent.MOUSE_RELEASED,
             e.getWhen() + 100000,
             e.getModifiers(),
             3,
             3,
             e.getClickCount(),
             e.isPopupTrigger());
     dispatchComponent.dispatchEvent(e2);
     e2 =
         new MouseEvent(
             dispatchComponent,
             MouseEvent.MOUSE_CLICKED,
             e.getWhen() + 100001,
             e.getModifiers(),
             3,
             3,
             1,
             e.isPopupTrigger());
     dispatchComponent.dispatchEvent(e2);
   }
   return false;
 }
  @Override
  public void mouseMoved(MouseEvent e) {
    final MouseEvent event = SwingUtilities.convertMouseEvent(e.getComponent(), e, getParent());
    final boolean insideRec = getBounds().contains(event.getPoint());
    boolean buttonsNotPressed =
        (e.getModifiersEx()
                & (InputEvent.BUTTON1_DOWN_MASK
                    | InputEvent.BUTTON2_DOWN_MASK
                    | InputEvent.BUTTON3_DOWN_MASK))
            == 0;
    if (!myPopupIsShowing && insideRec && buttonsNotPressed) {
      showPopup(null, false);
    } else if (myPopupIsShowing && !insideRec) {
      final Component over =
          SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY());
      JPopupMenu popup = myUnderPopup.isShowing() ? myUnderPopup : myAbovePopup;
      if (over != null && popup.isShowing()) {
        final Rectangle rec = new Rectangle(popup.getLocationOnScreen(), popup.getSize());
        int delta = 15;
        rec.x -= delta;
        rec.width += delta * 2;
        rec.y -= delta;
        rec.height += delta * 2;

        final Point eventPoint = e.getPoint();
        SwingUtilities.convertPointToScreen(eventPoint, e.getComponent());

        if (rec.contains(eventPoint)) {
          return;
        }
      }

      closePopup();
    }
  }
    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;
    }
    private void setDispatchComponent(MouseEvent event) {
      // Get location
      Point point = event.getPoint();

      // Get editor component
      Component editorComponent = grid.getEditorComponent();

      // Get dispatchComponent
      Point editorPoint = SwingUtilities.convertPoint(grid, point, editorComponent);
      dispatchComponent =
          SwingUtilities.getDeepestComponentAt(editorComponent, editorPoint.x, editorPoint.y);
    }
  @Nullable
  JBTabs getTabsAt(RelativePoint point) {
    Point thisPoint = point.getPoint(this);
    Component c = SwingUtilities.getDeepestComponentAt(this, thisPoint.x, thisPoint.y);
    while (c != null) {
      if (c instanceof JBTabs) {
        return (JBTabs) c;
      }
      c = c.getParent();
    }

    return null;
  }
Esempio n. 7
0
 public static JComponent getDeepest(JComponent outermostContainer, MouseEvent mouseEvent) {
   JComponent result;
   Assert.notNull(outermostContainer);
   Assert.notNull(mouseEvent);
   MouseEvent localizedMouseEvent =
       SwingUtilities.convertMouseEvent(mouseEvent.getComponent(), mouseEvent, outermostContainer);
   result =
       (JComponent)
           SwingUtilities.getDeepestComponentAt(
               outermostContainer,
               localizedMouseEvent.getPoint().x,
               localizedMouseEvent.getPoint().y);
   return result;
 }
Esempio n. 8
0
 private static JButton getButton(JList<String> list, Point pt, int index) {
   Component c =
       list.getCellRenderer().getListCellRendererComponent(list, "", index, false, false);
   Rectangle r = list.getCellBounds(index, index);
   c.setBounds(r);
   // c.doLayout(); //may be needed for mone LayoutManager
   pt.translate(-r.x, -r.y);
   Component b = SwingUtilities.getDeepestComponentAt(c, pt.x, pt.y);
   if (b instanceof JButton) {
     return (JButton) b;
   } else {
     return null;
   }
 }
    private void setDispatchComponent(MouseEvent e) {
      // Get location
      Point spreadPoint = e.getPoint();
      int row = grid.rowAtPoint(spreadPoint);
      int column = grid.columnAtPoint(spreadPoint);

      // Get editor component
      Component editorComponent = grid.getEditorComponent();

      // Get dispatchComponent
      Point editorPoint = SwingUtilities.convertPoint(grid, spreadPoint, editorComponent);
      dispatchComponent =
          SwingUtilities.getDeepestComponentAt(editorComponent, editorPoint.x, editorPoint.y);
    }
 // Event forwarding. We need it if user does press-and-drag gesture for opening popup and
 // choosing item there.
 // It works in JComboBox, here we provide the same behavior
 private void dispatchEventToPopup(MouseEvent e) {
   if (myPopup != null && myPopup.isVisible()) {
     JComponent content = myPopup.getContent();
     Rectangle rectangle = content.getBounds();
     Point location = rectangle.getLocation();
     SwingUtilities.convertPointToScreen(location, content);
     Point eventPoint = e.getLocationOnScreen();
     rectangle.setLocation(location);
     if (rectangle.contains(eventPoint)) {
       MouseEvent event =
           SwingUtilities.convertMouseEvent(e.getComponent(), e, myPopup.getContent());
       Component component =
           SwingUtilities.getDeepestComponentAt(content, event.getX(), event.getY());
       if (component != null) component.dispatchEvent(event);
     }
   }
 }
 protected static void processMagnification(IdeFrame frame, double magnification) {
   Point mouse = MouseInfo.getPointerInfo().getLocation();
   SwingUtilities.convertPointFromScreen(mouse, frame.getComponent());
   Component componentAt =
       SwingUtilities.getDeepestComponentAt(frame.getComponent(), mouse.x, mouse.y);
   if (componentAt != null) {
     Editor editor =
         PlatformDataKeys.EDITOR.getData(DataManager.getInstance().getDataContext(componentAt));
     if (editor != null) {
       double currentSize = editor.getColorsScheme().getEditorFontSize();
       int defaultFontSize =
           EditorColorsManager.getInstance().getGlobalScheme().getEditorFontSize();
       ((EditorEx) editor)
           .setFontSize((int) (Math.max(currentSize + magnification * 3, defaultFontSize)));
     }
   }
 }
Esempio n. 12
0
  /**
   * Obtains the deepest component below the glass pane at the specified point.
   *
   * @param pt The point.
   * @return The deepest component, or <code>null</code> if there is no component at the specified
   *     point.
   */
  protected Component getDeepestComponent(Point pt) {
    // Get hold of the content pane, since this contains the components
    // that we want to relay mouse events to
    SwingUtilities.getRoot(glassPane);

    Container contentPane = glassPane.getRootPane().getContentPane();

    // Convert the mouse point from the glass pane coordinate system
    // into the coordinate system of the content pane.
    Point contentPanePt = SwingUtilities.convertPoint(glassPane, pt, contentPane);

    // Find the deepest component - i.e. the one that should get the mouse
    // event.
    Component deepestComponent =
        SwingUtilities.getDeepestComponentAt(contentPane, contentPanePt.x, contentPanePt.y);

    return deepestComponent;
  }
 @Override
 public void mousePressed(final MouseEvent e) {
   if (UIUtil.isActionClick(e)) {
     if (e.getClickCount() == 1) {
       myActionClickCount = 0;
     }
     // clicks on the close window button don't count in determining whether we have a
     // double-click on tab (IDEA-70403)
     final Component deepestComponent =
         SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY());
     if (!(deepestComponent instanceof InplaceButton)) {
       myActionClickCount++;
     }
     if (myActionClickCount == 2 && !isFloating()) {
       final ActionManager mgr = ActionManager.getInstance();
       mgr.tryToExecute(mgr.getAction("HideAllWindows"), e, null, ActionPlaces.UNKNOWN, true);
     }
   }
 }
Esempio n. 14
0
    private void redispatch(MouseEvent e) {

      setGlassPane(false);
      Point thePoint =
          SwingUtilities.convertPoint(myRootFrame.getGlassPane(), e.getX(), e.getY(), myRootFrame);
      Component theComponent =
          SwingUtilities.getDeepestComponentAt(myRootFrame, thePoint.x, thePoint.y);

      MouseEvent theEvt =
          SwingUtilities.convertMouseEvent(myRootFrame.getGlassPane(), e, theComponent);
      logger.debug(
          "Redispatching mouse event to component: " + theComponent.getClass() + e.isConsumed());
      theComponent.dispatchEvent(theEvt);

      Point theLocalPoint =
          SwingUtilities.convertPoint(myRootFrame.getGlassPane(), e.getX(), e.getY(), CPanel.this);
      if (contains(theLocalPoint))
        dispatchEvent(SwingUtilities.convertMouseEvent(myRootFrame.getGlassPane(), e, CPanel.this));

      setGlassPane(true);
    }
Esempio n. 15
0
  /**
   * Re-dispatches glass pane mouse events only in case they occur on the security panel.
   *
   * @param glassPane the glass pane
   * @param e the mouse event in question
   */
  private void redispatchMouseEvent(Component glassPane, MouseEvent e) {
    Point glassPanePoint = e.getPoint();

    Point securityPanelPoint =
        SwingUtilities.convertPoint(glassPane, glassPanePoint, securityPanel);

    Component component;
    Point componentPoint;

    if (securityPanelPoint.y > 0) {
      component = securityPanel;
      componentPoint = securityPanelPoint;
    } else {
      Container contentPane =
          callRenderer.getCallContainer().getCallWindow().getFrame().getContentPane();

      Point containerPoint = SwingUtilities.convertPoint(glassPane, glassPanePoint, contentPane);

      component =
          SwingUtilities.getDeepestComponentAt(contentPane, containerPoint.x, containerPoint.y);

      componentPoint = SwingUtilities.convertPoint(contentPane, glassPanePoint, component);
    }

    if (component != null)
      component.dispatchEvent(
          new MouseEvent(
              component,
              e.getID(),
              e.getWhen(),
              e.getModifiers(),
              componentPoint.x,
              componentPoint.y,
              e.getClickCount(),
              e.isPopupTrigger()));

    e.consume();
  }
Esempio n. 16
0
  public static void feedMouseEventToPanel(int x, int y) {
    Point p = new Point(x, y);
    SwingUtilities.convertPointFromScreen(p, frame.getContentPane());

    System.out.println("x " + x + " y " + y);
    System.out.println("p.x " + p.x + " p.y " + p.y);

    if ((p.x > 0 && p.x < frame.getWidth()) && (p.y > 0 && p.y < frame.getHeight())) {
      Component comp = SwingUtilities.getDeepestComponentAt(frame.getContentPane(), p.x, p.y);

      System.out.println(comp.toString());

      Toolkit.getDefaultToolkit()
          .getSystemEventQueue()
          .postEvent(new MouseEvent(comp, MouseEvent.MOUSE_PRESSED, 0, 0, p.x, p.y, 1, false));
      Toolkit.getDefaultToolkit()
          .getSystemEventQueue()
          .postEvent(new MouseEvent(comp, MouseEvent.MOUSE_RELEASED, 0, 0, p.x, p.y, 1, false));
      Toolkit.getDefaultToolkit()
          .getSystemEventQueue()
          .postEvent(new MouseEvent(comp, MouseEvent.MOUSE_CLICKED, 0, 0, p.x, p.y, 1, false));
    }
  }
  /**
   * @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;
  }
    private MouseEvent transformMouseEvent(MouseEvent event) {
      if (event == null) {
        throw new IllegalArgumentException("MouseEvent is null");
      }
      MouseEvent newEvent;
      if (event instanceof MouseWheelEvent) {
        MouseWheelEvent mouseWheelEvent = (MouseWheelEvent) event;
        newEvent =
            new MouseWheelEvent(
                mouseWheelEvent.getComponent(),
                mouseWheelEvent.getID(),
                mouseWheelEvent.getWhen(),
                mouseWheelEvent.getModifiers(),
                mouseWheelEvent.getX(),
                mouseWheelEvent.getY(),
                mouseWheelEvent.getClickCount(),
                mouseWheelEvent.isPopupTrigger(),
                mouseWheelEvent.getScrollType(),
                mouseWheelEvent.getScrollAmount(),
                mouseWheelEvent.getWheelRotation());
      } else {
        newEvent =
            new MouseEvent(
                event.getComponent(),
                event.getID(),
                event.getWhen(),
                event.getModifiers(),
                event.getX(),
                event.getY(),
                event.getClickCount(),
                event.isPopupTrigger(),
                event.getButton());
      }
      if (view != null && at.getDeterminant() != 0) {
        Rectangle viewBounds = getTransformedSize();
        Insets insets = JXTransformer.this.getInsets();
        int xgap = (getWidth() - (viewBounds.width + insets.left + insets.right)) / 2;
        int ygap = (getHeight() - (viewBounds.height + insets.top + insets.bottom)) / 2;

        double x = newEvent.getX() + viewBounds.getX() - insets.left;
        double y = newEvent.getY() + viewBounds.getY() - insets.top;
        Point2D p = new Point2D.Double(x - xgap, y - ygap);

        Point2D tp;
        try {
          tp = at.inverseTransform(p, null);
        } catch (NoninvertibleTransformException ex) {
          // can't happen, we check it before
          throw new AssertionError("NoninvertibleTransformException");
        }
        // Use transformed coordinates to get the current component
        mouseCurrentComponent =
            SwingUtilities.getDeepestComponentAt(view, (int) tp.getX(), (int) tp.getY());
        if (mouseCurrentComponent == null) {
          mouseCurrentComponent = JXTransformer.this;
        }
        Component tempComponent = mouseCurrentComponent;
        if (mouseDraggedComponent != null) {
          tempComponent = mouseDraggedComponent;
        }

        Point point =
            SwingUtilities.convertPoint(view, (int) tp.getX(), (int) tp.getY(), tempComponent);
        newEvent.setSource(tempComponent);
        newEvent.translatePoint(point.x - event.getX(), point.y - event.getY());
      }
      return newEvent;
    }
 private void setDispatchComponent(MouseEvent e) {
   Component editorComponent = getEditorComponent();
   Point p = e.getPoint();
   Point p2 = SwingUtilities.convertPoint(JListMutable.this, p, editorComponent);
   dispatchComponent = SwingUtilities.getDeepestComponentAt(editorComponent, p2.x, p2.y);
 }
Esempio n. 20
0
  public synchronized void startModal() {
    logger.debug("Starting modal");
    if (isVisible() && !isShowing()) {
      Component parent = this.getParent();
      while (parent != null) {
        if (!(parent.isVisible())) {
          parent.setVisible(true);
        }

        parent = parent.getParent();
      }
    }

    try {
      if (SwingUtilities.isEventDispatchThread()) {
        EventQueue theQueue = getToolkit().getSystemEventQueue();

        while (isVisible()) {
          AWTEvent event = theQueue.getNextEvent();

          Object src = event.getSource();
          if (event instanceof ActiveEvent) {
            ((ActiveEvent) event).dispatch();
          } else if (src instanceof Component) {
            Component src2 = (Component) src;

            if (!(event instanceof MouseEvent)) {
              src2.dispatchEvent(event);
            } else {
              MouseEvent mouseEvent = (MouseEvent) event;

              if (isVisible()
                  && (mouseEvent.getID() == MouseEvent.MOUSE_PRESSED
                      || mouseEvent.getID() == MouseEvent.MOUSE_CLICKED)) {
                Component target =
                    SwingUtilities.getDeepestComponentAt(
                        src2, mouseEvent.getX(), mouseEvent.getY());

                // It would be nice if we could go
                // SwingUtilities.isDescendingFrom(target, this)
                // But it dosent account for popups

                if (isChild(target)) {
                  src2.dispatchEvent(event);
                } else {
                  if (mouseEvent.getID() == MouseEvent.MOUSE_PRESSED) {
                    // Beep
                    getToolkit().beep();
                  }
                }
              } else {
                src2.dispatchEvent(event);
              }
            }
          }
        }
      } else {
        while (isVisible()) {
          wait();
        }
      }
    } catch (InterruptedException exception) {
      logger.error("Error: ", exception);
    }
  }