use of com.intellij.ui.awt.RelativePoint in project intellij-community by JetBrains.
the class IdeTooltipManager method hideCurrent.
private boolean hideCurrent(@Nullable MouseEvent me, @Nullable IdeTooltip tooltipToShow, @Nullable AnAction action, @Nullable AnActionEvent event, final boolean animationEnabled) {
if (myCurrentTooltip != null && me != null && myCurrentTooltip.isInside(new RelativePoint(me))) {
if (me.getButton() == MouseEvent.NOBUTTON || myCurrentTipUi == null || myCurrentTipUi.isBlockClicks()) {
return false;
}
}
myShowRequest = null;
myQueuedComponent = null;
myQueuedTooltip = null;
if (myCurrentTooltip == null)
return true;
if (myCurrentTipUi != null) {
RelativePoint target = me != null ? new RelativePoint(me) : null;
boolean isInsideOrMovingForward = target != null && (myCurrentTipUi.isInside(target) || myCurrentTipUi.isMovingForward(target));
boolean canAutoHide = myCurrentTooltip.canAutohideOn(new TooltipEvent(me, isInsideOrMovingForward, action, event));
boolean implicitMouseMove = me != null && (me.getID() == MouseEvent.MOUSE_MOVED || me.getID() == MouseEvent.MOUSE_EXITED || me.getID() == MouseEvent.MOUSE_ENTERED);
if (!canAutoHide || (isInsideOrMovingForward && implicitMouseMove) || (myCurrentTooltip.isExplicitClose() && implicitMouseMove) || (tooltipToShow != null && !tooltipToShow.isHint() && Comparing.equal(myCurrentTooltip, tooltipToShow))) {
if (myHideRunnable != null) {
myHideRunnable = null;
}
return false;
}
}
myHideRunnable = () -> {
if (myHideRunnable != null) {
hideCurrentNow(animationEnabled);
myHideRunnable = null;
}
};
if (me != null && me.getButton() == MouseEvent.NOBUTTON) {
myAlarm.addRequest(myHideRunnable, Registry.intValue("ide.tooltip.autoDismissDeadZone"));
} else {
myHideRunnable.run();
myHideRunnable = null;
}
return true;
}
use of com.intellij.ui.awt.RelativePoint in project intellij-community by JetBrains.
the class ToolWindowManagerImpl method notifyByBalloon.
@Override
public void notifyByBalloon(@NotNull final String toolWindowId, @NotNull final MessageType type, @NotNull final String text, @Nullable final Icon icon, @Nullable final HyperlinkListener listener) {
checkId(toolWindowId);
Balloon existing = myWindow2Balloon.get(toolWindowId);
if (existing != null) {
existing.hide();
}
final Stripe stripe = myToolWindowsPane.getStripeFor(toolWindowId);
if (stripe == null) {
return;
}
final ToolWindowImpl window = getInternalDecorator(toolWindowId).getToolWindow();
if (!window.isAvailable()) {
window.setPlaceholderMode(true);
stripe.updatePresentation();
stripe.revalidate();
stripe.repaint();
}
final ToolWindowAnchor anchor = getInfo(toolWindowId).getAnchor();
final Ref<Balloon.Position> position = Ref.create(Balloon.Position.below);
if (ToolWindowAnchor.TOP == anchor) {
position.set(Balloon.Position.below);
} else if (ToolWindowAnchor.BOTTOM == anchor) {
position.set(Balloon.Position.above);
} else if (ToolWindowAnchor.LEFT == anchor) {
position.set(Balloon.Position.atRight);
} else if (ToolWindowAnchor.RIGHT == anchor) {
position.set(Balloon.Position.atLeft);
}
final BalloonHyperlinkListener listenerWrapper = new BalloonHyperlinkListener(listener);
final Balloon balloon = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(text.replace("\n", "<br>"), icon, type.getPopupBackground(), listenerWrapper).setHideOnClickOutside(false).setHideOnFrameResize(false).createBalloon();
FrameStateManager.getInstance().getApplicationActive().doWhenDone(() -> {
final Alarm alarm = new Alarm();
alarm.addRequest(() -> {
((BalloonImpl) balloon).setHideOnClickOutside(true);
Disposer.dispose(alarm);
}, 100);
});
listenerWrapper.myBalloon = balloon;
myWindow2Balloon.put(toolWindowId, balloon);
Disposer.register(balloon, () -> {
window.setPlaceholderMode(false);
stripe.updatePresentation();
stripe.revalidate();
stripe.repaint();
myWindow2Balloon.remove(toolWindowId);
});
Disposer.register(getProject(), balloon);
execute(new ArrayList<>(Collections.<FinalizableCommand>singletonList(new FinalizableCommand(null) {
@Override
public void run() {
final StripeButton button = stripe.getButtonFor(toolWindowId);
LOG.assertTrue(button != null, "Button was not found, popup won't be shown. Toolwindow id: " + toolWindowId + ", message: " + text + ", message type: " + type);
//noinspection ConstantConditions
if (button == null)
return;
final Runnable show = () -> {
PositionTracker<Balloon> tracker;
if (button.isShowing()) {
tracker = new PositionTracker<Balloon>(button) {
@Override
@Nullable
public RelativePoint recalculateLocation(Balloon object) {
Stripe twStripe = myToolWindowsPane.getStripeFor(toolWindowId);
StripeButton twButton = twStripe != null ? twStripe.getButtonFor(toolWindowId) : null;
if (twButton == null) {
return null;
}
//noinspection ConstantConditions
if (getToolWindow(toolWindowId).getAnchor() != anchor) {
object.hide();
return null;
}
final Point point = new Point(twButton.getBounds().width / 2, twButton.getHeight() / 2 - 2);
return new RelativePoint(twButton, point);
}
};
} else {
tracker = new PositionTracker<Balloon>(myToolWindowsPane) {
@Override
public RelativePoint recalculateLocation(Balloon object) {
final Rectangle bounds = myToolWindowsPane.getBounds();
final Point target = UIUtil.getCenterPoint(bounds, new Dimension(1, 1));
if (ToolWindowAnchor.TOP == anchor) {
target.y = 0;
} else if (ToolWindowAnchor.BOTTOM == anchor) {
target.y = bounds.height - 3;
} else if (ToolWindowAnchor.LEFT == anchor) {
target.x = 0;
} else if (ToolWindowAnchor.RIGHT == anchor) {
target.x = bounds.width;
}
return new RelativePoint(myToolWindowsPane, target);
}
};
}
if (!balloon.isDisposed()) {
balloon.show(tracker, position.get());
}
};
if (!button.isValid()) {
//noinspection SSBasedInspection
SwingUtilities.invokeLater(show);
} else {
show.run();
}
}
})));
}
use of com.intellij.ui.awt.RelativePoint in project intellij-community by JetBrains.
the class ComboContentLayout method showContentPopup.
@Override
public void showContentPopup(ListPopup listPopup) {
final int width = myComboLabel.getSize().width;
listPopup.setMinimumSize(new Dimension(width, 0));
listPopup.show(new RelativePoint(myComboLabel, new Point(-2, myComboLabel.getHeight())));
}
use of com.intellij.ui.awt.RelativePoint in project intellij-community by JetBrains.
the class SlideComponent method updateBalloonText.
private void updateBalloonText() {
final Point point = myVertical ? new Point(0, myPointerValue) : new Point(myPointerValue, 0);
myLabel.setText(myTitle + ": " + Unit.formatValue(myValue, myUnit));
if (myTooltipHint == null) {
myTooltipHint = new LightweightHint(myLabel);
myTooltipHint.setCancelOnClickOutside(false);
myTooltipHint.setCancelOnOtherWindowOpen(false);
final HintHint hint = new HintHint(this, point).setPreferredPosition(myVertical ? Balloon.Position.atLeft : Balloon.Position.above).setBorderColor(Color.BLACK).setAwtTooltip(true).setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD)).setTextBg(HintUtil.getInformationColor()).setShowImmediately(true);
final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
myTooltipHint.show(this, point.x, point.y, owner instanceof JComponent ? (JComponent) owner : null, hint);
} else {
myTooltipHint.setLocation(new RelativePoint(this, point));
}
}
use of com.intellij.ui.awt.RelativePoint in project intellij-community by JetBrains.
the class DockManagerImpl method createNewDockContainerFor.
public void createNewDockContainerFor(DockableContent content, RelativePoint point) {
DockContainer container = getFactory(content.getDockContainerType()).createContainer(content);
register(container);
final DockWindow window = createWindowFor(null, container);
Dimension size = content.getPreferredSize();
Point showPoint = point.getScreenPoint();
showPoint.x -= size.width / 2;
showPoint.y -= size.height / 2;
Rectangle target = new Rectangle(showPoint, size);
ScreenUtil.moveRectangleToFitTheScreen(target);
ScreenUtil.cropRectangleToFitTheScreen(target);
window.setLocation(target.getLocation());
window.myDockContentUiContainer.setPreferredSize(target.getSize());
window.show(false);
window.getFrame().pack();
container.add(content, new RelativePoint(target.getLocation()));
SwingUtilities.invokeLater(() -> window.myUiContainer.setPreferredSize(null));
}
Aggregations