Search in sources :

Example 11 with BalloonBuilder

use of com.intellij.openapi.ui.popup.BalloonBuilder in project intellij-community by JetBrains.

the class GotItMessage method show.

public void show(RelativePoint point, Balloon.Position position) {
    if (myDisposable != null && Disposer.isDisposed(myDisposable)) {
        return;
    }
    final GotItPanel panel = new GotItPanel();
    panel.myTitle.setText(myTitle);
    panel.myMessage.setText(myMessage);
    if (myHyperlinkListener != null) {
        panel.myMessage.addHyperlinkListener(myHyperlinkListener);
    }
    panel.myButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    final BalloonBuilder builder = JBPopupFactory.getInstance().createBalloonBuilder(panel.myRoot);
    if (myDisposable != null) {
        builder.setDisposable(myDisposable);
    }
    final Balloon balloon = builder.setFillColor(UIUtil.getListBackground()).setHideOnClickOutside(false).setHideOnAction(false).setHideOnFrameResize(false).setHideOnKeyOutside(false).setShowCallout(myShowCallout).setBlockClicksThroughBalloon(true).createBalloon();
    panel.myButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            balloon.hide();
            if (myCallback != null) {
                myCallback.run();
            }
        }
    });
    balloon.show(point, position);
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) Balloon(com.intellij.openapi.ui.popup.Balloon) BalloonBuilder(com.intellij.openapi.ui.popup.BalloonBuilder)

Example 12 with BalloonBuilder

use of com.intellij.openapi.ui.popup.BalloonBuilder in project intellij-community by JetBrains.

the class IdeTooltipManager method show.

private void show(final IdeTooltip tooltip, @Nullable Runnable beforeShow, boolean animationEnabled) {
    boolean toCenterX;
    boolean toCenterY;
    boolean toCenter = tooltip.isToCenter();
    boolean small = false;
    if (!toCenter && tooltip.isToCenterIfSmall()) {
        Dimension size = tooltip.getComponent().getSize();
        toCenterX = size.width < 64;
        toCenterY = size.height < 64;
        toCenter = toCenterX || toCenterY;
        small = true;
    } else {
        toCenterX = true;
        toCenterY = true;
    }
    Point effectivePoint = tooltip.getPoint();
    if (toCenter) {
        Rectangle bounds = tooltip.getComponent().getBounds();
        effectivePoint.x = toCenterX ? bounds.width / 2 : effectivePoint.x;
        effectivePoint.y = toCenterY ? bounds.height / 2 : effectivePoint.y;
    }
    if (myCurrentComponent == tooltip.getComponent() && myCurrentTipUi != null && !myCurrentTipUi.isDisposed()) {
        myCurrentTipUi.show(new RelativePoint(tooltip.getComponent(), effectivePoint), tooltip.getPreferredPosition());
        return;
    }
    if (myCurrentComponent == tooltip.getComponent() && effectivePoint.equals(new Point(myX, myY))) {
        return;
    }
    Color bg = tooltip.getTextBackground() != null ? tooltip.getTextBackground() : getTextBackground(true);
    Color fg = tooltip.getTextForeground() != null ? tooltip.getTextForeground() : getTextForeground(true);
    Color border = tooltip.getBorderColor() != null ? tooltip.getBorderColor() : getBorderColor(true);
    BalloonBuilder builder = myPopupFactory.createBalloonBuilder(tooltip.getTipComponent()).setFillColor(bg).setBorderColor(border).setBorderInsets(tooltip.getBorderInsets()).setAnimationCycle(animationEnabled ? Registry.intValue("ide.tooltip.animationCycle") : 0).setShowCallout(true).setCalloutShift(small && tooltip.getCalloutShift() == 0 ? 2 : tooltip.getCalloutShift()).setPositionChangeXShift(tooltip.getPositionChangeX()).setPositionChangeYShift(tooltip.getPositionChangeY()).setHideOnKeyOutside(!tooltip.isExplicitClose()).setHideOnAction(!tooltip.isExplicitClose()).setRequestFocus(tooltip.isRequestFocus()).setLayer(tooltip.getLayer());
    tooltip.getTipComponent().setForeground(fg);
    tooltip.getTipComponent().setBorder(JBUI.Borders.empty(1, 3, 2, 3));
    tooltip.getTipComponent().setFont(tooltip.getFont() != null ? tooltip.getFont() : getTextFont(true));
    if (beforeShow != null) {
        beforeShow.run();
    }
    myCurrentTipUi = (BalloonImpl) builder.createBalloon();
    myCurrentTipUi.setAnimationEnabled(animationEnabled);
    tooltip.setUi(myCurrentTipUi);
    myCurrentComponent = tooltip.getComponent();
    myX = effectivePoint.x;
    myY = effectivePoint.y;
    myCurrentTipIsCentered = toCenter;
    myCurrentTooltip = tooltip;
    myShowRequest = null;
    myQueuedComponent = null;
    myQueuedTooltip = null;
    myLastDisposable = myCurrentTipUi;
    Disposer.register(myLastDisposable, new Disposable() {

        @Override
        public void dispose() {
            myLastDisposable = null;
        }
    });
    myCurrentTipUi.show(new RelativePoint(tooltip.getComponent(), effectivePoint), tooltip.getPreferredPosition());
    myAlarm.addRequest(() -> {
        if (myCurrentTooltip == tooltip && tooltip.canBeDismissedOnTimeout()) {
            hideCurrent(null, null, null);
        }
    }, tooltip.getDismissDelay());
}
Also used : Disposable(com.intellij.openapi.Disposable) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) BalloonBuilder(com.intellij.openapi.ui.popup.BalloonBuilder)

Example 13 with BalloonBuilder

use of com.intellij.openapi.ui.popup.BalloonBuilder in project intellij-community by JetBrains.

the class InplaceRefactoring method showBalloon.

protected void showBalloon() {
    final JComponent component = getComponent();
    if (component == null)
        return;
    if (ApplicationManager.getApplication().isHeadlessEnvironment())
        return;
    final BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createDialogBalloonBuilder(component, null).setSmallVariant(true);
    myBalloon = balloonBuilder.createBalloon();
    Disposer.register(myProject, myBalloon);
    Disposer.register(myBalloon, new Disposable() {

        @Override
        public void dispose() {
            releaseIfNotRestart();
            myEditor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION, null);
        }
    });
    EditorUtil.disposeWithEditor(myEditor, myBalloon);
    myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
    final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
    myBalloon.show(new PositionTracker<Balloon>(myEditor.getContentComponent()) {

        @Override
        public RelativePoint recalculateLocation(Balloon object) {
            if (myTarget != null && !popupFactory.isBestPopupLocationVisible(myEditor)) {
                return myTarget;
            }
            if (myCaretRangeMarker != null && myCaretRangeMarker.isValid()) {
                myEditor.putUserData(PopupFactoryImpl.ANCHOR_POPUP_POSITION, myEditor.offsetToVisualPosition(myCaretRangeMarker.getStartOffset()));
            }
            final RelativePoint target = popupFactory.guessBestPopupLocation(myEditor);
            final Point screenPoint = target.getScreenPoint();
            int y = screenPoint.y;
            if (target.getPoint().getY() > myEditor.getLineHeight() + myBalloon.getPreferredSize().getHeight()) {
                y -= myEditor.getLineHeight();
            }
            myTarget = new RelativePoint(new Point(screenPoint.x, y));
            return myTarget;
        }
    }, Balloon.Position.above);
}
Also used : Disposable(com.intellij.openapi.Disposable) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) Balloon(com.intellij.openapi.ui.popup.Balloon) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) BalloonBuilder(com.intellij.openapi.ui.popup.BalloonBuilder)

Example 14 with BalloonBuilder

use of com.intellij.openapi.ui.popup.BalloonBuilder in project intellij-community by JetBrains.

the class PyStudyExecutor method showNoSdkNotification.

public void showNoSdkNotification(@NotNull final Project project) {
    final String text = "<html>No Python interpreter configured for the project<br><a href=\"\">Configure interpreter</a></html>";
    final BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(text, null, MessageType.WARNING.getPopupBackground(), event -> {
        if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
            ApplicationManager.getApplication().invokeLater(() -> ShowSettingsUtil.getInstance().showSettingsDialog(project, "Project Interpreter"));
        }
    });
    balloonBuilder.setHideOnLinkClick(true);
    final Balloon balloon = balloonBuilder.createBalloon();
    StudyUtils.showCheckPopUp(project, balloon);
}
Also used : Balloon(com.intellij.openapi.ui.popup.Balloon) BalloonBuilder(com.intellij.openapi.ui.popup.BalloonBuilder)

Aggregations

BalloonBuilder (com.intellij.openapi.ui.popup.BalloonBuilder)14 Balloon (com.intellij.openapi.ui.popup.Balloon)12 RelativePoint (com.intellij.ui.awt.RelativePoint)7 Disposable (com.intellij.openapi.Disposable)3 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2 Project (com.intellij.openapi.project.Project)2 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)2 JBLabel (com.intellij.ui.components.JBLabel)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 MouseEvent (java.awt.event.MouseEvent)2 ArrayList (java.util.ArrayList)2 Executor (com.intellij.execution.Executor)1 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)1 JsonBundle (com.intellij.json.JsonBundle)1 CommonShortcuts (com.intellij.openapi.actionSystem.CommonShortcuts)1 ModalityState (com.intellij.openapi.application.ModalityState)1 FileChooserDescriptorFactory (com.intellij.openapi.fileChooser.FileChooserDescriptorFactory)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)1