Search in sources :

Example 1 with BalloonImpl

use of com.intellij.ui.BalloonImpl 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 2 with BalloonImpl

use of com.intellij.ui.BalloonImpl 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 3 with BalloonImpl

use of com.intellij.ui.BalloonImpl in project intellij-community by JetBrains.

the class BalloonPopupBuilderImpl method createBalloon.

@NotNull
@Override
public Balloon createBalloon() {
    final BalloonImpl result = new BalloonImpl(myContent, myBorder, myBorderInsets, myFill, myHideOnMouseOutside, myHideOnKeyOutside, myHideOnAction, myHideOnCloseClick, myShowCallout, myCloseButtonEnabled, myFadeoutTime, myHideOnFrameResize, myHideOnLinkClick, myClickHandler, myCloseOnClick, myAnimationCycle, myCalloutShift, myPositionChangeXShift, myPositionChangeYShift, myDialogMode, myTitle, myContentInsets, myShadow, mySmallVariant, myBlockClicks, myLayer, myRequestFocus, myPointerSize, myCornerToPointerDistance);
    if (myStorage != null && myAnchor != null) {
        List<Balloon> balloons = myStorage.get(myAnchor);
        if (balloons == null) {
            myStorage.put(myAnchor, balloons = new ArrayList<>());
            Disposer.register(myAnchor, new Disposable() {

                @Override
                public void dispose() {
                    List<Balloon> toDispose = myStorage.remove(myAnchor);
                    if (toDispose != null) {
                        for (Balloon balloon : toDispose) {
                            if (!balloon.isDisposed()) {
                                Disposer.dispose(balloon);
                            }
                        }
                    }
                }
            });
        }
        balloons.add(result);
        result.addListener(new JBPopupAdapter() {

            @Override
            public void onClosed(LightweightWindowEvent event) {
                if (!result.isDisposed()) {
                    Disposer.dispose(result);
                }
            }
        });
    }
    return result;
}
Also used : Disposable(com.intellij.openapi.Disposable) ArrayList(java.util.ArrayList) BalloonImpl(com.intellij.ui.BalloonImpl) Balloon(com.intellij.openapi.ui.popup.Balloon) JBPopupAdapter(com.intellij.openapi.ui.popup.JBPopupAdapter) ArrayList(java.util.ArrayList) List(java.util.List) LightweightWindowEvent(com.intellij.openapi.ui.popup.LightweightWindowEvent) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Balloon (com.intellij.openapi.ui.popup.Balloon)3 BalloonImpl (com.intellij.ui.BalloonImpl)3 Disposable (com.intellij.openapi.Disposable)1 JBPopupAdapter (com.intellij.openapi.ui.popup.JBPopupAdapter)1 LightweightWindowEvent (com.intellij.openapi.ui.popup.LightweightWindowEvent)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 StringSelection (java.awt.datatransfer.StringSelection)1 AWTEventListener (java.awt.event.AWTEventListener)1 MouseEvent (java.awt.event.MouseEvent)1 MouseListener (java.awt.event.MouseListener)1 MouseMotionListener (java.awt.event.MouseMotionListener)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1