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;
}
}
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();
}
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;
}
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());
}
}
}
}
}
Aggregations