Search in sources :

Example 6 with IdeTooltip

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

the class HintManagerImpl method getHintPositionRelativeTo.

private static Point getHintPositionRelativeTo(@NotNull final LightweightHint hint, @NotNull final Editor editor, @PositionFlags short constraint, @NotNull final Rectangle lookupBounds, final LogicalPosition pos) {
    JComponent externalComponent = getExternalComponent(editor);
    IdeTooltip ideTooltip = hint.getCurrentIdeTooltip();
    if (ideTooltip != null) {
        Point point = ideTooltip.getPoint();
        return SwingUtilities.convertPoint(ideTooltip.getComponent(), point, externalComponent);
    }
    Dimension hintSize = hint.getComponent().getPreferredSize();
    int layeredPaneHeight = externalComponent.getHeight();
    switch(constraint) {
        case LEFT:
            {
                int y = lookupBounds.y;
                if (y < 0) {
                    y = 0;
                } else if (y + hintSize.height >= layeredPaneHeight) {
                    y = layeredPaneHeight - hintSize.height;
                }
                return new Point(lookupBounds.x - hintSize.width, y);
            }
        case RIGHT:
            int y = lookupBounds.y;
            if (y < 0) {
                y = 0;
            } else if (y + hintSize.height >= layeredPaneHeight) {
                y = layeredPaneHeight - hintSize.height;
            }
            return new Point(lookupBounds.x + lookupBounds.width, y);
        case ABOVE:
            Point posAboveCaret = getHintPosition(hint, editor, pos, ABOVE);
            return new Point(lookupBounds.x, Math.min(posAboveCaret.y, lookupBounds.y - hintSize.height));
        case UNDER:
            Point posUnderCaret = getHintPosition(hint, editor, pos, UNDER);
            return new Point(lookupBounds.x, Math.max(posUnderCaret.y, lookupBounds.y + lookupBounds.height));
        default:
            LOG.error("");
            return null;
    }
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) IdeTooltip(com.intellij.ide.IdeTooltip) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 7 with IdeTooltip

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

the class LightweightHint method hide.

public void hide(boolean ok) {
    if (isVisible()) {
        if (myIsRealPopup) {
            if (ok) {
                myPopup.closeOk(null);
            } else {
                myPopup.cancel();
            }
            myPopup = null;
        } else {
            if (myCurrentIdeTooltip != null) {
                IdeTooltip tooltip = myCurrentIdeTooltip;
                myCurrentIdeTooltip = null;
                tooltip.hide();
            } else {
                JRootPane rootPane = myComponent.getRootPane();
                JLayeredPane layeredPane = rootPane == null ? null : rootPane.getLayeredPane();
                if (layeredPane != null) {
                    Rectangle bounds = myComponent.getBounds();
                    try {
                        if (myFocusBackComponent != null) {
                            LayoutFocusTraversalPolicyExt.setOverridenDefaultComponent(myFocusBackComponent);
                        }
                        layeredPane.remove(myComponent);
                    } finally {
                        LayoutFocusTraversalPolicyExt.setOverridenDefaultComponent(null);
                    }
                    layeredPane.paintImmediately(bounds.x, bounds.y, bounds.width, bounds.height);
                }
            }
        }
    }
    if (myEscListener != null) {
        myComponent.unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0));
    }
    TooltipController.getInstance().hide(this);
    fireHintHidden();
}
Also used : IdeTooltip(com.intellij.ide.IdeTooltip)

Example 8 with IdeTooltip

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

the class UIUtil method createCompleteMatchInfo.

@NotNull
public static JComponent createCompleteMatchInfo(final Producer<Configuration> configurationProducer) {
    final JLabel completeMatchInfo = new JLabel(AllIcons.RunConfigurations.Variables);
    final Point location = completeMatchInfo.getLocation();
    final JLabel label = new JLabel(SSRBundle.message("complete.match.variable.tooltip.message", SSRBundle.message("no.constraints.specified.tooltip.message")));
    final IdeTooltip tooltip = new IdeTooltip(completeMatchInfo, location, label);
    tooltip.setPreferredPosition(Balloon.Position.atRight).setCalloutShift(6).setHint(true).setExplicitClose(true);
    completeMatchInfo.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent e) {
            final Configuration configuration = configurationProducer.produce();
            if (configuration == null) {
                return;
            }
            final MatchOptions matchOptions = configuration.getMatchOptions();
            final MatchVariableConstraint constraint = getOrAddVariableConstraint(Configuration.CONTEXT_VAR_NAME, configuration);
            if (isTarget(Configuration.CONTEXT_VAR_NAME, matchOptions)) {
                constraint.setPartOfSearchResults(true);
            }
            label.setText(SSRBundle.message("complete.match.variable.tooltip.message", getShortParamString(constraint)));
            final IdeTooltipManager tooltipManager = IdeTooltipManager.getInstance();
            tooltipManager.show(tooltip, true);
        }

        @Override
        public void mouseExited(MouseEvent e) {
            IdeTooltipManager.getInstance().hide(tooltip);
        }
    });
    return completeMatchInfo;
}
Also used : MouseEvent(java.awt.event.MouseEvent) ReplaceConfiguration(com.intellij.structuralsearch.plugin.replace.ui.ReplaceConfiguration) IdeTooltipManager(com.intellij.ide.IdeTooltipManager) MouseAdapter(java.awt.event.MouseAdapter) IdeTooltip(com.intellij.ide.IdeTooltip) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with IdeTooltip

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

the class ParameterInfoController method adjustPositionForLookup.

private void adjustPositionForLookup(@NotNull Lookup lookup) {
    if (!myHint.isVisible() || myEditor.isDisposed()) {
        Disposer.dispose(this);
        return;
    }
    IdeTooltip tooltip = myHint.getCurrentIdeTooltip();
    if (tooltip != null) {
        JRootPane root = myEditor.getComponent().getRootPane();
        if (root != null) {
            Point p = tooltip.getShowingPoint().getPoint(root.getLayeredPane());
            if (lookup.isPositionedAboveCaret()) {
                if (Position.above == tooltip.getPreferredPosition()) {
                    myHint.pack();
                    myHint.updatePosition(Position.below);
                    myHint.updateLocation(p.x, p.y + tooltip.getPositionChangeY());
                }
            } else {
                if (Position.below == tooltip.getPreferredPosition()) {
                    myHint.pack();
                    myHint.updatePosition(Position.above);
                    myHint.updateLocation(p.x, p.y - tooltip.getPositionChangeY());
                }
            }
        }
    }
}
Also used : 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