Example usage for com.intellij.openapi.ui.popup JBPopupFactory guessBestPopupLocation

List of usage examples for com.intellij.openapi.ui.popup JBPopupFactory guessBestPopupLocation

Introduction

In this page you can find the example usage for com.intellij.openapi.ui.popup JBPopupFactory guessBestPopupLocation.

Prototype

@NotNull
public abstract RelativePoint guessBestPopupLocation(@NotNull Editor editor);

Source Link

Document

Returns the location where a popup invoked from the specified editor should be displayed.

Usage

From source file:com.intellij.lang.customFolding.GotoCustomRegionAction.java

License:Apache License

private static void notifyCustomRegionsUnavailable(@NotNull Editor editor, @NotNull Project project) {
    final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
    Balloon balloon = popupFactory// w ww. j a va2s . c o m
            .createHtmlTextBalloonBuilder(IdeBundle.message("goto.custom.region.message.unavailable"),
                    MessageType.INFO, null)
            .setFadeoutTime(2000).setHideOnClickOutside(true).setHideOnKeyOutside(true).createBalloon();
    Disposer.register(project, balloon);
    balloon.show(popupFactory.guessBestPopupLocation(editor), Balloon.Position.below);
}

From source file:com.intellij.refactoring.rename.inplace.InplaceRefactoring.java

License:Apache License

protected void showBalloon() {
    final JComponent component = getComponent();
    if (component == null)
        return;/*from w ww.  ja v a  2s . com*/
    if (ApplicationManager.getApplication().isHeadlessEnvironment())
        return;
    final BalloonBuilder balloonBuilder = JBPopupFactory.getInstance()
            .createDialogBalloonBuilder(component, null).setSmallVariant(true);
    myBalloon = balloonBuilder.createBalloon();
    final Editor topLevelEditor = InjectedLanguageUtil.getTopLevelEditor(myEditor);
    Disposer.register(myProject, myBalloon);
    Disposer.register(myBalloon, new Disposable() {
        @Override
        public void dispose() {
            releaseIfNotRestart();
            topLevelEditor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION, null);
        }
    });
    topLevelEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
    final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
    myBalloon.show(new PositionTracker<Balloon>(topLevelEditor.getContentComponent()) {
        @Override
        public RelativePoint recalculateLocation(Balloon object) {
            if (myTarget != null && !popupFactory.isBestPopupLocationVisible(topLevelEditor)) {
                return myTarget;
            }
            if (myCaretRangeMarker != null && myCaretRangeMarker.isValid()) {
                topLevelEditor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION,
                        topLevelEditor.offsetToVisualPosition(myCaretRangeMarker.getStartOffset()));
            }
            final RelativePoint target = popupFactory.guessBestPopupLocation(topLevelEditor);
            final Point screenPoint = target.getScreenPoint();
            int y = screenPoint.y;
            if (target.getPoint().getY() > topLevelEditor.getLineHeight()
                    + myBalloon.getPreferredSize().getHeight()) {
                y -= topLevelEditor.getLineHeight();
            }
            myTarget = new RelativePoint(new Point(screenPoint.x, y));
            return myTarget;
        }
    }, Balloon.Position.above);
}

From source file:glslplugin.actions.GLSLDeduceExpressionTypeAction.java

License:Open Source License

private void showBalloon(AnActionEvent e, String html) {
    final Editor editor = e.getData(CommonDataKeys.EDITOR_EVEN_IF_INACTIVE);
    if (editor == null)
        return;//w  ww .j  av a2s .co m
    final JBPopupFactory factory = JBPopupFactory.getInstance();
    final BalloonBuilder builder = factory.createBalloonBuilder(new JLabel(html));
    Balloon balloon = builder.createBalloon();
    RelativePoint position = factory.guessBestPopupLocation(editor);
    balloon.show(position, Balloon.Position.below);
}