com.intellij.openapi.ui.popup.BalloonBuilder Java Examples

The following examples show how to use com.intellij.openapi.ui.popup.BalloonBuilder. 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: LivePreview.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void showBalloon(Editor editor, String replacementPreviewText) {
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    myReplacementPreviewText = replacementPreviewText;
    return;
  }

  ReplacementView replacementView = new ReplacementView(replacementPreviewText);

  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();
  EditorUtil.disposeWithEditor(editor, myReplacementBalloon);
  myReplacementBalloon.show(new ReplacementBalloonPositionTracker(editor), Balloon.Position.below);
}
 
Example #2
Source File: UiUtils.java    From Crucible4IDEA with MIT License 6 votes vote down vote up
public static void showBalloon(@NotNull final Project project, @NotNull final String message,
                               @NotNull final MessageType messageType) {
  final JFrame frame = WindowManager.getInstance().getFrame(project.isDefault() ? null : project);
  if (frame == null) return;
  final JComponent component = frame.getRootPane();
  if (component == null) return;
  final Rectangle rect = component.getVisibleRect();
  final Point p = new Point(rect.x + rect.width - 10, rect.y + 10);
  final RelativePoint point = new RelativePoint(component, p);

  final BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().
    createHtmlTextBalloonBuilder(message, messageType.getDefaultIcon(),
                                 messageType.getPopupBackground(), null);
  balloonBuilder.setShowCallout(false).setCloseButtonEnabled(true)
                .createBalloon().show(point, Balloon.Position.atLeft);
}
 
Example #3
Source File: ExternalSystemUiUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * 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(@Nonnull JComponent component, @Nonnull MessageType messageType, @Nonnull String message) {
  final BalloonBuilder builder = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(message, messageType, null)
    .setDisposable(ApplicationManager.getApplication())
    .setFadeoutTime(BALLOON_FADEOUT_TIME);
  Balloon balloon = builder.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 #4
Source File: PropertyEditorPanel.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Balloon showPopupHelper(
  InspectorGroupManagerService inspectorService,
  Project project,
  @Nullable DiagnosticsNode node,
  @NotNull InspectorService.Location location,
  FlutterDartAnalysisServer service
) {
  final Color GRAPHITE_COLOR = new JBColor(new Color(236, 236, 236, 215), new Color(60, 63, 65, 215));

  final Disposable panelDisposable = Disposer.newDisposable();
  final PropertyEditorPanel panel =
    new PropertyEditorPanel(inspectorService, project, service, true, true, panelDisposable);

  final StableWidgetTracker tracker = new StableWidgetTracker(location, service, project, panelDisposable);

  final EventStream<VirtualFile> activeFile = new EventStream<>(location.getFile());
  panel.initalize(node, tracker.getCurrentOutlines(), activeFile);

  panel.setBackground(GRAPHITE_COLOR);
  panel.setOpaque(false);
  final BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createBalloonBuilder(panel);
  balloonBuilder.setFadeoutTime(0);
  balloonBuilder.setFillColor(GRAPHITE_COLOR);
  balloonBuilder.setAnimationCycle(0);
  balloonBuilder.setHideOnClickOutside(true);
  balloonBuilder.setHideOnKeyOutside(false);
  balloonBuilder.setHideOnAction(false);
  balloonBuilder.setCloseButtonEnabled(false);
  balloonBuilder.setBlockClicksThroughBalloon(true);
  balloonBuilder.setRequestFocus(true);
  balloonBuilder.setShadow(true);
  final Balloon balloon = balloonBuilder.createBalloon();
  Disposer.register(balloon, panelDisposable);

  return balloon;
}
 
Example #5
Source File: InplaceChangeSignature.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void showBalloon() {
  NonFocusableCheckBox checkBox = new NonFocusableCheckBox(RefactoringBundle.message("delegation.panel.delegate.via.overloading.method"));
  checkBox.addActionListener(e -> {
    myDelegate = checkBox.isSelected();
    updateCurrentInfo();
  });
  JPanel content = new JPanel(new BorderLayout());
  content.add(new JBLabel("Performed signature modifications:"), BorderLayout.NORTH);
  content.add(myPreview.getComponent(), BorderLayout.CENTER);
  updateMethodSignature(myStableChange);
  content.add(checkBox, BorderLayout.SOUTH);
  final BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createDialogBalloonBuilder(content, null).setSmallVariant(true);
  myBalloon = balloonBuilder.createBalloon();
  myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
  myBalloon.show(new PositionTracker<Balloon>(myEditor.getContentComponent()) {
    @Override
    public RelativePoint recalculateLocation(Balloon object) {
      int offset = myStableChange.getMethod().getTextOffset();
      VisualPosition visualPosition = myEditor.offsetToVisualPosition(offset);
      Point point = myEditor.visualPositionToXY(new VisualPosition(visualPosition.line, visualPosition.column));
      return new RelativePoint(myEditor.getContentComponent(), point);
    }
  }, Balloon.Position.above);
  Disposer.register(myBalloon, () -> {
    EditorFactory.getInstance().releaseEditor(myPreview);
    myPreview = null;
  });
}
 
Example #6
Source File: ManageCodeStyleSchemesDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void showStatus(final Component component, final String message, MessageType messageType) {
  BalloonBuilder balloonBuilder = JBPopupFactory.getInstance()
    .createHtmlTextBalloonBuilder(message, messageType.getDefaultIcon(),
                                  messageType.getPopupBackground(), null);
  balloonBuilder.setFadeoutTime(5000);
  final Balloon balloon = balloonBuilder.createBalloon();
  final Rectangle rect = component.getBounds();
  final Point p = new Point(rect.x, rect.y + rect.height);
  final RelativePoint point = new RelativePoint(component, p);
  balloon.show(point, Balloon.Position.below);
  Disposer.register(ProjectManager.getInstance().getDefaultProject(), balloon);
}
 
Example #7
Source File: GeneralCodeStylePanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void showError(final JTextField field, final String message) {
  BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(message, MessageType.ERROR, null);
  balloonBuilder.setFadeoutTime(1500);
  final Balloon balloon = balloonBuilder.createBalloon();
  final Rectangle rect = field.getBounds();
  final Point p = new Point(0, rect.height);
  final RelativePoint point = new RelativePoint(field, p);
  balloon.show(point, Balloon.Position.below);
  Disposer.register(ProjectManager.getInstance().getDefaultProject(), balloon);
}
 
Example #8
Source File: BalloonPopupBuilderImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public BalloonBuilder setClickHandler(ActionListener listener, boolean closeOnClick) {
  myClickHandler = listener;
  myCloseOnClick = closeOnClick;
  return this;
}
 
Example #9
Source File: MessageUtils.java    From leetcode-editor with Apache License 2.0 5 votes vote down vote up
public static void showMsg(JComponent component, MessageType messageType, String title, String body) {
    JBPopupFactory factory = JBPopupFactory.getInstance();
    BalloonBuilder builder = factory.createHtmlTextBalloonBuilder(body, messageType, null);
    builder.setTitle(title);
    builder.setFillColor(JBColor.background());
    Balloon b = builder.createBalloon();
    Rectangle r = component.getBounds();
    RelativePoint p = new RelativePoint(component, new Point(r.x + r.width, r.y + 30));
    b.show(p, Balloon.Position.atRight);
}
 
Example #10
Source File: GotItMessage.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void show(RelativePoint point, Balloon.Position position) {
  final GotItPanel panel = new GotItPanel();
  panel.myTitle.setText(myTitle);
  panel.myMessage.setText(myMessage);

  panel.myButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  final BalloonBuilder builder = JBPopupFactory.getInstance().createBalloonBuilder(panel.myRoot);
  if (myDisposable != null) {
    builder.setDisposable(myDisposable);
  }

  builder.setFillColor(UIUtil.getListBackground());
  builder.setHideOnClickOutside(false);
  builder.setHideOnAction(false);
  builder.setHideOnFrameResize(false);
  builder.setHideOnKeyOutside(false);
  builder.setShowCallout(myShowCallout);
  builder.setBlockClicksThroughBalloon(true);
  final Balloon balloon = builder.createBalloon();
  panel.myButton.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
      balloon.hide();
      if (myCallback != null) {
        myCallback.run();
      }
    }
  });

  balloon.show(point, position);
}
 
Example #11
Source File: UsagePreviewPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void showBalloon(Project project, Editor editor, TextRange range, @Nonnull FindModel findModel) {
  try {
    String replacementPreviewText = FindManager.getInstance(project).getStringToReplace(editor.getDocument().getText(range), findModel, range.getStartOffset(), editor.getDocument().getText());
    if (!Registry.is("ide.find.show.replacement.hint.for.simple.regexp") && (Comparing.equal(replacementPreviewText, findModel.getStringToReplace()))) {
      return;
    }
    ReplacementView replacementView = new ReplacementView(replacementPreviewText);

    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);
    Balloon balloon = balloonBuilder.createBalloon();
    EditorUtil.disposeWithEditor(editor, balloon);

    balloon.show(new ReplacementBalloonPositionTracker(project, editor, range, findModel), Balloon.Position.below);
    editor.putUserData(REPLACEMENT_BALLOON_KEY, balloon);

  }
  catch (FindManager.MalformedReplacementStringException e) {
    //Not a problem, just don't show balloon in this case
  }
}
 
Example #12
Source File: GLSLDeduceExpressionTypeAction.java    From glsl4idea with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void showBalloon(AnActionEvent e, String html) {
    final Editor editor = e.getData(CommonDataKeys.EDITOR_EVEN_IF_INACTIVE);
    if(editor == null) return;
    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);
}
 
Example #13
Source File: IdeaUtils.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
public static void showPopup(@Nonnull final String text, @Nonnull final MessageType type) {
  SwingUtils.safeSwing(new Runnable() {
    @Override
    public void run() {
      final JBPopupFactory factory = JBPopupFactory.getInstance();
      final BalloonBuilder builder = factory.createHtmlTextBalloonBuilder(StringEscapeUtils.escapeHtml(text), type, null);
      final Balloon balloon = builder.createBalloon();
      balloon.setAnimationEnabled(true);
      final Component frame = WindowManager.getInstance().findVisibleFrame();
      if (frame != null) {
        balloon.show(new RelativePoint(frame, new Point(frame.getWidth(), frame.getHeight())), Balloon.Position.below);
      }
    }
  });
}
 
Example #14
Source File: PropertyEditorPanel.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Balloon showPopupHelper(
  InspectorGroupManagerService inspectorService,
  Project project,
  @Nullable DiagnosticsNode node,
  @NotNull InspectorService.Location location,
  FlutterDartAnalysisServer service
) {
  final Color GRAPHITE_COLOR = new JBColor(new Color(236, 236, 236, 215), new Color(60, 63, 65, 215));

  final Disposable panelDisposable = Disposer.newDisposable();
  final PropertyEditorPanel panel =
    new PropertyEditorPanel(inspectorService, project, service, true, true, panelDisposable);

  final StableWidgetTracker tracker = new StableWidgetTracker(location, service, project, panelDisposable);

  final EventStream<VirtualFile> activeFile = new EventStream<>(location.getFile());
  panel.initalize(node, tracker.getCurrentOutlines(), activeFile);

  panel.setBackground(GRAPHITE_COLOR);
  panel.setOpaque(false);
  final BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createBalloonBuilder(panel);
  balloonBuilder.setFadeoutTime(0);
  balloonBuilder.setFillColor(GRAPHITE_COLOR);
  balloonBuilder.setAnimationCycle(0);
  balloonBuilder.setHideOnClickOutside(true);
  balloonBuilder.setHideOnKeyOutside(false);
  balloonBuilder.setHideOnAction(false);
  balloonBuilder.setCloseButtonEnabled(false);
  balloonBuilder.setBlockClicksThroughBalloon(true);
  balloonBuilder.setRequestFocus(true);
  balloonBuilder.setShadow(true);
  final Balloon balloon = balloonBuilder.createBalloon();
  Disposer.register(balloon, panelDisposable);

  return balloon;
}
 
Example #15
Source File: IdeTooltipManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
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 borderColor = tooltip.getBorderColor() != null ? tooltip.getBorderColor() : getBorderColor(true);

  BalloonBuilder builder = JBPopupFactory.getInstance().createBalloonBuilder(tooltip.getTipComponent()).setFillColor(bg).setBorderColor(borderColor).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(tooltip.getComponentBorder());
  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());
}
 
Example #16
Source File: BalloonPopupBuilderImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public BalloonBuilder setDisposable(@Nonnull Disposable anchor) {
  myAnchor = anchor;
  return this;
}
 
Example #17
Source File: BalloonPopupBuilderImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public BalloonBuilder setLayer(Balloon.Layer layer) {
  myLayer = layer;
  return this;
}
 
Example #18
Source File: BalloonPopupBuilderImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public BalloonBuilder setSmallVariant(boolean smallVariant) {
  mySmallVariant = smallVariant;
  return this;
}
 
Example #19
Source File: BalloonPopupBuilderImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public BalloonBuilder setShadow(boolean shadow) {
  myShadow = shadow;
  return this;
}
 
Example #20
Source File: BalloonPopupBuilderImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public BalloonBuilder setContentInsets(Insets insets) {
  myContentInsets = insets;
  return this;
}
 
Example #21
Source File: BalloonPopupBuilderImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public BalloonBuilder setTitle(@Nullable String title) {
  myTitle = title;
  return this;
}
 
Example #22
Source File: BalloonPopupBuilderImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public BalloonBuilder setCalloutShift(int length) {
  myCalloutShift = length;
  return this;
}
 
Example #23
Source File: BalloonPopupBuilderImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public BalloonBuilder setCloseButtonEnabled(boolean enabled) {
  myCloseButtonEnabled = enabled;
  return this;
}
 
Example #24
Source File: BalloonPopupBuilderImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public BalloonBuilder setPositionChangeYShift(int positionChangeYShift) {
  myPositionChangeYShift = positionChangeYShift;
  return this;
}
 
Example #25
Source File: BalloonPopupBuilderImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public BalloonBuilder setPositionChangeXShift(int positionChangeXShift) {
  myPositionChangeXShift = positionChangeXShift;
  return this;
}
 
Example #26
Source File: BalloonPopupBuilderImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public BalloonBuilder setHideOnLinkClick(boolean hide) {
  myHideOnLinkClick = hide;
  return this;
}
 
Example #27
Source File: BalloonPopupBuilderImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public BalloonBuilder setHideOnFrameResize(boolean hide) {
  myHideOnFrameResize = hide;
  return this;
}
 
Example #28
Source File: BalloonPopupBuilderImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public BalloonBuilder setAnimationCycle(int time) {
  myAnimationCycle = time;
  return this;
}
 
Example #29
Source File: BalloonPopupBuilderImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public BalloonBuilder setHideOnCloseClick(boolean hideOnCloseClick) {
  myHideOnCloseClick = hideOnCloseClick;
  return this;
}
 
Example #30
Source File: BalloonPopupBuilderImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public BalloonBuilder setCornerToPointerDistance(int distance) {
  myCornerToPointerDistance = distance;
  return this;
}