Java Code Examples for com.intellij.ui.awt.RelativePoint#getPoint()

The following examples show how to use com.intellij.ui.awt.RelativePoint#getPoint() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditorGutterComponentImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void calcAnnotationExtraSize() {
  myTextAnnotationExtraSize = 0;
  if (!myEditor.isInDistractionFreeMode() || isMirrored()) return;

  Window frame = SwingUtilities.getWindowAncestor(myEditor.getComponent());
  if (frame == null) return;

  EditorSettings settings = myEditor.getSettings();
  int rightMargin = settings.getRightMargin(myEditor.getProject());
  if (rightMargin <= 0) return;

  JComponent editorComponent = myEditor.getComponent();
  RelativePoint point = new RelativePoint(editorComponent, new Point(0, 0));
  Point editorLocationInWindow = point.getPoint(frame);

  int editorLocationX = (int)editorLocationInWindow.getX();
  int rightMarginX = rightMargin * EditorUtil.getSpaceWidth(Font.PLAIN, myEditor) + editorLocationX;

  int width = editorLocationX + editorComponent.getWidth();
  if (rightMarginX < width && editorLocationX < width - rightMarginX) {
    int centeredSize = (width - rightMarginX - editorLocationX) / 2 - (getLineMarkerAreaWidth() + getLineNumberAreaWidth() + getFoldingAreaWidth() + 2 * getGapBetweenAreas());
    myTextAnnotationExtraSize = Math.max(0, centeredSize - myTextAnnotationGuttersSize);
  }
}
 
Example 2
Source File: LightweightHint.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void setLocation(@Nonnull RelativePoint point) {
  if (isRealPopup()) {
    myPopup.setLocation(point.getScreenPoint());
  }
  else {
    if (myCurrentIdeTooltip != null) {
      myCurrentIdeTooltip.setPoint(point.getPoint());
      myCurrentIdeTooltip.setComponent(point.getComponent());
      IdeTooltipManager.getInstance().show(myCurrentIdeTooltip, true, false);
    }
    else {
      Point targetPoint = point.getPoint(myComponent.getParent());
      myComponent.setLocation(targetPoint);

      myComponent.revalidate();
      myComponent.repaint();
    }
  }
}
 
Example 3
Source File: ShowPopupMenuAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void actionPerformed(AnActionEvent e) {
  final RelativePoint relPoint = JBPopupFactory.getInstance().guessBestPopupLocation(e.getDataContext());

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

  Point popupMenuPoint = relPoint.getPoint(focusOwner);

  final Editor editor = e.getData(PlatformDataKeys.EDITOR);
  int coord = editor != null
              ? Math.max(0, popupMenuPoint.y - 1) //To avoid cursor jump to the line below. http://www.jetbrains.net/jira/browse/IDEADEV-10644
              : popupMenuPoint.y;

  focusOwner.dispatchEvent(
    new MouseEvent(
      focusOwner,
      MouseEvent.MOUSE_PRESSED,
      System.currentTimeMillis(), 0,
      popupMenuPoint.x,
      coord,
      1,
      true
    )
  );
}
 
Example 4
Source File: DesktopEditorsSplitters.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
JBTabs getTabsAt(RelativePoint point) {
  Point thisPoint = point.getPoint(myComponent);
  Component c = SwingUtilities.getDeepestComponentAt(myComponent, thisPoint.x, thisPoint.y);
  while (c != null) {
    if (c instanceof JBTabs) {
      return (JBTabs)c;
    }
    c = c.getParent();
  }

  return null;
}
 
Example 5
Source File: ChangesDnDSupport.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean update(DnDEvent aEvent) {
  aEvent.hideHighlighter();
  aEvent.setDropPossible(false, "");

  Object attached = aEvent.getAttachedObject();
  if (!(attached instanceof ChangeListDragBean)) return false;

  final ChangeListDragBean dragBean = (ChangeListDragBean)attached;
  if (dragBean.getSourceComponent() != myTree) return false;
  dragBean.setTargetNode(null);

  RelativePoint dropPoint = aEvent.getRelativePoint();
  Point onTree = dropPoint.getPoint(myTree);
  final TreePath dropPath = myTree.getPathForLocation(onTree.x, onTree.y);

  if (dropPath == null) return false;

  ChangesBrowserNode dropNode = (ChangesBrowserNode)dropPath.getLastPathComponent();
  while (!((ChangesBrowserNode)dropNode.getParent()).isRoot()) {
    dropNode = (ChangesBrowserNode)dropNode.getParent();
  }

  if (!dropNode.canAcceptDrop(dragBean)) {
    return false;
  }

  final Rectangle tableCellRect = myTree.getPathBounds(new TreePath(dropNode.getPath()));
  if (fitsInBounds(tableCellRect)) {
    aEvent.setHighlighting(new RelativeRectangle(myTree, tableCellRect), DnDEvent.DropTargetHighlightingType.RECTANGLE);
  }

  aEvent.setDropPossible(true);
  dragBean.setTargetNode(dropNode);

  return false;
}
 
Example 6
Source File: JBRunnerTabs.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void processDropOver(TabInfo over, RelativePoint relativePoint) {
  final Point point = relativePoint.getPoint(getComponent());
  myShowDropLocation = shouldAddToGlobal(point);
  super.processDropOver(over, relativePoint);
  for (Map.Entry<TabInfo, TabLabel> entry : myInfo2Label.entrySet()) {
    final TabLabel label = entry.getValue();
    if (label.getBounds().contains(point) && myDropInfo != entry.getKey()) {
      select(entry.getKey(), false);
      break;
    }
  }
}
 
Example 7
Source File: RunnerContentUi.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void add(@Nonnull DockableContent dockable, RelativePoint dropTarget) {
  final DockableGrid dockableGrid = (DockableGrid)dockable;
  final RunnerContentUi prev = dockableGrid.getRunnerUi();

  saveUiState();

  final List<Content> contents = dockableGrid.getContents();
  final boolean wasRestoring = myOriginal != null && myOriginal.isStateBeingRestored();
  setStateIsBeingRestored(true, this);
  try {
    final Point point = dropTarget != null ? dropTarget.getPoint(myComponent) : null;
    boolean hadGrid = !myTabs.shouldAddToGlobal(point);

    for (Content content : contents) {
      final View view = getStateFor(content);
      if (view.isMinimizedInGrid()) continue;
      prev.myManager.removeContent(content, false);
      myManager.removeContent(content, false);
      if (hadGrid && !wasRestoring) {
        view.assignTab(getTabFor(getSelectedGrid()));
        view.setPlaceInGrid(calcPlaceInGrid(point, myComponent.getSize()));
      }
      else if (contents.size() == 1 && !wasRestoring) {
        view.assignTab(null);
        view.setPlaceInGrid(myLayoutSettings.getDefaultGridPlace(content));
      }
      view.setWindow(myWindow);
      myManager.addContent(content);
    }
  }
  finally {
    setStateIsBeingRestored(false, this);
  }

  saveUiState();

  updateTabsUI(true);
}
 
Example 8
Source File: RunnerContentUi.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private JBTabs getTabsAt(DockableContent content, RelativePoint point) {
  if (content instanceof DockableGrid) {
    final Point p = point.getPoint(getComponent());
    Component c = SwingUtilities.getDeepestComponentAt(getComponent(), p.x, p.y);
    while (c != null) {
      if (c instanceof JBRunnerTabs) {
        return (JBTabs)c;
      }
      c = c.getParent();
    }
  }
  return null;
}
 
Example 9
Source File: Callout.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void showTextBelow(JComponent component, String text) {
  final RelativePoint calloutPoint = RelativePoint.getSouthWestOf(component);
  calloutPoint.getPoint().x += 5;
  Callout.showText(calloutPoint, Callout.SOUTH_EAST, text);
}