Search in sources :

Example 11 with Balloon

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

the class DiffUtil method showSuccessPopup.

public static void showSuccessPopup(@NotNull String message, @NotNull RelativePoint point, @NotNull Disposable disposable, @Nullable Runnable hyperlinkHandler) {
    HyperlinkListener listener = null;
    if (hyperlinkHandler != null) {
        listener = new HyperlinkAdapter() {

            @Override
            protected void hyperlinkActivated(HyperlinkEvent e) {
                hyperlinkHandler.run();
            }
        };
    }
    Color bgColor = MessageType.INFO.getPopupBackground();
    Balloon balloon = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(message, null, bgColor, listener).setAnimationCycle(200).createBalloon();
    balloon.show(point, Balloon.Position.below);
    Disposer.register(disposable, balloon);
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) HyperlinkListener(javax.swing.event.HyperlinkListener) Balloon(com.intellij.openapi.ui.popup.Balloon)

Example 12 with Balloon

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

the class IdeGlassPaneImpl method preprocess.

private boolean preprocess(final MouseEvent e, final boolean motion, JRootPane eventRootPane) {
    try {
        if (UIUtil.getWindow(this) != UIUtil.getWindow(e.getComponent()))
            return false;
        final MouseEvent event = MouseEventAdapter.convert(e, eventRootPane);
        if (event.isAltDown() && SwingUtilities.isLeftMouseButton(event) && event.getID() == MouseEvent.MOUSE_PRESSED) {
            Component c = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY());
            Balloon balloon = JBPopupFactory.getInstance().getParentBalloonFor(c);
            if (balloon instanceof BalloonImpl) {
                JComponent component = ((BalloonImpl) balloon).getComponent();
                component.getToolkit().getSystemClipboard().setContents(new StringSelection(UIUtil.getDebugText(component)), EmptyClipboardOwner.INSTANCE);
            }
        }
        if (!IdeGlassPaneUtil.canBePreprocessed(e)) {
            return false;
        }
        for (EventListener each : mySortedMouseListeners) {
            if (motion && each instanceof MouseMotionListener) {
                fireMouseMotion((MouseMotionListener) each, event);
            } else if (!motion && each instanceof MouseListener) {
                fireMouseEvent((MouseListener) each, event);
            }
            if (event.isConsumed()) {
                e.consume();
                return true;
            }
        }
        return false;
    } finally {
        if (eventRootPane == myRootPane) {
            Cursor cursor;
            if (!myListener2Cursor.isEmpty()) {
                cursor = myListener2Cursor.values().iterator().next();
                final Point point = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), myRootPane.getContentPane());
                Component target = SwingUtilities.getDeepestComponentAt(myRootPane.getContentPane().getParent(), point.x, point.y);
                if (canProcessCursorFor(target)) {
                    target = getCompWithCursor(target);
                    restoreLastComponent(target);
                    if (target != null) {
                        if (myLastCursorComponent != target) {
                            myLastCursorComponent = target;
                            myLastOriginalCursor = target.getCursor();
                        }
                        if (cursor != null && !cursor.equals(target.getCursor())) {
                            if (target instanceof JComponent) {
                                ((JComponent) target).putClientProperty(PREPROCESSED_CURSOR_KEY, Boolean.TRUE);
                            }
                            target.setCursor(cursor);
                        }
                    }
                    getRootPane().setCursor(cursor);
                }
            } else if (!e.isConsumed() && e.getID() != MouseEvent.MOUSE_DRAGGED) {
                cursor = Cursor.getDefaultCursor();
                JRootPane rootPane = getRootPane();
                if (rootPane != null) {
                    rootPane.setCursor(cursor);
                } else {
                    LOG.warn("Root pane is null. Event: " + e);
                }
                restoreLastComponent(null);
                myLastOriginalCursor = null;
                myLastCursorComponent = null;
            }
            myListener2Cursor.clear();
        }
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseListener(java.awt.event.MouseListener) Balloon(com.intellij.openapi.ui.popup.Balloon) BalloonImpl(com.intellij.ui.BalloonImpl) AWTEventListener(java.awt.event.AWTEventListener) MouseMotionListener(java.awt.event.MouseMotionListener) StringSelection(java.awt.datatransfer.StringSelection)

Example 13 with Balloon

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

the class ToolWindowManagerImpl method notifyByBalloon.

@Override
public void notifyByBalloon(@NotNull final String toolWindowId, @NotNull final MessageType type, @NotNull final String text, @Nullable final Icon icon, @Nullable final HyperlinkListener listener) {
    checkId(toolWindowId);
    Balloon existing = myWindow2Balloon.get(toolWindowId);
    if (existing != null) {
        existing.hide();
    }
    final Stripe stripe = myToolWindowsPane.getStripeFor(toolWindowId);
    if (stripe == null) {
        return;
    }
    final ToolWindowImpl window = getInternalDecorator(toolWindowId).getToolWindow();
    if (!window.isAvailable()) {
        window.setPlaceholderMode(true);
        stripe.updatePresentation();
        stripe.revalidate();
        stripe.repaint();
    }
    final ToolWindowAnchor anchor = getInfo(toolWindowId).getAnchor();
    final Ref<Balloon.Position> position = Ref.create(Balloon.Position.below);
    if (ToolWindowAnchor.TOP == anchor) {
        position.set(Balloon.Position.below);
    } else if (ToolWindowAnchor.BOTTOM == anchor) {
        position.set(Balloon.Position.above);
    } else if (ToolWindowAnchor.LEFT == anchor) {
        position.set(Balloon.Position.atRight);
    } else if (ToolWindowAnchor.RIGHT == anchor) {
        position.set(Balloon.Position.atLeft);
    }
    final BalloonHyperlinkListener listenerWrapper = new BalloonHyperlinkListener(listener);
    final Balloon balloon = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(text.replace("\n", "<br>"), icon, type.getPopupBackground(), listenerWrapper).setHideOnClickOutside(false).setHideOnFrameResize(false).createBalloon();
    FrameStateManager.getInstance().getApplicationActive().doWhenDone(() -> {
        final Alarm alarm = new Alarm();
        alarm.addRequest(() -> {
            ((BalloonImpl) balloon).setHideOnClickOutside(true);
            Disposer.dispose(alarm);
        }, 100);
    });
    listenerWrapper.myBalloon = balloon;
    myWindow2Balloon.put(toolWindowId, balloon);
    Disposer.register(balloon, () -> {
        window.setPlaceholderMode(false);
        stripe.updatePresentation();
        stripe.revalidate();
        stripe.repaint();
        myWindow2Balloon.remove(toolWindowId);
    });
    Disposer.register(getProject(), balloon);
    execute(new ArrayList<>(Collections.<FinalizableCommand>singletonList(new FinalizableCommand(null) {

        @Override
        public void run() {
            final StripeButton button = stripe.getButtonFor(toolWindowId);
            LOG.assertTrue(button != null, "Button was not found, popup won't be shown. Toolwindow id: " + toolWindowId + ", message: " + text + ", message type: " + type);
            //noinspection ConstantConditions
            if (button == null)
                return;
            final Runnable show = () -> {
                PositionTracker<Balloon> tracker;
                if (button.isShowing()) {
                    tracker = new PositionTracker<Balloon>(button) {

                        @Override
                        @Nullable
                        public RelativePoint recalculateLocation(Balloon object) {
                            Stripe twStripe = myToolWindowsPane.getStripeFor(toolWindowId);
                            StripeButton twButton = twStripe != null ? twStripe.getButtonFor(toolWindowId) : null;
                            if (twButton == null) {
                                return null;
                            }
                            //noinspection ConstantConditions
                            if (getToolWindow(toolWindowId).getAnchor() != anchor) {
                                object.hide();
                                return null;
                            }
                            final Point point = new Point(twButton.getBounds().width / 2, twButton.getHeight() / 2 - 2);
                            return new RelativePoint(twButton, point);
                        }
                    };
                } else {
                    tracker = new PositionTracker<Balloon>(myToolWindowsPane) {

                        @Override
                        public RelativePoint recalculateLocation(Balloon object) {
                            final Rectangle bounds = myToolWindowsPane.getBounds();
                            final Point target = UIUtil.getCenterPoint(bounds, new Dimension(1, 1));
                            if (ToolWindowAnchor.TOP == anchor) {
                                target.y = 0;
                            } else if (ToolWindowAnchor.BOTTOM == anchor) {
                                target.y = bounds.height - 3;
                            } else if (ToolWindowAnchor.LEFT == anchor) {
                                target.x = 0;
                            } else if (ToolWindowAnchor.RIGHT == anchor) {
                                target.x = bounds.width;
                            }
                            return new RelativePoint(myToolWindowsPane, target);
                        }
                    };
                }
                if (!balloon.isDisposed()) {
                    balloon.show(tracker, position.get());
                }
            };
            if (!button.isValid()) {
                //noinspection SSBasedInspection
                SwingUtilities.invokeLater(show);
            } else {
                show.run();
            }
        }
    })));
}
Also used : Balloon(com.intellij.openapi.ui.popup.Balloon) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) BalloonImpl(com.intellij.ui.BalloonImpl) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with Balloon

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

the class SearchForUsagesRunnable method searchUsages.

private void searchUsages(@NotNull final AtomicBoolean findStartedBalloonShown) {
    ProgressIndicator indicator = ProgressWrapper.unwrap(ProgressManager.getInstance().getProgressIndicator());
    assert indicator != null : "must run find usages under progress";
    TooManyUsagesStatus.createFor(indicator);
    Alarm findUsagesStartedBalloon = new Alarm();
    findUsagesStartedBalloon.addRequest(() -> {
        notifyByFindBalloon(null, MessageType.WARNING, myProcessPresentation, myProject, Collections.singletonList(StringUtil.escapeXml(UsageViewManagerImpl.getProgressTitle(myPresentation))));
        findStartedBalloonShown.set(true);
    }, 300, ModalityState.NON_MODAL);
    UsageSearcher usageSearcher = mySearcherFactory.create();
    usageSearcher.generate(usage -> {
        ProgressIndicator indicator1 = ProgressWrapper.unwrap(ProgressManager.getInstance().getProgressIndicator());
        assert indicator1 != null : "must run find usages under progress";
        if (indicator1.isCanceled())
            return false;
        if (!UsageViewManagerImpl.isInScope(usage, mySearchScopeToWarnOfFallingOutOf)) {
            myOutOfScopeUsages.incrementAndGet();
            return true;
        }
        boolean incrementCounter = !UsageViewManager.isSelfUsage(usage, mySearchFor);
        if (incrementCounter) {
            final int usageCount = myUsageCountWithoutDefinition.incrementAndGet();
            if (usageCount == 1 && !myProcessPresentation.isShowPanelIfOnlyOneUsage()) {
                myFirstUsage.compareAndSet(null, usage);
            }
            final UsageViewImpl usageView = getUsageView(indicator1);
            TooManyUsagesStatus tooManyUsagesStatus = TooManyUsagesStatus.getFrom(indicator1);
            if (usageCount > UsageLimitUtil.USAGES_LIMIT && tooManyUsagesStatus.switchTooManyUsagesStatus()) {
                UsageViewManagerImpl.showTooManyUsagesWarning(myProject, tooManyUsagesStatus, indicator1, myPresentation, usageCount, usageView);
            }
            tooManyUsagesStatus.pauseProcessingIfTooManyUsages();
            if (usageView != null) {
                ApplicationManager.getApplication().runReadAction(() -> usageView.appendUsage(usage));
            }
        }
        return !indicator1.isCanceled();
    });
    if (getUsageView(indicator) != null) {
        ApplicationManager.getApplication().invokeLater(() -> myUsageViewManager.showToolWindow(true), myProject.getDisposed());
    }
    Disposer.dispose(findUsagesStartedBalloon);
    ApplicationManager.getApplication().invokeLater(() -> {
        if (findStartedBalloonShown.get()) {
            Balloon balloon = ToolWindowManager.getInstance(myProject).getToolWindowBalloon(ToolWindowId.FIND);
            if (balloon != null) {
                balloon.hide();
            }
        }
    }, myProject.getDisposed());
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Alarm(com.intellij.util.Alarm) Balloon(com.intellij.openapi.ui.popup.Balloon) TooManyUsagesStatus(com.intellij.openapi.progress.util.TooManyUsagesStatus)

Example 15 with Balloon

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

the class BalloonImpl method createComponent.

private void createComponent() {
    myComp = new MyComponent(myContent, this, myShadowBorderProvider != null ? null : myShowPointer ? myPosition.createBorder(this) : getPointlessBorder());
    if (myActionProvider == null) {
        final Consumer<MouseEvent> listener = event -> {
            SwingUtilities.invokeLater(() -> hide());
        };
        myActionProvider = new ActionProvider() {

            private ActionButton myCloseButton;

            @NotNull
            @Override
            public List<ActionButton> createActions() {
                myCloseButton = new CloseButton(listener);
                return Collections.singletonList(myCloseButton);
            }

            @Override
            public void layout(@NotNull Rectangle lpBounds) {
                if (!myCloseButton.isVisible()) {
                    return;
                }
                Icon icon = getCloseButton();
                int iconWidth = icon.getIconWidth();
                int iconHeight = icon.getIconHeight();
                Rectangle r = new Rectangle(lpBounds.x + lpBounds.width - iconWidth + (int) (iconWidth * 0.3), lpBounds.y - (int) (iconHeight * 0.3), iconWidth, iconHeight);
                Insets border = getShadowBorderInsets();
                r.x -= border.left;
                r.y -= border.top;
                myCloseButton.setBounds(r);
            }
        };
    }
    myComp.clear();
    myComp.myAlpha = isAnimationEnabled() ? 0f : -1;
    myComp.setBorder(new EmptyBorder(getShadowBorderInsets()));
    myLayeredPane.add(myComp);
    // the second balloon must be over the first one
    myLayeredPane.setLayer(myComp, getLayer(), 0);
    myPosition.updateBounds(this);
    if (myBlockClicks) {
        myComp.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                e.consume();
            }

            @Override
            public void mousePressed(MouseEvent e) {
                e.consume();
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                e.consume();
            }
        });
    }
}
Also used : com.intellij.openapi.util(com.intellij.openapi.util) AccessibleContextUtil(com.intellij.util.ui.accessibility.AccessibleContextUtil) Wrapper(com.intellij.ui.components.panels.Wrapper) AllIcons(com.intellij.icons.AllIcons) HyperlinkEvent(javax.swing.event.HyperlinkEvent) Area(java.awt.geom.Area) Rectangle2D(java.awt.geom.Rectangle2D) HashSet(com.intellij.util.containers.HashSet) FocusRequestor(com.intellij.openapi.wm.FocusRequestor) ShadowBorderPainter(com.intellij.openapi.ui.impl.ShadowBorderPainter) Balloon(com.intellij.openapi.ui.popup.Balloon) RGBImageFilter(java.awt.image.RGBImageFilter) LightweightWindowEvent(com.intellij.openapi.ui.popup.LightweightWindowEvent) IdeGlassPaneUtil(com.intellij.openapi.wm.IdeGlassPaneUtil) NonOpaquePanel(com.intellij.ui.components.panels.NonOpaquePanel) BufferedImage(java.awt.image.BufferedImage) com.intellij.ide(com.intellij.ide) Set(java.util.Set) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) com.intellij.util.ui(com.intellij.util.ui) java.awt.event(java.awt.event) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ApplicationManager(com.intellij.openapi.application.ApplicationManager) EmptyBorder(javax.swing.border.EmptyBorder) Registry(com.intellij.openapi.util.registry.Registry) GeneralPath(java.awt.geom.GeneralPath) NotNull(org.jetbrains.annotations.NotNull) RelativePoint(com.intellij.ui.awt.RelativePoint) ImageFilter(java.awt.image.ImageFilter) Consumer(com.intellij.util.Consumer) DataContext(com.intellij.openapi.actionSystem.DataContext) GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig) ScreenReader(com.intellij.util.ui.accessibility.ScreenReader) ActionManager(com.intellij.openapi.actionSystem.ActionManager) AnActionListener(com.intellij.openapi.actionSystem.ex.AnActionListener) JdkConstants(org.intellij.lang.annotations.JdkConstants) JBPopupListener(com.intellij.openapi.ui.popup.JBPopupListener) AnAction(com.intellij.openapi.actionSystem.AnAction) java.awt(java.awt) MnemonicHelper(com.intellij.openapi.MnemonicHelper) ObjectUtils(com.intellij.util.ObjectUtils) IdeGlassPaneEx(com.intellij.openapi.wm.impl.IdeGlassPaneEx) Collections(java.util.Collections) Alarm(com.intellij.util.Alarm) javax.swing(javax.swing) NotNull(org.jetbrains.annotations.NotNull) List(java.util.List) EmptyBorder(javax.swing.border.EmptyBorder)

Aggregations

Balloon (com.intellij.openapi.ui.popup.Balloon)40 RelativePoint (com.intellij.ui.awt.RelativePoint)14 BalloonBuilder (com.intellij.openapi.ui.popup.BalloonBuilder)11 IdeFrame (com.intellij.openapi.wm.IdeFrame)5 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)4 Disposable (com.intellij.openapi.Disposable)3 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)3 LightweightWindowEvent (com.intellij.openapi.ui.popup.LightweightWindowEvent)3 BalloonImpl (com.intellij.ui.BalloonImpl)3 HyperlinkEvent (javax.swing.event.HyperlinkEvent)3 Executor (com.intellij.execution.Executor)2 Notification (com.intellij.notification.Notification)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 BalloonLayout (com.intellij.ui.BalloonLayout)2 Alarm (com.intellij.util.Alarm)2 java.awt (java.awt)2 MouseEvent (java.awt.event.MouseEvent)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2