public static void showTestResultPopUp(
     final String text, Color color, @NotNull final Project project) {
   BalloonBuilder balloonBuilder =
       JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(text, null, color, null);
   final Balloon balloon = balloonBuilder.createBalloon();
   StudyUtils.showCheckPopUp(project, balloon);
 }
  @NotNull
  @Override
  public BalloonBuilder createHtmlTextBalloonBuilder(
      @NotNull final String htmlContent,
      @Nullable final Icon icon,
      final Color fillColor,
      @Nullable final HyperlinkListener listener) {

    JEditorPane text =
        IdeTooltipManager.initPane(htmlContent, new HintHint().setAwtTooltip(true), null);

    if (listener != null) {
      text.addHyperlinkListener(listener);
    }
    text.setEditable(false);
    NonOpaquePanel.setTransparent(text);
    text.setBorder(null);

    JLabel label = new JLabel();
    final JPanel content =
        new NonOpaquePanel(
            new BorderLayout(
                (int) (label.getIconTextGap() * 1.5), (int) (label.getIconTextGap() * 1.5)));

    final NonOpaquePanel textWrapper = new NonOpaquePanel(new GridBagLayout());
    JScrollPane scrolledText = new JScrollPane(text);
    scrolledText.setBackground(fillColor);
    scrolledText.getViewport().setBackground(fillColor);
    scrolledText.getViewport().setBorder(null);
    scrolledText.setBorder(null);
    textWrapper.add(scrolledText);
    content.add(textWrapper, BorderLayout.CENTER);

    final NonOpaquePanel north = new NonOpaquePanel(new BorderLayout());
    north.add(new JLabel(icon), BorderLayout.NORTH);
    content.add(north, BorderLayout.WEST);

    content.setBorder(new EmptyBorder(2, 4, 2, 4));

    final BalloonBuilder builder = createBalloonBuilder(content);

    builder.setFillColor(fillColor);

    return builder;
  }
 /**
  * Asks to show balloon that contains information related to the given component.
  *
  * @param component component for which we want to show information
  * @param messageType balloon message type
  * @param message message to show
  */
 public static void showBalloon(
     @NotNull JComponent component, @NotNull MessageType messageType, @NotNull String message) {
   final BalloonBuilder delegate =
       JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(message, messageType, null);
   BalloonBuilder balloonBuilder = new GradleBalloonBuilder(delegate, APPLICATION_BALLOONS);
   ApplicationBalloonsDisposeActivator.ensureActivated();
   Balloon balloon = balloonBuilder.setFadeoutTime(TimeUnit.SECONDS.toMillis(1)).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);
 }
 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);
 }
  private void showBalloon(FindResult cursor, Editor editor, String replacementPreviewText) {
    if (ApplicationManager.getApplication().isUnitTestMode()) {
      myReplacementPreviewText = replacementPreviewText;
      return;
    }

    ReplacementView replacementView = new ReplacementView(replacementPreviewText, cursor);

    BalloonBuilder balloonBuilder =
        JBPopupFactory.getInstance().createBalloonBuilder(replacementView);
    balloonBuilder.setFadeoutTime(0);
    balloonBuilder.setFillColor(IdeTooltipManager.GRAPHITE_COLOR);
    balloonBuilder.setAnimationCycle(0);
    balloonBuilder.setHideOnClickOutside(false);
    balloonBuilder.setHideOnKeyOutside(false);
    balloonBuilder.setHideOnAction(false);
    balloonBuilder.setCloseButtonEnabled(true);
    myReplacementBalloon = balloonBuilder.createBalloon();

    myReplacementBalloon.show(
        new ReplacementBalloonPositionTracker(editor), Balloon.Position.above);
  }
  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()
        && 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())
            .setPreferredPosition(tooltip.getPreferredPosition())
            .setFillColor(bg)
            .setBorderColor(border)
            .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())
            .setLayer(tooltip.getLayer());
    tooltip.getTipComponent().setForeground(fg);
    tooltip.getTipComponent().setBorder(new EmptyBorder(1, 3, 2, 3));
    tooltip
        .getTipComponent()
        .setFont(tooltip.getFont() != null ? tooltip.getFont() : getTextFont(true));

    if (beforeShow != null) {
      beforeShow.run();
    }

    myCurrentTipUi = (BalloonImpl) builder.createBalloon();
    tooltip.setUi(myCurrentTipUi);
    myCurrentComponent = tooltip.getComponent();
    myX = effectivePoint.x;
    myY = effectivePoint.y;
    myCurrentTipIsCentered = toCenter;
    myCurrentTooltip = tooltip;
    myShowRequest = null;
    myQueuedComponent = null;
    myQueuedTooltip = null;

    myCurrentTipUi.show(
        new RelativePoint(tooltip.getComponent(), effectivePoint), tooltip.getPreferredPosition());
    myAlarm.addRequest(
        new Runnable() {
          @Override
          public void run() {
            if (myCurrentTooltip == tooltip && tooltip.canBeDismissedOnTimeout()) {
              hideCurrent(null, null, null);
            }
          }
        },
        tooltip.getDismissDelay());
  }