Example usage for com.intellij.openapi.ui.popup Balloon show

List of usage examples for com.intellij.openapi.ui.popup Balloon show

Introduction

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

Prototype

void show(RelativePoint target, Position preferredPosition);

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);/*from   ww  w . ja  v a  2s  .  co  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.chrisrm.idea.notifications.Notify.java

License:Open Source License

/**
 * Show a notification using the Balloon API instead of the bus
 * Credit to @vladsch// ww  w. j  a v  a  2 s. com
 *
 * @param project      the project to display into
 * @param notification the notification to display
 */
private static void showFullNotification(final Project project, final Notification notification) {
    {
        final IdeFrame frame = WindowManager.getInstance().getIdeFrame(project);
        final Rectangle bounds = frame.getComponent().getBounds();
        final RelativePoint target = new RelativePoint(new Point(bounds.x + bounds.width, 0));

        try {
            // Create a notification balloon using the manager
            final Balloon balloon = NotificationsManagerImpl.createBalloon(frame, notification, true, true,
                    BalloonLayoutData.fullContent(), () -> {
                    });
            // Display the balloon at the top right
            balloon.show(target, Balloon.Position.atLeft);
        } catch (final NoSuchMethodError | NoClassDefFoundError | NoSuchFieldError e) {
            notification.notify(project);
        }
    }
}

From source file:com.demonwav.mcdev.platform.mcp.actions.FindSrgMappingAction.java

License:Open Source License

private void showBalloon(@NotNull AnActionEvent e) {
    final Balloon balloon = JBPopupFactory.getInstance()
            .createHtmlTextBalloonBuilder("No mappings found", null, LightColors.YELLOW, null)
            .setHideOnAction(true).setHideOnClickOutside(true).setHideOnKeyOutside(true).createBalloon();

    final StatusBar statusBar = WindowManager.getInstance()
            .getStatusBar(DataKeys.PROJECT.getData(e.getDataContext()));

    ApplicationManager.getApplication().invokeLater(
            () -> balloon.show(RelativePoint.getCenterOf(statusBar.getComponent()), Balloon.Position.atRight));
}

From source file:com.demonwav.mcdev.platform.mcp.actions.FindSrgMappingAction.java

License:Open Source License

private void showSuccessBalloon(@NotNull Editor editor, @NotNull PsiElement element, @NotNull String text) {
    final Balloon balloon = JBPopupFactory.getInstance()
            .createHtmlTextBalloonBuilder("SRG name: " + text, null, LightColors.SLIGHTLY_GREEN, null)
            .setHideOnAction(true).setHideOnClickOutside(true).setHideOnKeyOutside(true).createBalloon();

    ApplicationManager.getApplication()/*from  ww  w .  ja  va2  s  .  c  o  m*/
            .invokeLater(
                    () -> balloon.show(
                            new RelativePoint(editor.getContentComponent(),
                                    editor.visualPositionToXY(editor
                                            .offsetToVisualPosition(element.getTextRange().getEndOffset()))),
                            Balloon.Position.atRight));
}

From source file:com.demonwav.mcdev.platform.mcp.actions.GotoAtEntryAction.java

License:Open Source License

private void showBalloon(@NotNull AnActionEvent e) {
    final Balloon balloon = JBPopupFactory.getInstance()
            .createHtmlTextBalloonBuilder("No access transformer entry found", null, LightColors.YELLOW, null)
            .setHideOnAction(true).setHideOnClickOutside(true).setHideOnKeyOutside(true).createBalloon();

    final StatusBar statusBar = WindowManager.getInstance()
            .getStatusBar(DataKeys.PROJECT.getData(e.getDataContext()));

    ApplicationManager.getApplication().invokeLater(
            () -> balloon.show(RelativePoint.getCenterOf(statusBar.getComponent()), Balloon.Position.atRight));
}

From source file:com.gogh.plugin.action.SelectPlatform.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    Balloon myBalloon = buildBalloon(jbPanel).setCloseButtonEnabled(false).createBalloon();
    myBalloon.show(JBPopupFactory.getInstance()
            .guessBestPopupLocation(CommonDataKeys.EDITOR.getData(e.getDataContext())), Balloon.Position.below);
}

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/*  ww w . j  av a  2 s .  c  o  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.codeInsight.intention.impl.QuickEditHandler.java

License:Apache License

public void navigate(int injectedOffset) {
    if (myAction.isShowInBalloon()) {
        Ref<Balloon> ref = Ref.create(null);
        final JComponent component = myAction.createBalloonComponent(myNewFile, ref);
        if (component != null) {
            final Balloon balloon = JBPopupFactory.getInstance().createBalloonBuilder(component).setShadow(true)
                    .setAnimationCycle(0).setHideOnClickOutside(true).setHideOnKeyOutside(true)
                    .setHideOnAction(false).setFillColor(UIUtil.getControlColor()).createBalloon();
            ref.set(balloon);/*w ww . j a va2s .  co  m*/
            Disposer.register(myNewFile.getProject(), balloon);
            final Balloon.Position position = QuickEditAction.getBalloonPosition(myEditor);
            RelativePoint point = JBPopupFactory.getInstance().guessBestPopupLocation(myEditor);
            if (position == Balloon.Position.above) {
                final Point p = point.getPoint();
                point = new RelativePoint(point.getComponent(), new Point(p.x, p.y - myEditor.getLineHeight()));
            }
            balloon.show(point, position);
        }
    } else {
        final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(myProject);
        final FileEditor[] editors = fileEditorManager.getEditors(myNewVirtualFile);
        if (editors.length == 0) {
            final EditorWindow curWindow = fileEditorManager.getCurrentWindow();
            mySplittedWindow = curWindow.split(SwingConstants.HORIZONTAL, false, myNewVirtualFile, true);
        }
        Editor editor = fileEditorManager
                .openTextEditor(new OpenFileDescriptor(myProject, myNewVirtualFile, injectedOffset), true);
        // fold missing values
        if (editor != null) {
            editor.putUserData(QuickEditAction.QUICK_EDIT_HANDLER, this);
            final FoldingModel foldingModel = editor.getFoldingModel();
            foldingModel.runBatchFoldingOperation(new Runnable() {
                @Override
                public void run() {
                    for (RangeMarker o : ContainerUtil
                            .reverse(((DocumentEx) myNewDocument).getGuardedBlocks())) {
                        String replacement = o.getUserData(REPLACEMENT_KEY);
                        if (StringUtil.isEmpty(replacement))
                            continue;
                        FoldRegion region = foldingModel.addFoldRegion(o.getStartOffset(), o.getEndOffset(),
                                replacement);
                        if (region != null)
                            region.setExpanded(false);
                    }
                }
            });
        }
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
            }
        });

    }
}