use of java.awt.event.MouseEvent in project intellij-community by JetBrains.
the class CompareRevisionsFromHistoryAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getRequiredData(CommonDataKeys.PROJECT);
FileHistoryUi ui = e.getRequiredData(VcsLogInternalDataKeys.FILE_HISTORY_UI);
FilePath filePath = e.getRequiredData(VcsDataKeys.FILE_PATH);
if (e.getInputEvent() instanceof MouseEvent && ui.getTable().isResizingColumns()) {
// disable action during columns resize
return;
}
VcsLogUtil.triggerUsage(e);
List<CommitId> commits = ui.getVcsLog().getSelectedCommits();
if (commits.size() != 1 && commits.size() != 2)
return;
List<Integer> commitIds = ContainerUtil.map(commits, c -> ui.getLogData().getCommitIndex(c.getHash(), c.getRoot()));
ui.getLogData().getCommitDetailsGetter().loadCommitsData(commitIds, details -> {
if (details.size() == 2) {
VcsFileRevision newestRevision = ui.createRevision(details.get(0));
VcsFileRevision olderRevision = ui.createRevision(details.get(1));
if (olderRevision != null && newestRevision != null) {
myDiffHandler.showDiffForTwo(project, filePath, olderRevision, newestRevision);
}
} else if (details.size() == 1) {
VcsFullCommitDetails detail = ObjectUtils.notNull(ContainerUtil.getFirstItem(details));
List<Change> changes = ui.collectRelevantChanges(detail);
if (filePath.isDirectory()) {
VcsDiffUtil.showChangesDialog(project, "Changes in " + detail.getId().toShortString() + " for " + filePath.getName(), ContainerUtil.newArrayList(changes));
} else {
ShowDiffAction.showDiffForChange(project, changes, 0, new ShowDiffContext());
}
}
}, null);
}
use of java.awt.event.MouseEvent in project intellij-community by JetBrains.
the class ShortcutPromoterManager method beforeActionPerformed.
@Override
public void beforeActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
final InputEvent input = event.getInputEvent();
if (input instanceof MouseEvent) {
final String id = ActionManager.getInstance().getId(action);
final ShortcutPromoterEP ep = myExtensions.get(id);
if (ep != null) {
PromoterState state = myState.get(id);
if (state == null) {
state = new PromoterState();
myState.put(id, state);
}
state.incClicks();
}
}
}
use of java.awt.event.MouseEvent in project intellij-community by JetBrains.
the class FileEditorManagerImpl method isOpenInNewWindow.
private static boolean isOpenInNewWindow() {
AWTEvent event = IdeEventQueue.getInstance().getTrueCurrentEvent();
// Shift was used while clicking
if (event instanceof MouseEvent && ((MouseEvent) event).isShiftDown() && (event.getID() == MouseEvent.MOUSE_CLICKED || event.getID() == MouseEvent.MOUSE_PRESSED || event.getID() == MouseEvent.MOUSE_RELEASED)) {
return true;
}
if (event instanceof KeyEvent) {
KeyEvent ke = (KeyEvent) event;
Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
String[] ids = keymap.getActionIds(KeyStroke.getKeyStroke(ke.getKeyCode(), ke.getModifiers()));
return Arrays.asList(ids).contains("OpenElementInNewWindow");
}
return false;
}
use of java.awt.event.MouseEvent 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 java.awt.event.MouseEvent in project intellij-community by JetBrains.
the class IdeGlassPaneImpl method dispatch.
public boolean dispatch(@NotNull final AWTEvent e) {
JRootPane eventRootPane = myRootPane;
if (e instanceof MouseEvent) {
MouseEvent me = (MouseEvent) e;
Window eventWindow = UIUtil.getWindow(me.getComponent());
if (isContextMenu(eventWindow))
return false;
final Window thisGlassWindow = SwingUtilities.getWindowAncestor(myRootPane);
if (eventWindow instanceof JWindow) {
eventRootPane = ((JWindow) eventWindow).getRootPane();
if (eventRootPane != null) {
if (!(eventRootPane.getGlassPane() instanceof IdeGlassPane)) {
final Container parentWindow = eventWindow.getParent();
if (parentWindow instanceof Window) {
eventWindow = (Window) parentWindow;
}
}
}
}
if (eventWindow != thisGlassWindow)
return false;
}
if (e.getID() == MouseEvent.MOUSE_DRAGGED) {
if (ApplicationManager.getApplication() != null) {
IdeTooltipManager.getInstance().hideCurrent((MouseEvent) e);
}
}
boolean dispatched;
if (e.getID() == MouseEvent.MOUSE_PRESSED || e.getID() == MouseEvent.MOUSE_RELEASED || e.getID() == MouseEvent.MOUSE_CLICKED) {
dispatched = preprocess((MouseEvent) e, false, eventRootPane);
} else if (e.getID() == MouseEvent.MOUSE_MOVED || e.getID() == MouseEvent.MOUSE_DRAGGED) {
dispatched = preprocess((MouseEvent) e, true, eventRootPane);
} else if (e.getID() == MouseEvent.MOUSE_EXITED || e.getID() == MouseEvent.MOUSE_ENTERED) {
dispatched = preprocess((MouseEvent) e, false, eventRootPane);
} else {
return false;
}
MouseEvent me = (MouseEvent) e;
final Component meComponent = me.getComponent();
if (!dispatched && meComponent != null) {
final Window eventWindow = UIUtil.getWindow(meComponent);
if (eventWindow != SwingUtilities.getWindowAncestor(myRootPane)) {
return false;
}
int button1 = MouseEvent.BUTTON1_MASK | MouseEvent.BUTTON1_DOWN_MASK;
final boolean pureMouse1Event = (me.getModifiersEx() | button1) == button1;
if (pureMouse1Event && me.getClickCount() <= 1 && !me.isPopupTrigger()) {
final Point point = SwingUtilities.convertPoint(meComponent, me.getPoint(), myRootPane.getContentPane());
JMenuBar menuBar = myRootPane.getJMenuBar();
point.y += menuBar != null ? menuBar.getHeight() : 0;
final Component target = SwingUtilities.getDeepestComponentAt(myRootPane.getContentPane().getParent(), point.x, point.y);
if (target instanceof DnDAware) {
final Point targetPoint = SwingUtilities.convertPoint(myRootPane.getContentPane().getParent(), point.x, point.y, target);
final boolean overSelection = ((DnDAware) target).isOverSelection(targetPoint);
if (overSelection) {
final MouseListener[] listeners = target.getListeners(MouseListener.class);
final MouseEvent mouseEvent = MouseEventAdapter.convert(me, target);
switch(me.getID()) {
case MouseEvent.MOUSE_PRESSED:
boolean consumed = false;
if (target.isFocusable()) {
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(target, true);
});
}
for (final MouseListener listener : listeners) {
final String className = listener.getClass().getName();
if (className.indexOf("BasicTreeUI$") >= 0 || className.indexOf("MacTreeUI$") >= 0)
continue;
fireMouseEvent(listener, mouseEvent);
if (mouseEvent.isConsumed()) {
consumed = true;
break;
}
}
if (!mouseEvent.isConsumed()) {
final AWTEventListener[] eventListeners = Toolkit.getDefaultToolkit().getAWTEventListeners(MouseEvent.MOUSE_EVENT_MASK);
if (eventListeners != null && eventListeners.length > 0) {
for (final AWTEventListener eventListener : eventListeners) {
eventListener.eventDispatched(me);
if (me.isConsumed())
break;
}
if (me.isConsumed()) {
consumed = true;
break;
}
}
}
if (!consumed) {
myPrevPressEvent = mouseEvent;
} else {
me.consume();
}
dispatched = true;
break;
case MouseEvent.MOUSE_RELEASED:
if (myPrevPressEvent != null && myPrevPressEvent.getComponent() == target) {
for (final MouseListener listener : listeners) {
final String className = listener.getClass().getName();
if (className.indexOf("BasicTreeUI$") >= 0 || className.indexOf("MacTreeUI$") >= 0) {
fireMouseEvent(listener, myPrevPressEvent);
fireMouseEvent(listener, mouseEvent);
if (mouseEvent.isConsumed()) {
break;
}
}
fireMouseEvent(listener, mouseEvent);
if (mouseEvent.isConsumed()) {
break;
}
}
if (mouseEvent.isConsumed()) {
me.consume();
}
myPrevPressEvent = null;
dispatched = true;
}
break;
default:
myPrevPressEvent = null;
break;
}
}
}
}
}
if (isVisible() && getComponentCount() == 0) {
boolean cursorSet = false;
if (meComponent != null) {
final Point point = SwingUtilities.convertPoint(meComponent, me.getPoint(), myRootPane.getContentPane());
if (myRootPane.getMenuBar() != null && myRootPane.getMenuBar().isVisible()) {
point.y += myRootPane.getMenuBar().getHeight();
}
final Component target = SwingUtilities.getDeepestComponentAt(myRootPane.getContentPane().getParent(), point.x, point.y);
if (target != null) {
setCursor(target.getCursor());
cursorSet = true;
}
}
if (!cursorSet) {
setCursor(Cursor.getDefaultCursor());
}
}
return dispatched;
}
Aggregations