com.intellij.ui.awt.RelativePoint Java Examples

The following examples show how to use com.intellij.ui.awt.RelativePoint. 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: SqlEditorPanel.java    From CodeGen with MIT License 6 votes vote down vote up
@Override
public boolean valid() {
    // 1. check empty
    String sqls = sqlTextArea.getDocument().getText();
    if (StringUtils.isBlank(sqls)) {
        JBalloon.buildSimple("Input sqls can not be empty!")
                .show(RelativePoint.getSouthOf(this.sqlScrollPane));
        return false;
    }
    // 2. check parse
    Parser parser = new DefaultParser();
    List<Table> tables = parser.parseSQLs(sqls);
    if (tables == null || tables.isEmpty()) {
        JBalloon.buildSimple("Can not parse sqls, please check sql format!")
                .show(RelativePoint.getSouthOf(this.sqlScrollPane));
        return false;
    }
    return true;
}
 
Example #2
Source File: GTMProject.java    From gtm-jetbrains-plugin with MIT License 6 votes vote down vote up
private void installGtmWidget() {
    StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject);
    if (statusBar != null) {
        statusBar.addWidget(myStatusWidget, myProject);
        myStatusWidget.installed();
        if (!GTMRecord.initGtmExePath()) {
            JBPopupFactory.getInstance()
                    .createHtmlTextBalloonBuilder(GTMConfig.getInstance().gtmNotFound, ERROR, null)
                    .setFadeoutTime(30000)
                    .createBalloon()
                    .show(RelativePoint.getSouthEastOf(statusBar.getComponent()),
                            Balloon.Position.atRight);
            return;
        }
        if (!GTMRecord.checkVersion()) {
            JBPopupFactory.getInstance()
                    .createHtmlTextBalloonBuilder(GTMConfig.getInstance().gtmVerOutdated, WARNING, null)
                    .setFadeoutTime(30000)
                    .createBalloon()
                    .show(RelativePoint.getSouthEastOf(statusBar.getComponent()),
                            Balloon.Position.atRight);
        }
    }
}
 
Example #3
Source File: LookupImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void showElementActions(@Nullable InputEvent event) {
  if (!isVisible()) return;

  LookupElement element = getCurrentItem();
  if (element == null) {
    return;
  }

  Collection<LookupElementAction> actions = getActionsFor(element);
  if (actions.isEmpty()) {
    return;
  }

  //UIEventLogger.logUIEvent(UIEventId.LookupShowElementActions);

  Rectangle itemBounds = getCurrentItemBounds();
  Rectangle visibleRect = SwingUtilities.convertRectangle(myList, myList.getVisibleRect(), getComponent());
  ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(new LookupActionsStep(actions, this, element));
  Point p = (itemBounds.intersects(visibleRect) || event == null)
            ? new Point(itemBounds.x + itemBounds.width, itemBounds.y)
            : SwingUtilities.convertPoint(event.getComponent(), new Point(0, event.getComponent().getHeight() + JBUIScale.scale(2)), getComponent());

  listPopup.show(new RelativePoint(getComponent(), p));
}
 
Example #4
Source File: LightweightHint.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean fitsLayeredPane(JLayeredPane pane, JComponent component, RelativePoint desiredLocation, HintHint hintHint) {
  if (hintHint.isAwtTooltip()) {
    Dimension size = component.getPreferredSize();
    Dimension paneSize = pane.getSize();

    Point target = desiredLocation.getPointOn(pane).getPoint();
    Balloon.Position pos = hintHint.getPreferredPosition();
    int pointer = BalloonImpl.getPointerLength(pos, false) + BalloonImpl.getNormalInset();
    if (pos == Balloon.Position.above || pos == Balloon.Position.below) {
      boolean heightFit = target.y - size.height - pointer > 0 || target.y + size.height + pointer < paneSize.height;
      return heightFit && size.width + pointer < paneSize.width;
    }
    else {
      boolean widthFit = target.x - size.width - pointer > 0 || target.x + size.width + pointer < paneSize.width;
      return widthFit && size.height + pointer < paneSize.height;
    }
  }
  else {
    final Rectangle lpRect = new Rectangle(pane.getLocationOnScreen().x, pane.getLocationOnScreen().y, pane.getWidth(), pane.getHeight());
    Rectangle componentRect = new Rectangle(desiredLocation.getScreenPoint().x, desiredLocation.getScreenPoint().y, component.getPreferredSize().width, component.getPreferredSize().height);
    return lpRect.contains(componentRect);
  }
}
 
Example #5
Source File: ProjectConfigurationProblem.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void fix(final JComponent contextComponent, RelativePoint relativePoint) {
  JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<ConfigurationErrorQuickFix>(null, myDescription.getFixes()) {
    @Nonnull
    @Override
    public String getTextFor(ConfigurationErrorQuickFix value) {
      return value.getActionName();
    }

    @Override
    public PopupStep onChosen(final ConfigurationErrorQuickFix selectedValue, boolean finalChoice) {
      return doFinalStep(new Runnable() {
        @Override
        public void run() {
          selectedValue.performFix();
        }
      });
    }
  }).show(relativePoint);
}
 
Example #6
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
private InplaceButton createSettingsButton(@NotNull final FindUsagesHandler handler,
    @NotNull final RelativePoint popupPosition, final Editor editor, final int maxUsages,
    @NotNull final Runnable cancelAction) {
  String shortcutText = "";
  KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut();
  if (shortcut != null) {
    shortcutText = "(" + KeymapUtil.getShortcutText(shortcut) + ")";
  }
  return new InplaceButton("Settings..." + shortcutText, AllIcons.General.Settings,
      new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
          SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
              showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
            }
          });
          cancelAction.run();
        }
      }
  );
}
 
Example #7
Source File: DockableEditorTabbedContainer.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private JBTabs getTabsAt(DockableContent content, RelativePoint point) {
  if (content instanceof EditorTabbedContainer.DockableEditor) {
    JBTabs targetTabs = mySplitters.getTabsAt(point);
    if (targetTabs != null) {
      return targetTabs;
    } else {
      EditorWindow wnd = mySplitters.getCurrentWindow();
      if (wnd != null) {
        EditorTabbedContainer tabs = ((DesktopEditorWindow)wnd).getTabbedPane();
        if (tabs != null) {
          return tabs.getTabs();
        }
      } else {
        DesktopEditorWindow[] windows = mySplitters.getWindows();
        for (DesktopEditorWindow each : windows) {
          if (each.getTabbedPane() != null && each.getTabbedPane().getTabs() != null) {
            return each.getTabbedPane().getTabs();
          }
        }
      }
    }
  }

  return null;
}
 
Example #8
Source File: SlideComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void updateBalloonText() {
  final Point point = myVertical ? new Point(0, myPointerValue) : new Point(myPointerValue, 0);
  myLabel.setText(myTitle + ": " + Unit.formatValue(myValue, myUnit));
  if (myTooltipHint == null) {
    myTooltipHint = new LightweightHint(myLabel);
    myTooltipHint.setCancelOnClickOutside(false);
    myTooltipHint.setCancelOnOtherWindowOpen(false);

    final HintHint hint = new HintHint(this, point)
      .setPreferredPosition(myVertical ? Balloon.Position.atLeft : Balloon.Position.above)
      .setBorderColor(Color.BLACK)
      .setAwtTooltip(true)
      .setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD))
      .setTextBg(HintUtil.INFORMATION_COLOR)
      .setShowImmediately(true);

    final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    myTooltipHint.show(this, point.x, point.y, owner instanceof JComponent ? (JComponent)owner : null, hint);
  }
  else {
    myTooltipHint.setLocation(new RelativePoint(this, point));
  }
}
 
Example #9
Source File: IdeStatusBarImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private MultipleTextValuesPresentationWrapper(@Nonnull final StatusBarWidget.MultipleTextValuesPresentation presentation) {
  myPresentation = presentation;
  setVisible(StringUtil.isNotEmpty(myPresentation.getSelectedValue()));
  setTextAlignment(Component.CENTER_ALIGNMENT);
  new ClickListener() {
    @Override
    public boolean onClick(@Nonnull MouseEvent e, int clickCount) {
      final ListPopup popup = myPresentation.getPopupStep();
      if (popup == null) return false;
      final Dimension dimension = popup.getContent().getPreferredSize();
      final Point at = new Point(0, -dimension.height);
      popup.show(new RelativePoint(e.getComponent(), at));
      return true;
    }
  }.installOn(this);
}
 
Example #10
Source File: PsiElementListNavigator.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void openTargets(MouseEvent e,
                               NavigatablePsiElement[] targets,
                               String title,
                               final String findUsagesTitle,
                               ListCellRenderer listRenderer,
                               @Nullable BackgroundUpdaterTask listUpdaterTask) {
  JBPopup popup = navigateOrCreatePopup(targets, title, findUsagesTitle, listRenderer, listUpdaterTask);
  if (popup != null) {
    RelativePoint point = new RelativePoint(e);
    if (listUpdaterTask != null) {
      runActionAndListUpdaterTask(() -> popup.show(point), listUpdaterTask);
    }
    else {
      popup.show(point);
    }
  }
}
 
Example #11
Source File: PopupUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void showBalloonForComponent(@Nonnull Component component, @Nonnull final String message, final MessageType type,
                                           final boolean atTop, @Nullable final Disposable disposable) {
  final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
  if (popupFactory == null) return;
  BalloonBuilder balloonBuilder = popupFactory.createHtmlTextBalloonBuilder(message, type, null);
  balloonBuilder.setDisposable(disposable == null ? ApplicationManager.getApplication() : disposable);
  Balloon balloon = balloonBuilder.createBalloon();
  Dimension size = component.getSize();
  Balloon.Position position;
  int x;
  int y;
  if (size == null) {
    x = y = 0;
    position = Balloon.Position.above;
  }
  else {
    x = Math.min(10, size.width / 2);
    y = size.height;
    position = Balloon.Position.below;
  }
  balloon.show(new RelativePoint(component, new Point(x, y)), position);
}
 
Example #12
Source File: AbstractNavigationHandler.java    From NutzCodeInsight with Apache License 2.0 6 votes vote down vote up
@Override
public final void navigate(MouseEvent mouseEvent, PsiElement psiElement) {
    if (canNavigate(psiElement)) {
        final Project project = psiElement.getProject();
        final List<VirtualFile> fileList = findTemplteFileList(psiElement);
        if (fileList.size() == 1) {
            FileEditorManager.getInstance(project).openFile(fileList.get(0), true);
        } else if (fileList.size() > 1) {
            final List<VirtualFile> infos = new ArrayList<>(fileList);
            List<PsiElement> elements = new ArrayList<>();
            PsiManager psiManager = PsiManager.getInstance(psiElement.getProject());
            infos.forEach(virtualFile -> elements.add(psiManager.findFile(virtualFile).getNavigationElement()));
            NavigationUtil.getPsiElementPopup(elements.toArray(new PsiElement[0]), title).show(new RelativePoint(mouseEvent));
        } else {
            if (fileList == null || fileList.size() <= 0) {
                Messages.showErrorDialog("没有找到这个资源文件,请检查!", "错误提示");
            }
        }
    }

}
 
Example #13
Source File: QueryPanel.java    From nosql4idea with Apache License 2.0 6 votes vote down vote up
void notifyOnErrorForOperator(JComponent component, Exception ex) {
    String message;
    if (ex instanceof JSONParseException) {
        message = StringUtils.removeStart(ex.getMessage(), "\n");
    } else {
        message = String.format("%s: %s", ex.getClass().getSimpleName(), ex.getMessage());
    }
    NonOpaquePanel nonOpaquePanel = new NonOpaquePanel();
    JTextPane textPane = Messages.configureMessagePaneUi(new JTextPane(), message);
    textPane.setFont(COURIER_FONT);
    textPane.setBackground(MessageType.ERROR.getPopupBackground());
    nonOpaquePanel.add(textPane, BorderLayout.CENTER);
    nonOpaquePanel.add(new JLabel(MessageType.ERROR.getDefaultIcon()), BorderLayout.WEST);

    JBPopupFactory.getInstance().createBalloonBuilder(nonOpaquePanel)
            .setFillColor(MessageType.ERROR.getPopupBackground())
            .createBalloon()
            .show(new RelativePoint(component, new Point(0, 0)), Balloon.Position.above);
}
 
Example #14
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 #15
Source File: DockManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void createNewDockContainerFor(DockableContent content, RelativePoint point) {
  DockContainer container = getFactory(content.getDockContainerType()).createContainer(content);
  register(container);

  final DockWindow window = createWindowFor(null, container);

  Dimension size = content.getPreferredSize();
  Point showPoint = point.getScreenPoint();
  showPoint.x -= size.width / 2;
  showPoint.y -= size.height / 2;

  Rectangle target = new Rectangle(showPoint, size);
  ScreenUtil.moveRectangleToFitTheScreen(target);
  ScreenUtil.cropRectangleToFitTheScreen(target);


  window.setLocation(target.getLocation());
  window.myDockContentUiContainer.setPreferredSize(target.getSize());

  window.show(false);
  window.getFrame().pack();

  container.add(content, new RelativePoint(target.getLocation()));

  SwingUtilities.invokeLater(() -> window.myUiContainer.setPreferredSize(null));
}
 
Example #16
Source File: AbstractPopup.java    From consulo with Apache License 2.0 6 votes vote down vote up
private RelativePoint relativePointWithDominantRectangle(final JLayeredPane layeredPane, final Rectangle bounds) {
  Dimension size = getSizeForPositioning();
  List<Supplier<Point>> optionsToTry = Arrays.asList(() -> new Point(bounds.x + bounds.width, bounds.y), () -> new Point(bounds.x - size.width, bounds.y));
  for (Supplier<Point> option : optionsToTry) {
    Point location = option.get();
    SwingUtilities.convertPointToScreen(location, layeredPane);
    Point adjustedLocation = fitToScreenAdjustingVertically(location, size);
    if (adjustedLocation != null) return new RelativePoint(adjustedLocation).getPointOn(layeredPane);
  }

  setDimensionServiceKey(null); // going to cut width
  Point rightTopCorner = new Point(bounds.x + bounds.width, bounds.y);
  final Point rightTopCornerScreen = (Point)rightTopCorner.clone();
  SwingUtilities.convertPointToScreen(rightTopCornerScreen, layeredPane);
  Rectangle screen = ScreenUtil.getScreenRectangle(rightTopCornerScreen.x, rightTopCornerScreen.y);
  final int spaceOnTheLeft = bounds.x;
  final int spaceOnTheRight = screen.x + screen.width - rightTopCornerScreen.x;
  if (spaceOnTheLeft > spaceOnTheRight) {
    myComponent.setPreferredSize(new Dimension(spaceOnTheLeft, Math.max(size.height, JBUIScale.scale(200))));
    return new RelativePoint(layeredPane, new Point(0, bounds.y));
  }
  else {
    myComponent.setPreferredSize(new Dimension(spaceOnTheRight, Math.max(size.height, JBUIScale.scale(200))));
    return new RelativePoint(layeredPane, rightTopCorner);
  }
}
 
Example #17
Source File: LSPServerStatusWidget.java    From lsp4intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public Consumer<MouseEvent> getClickConsumer() {
    return (MouseEvent t) -> {
        JBPopupFactory.ActionSelectionAid mnemonics = JBPopupFactory.ActionSelectionAid.MNEMONICS;
        Component component = t.getComponent();
        List<AnAction> actions = new ArrayList<>();
        if (wrapper.getStatus() == ServerStatus.INITIALIZED) {
            actions.add(new ShowConnectedFiles());
        }
        actions.add(new ShowTimeouts());
        if (wrapper.isRestartable()) {
            actions.add(new Restart());
        }

        String title = "Server actions";
        DataContext context = DataManager.getInstance().getDataContext(component);
        DefaultActionGroup group = new DefaultActionGroup(actions);
        ListPopup popup = JBPopupFactory.getInstance()
                .createActionGroupPopup(title, group, context, mnemonics, true);
        Dimension dimension = popup.getContent().getPreferredSize();
        Point at = new Point(0, -dimension.height);
        popup.show(new RelativePoint(t.getComponent(), at));
    };
}
 
Example #18
Source File: DebuggerUIUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Deprecated
public static RelativePoint calcPopupLocation(@Nonnull Editor editor, final int line) {
  Point p = editor.logicalPositionToXY(new LogicalPosition(line + 1, 0));

  final Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
  if (!visibleArea.contains(p)) {
    p = new Point((visibleArea.x + visibleArea.width) / 2, (visibleArea.y + visibleArea.height) / 2);
  }
  return new RelativePoint(editor.getContentComponent(), p);
}
 
Example #19
Source File: ClasspathPanelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected RelativePoint getPointToShowResults() {
  Rectangle rect = myEntryTable.getCellRect(myEntryTable.getSelectedRow(), 1, false);
  Point location = rect.getLocation();
  location.y += rect.height;
  return new RelativePoint(myEntryTable, location);
}
 
Example #20
Source File: InfoAndProgressPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public BalloonHandler notifyByBalloon(MessageType type, String htmlBody, @Nullable Icon icon, @Nullable HyperlinkListener listener) {
  final Balloon balloon =
          JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(htmlBody.replace("\n", "<br>"), icon != null ? icon : type.getDefaultIcon(), type.getPopupBackground(), listener).createBalloon();

  SwingUtilities.invokeLater(() -> {
    Balloon oldBalloon = SoftReference.dereference(myLastShownBalloon);
    if (oldBalloon != null) {
      balloon.setAnimationEnabled(false);
      oldBalloon.setAnimationEnabled(false);
      oldBalloon.hide();
    }
    myLastShownBalloon = new WeakReference<>(balloon);

    Component comp = this;
    if (comp.isShowing()) {
      int offset = comp.getHeight() / 2;
      Point point = new Point(comp.getWidth() - offset, comp.getHeight() - offset);
      balloon.show(new RelativePoint(comp, point), Balloon.Position.above);
    }
    else {
      final JRootPane rootPane = SwingUtilities.getRootPane(comp);
      if (rootPane != null && rootPane.isShowing()) {
        final Container contentPane = rootPane.getContentPane();
        final Rectangle bounds = contentPane.getBounds();
        final Point target = UIUtil.getCenterPoint(bounds, JBUI.size(1, 1));
        target.y = bounds.height - 3;
        balloon.show(new RelativePoint(contentPane, target), Balloon.Position.above);
      }
    }
  });

  return () -> SwingUtilities.invokeLater(balloon::hide);
}
 
Example #21
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private void navigateAndHint(@NotNull Usage usage, @Nullable final String hint,
    @NotNull final FindUsagesHandler handler, @NotNull final RelativePoint popupPosition,
    final int maxUsages, @NotNull final FindUsagesOptions options) {
  usage.navigate(true);
  if (hint == null) return;
  final Editor newEditor = getEditorFor(usage);
  if (newEditor == null) return;
  final Project project = handler.getProject();
  //opening editor is performing in invokeLater
  IdeFocusManager.getInstance(project).doWhenFocusSettlesDown(new Runnable() {
    @Override
    public void run() {
      newEditor.getScrollingModel().runActionOnScrollingFinished(new Runnable() {
        @Override
        public void run() {
          // after new editor created, some editor resizing events are still bubbling. To prevent hiding hint, invokeLater this
          IdeFocusManager.getInstance(project).doWhenFocusSettlesDown(new Runnable() {
            @Override
            public void run() {
              if (newEditor.getComponent().isShowing()) {
                showHint(hint, newEditor, popupPosition, handler, maxUsages, options);
              }
            }
          });
        }
      });
    }
  });
}
 
Example #22
Source File: ActionMacroManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void showBalloon() {
  if (myBalloon != null) {
    Disposer.dispose(myBalloon);
    return;
  }

  myBalloon = JBPopupFactory.getInstance().createBalloonBuilder(myBalloonComponent).setAnimationCycle(200).setCloseButtonEnabled(true).setHideOnAction(false).setHideOnClickOutside(false)
          .setHideOnFrameResize(false).setHideOnKeyOutside(false).setSmallVariant(true).setShadow(true).createBalloon();

  Disposer.register(myBalloon, new Disposable() {
    @Override
    public void dispose() {
      myBalloon = null;
    }
  });

  myBalloon.addListener(new JBPopupAdapter() {
    @Override
    public void onClosed(LightweightWindowEvent event) {
      if (myBalloon != null) {
        Disposer.dispose(myBalloon);
      }
    }
  });

  myBalloon.show(new PositionTracker<Balloon>(myIcon) {
    @Override
    public RelativePoint recalculateLocation(Balloon object) {
      return new RelativePoint(myIcon, new Point(myIcon.getSize().width / 2, 4));
    }
  }, Balloon.Position.above);
}
 
Example #23
Source File: Utils.java    From android-butterknife-zelezny with Apache License 2.0 5 votes vote down vote up
/**
 * Display simple notification of given type
 *
 * @param project
 * @param type
 * @param text
 */
public static void showNotification(Project project, MessageType type, String text) {
    StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);

    JBPopupFactory.getInstance()
            .createHtmlTextBalloonBuilder(text, type, null)
            .setFadeoutTime(7500)
            .createBalloon()
            .show(RelativePoint.getCenterOf(statusBar.getComponent()), Balloon.Position.atRight);
}
 
Example #24
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private static Rectangle fitToScreen(@NotNull Dimension newDim,
    @NotNull RelativePoint popupPosition, JTable table) {
  Rectangle rectangle = new Rectangle(popupPosition.getScreenPoint(), newDim);
  ScreenUtil.fitToScreen(rectangle);
  if (rectangle.getHeight() != newDim.getHeight()) {
    int newHeight = (int) rectangle.getHeight();
    int roundedHeight = newHeight - newHeight % table.getRowHeight();
    rectangle.setSize((int) rectangle.getWidth(), Math.max(roundedHeight, table.getRowHeight()));
  }
  return rectangle;
}
 
Example #25
Source File: RunnerContentUi.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public ContentResponse getContentResponse(@Nonnull DockableContent content, RelativePoint point) {
  if (!(content instanceof DockableGrid)) {
    return ContentResponse.DENY;
  }
  final RunnerContentUi ui = ((DockableGrid)content).getOriginalRunnerUi();
  return ui.getProject() == myProject && ui.mySessionName.equals(mySessionName) ? ContentResponse.ACCEPT_MOVE : ContentResponse.DENY;
}
 
Example #26
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 #27
Source File: ListPopupImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void showUnderneathOfLabel(@Nonnull JLabel label) {
  int offset = -UIUtil.getListCellHPadding() - UIUtil.getListViewportPadding().left;
  if (label.getIcon() != null) {
    offset += label.getIcon().getIconWidth() + label.getIconTextGap();
  }
  show(new RelativePoint(label, new Point(offset, label.getHeight() + 1)));
}
 
Example #28
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private void showHint(@NotNull String text, @Nullable final Editor editor,
    @NotNull final RelativePoint popupPosition, @NotNull FindUsagesHandler handler, int maxUsages,
    @NotNull FindUsagesOptions options) {
  JComponent label =
      createHintComponent(text, handler, popupPosition, editor, HIDE_HINTS_ACTION, maxUsages,
          options);

  HintManager.getInstance().showHint(label, popupPosition, HintManager.HIDE_BY_ANY_KEY |
      HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0);
}
 
Example #29
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 5 votes vote down vote up
private static boolean showPopupIfNeedTo(@NotNull JBPopup popup,
    @NotNull RelativePoint popupPosition) {
  if (!popup.isDisposed() && !popup.isVisible()) {
    popup.show(popupPosition);
    return true;
  } else {
    return false;
  }
}
 
Example #30
Source File: AbstractPopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static RelativePoint toRelativePoint(@Nonnull Point screenPoint, @Nullable Component component) {
  if (component == null) {
    return RelativePoint.fromScreen(screenPoint);
  }
  SwingUtilities.convertPointFromScreen(screenPoint, component);
  return new RelativePoint(component, screenPoint);
}