Search in sources :

Example 31 with RelativePoint

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

the class IdeTooltipManager method hideCurrent.

private boolean hideCurrent(@Nullable MouseEvent me, @Nullable IdeTooltip tooltipToShow, @Nullable AnAction action, @Nullable AnActionEvent event, final boolean animationEnabled) {
    if (myCurrentTooltip != null && me != null && myCurrentTooltip.isInside(new RelativePoint(me))) {
        if (me.getButton() == MouseEvent.NOBUTTON || myCurrentTipUi == null || myCurrentTipUi.isBlockClicks()) {
            return false;
        }
    }
    myShowRequest = null;
    myQueuedComponent = null;
    myQueuedTooltip = null;
    if (myCurrentTooltip == null)
        return true;
    if (myCurrentTipUi != null) {
        RelativePoint target = me != null ? new RelativePoint(me) : null;
        boolean isInsideOrMovingForward = target != null && (myCurrentTipUi.isInside(target) || myCurrentTipUi.isMovingForward(target));
        boolean canAutoHide = myCurrentTooltip.canAutohideOn(new TooltipEvent(me, isInsideOrMovingForward, action, event));
        boolean implicitMouseMove = me != null && (me.getID() == MouseEvent.MOUSE_MOVED || me.getID() == MouseEvent.MOUSE_EXITED || me.getID() == MouseEvent.MOUSE_ENTERED);
        if (!canAutoHide || (isInsideOrMovingForward && implicitMouseMove) || (myCurrentTooltip.isExplicitClose() && implicitMouseMove) || (tooltipToShow != null && !tooltipToShow.isHint() && Comparing.equal(myCurrentTooltip, tooltipToShow))) {
            if (myHideRunnable != null) {
                myHideRunnable = null;
            }
            return false;
        }
    }
    myHideRunnable = () -> {
        if (myHideRunnable != null) {
            hideCurrentNow(animationEnabled);
            myHideRunnable = null;
        }
    };
    if (me != null && me.getButton() == MouseEvent.NOBUTTON) {
        myAlarm.addRequest(myHideRunnable, Registry.intValue("ide.tooltip.autoDismissDeadZone"));
    } else {
        myHideRunnable.run();
        myHideRunnable = null;
    }
    return true;
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 32 with RelativePoint

use of com.intellij.ui.awt.RelativePoint 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 33 with RelativePoint

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

the class ComboContentLayout method showContentPopup.

@Override
public void showContentPopup(ListPopup listPopup) {
    final int width = myComboLabel.getSize().width;
    listPopup.setMinimumSize(new Dimension(width, 0));
    listPopup.show(new RelativePoint(myComboLabel, new Point(-2, myComboLabel.getHeight())));
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 34 with RelativePoint

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

the class SlideComponent method updateBalloonText.

private void updateBalloonText() {
    final Point point = myVertical ? new Point(0, myPointerValue) : new Point(myPointerValue, 0);
    myLabel.setText(myTitle + ": " + Unit.formatValue(myValue, myUnit));
    if (myTooltipHint == null) {
        myTooltipHint = new LightweightHint(myLabel);
        myTooltipHint.setCancelOnClickOutside(false);
        myTooltipHint.setCancelOnOtherWindowOpen(false);
        final HintHint hint = new HintHint(this, point).setPreferredPosition(myVertical ? Balloon.Position.atLeft : Balloon.Position.above).setBorderColor(Color.BLACK).setAwtTooltip(true).setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD)).setTextBg(HintUtil.getInformationColor()).setShowImmediately(true);
        final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
        myTooltipHint.show(this, point.x, point.y, owner instanceof JComponent ? (JComponent) owner : null, hint);
    } else {
        myTooltipHint.setLocation(new RelativePoint(this, point));
    }
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 35 with RelativePoint

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

the class DockManagerImpl method createNewDockContainerFor.

public void createNewDockContainerFor(DockableContent content, RelativePoint point) {
    DockContainer container = getFactory(content.getDockContainerType()).createContainer(content);
    register(container);
    final DockWindow window = createWindowFor(null, container);
    Dimension size = content.getPreferredSize();
    Point showPoint = point.getScreenPoint();
    showPoint.x -= size.width / 2;
    showPoint.y -= size.height / 2;
    Rectangle target = new Rectangle(showPoint, size);
    ScreenUtil.moveRectangleToFitTheScreen(target);
    ScreenUtil.cropRectangleToFitTheScreen(target);
    window.setLocation(target.getLocation());
    window.myDockContentUiContainer.setPreferredSize(target.getSize());
    window.show(false);
    window.getFrame().pack();
    container.add(content, new RelativePoint(target.getLocation()));
    SwingUtilities.invokeLater(() -> window.myUiContainer.setPreferredSize(null));
}
Also used : RelativeRectangle(com.intellij.ui.awt.RelativeRectangle) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Aggregations

RelativePoint (com.intellij.ui.awt.RelativePoint)127 Project (com.intellij.openapi.project.Project)16 Balloon (com.intellij.openapi.ui.popup.Balloon)15 JBPopup (com.intellij.openapi.ui.popup.JBPopup)15 NotNull (org.jetbrains.annotations.NotNull)15 MouseEvent (java.awt.event.MouseEvent)12 Nullable (org.jetbrains.annotations.Nullable)10 Editor (com.intellij.openapi.editor.Editor)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 PsiElement (com.intellij.psi.PsiElement)8 JBList (com.intellij.ui.components.JBList)8 Disposable (com.intellij.openapi.Disposable)7 BalloonBuilder (com.intellij.openapi.ui.popup.BalloonBuilder)7 BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)7 ArrayList (java.util.ArrayList)7 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)6 ListPopup (com.intellij.openapi.ui.popup.ListPopup)6 PsiFile (com.intellij.psi.PsiFile)5 HintHint (com.intellij.ui.HintHint)5 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)4