Example usage for com.intellij.openapi.ui.popup BalloonBuilder createBalloon

List of usage examples for com.intellij.openapi.ui.popup BalloonBuilder createBalloon

Introduction

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

Prototype

@NotNull
    Balloon createBalloon();

Source Link

Usage

From source file:com.android.tools.idea.gradle.editor.ui.ReferencedValuesGradleEditorComponent.java

License:Apache License

public ReferencedValuesGradleEditorComponent() {
    super(new GridBagLayout());
    final JBLabel label = new JBLabel("<~>");
    label.setCursor(new Cursor(Cursor.HAND_CURSOR));
    setBackground(GradleEditorUiConstants.BACKGROUND_COLOR);
    TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme()
            .getAttributes(EditorColors.FOLDED_TEXT_ATTRIBUTES);
    if (attributes != null) {
        Color color = attributes.getForegroundColor();
        if (color != null) {
            label.setForeground(color);//www .  j  a  v  a2 s . c o  m
        }
    }
    add(label, new GridBag());
    label.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent e) {
            WeakReference<Project> projectRef = myProjectRef;
            if (projectRef == null) {
                return;
            }
            Project project = projectRef.get();
            if (project == null) {
                return;
            }
            final Ref<Balloon> balloonRef = new Ref<Balloon>();
            Content content = new Content(project, new Runnable() {
                @Override
                public void run() {
                    Balloon balloon = balloonRef.get();
                    if (balloon != null && !balloon.isDisposed()) {
                        Disposer.dispose(balloon);
                        balloonRef.set(null);
                    }
                }
            });
            BalloonBuilder builder = JBPopupFactory.getInstance().createBalloonBuilder(content)
                    .setDisposable(project).setShowCallout(false)
                    .setAnimationCycle(GradleEditorUiConstants.ANIMATION_TIME_MILLIS)
                    .setFillColor(JBColor.border());
            Balloon balloon = builder.createBalloon();
            balloonRef.set(balloon);
            balloon.show(new RelativePoint(label, new Point(label.getWidth() / 2, label.getHeight())),
                    Balloon.Position.atRight);
        }
    });
}

From source file:com.igormaznitsa.ideamindmap.utils.IdeaUtils.java

License:Apache License

public static void showPopup(@Nonnull final String text, @Nonnull final MessageType type) {
    SwingUtils.safeSwing(new Runnable() {
        @Override/*from  www .j  a va  2  s.  co  m*/
        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);
        }
    });
}

From source file:com.intellij.application.options.codeStyle.ManageCodeStyleSchemesDialog.java

License:Apache License

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);
}

From source file:com.intellij.application.options.GeneralCodeStylePanel.java

License:Apache License

private static void showError(final JTextField field, final String message) {
    BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(message,
            MessageType.ERROR.getDefaultIcon(), MessageType.ERROR.getPopupBackground(), 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);
}

From source file:com.intellij.find.impl.livePreview.LivePreview.java

License:Apache License

private void showBalloon(Editor editor, String replacementPreviewText) {
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        myReplacementPreviewText = replacementPreviewText;
        return;/*from  w  w w  .j a v a  2  s .c  om*/
    }

    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();

    myReplacementBalloon.show(new ReplacementBalloonPositionTracker(editor), Balloon.Position.above);
}

From source file:com.intellij.ide.IdeTooltipManager.java

License:Apache License

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;/* ww w. ja  v a2 s.c  om*/
        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.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())
            .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();
    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;

    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());
}

From source file:com.intellij.notification.impl.NotificationsManagerImpl.java

License:Apache License

public static Balloon createBalloon(@NotNull final IdeFrame window, final Notification notification,
        final boolean showCallout, final boolean hideOnClickOutside) {
    final JEditorPane text = new JEditorPane();
    text.setEditorKit(UIUtil.getHTMLEditorKit());

    final HyperlinkListener listener = NotificationsUtil.wrapListener(notification);
    if (listener != null) {
        text.addHyperlinkListener(listener);
    }//  w w w .  j a  va 2  s. co m

    final JLabel label = new JLabel(NotificationsUtil.buildHtml(notification, null));
    text.setText(NotificationsUtil.buildHtml(notification,
            "width:" + Math.min(350, label.getPreferredSize().width) + "px;"));
    text.setEditable(false);
    text.setOpaque(false);

    if (UIUtil.isUnderNimbusLookAndFeel()) {
        text.setBackground(UIUtil.TRANSPARENT_COLOR);
    }

    text.setBorder(null);

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

    if (text.getCaret() != null) {
        text.setCaretPosition(0);
    }
    JScrollPane pane = ScrollPaneFactory.createScrollPane(text,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    pane.setBorder(null);
    pane.setOpaque(false);
    pane.getViewport().setOpaque(false);
    content.add(pane, BorderLayout.CENTER);

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

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

    Dimension preferredSize = text.getPreferredSize();
    text.setSize(preferredSize);

    Dimension paneSize = new Dimension(text.getPreferredSize());
    int maxHeight = Math.min(400, window.getComponent().getHeight() - 20);
    int maxWidth = Math.min(600, window.getComponent().getWidth() - 20);
    if (paneSize.height > maxHeight) {
        pane.setPreferredSize(
                new Dimension(Math.min(maxWidth, paneSize.width + UIUtil.getScrollBarWidth()), maxHeight));
    } else if (paneSize.width > maxWidth) {
        pane.setPreferredSize(new Dimension(maxWidth, paneSize.height + UIUtil.getScrollBarWidth()));
    }

    final BalloonBuilder builder = JBPopupFactory.getInstance().createBalloonBuilder(content);
    builder.setFillColor(new JBColor(Gray._234, Gray._92)).setCloseButtonEnabled(true)
            .setShowCallout(showCallout).setShadow(false).setHideOnClickOutside(hideOnClickOutside)
            .setHideOnAction(hideOnClickOutside).setHideOnKeyOutside(hideOnClickOutside)
            .setHideOnFrameResize(false).setBorderColor(new JBColor(Gray._180, Gray._110));

    final Balloon balloon = builder.createBalloon();
    balloon.setAnimationEnabled(false);
    notification.setBalloon(balloon);
    return balloon;
}

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 . j a  va  2s  .  c o  m*/
    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:com.kstenschke.clearcache.ClearCacheAction.java

License:Apache License

/**
 * @param   event    ActionSystem event/*from  w w w . ja v  a2s  .co  m*/
 */
public void actionPerformed(AnActionEvent event) {
    String[] cachePaths = {};

    String cachePathsPrefString = ClearCachePreferences.getPaths();
    if (cachePathsPrefString != null && !cachePathsPrefString.isEmpty()) {
        cachePaths = StringHelper.extractTreePathStringsFromPref(cachePathsPrefString);
    }

    if (cachePaths == null || cachePaths.length == 0) {
        JOptionPane.showMessageDialog(null, "Please configure cache path(s) in the plugin preferences.");
    } else {
        Integer[] amountDeleted = this.clearFoldersContent(cachePaths);

        Balloon.Position pos = Balloon.Position.below;
        String balloonText = "Deleted " + amountDeleted[0] + " directories and " + amountDeleted[1] + " files";

        BalloonBuilder builder = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(balloonText, null,
                new Color(245, 245, 245), null);
        Balloon balloon = builder.createBalloon();
        balloon.setAnimationEnabled(true);

        Component eventComponent = event.getInputEvent().getComponent();
        Point componentLocation = eventComponent.getLocation();
        Integer x = new Double(componentLocation.getX()).intValue() + eventComponent.getWidth() + 40;
        Integer y = new Double(componentLocation.getY()).intValue() + eventComponent.getHeight() + 42;
        RelativePoint balloonPosition = new RelativePoint(new Point(x, y));

        balloon.show(balloonPosition, pos);
    }
}

From source file:com.kstenschke.shifter.models.shiftertypes.NumericValue.java

License:Apache License

/**
 * @param   value//  w  ww .ja v a2 s  .  c om
 * @param   isUp
 * @param   editor
 * @return  String          UNIX timestamp shifted plus/minus one day
 */
private String getShiftedUnixTimestamp(String value, boolean isUp, Editor editor) {
    int strLenOriginal = value.length();
    long shiftedTimestamp;

    shiftedTimestamp = Long.parseLong(value) + ((isUp ? SECONDS_PER_DAY : -SECONDS_PER_DAY)
            * (timestampShiftMode == ShifterPreferences.SHIFTING_MODE_TIMESTAMP_SECONDS ? 1 : 1000));

    // Create and show balloon with human-readable date
    Balloon.Position pos = Balloon.Position.above;
    String balloonText = "UNIX Time: " + new Date(shiftedTimestamp * 1000).toString() + "\nMilliseconds: "
            + new Date(shiftedTimestamp).toString();
    BalloonBuilder builder = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(balloonText, null,
            new JBColor(new Color(255, 255, 231), new Color(255, 255, 231)), null);
    Balloon balloon = builder.createBalloon();

    Point caretPos = editor.visualPositionToXY(editor.getCaretModel().getVisualPosition());
    RelativePoint balloonPosition = new RelativePoint(editor.getContentComponent(), caretPos);
    balloon.show(balloonPosition, pos);

    String valueShifted = Long.toString(shiftedTimestamp);

    if (strLenOriginal > valueShifted.length()) {
        // String has shrunk in length - maintain original leading zero's
        valueShifted = UtilsTextual.formatAmountDigits(valueShifted, strLenOriginal);
    }

    return valueShifted;
}