Search in sources :

Example 1 with IdeTooltip

use of com.intellij.ide.IdeTooltip in project intellij-community by JetBrains.

the class GraphTableController method showTooltip.

private boolean showTooltip(int row, int column, @NotNull Point point, boolean now) {
    JComponent tipComponent = myCommitRenderer.getTooltip(myTable.getValueAt(row, myTable.convertColumnIndexToView(column)), calcPoint4Graph(point), row);
    if (tipComponent != null) {
        myTable.getExpandableItemsHandler().setEnabled(false);
        IdeTooltip tooltip = new IdeTooltip(myTable, point, new Wrapper(tipComponent)).setPreferredPosition(Balloon.Position.below);
        IdeTooltipManager.getInstance().show(tooltip, now);
        return true;
    }
    return false;
}
Also used : Wrapper(com.intellij.ui.components.panels.Wrapper) IdeTooltip(com.intellij.ide.IdeTooltip)

Example 2 with IdeTooltip

use of com.intellij.ide.IdeTooltip in project intellij-community by JetBrains.

the class GraphTableController method showToolTip.

private void showToolTip(@NotNull String text, @NotNull MouseEvent e) {
    // standard tooltip does not allow to customize its location, and locating tooltip above can obscure some important info
    Point point = new Point(e.getX() + 5, e.getY());
    JEditorPane tipComponent = IdeTooltipManager.initPane(text, new HintHint(myTable, point).setAwtTooltip(true), null);
    IdeTooltip tooltip = new IdeTooltip(myTable, point, new Wrapper(tipComponent)).setPreferredPosition(Balloon.Position.atRight);
    IdeTooltipManager.getInstance().show(tooltip, false);
}
Also used : Wrapper(com.intellij.ui.components.panels.Wrapper) HintHint(com.intellij.ui.HintHint) IdeTooltip(com.intellij.ide.IdeTooltip)

Example 3 with IdeTooltip

use of com.intellij.ide.IdeTooltip 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 4 with IdeTooltip

use of com.intellij.ide.IdeTooltip in project intellij-community by JetBrains.

the class ParameterInfoController method updateComponent.

public void updateComponent() {
    if (myKeepOnHintHidden) {
        boolean removeHints = true;
        PsiElement owner = myComponent.getParameterOwner();
        if (owner != null && owner.isValid()) {
            int caretOffset = myEditor.getCaretModel().getOffset();
            TextRange ownerTextRange = owner.getTextRange();
            if (ownerTextRange != null) {
                if (caretOffset > ownerTextRange.getStartOffset() && caretOffset < ownerTextRange.getEndOffset()) {
                    removeHints = false;
                } else {
                    for (PsiElement element : owner.getChildren()) {
                        if (element instanceof PsiErrorElement) {
                            removeHints = false;
                            break;
                        }
                    }
                }
            }
        }
        if (removeHints) {
            Disposer.dispose(this);
            return;
        }
    }
    if (!myHint.isVisible() && !myKeepOnHintHidden && !ApplicationManager.getApplication().isUnitTestMode()) {
        Disposer.dispose(this);
        return;
    }
    final PsiFile file = PsiUtilBase.getPsiFileInEditor(myEditor, myProject);
    CharSequence chars = myEditor.getDocument().getCharsSequence();
    boolean noDelimiter = myHandler instanceof ParameterInfoHandlerWithTabActionSupport && ((ParameterInfoHandlerWithTabActionSupport) myHandler).getActualParameterDelimiterType() == TokenType.WHITE_SPACE;
    int caretOffset = myEditor.getCaretModel().getOffset();
    final int offset = noDelimiter ? caretOffset : CharArrayUtil.shiftBackward(chars, caretOffset - 1, " \t") + 1;
    final UpdateParameterInfoContext context = new MyUpdateParameterInfoContext(offset, file);
    final Object elementForUpdating = myHandler.findElementForUpdatingParameterInfo(context);
    if (elementForUpdating != null) {
        myHandler.updateParameterInfo(elementForUpdating, context);
        if (!myDisposed && myHint.isVisible() && !myEditor.isDisposed() && myEditor.getComponent().getRootPane() != null) {
            myComponent.update();
            IdeTooltip tooltip = myHint.getCurrentIdeTooltip();
            short position = tooltip != null ? toShort(tooltip.getPreferredPosition()) : HintManager.UNDER;
            Pair<Point, Short> pos = myProvider.getBestPointPosition(myHint, elementForUpdating instanceof PsiElement ? (PsiElement) elementForUpdating : null, caretOffset, true, position);
            HintManagerImpl.adjustEditorHintPosition(myHint, myEditor, pos.getFirst(), pos.getSecond());
        }
    } else {
        context.removeHint();
    }
}
Also used : TextRange(com.intellij.openapi.util.TextRange) ParameterInfoHandlerWithTabActionSupport(com.intellij.lang.parameterInfo.ParameterInfoHandlerWithTabActionSupport) UpdateParameterInfoContext(com.intellij.lang.parameterInfo.UpdateParameterInfoContext) HintHint(com.intellij.ui.HintHint) LightweightHint(com.intellij.ui.LightweightHint) IdeTooltip(com.intellij.ide.IdeTooltip)

Example 5 with IdeTooltip

use of com.intellij.ide.IdeTooltip in project intellij-community by JetBrains.

the class HintManagerImpl method getHintPosition.

/**
   * @return coordinates in layered pane coordinate system.
   */
public Point getHintPosition(@NotNull LightweightHint hint, @NotNull Editor editor, @PositionFlags short constraint) {
    LogicalPosition pos = editor.getCaretModel().getLogicalPosition();
    final DataContext dataContext = ((EditorEx) editor).getDataContext();
    final Rectangle dominantArea = PlatformDataKeys.DOMINANT_HINT_AREA_RECTANGLE.getData(dataContext);
    LOG.assertTrue(SwingUtilities.isEventDispatchThread());
    if (dominantArea != null) {
        return getHintPositionRelativeTo(hint, editor, constraint, dominantArea, pos);
    }
    JRootPane rootPane = editor.getComponent().getRootPane();
    if (rootPane != null) {
        JLayeredPane lp = rootPane.getLayeredPane();
        for (HintInfo info : getHintsStackArray()) {
            if (!info.hint.isSelectingHint())
                continue;
            IdeTooltip tooltip = info.hint.getCurrentIdeTooltip();
            if (tooltip != null) {
                Point p = tooltip.getShowingPoint().getPoint(lp);
                if (info.hint != hint) {
                    switch(constraint) {
                        case ABOVE:
                            if (tooltip.getPreferredPosition() == Balloon.Position.below) {
                                p.y -= tooltip.getPositionChangeY();
                            }
                            break;
                        case UNDER:
                        case RIGHT_UNDER:
                            if (tooltip.getPreferredPosition() == Balloon.Position.above) {
                                p.y += tooltip.getPositionChangeY();
                            }
                            break;
                        case RIGHT:
                            if (tooltip.getPreferredPosition() == Balloon.Position.atLeft) {
                                p.x += tooltip.getPositionChangeX();
                            }
                            break;
                        case LEFT:
                            if (tooltip.getPreferredPosition() == Balloon.Position.atRight) {
                                p.x -= tooltip.getPositionChangeX();
                            }
                            break;
                    }
                }
                return p;
            }
            Rectangle rectangle = info.hint.getBounds();
            JComponent c = info.hint.getComponent();
            rectangle = SwingUtilities.convertRectangle(c.getParent(), rectangle, lp);
            return getHintPositionRelativeTo(hint, editor, constraint, rectangle, pos);
        }
    }
    return getHintPosition(hint, editor, pos, constraint);
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) EditorEx(com.intellij.openapi.editor.ex.EditorEx) RelativePoint(com.intellij.ui.awt.RelativePoint) IdeTooltip(com.intellij.ide.IdeTooltip)

Aggregations

IdeTooltip (com.intellij.ide.IdeTooltip)9 RelativePoint (com.intellij.ui.awt.RelativePoint)3 HintHint (com.intellij.ui.HintHint)2 Wrapper (com.intellij.ui.components.panels.Wrapper)2 MouseEvent (java.awt.event.MouseEvent)2 IdeTooltipManager (com.intellij.ide.IdeTooltipManager)1 TooltipEvent (com.intellij.ide.TooltipEvent)1 ParameterInfoHandlerWithTabActionSupport (com.intellij.lang.parameterInfo.ParameterInfoHandlerWithTabActionSupport)1 UpdateParameterInfoContext (com.intellij.lang.parameterInfo.UpdateParameterInfoContext)1 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 TextRange (com.intellij.openapi.util.TextRange)1 ReplaceConfiguration (com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration)1 LightweightHint (com.intellij.ui.LightweightHint)1 OpaquePanel (com.intellij.ui.components.panels.OpaquePanel)1 MouseAdapter (java.awt.event.MouseAdapter)1 LineBorder (javax.swing.border.LineBorder)1 NotNull (org.jetbrains.annotations.NotNull)1