Search in sources :

Example 36 with RelativePoint

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

the class LightweightHint method updateLocation.

public void updateLocation(int x, int y) {
    Point point = new Point(x, y);
    fixActualPoint(point);
    setLocation(new RelativePoint(myParentComponent, point));
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 37 with RelativePoint

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

the class LightweightHint method show.

/**
   * Shows the hint in the layered pane. Coordinates <code>x</code> and <code>y</code>
   * are in <code>parentComponent</code> coordinate system. Note that the component
   * appears on 250 layer.
   */
@Override
public void show(@NotNull final JComponent parentComponent, final int x, final int y, final JComponent focusBackComponent, @NotNull final HintHint hintHint) {
    myParentComponent = parentComponent;
    myHintHint = hintHint;
    myFocusBackComponent = focusBackComponent;
    LOG.assertTrue(myParentComponent.isShowing());
    myEscListener = new MyEscListener();
    myComponent.registerKeyboardAction(myEscListener, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
    myComponent.registerKeyboardAction(myEscListener, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_FOCUSED);
    final JLayeredPane layeredPane = parentComponent.getRootPane().getLayeredPane();
    myComponent.validate();
    if (!myForceShowAsPopup && (myForceLightweightPopup || fitsLayeredPane(layeredPane, myComponent, new RelativePoint(parentComponent, new Point(x, y)), hintHint))) {
        beforeShow();
        final Dimension preferredSize = myComponent.getPreferredSize();
        if (hintHint.isAwtTooltip()) {
            IdeTooltip tooltip = new IdeTooltip(hintHint.getOriginalComponent(), hintHint.getOriginalPoint(), myComponent, hintHint, myComponent) {

                @Override
                protected boolean canAutohideOn(TooltipEvent event) {
                    if (!LightweightHint.this.canAutoHideOn(event)) {
                        return false;
                    } else if (event.getInputEvent() instanceof MouseEvent) {
                        return !(hintHint.isContentActive() && event.isIsEventInsideBalloon());
                    } else if (event.getAction() != null) {
                        return false;
                    } else {
                        return true;
                    }
                }

                @Override
                protected void onHidden() {
                    fireHintHidden();
                    TooltipController.getInstance().resetCurrent();
                }

                @Override
                public boolean canBeDismissedOnTimeout() {
                    return false;
                }
            }.setToCenterIfSmall(hintHint.isMayCenterTooltip()).setPreferredPosition(hintHint.getPreferredPosition()).setHighlighterType(hintHint.isHighlighterType()).setTextForeground(hintHint.getTextForeground()).setTextBackground(hintHint.getTextBackground()).setBorderColor(hintHint.getBorderColor()).setBorderInsets(hintHint.getBorderInsets()).setFont(hintHint.getTextFont()).setCalloutShift(hintHint.getCalloutShift()).setPositionChangeShift(hintHint.getPositionChangeX(), hintHint.getPositionChangeY()).setExplicitClose(hintHint.isExplicitClose()).setRequestFocus(hintHint.isRequestFocus()).setHint(true);
            myComponent.validate();
            myCurrentIdeTooltip = IdeTooltipManager.getInstance().show(tooltip, hintHint.isShowImmediately(), hintHint.isAnimationEnabled());
        } else {
            final Point layeredPanePoint = SwingUtilities.convertPoint(parentComponent, x, y, layeredPane);
            myComponent.setBounds(layeredPanePoint.x, layeredPanePoint.y, preferredSize.width, preferredSize.height);
            layeredPane.add(myComponent, JLayeredPane.POPUP_LAYER);
            myComponent.validate();
            myComponent.repaint();
        }
    } else {
        myIsRealPopup = true;
        Point actualPoint = new Point(x, y);
        JComponent actualComponent = new OpaquePanel(new BorderLayout());
        actualComponent.add(myComponent, BorderLayout.CENTER);
        if (isAwtTooltip()) {
            int inset = BalloonImpl.getNormalInset();
            actualComponent.setBorder(new LineBorder(hintHint.getTextBackground(), inset));
            actualComponent.setBackground(hintHint.getTextBackground());
            actualComponent.validate();
        }
        myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(actualComponent, myFocusRequestor).setRequestFocus(myFocusRequestor != null).setFocusable(myFocusRequestor != null).setResizable(myResizable).setMovable(myTitle != null).setTitle(myTitle).setModalContext(false).setShowShadow(isRealPopup() && !isForceHideShadow()).setCancelKeyEnabled(false).setCancelOnClickOutside(myCancelOnClickOutside).setCancelCallback(() -> {
            onPopupCancel();
            return true;
        }).setCancelOnOtherWindowOpen(myCancelOnOtherWindowOpen).createPopup();
        beforeShow();
        myPopup.show(new RelativePoint(myParentComponent, new Point(actualPoint.x, actualPoint.y)));
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) LineBorder(javax.swing.border.LineBorder) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) OpaquePanel(com.intellij.ui.components.panels.OpaquePanel) RelativePoint(com.intellij.ui.awt.RelativePoint) TooltipEvent(com.intellij.ide.TooltipEvent) IdeTooltip(com.intellij.ide.IdeTooltip)

Example 38 with RelativePoint

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

the class LightweightHint method setLocation.

@Override
public void setLocation(@NotNull RelativePoint point) {
    if (isRealPopup()) {
        myPopup.setLocation(point.getScreenPoint());
    } else {
        if (myCurrentIdeTooltip != null) {
            Point screenPoint = point.getScreenPoint();
            if (!screenPoint.equals(new RelativePoint(myCurrentIdeTooltip.getComponent(), myCurrentIdeTooltip.getPoint()).getScreenPoint())) {
                myCurrentIdeTooltip.setPoint(point.getPoint());
                myCurrentIdeTooltip.setComponent(point.getComponent());
                IdeTooltipManager.getInstance().show(myCurrentIdeTooltip, true, false);
            }
        } else {
            Point targetPoint = point.getPoint(myComponent.getParent());
            myComponent.setLocation(targetPoint);
            myComponent.revalidate();
            myComponent.repaint();
        }
    }
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 39 with RelativePoint

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

the class AbstractPopup method show.

@Override
public void show(@NotNull RelativePoint aPoint) {
    final Point screenPoint = aPoint.getScreenPoint();
    show(aPoint.getComponent(), screenPoint.x, screenPoint.y, false);
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 40 with RelativePoint

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

the class AbstractPopup method guessBestPopupLocation.

@NotNull
private RelativePoint guessBestPopupLocation(@NotNull Editor editor) {
    RelativePoint preferredLocation = JBPopupFactory.getInstance().guessBestPopupLocation(editor);
    if (myDimensionServiceKey == null) {
        return preferredLocation;
    }
    Dimension preferredSize = DimensionService.getInstance().getSize(myDimensionServiceKey, myProject);
    if (preferredSize == null) {
        return preferredLocation;
    }
    Rectangle preferredBounds = new Rectangle(preferredLocation.getScreenPoint(), preferredSize);
    Rectangle adjustedBounds = new Rectangle(preferredBounds);
    ScreenUtil.moveRectangleToFitTheScreen(adjustedBounds);
    if (preferredBounds.y - adjustedBounds.y <= 0) {
        return preferredLocation;
    }
    int adjustedY = preferredBounds.y - editor.getLineHeight() - preferredSize.height;
    if (adjustedY < 0) {
        return preferredLocation;
    }
    Point point = new Point(preferredBounds.x, adjustedY);
    Component component = preferredLocation.getComponent();
    if (component == null) {
        return RelativePoint.fromScreen(point);
    }
    SwingUtilities.convertPointFromScreen(point, component);
    return new RelativePoint(component, point);
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) JTextComponent(javax.swing.text.JTextComponent) RelativePoint(com.intellij.ui.awt.RelativePoint) NotNull(org.jetbrains.annotations.NotNull)

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