use of java.awt.event.MouseEvent in project intellij-community by JetBrains.
the class PopupDispatcher method dispatchMouseEvent.
private boolean dispatchMouseEvent(AWTEvent event) {
if (event.getID() != MouseEvent.MOUSE_PRESSED) {
return false;
}
if (ourShowingStep == null) {
return false;
}
WizardPopup eachParent = ourShowingStep;
final MouseEvent mouseEvent = ((MouseEvent) event);
Point point = (Point) mouseEvent.getPoint().clone();
SwingUtilities.convertPointToScreen(point, mouseEvent.getComponent());
while (true) {
JComponent content = eachParent.getContent();
if (content == null || !content.isShowing()) {
getActiveRoot().cancel();
return false;
}
if (eachParent.getBounds().contains(point) || !eachParent.canClose()) {
return false;
}
eachParent = eachParent.getParent();
if (eachParent == null) {
getActiveRoot().cancel();
return false;
}
}
}
use of java.awt.event.MouseEvent in project intellij-community by JetBrains.
the class StackingPopupDispatcherImpl method dispatchMouseEvent.
@Override
protected boolean dispatchMouseEvent(AWTEvent event) {
if (event.getID() != MouseEvent.MOUSE_PRESSED) {
return false;
}
if (myStack.isEmpty()) {
return false;
}
AbstractPopup popup = (AbstractPopup) findPopup();
final MouseEvent mouseEvent = (MouseEvent) event;
Point point = (Point) mouseEvent.getPoint().clone();
SwingUtilities.convertPointToScreen(point, mouseEvent.getComponent());
while (true) {
if (popup != null && !popup.isDisposed()) {
final Component content = popup.getContent();
if (!content.isShowing()) {
popup.cancel();
return false;
}
final Rectangle bounds = new Rectangle(content.getLocationOnScreen(), content.getSize());
if (bounds.contains(point) || !popup.isCancelOnClickOutside()) {
return false;
}
if (!popup.canClose()) {
return false;
}
//click on context menu item
if (MenuSelectionManager.defaultManager().getSelectedPath().length > 0) {
return false;
}
popup.cancel(mouseEvent);
}
if (myStack.isEmpty()) {
return false;
}
popup = (AbstractPopup) myStack.peek();
if (popup == null || popup.isDisposed()) {
myStack.pop();
}
}
}
use of java.awt.event.MouseEvent in project intellij-community by JetBrains.
the class IdeFrameFixture method invokeMainMenu.
/**
* Invokes an action from main menu
*
* @param mainMenuAction is the typical AnAction with ActionPlaces.MAIN_MENU
*/
public void invokeMainMenu(@NotNull String mainMenuActionId) {
ActionManager actionManager = ActionManager.getInstance();
AnAction mainMenuAction = actionManager.getAction(mainMenuActionId);
JMenuBar jMenuBar = this.target().getRootPane().getJMenuBar();
MouseEvent fakeMainMenuMouseEvent = new MouseEvent(jMenuBar, MouseEvent.MOUSE_CLICKED, System.currentTimeMillis(), 0, MouseInfo.getPointerInfo().getLocation().x, MouseInfo.getPointerInfo().getLocation().y, 1, false);
ApplicationManager.getApplication().invokeLater(() -> actionManager.tryToExecute(mainMenuAction, fakeMainMenuMouseEvent, null, ActionPlaces.MAIN_MENU, true));
}
use of java.awt.event.MouseEvent in project intellij-community by JetBrains.
the class ClickListener method installOn.
public void installOn(@NotNull Component c) {
myListener = new MouseAdapter() {
private Point pressPoint;
private Point lastClickPoint;
private long lastTimeClicked = -1;
private int clickCount = 0;
@Override
public void mousePressed(MouseEvent e) {
final Point point = e.getPoint();
SwingUtilities.convertPointToScreen(point, e.getComponent());
if (Math.abs(lastTimeClicked - e.getWhen()) > UIUtil.getMultiClickInterval() || lastClickPoint != null && !isWithinEps(lastClickPoint, point)) {
clickCount = 0;
lastClickPoint = null;
}
clickCount++;
lastTimeClicked = e.getWhen();
if (!e.isPopupTrigger()) {
pressPoint = point;
}
}
@Override
public void mouseReleased(MouseEvent e) {
Point releasedAt = e.getPoint();
SwingUtilities.convertPointToScreen(releasedAt, e.getComponent());
Point clickedAt = pressPoint;
lastClickPoint = clickedAt;
pressPoint = null;
if (e.isConsumed() || clickedAt == null || e.isPopupTrigger() || !e.getComponent().contains(e.getPoint())) {
return;
}
if (isWithinEps(releasedAt, clickedAt) && onClick(e, clickCount)) {
e.consume();
}
}
};
c.addMouseListener(myListener);
}
use of java.awt.event.MouseEvent in project intellij-community by JetBrains.
the class LineTooltipRenderer method show.
@Override
public LightweightHint show(@NotNull final Editor editor, @NotNull final Point p, final boolean alignToRight, @NotNull final TooltipGroup group, @NotNull final HintHint hintHint) {
if (myText == null)
return null;
//setup text
myText = myText.replaceAll(String.valueOf(UIUtil.MNEMONIC), "");
final boolean expanded = myCurrentWidth > 0 && dressDescription(editor);
final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
final JComponent contentComponent = editor.getContentComponent();
final JComponent editorComponent = editor.getComponent();
if (!editorComponent.isShowing())
return null;
final JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();
final JEditorPane pane = IdeTooltipManager.initPane(new Html(myText).setKeepFont(true), hintHint, layeredPane);
hintHint.setContentActive(isActiveHtml(myText));
if (!hintHint.isAwtTooltip()) {
correctLocation(editor, pane, p, alignToRight, expanded, myCurrentWidth);
}
final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(pane);
scrollPane.setBorder(null);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setOpaque(hintHint.isOpaqueAllowed());
scrollPane.getViewport().setOpaque(hintHint.isOpaqueAllowed());
scrollPane.setBackground(hintHint.getTextBackground());
scrollPane.getViewport().setBackground(hintHint.getTextBackground());
scrollPane.setViewportBorder(null);
if (hintHint.isRequestFocus()) {
pane.setFocusable(true);
}
final Ref<AnAction> actionRef = new Ref<>();
final LightweightHint hint = new LightweightHint(scrollPane) {
@Override
public void hide() {
onHide(pane);
super.hide();
final AnAction action = actionRef.get();
if (action != null) {
action.unregisterCustomShortcutSet(contentComponent);
}
}
};
actionRef.set(new AnAction() {
// an action to expand description when tooltip was shown after mouse move; need to unregister from editor component
{
registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_SHOW_ERROR_DESCRIPTION)), contentComponent);
}
@Override
public void actionPerformed(final AnActionEvent e) {
// The tooltip gets the focus if using a screen reader and invocation through a keyboard shortcut.
hintHint.setRequestFocus(ScreenReader.isActive() && (e.getInputEvent() instanceof KeyEvent));
expand(hint, editor, p, pane, alignToRight, group, hintHint);
}
});
pane.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(final HyperlinkEvent e) {
myActiveLink = true;
if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
myActiveLink = false;
return;
}
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
final URL url = e.getURL();
if (url != null) {
BrowserUtil.browse(url);
hint.hide();
return;
}
final String description = e.getDescription();
if (description != null && handle(description, editor)) {
hint.hide();
return;
}
if (!expanded) {
expand(hint, editor, p, pane, alignToRight, group, hintHint);
} else {
stripDescription();
hint.hide();
TooltipController.getInstance().showTooltip(editor, new Point(p.x - 3, p.y - 3), createRenderer(myText, 0), false, group, hintHint);
}
}
}
});
// This listener makes hint transparent for mouse events. It means that hint is closed
// by MousePressed and this MousePressed goes into the underlying editor component.
pane.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(final MouseEvent e) {
if (!myActiveLink) {
MouseEvent newMouseEvent = SwingUtilities.convertMouseEvent(e.getComponent(), e, contentComponent);
hint.hide();
contentComponent.dispatchEvent(newMouseEvent);
}
}
@Override
public void mouseExited(final MouseEvent e) {
if (!expanded) {
hint.hide();
}
}
});
hintManager.showEditorHint(hint, editor, p, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_OTHER_HINT | HintManager.HIDE_BY_SCROLLING, 0, false, hintHint);
return hint;
}
Aggregations