use of com.intellij.openapi.ui.popup.Balloon in project intellij-community by JetBrains.
the class DiffUtil method showSuccessPopup.
public static void showSuccessPopup(@NotNull String message, @NotNull RelativePoint point, @NotNull Disposable disposable, @Nullable Runnable hyperlinkHandler) {
HyperlinkListener listener = null;
if (hyperlinkHandler != null) {
listener = new HyperlinkAdapter() {
@Override
protected void hyperlinkActivated(HyperlinkEvent e) {
hyperlinkHandler.run();
}
};
}
Color bgColor = MessageType.INFO.getPopupBackground();
Balloon balloon = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(message, null, bgColor, listener).setAnimationCycle(200).createBalloon();
balloon.show(point, Balloon.Position.below);
Disposer.register(disposable, balloon);
}
use of com.intellij.openapi.ui.popup.Balloon in project intellij-community by JetBrains.
the class IdeGlassPaneImpl method preprocess.
private boolean preprocess(final MouseEvent e, final boolean motion, JRootPane eventRootPane) {
try {
if (UIUtil.getWindow(this) != UIUtil.getWindow(e.getComponent()))
return false;
final MouseEvent event = MouseEventAdapter.convert(e, eventRootPane);
if (event.isAltDown() && SwingUtilities.isLeftMouseButton(event) && event.getID() == MouseEvent.MOUSE_PRESSED) {
Component c = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY());
Balloon balloon = JBPopupFactory.getInstance().getParentBalloonFor(c);
if (balloon instanceof BalloonImpl) {
JComponent component = ((BalloonImpl) balloon).getComponent();
component.getToolkit().getSystemClipboard().setContents(new StringSelection(UIUtil.getDebugText(component)), EmptyClipboardOwner.INSTANCE);
}
}
if (!IdeGlassPaneUtil.canBePreprocessed(e)) {
return false;
}
for (EventListener each : mySortedMouseListeners) {
if (motion && each instanceof MouseMotionListener) {
fireMouseMotion((MouseMotionListener) each, event);
} else if (!motion && each instanceof MouseListener) {
fireMouseEvent((MouseListener) each, event);
}
if (event.isConsumed()) {
e.consume();
return true;
}
}
return false;
} finally {
if (eventRootPane == myRootPane) {
Cursor cursor;
if (!myListener2Cursor.isEmpty()) {
cursor = myListener2Cursor.values().iterator().next();
final Point point = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), myRootPane.getContentPane());
Component target = SwingUtilities.getDeepestComponentAt(myRootPane.getContentPane().getParent(), point.x, point.y);
if (canProcessCursorFor(target)) {
target = getCompWithCursor(target);
restoreLastComponent(target);
if (target != null) {
if (myLastCursorComponent != target) {
myLastCursorComponent = target;
myLastOriginalCursor = target.getCursor();
}
if (cursor != null && !cursor.equals(target.getCursor())) {
if (target instanceof JComponent) {
((JComponent) target).putClientProperty(PREPROCESSED_CURSOR_KEY, Boolean.TRUE);
}
target.setCursor(cursor);
}
}
getRootPane().setCursor(cursor);
}
} else if (!e.isConsumed() && e.getID() != MouseEvent.MOUSE_DRAGGED) {
cursor = Cursor.getDefaultCursor();
JRootPane rootPane = getRootPane();
if (rootPane != null) {
rootPane.setCursor(cursor);
} else {
LOG.warn("Root pane is null. Event: " + e);
}
restoreLastComponent(null);
myLastOriginalCursor = null;
myLastCursorComponent = null;
}
myListener2Cursor.clear();
}
}
}
use of com.intellij.openapi.ui.popup.Balloon 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.openapi.ui.popup.Balloon in project intellij-community by JetBrains.
the class SearchForUsagesRunnable method searchUsages.
private void searchUsages(@NotNull final AtomicBoolean findStartedBalloonShown) {
ProgressIndicator indicator = ProgressWrapper.unwrap(ProgressManager.getInstance().getProgressIndicator());
assert indicator != null : "must run find usages under progress";
TooManyUsagesStatus.createFor(indicator);
Alarm findUsagesStartedBalloon = new Alarm();
findUsagesStartedBalloon.addRequest(() -> {
notifyByFindBalloon(null, MessageType.WARNING, myProcessPresentation, myProject, Collections.singletonList(StringUtil.escapeXml(UsageViewManagerImpl.getProgressTitle(myPresentation))));
findStartedBalloonShown.set(true);
}, 300, ModalityState.NON_MODAL);
UsageSearcher usageSearcher = mySearcherFactory.create();
usageSearcher.generate(usage -> {
ProgressIndicator indicator1 = ProgressWrapper.unwrap(ProgressManager.getInstance().getProgressIndicator());
assert indicator1 != null : "must run find usages under progress";
if (indicator1.isCanceled())
return false;
if (!UsageViewManagerImpl.isInScope(usage, mySearchScopeToWarnOfFallingOutOf)) {
myOutOfScopeUsages.incrementAndGet();
return true;
}
boolean incrementCounter = !UsageViewManager.isSelfUsage(usage, mySearchFor);
if (incrementCounter) {
final int usageCount = myUsageCountWithoutDefinition.incrementAndGet();
if (usageCount == 1 && !myProcessPresentation.isShowPanelIfOnlyOneUsage()) {
myFirstUsage.compareAndSet(null, usage);
}
final UsageViewImpl usageView = getUsageView(indicator1);
TooManyUsagesStatus tooManyUsagesStatus = TooManyUsagesStatus.getFrom(indicator1);
if (usageCount > UsageLimitUtil.USAGES_LIMIT && tooManyUsagesStatus.switchTooManyUsagesStatus()) {
UsageViewManagerImpl.showTooManyUsagesWarning(myProject, tooManyUsagesStatus, indicator1, myPresentation, usageCount, usageView);
}
tooManyUsagesStatus.pauseProcessingIfTooManyUsages();
if (usageView != null) {
ApplicationManager.getApplication().runReadAction(() -> usageView.appendUsage(usage));
}
}
return !indicator1.isCanceled();
});
if (getUsageView(indicator) != null) {
ApplicationManager.getApplication().invokeLater(() -> myUsageViewManager.showToolWindow(true), myProject.getDisposed());
}
Disposer.dispose(findUsagesStartedBalloon);
ApplicationManager.getApplication().invokeLater(() -> {
if (findStartedBalloonShown.get()) {
Balloon balloon = ToolWindowManager.getInstance(myProject).getToolWindowBalloon(ToolWindowId.FIND);
if (balloon != null) {
balloon.hide();
}
}
}, myProject.getDisposed());
}
use of com.intellij.openapi.ui.popup.Balloon in project intellij-community by JetBrains.
the class BalloonImpl method createComponent.
private void createComponent() {
myComp = new MyComponent(myContent, this, myShadowBorderProvider != null ? null : myShowPointer ? myPosition.createBorder(this) : getPointlessBorder());
if (myActionProvider == null) {
final Consumer<MouseEvent> listener = event -> {
SwingUtilities.invokeLater(() -> hide());
};
myActionProvider = new ActionProvider() {
private ActionButton myCloseButton;
@NotNull
@Override
public List<ActionButton> createActions() {
myCloseButton = new CloseButton(listener);
return Collections.singletonList(myCloseButton);
}
@Override
public void layout(@NotNull Rectangle lpBounds) {
if (!myCloseButton.isVisible()) {
return;
}
Icon icon = getCloseButton();
int iconWidth = icon.getIconWidth();
int iconHeight = icon.getIconHeight();
Rectangle r = new Rectangle(lpBounds.x + lpBounds.width - iconWidth + (int) (iconWidth * 0.3), lpBounds.y - (int) (iconHeight * 0.3), iconWidth, iconHeight);
Insets border = getShadowBorderInsets();
r.x -= border.left;
r.y -= border.top;
myCloseButton.setBounds(r);
}
};
}
myComp.clear();
myComp.myAlpha = isAnimationEnabled() ? 0f : -1;
myComp.setBorder(new EmptyBorder(getShadowBorderInsets()));
myLayeredPane.add(myComp);
// the second balloon must be over the first one
myLayeredPane.setLayer(myComp, getLayer(), 0);
myPosition.updateBounds(this);
if (myBlockClicks) {
myComp.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
e.consume();
}
@Override
public void mousePressed(MouseEvent e) {
e.consume();
}
@Override
public void mouseReleased(MouseEvent e) {
e.consume();
}
});
}
}
Aggregations