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