use of com.intellij.openapi.wm.impl.FocusManagerImpl in project intellij-community by JetBrains.
the class MacMessagesTest method actionPerformed.
@Override
public void actionPerformed(final AnActionEvent anActionEvent) {
JDialog controlDialog = new JDialog();
controlDialog.setTitle("Messages testing control panel");
controlDialog.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
controlDialog.setModal(false);
controlDialog.setFocusableWindowState(false);
controlDialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
Container cp = controlDialog.getContentPane();
cp.setLayout(new FlowLayout());
JButton showDialogWrapperButton = new JButton("Show a dialog wrapper");
showDialogWrapperButton.setFocusable(false);
FocusManagerImpl fmi = FocusManagerImpl.getInstance();
final Project p = fmi.getLastFocusedFrame().getProject();
showDialogWrapperButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
DialogWrapper dw = new SimpleDialogWrapper(p);
dw.setTitle(dw.getWindow().getName());
dw.show();
}
});
JButton showMessageButton = new JButton("Show a message");
showDialogWrapperButton.setFocusable(false);
showMessageButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
showTestMessage(p);
}
});
JButton showProgressIndicatorButton = new JButton("Show progress indicator");
showProgressIndicatorButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final Task task = new Task.Modal(null, "Test task", true) {
public void run(@NotNull final ProgressIndicator indicator) {
ApplicationManager.getApplication().invokeAndWait(() -> {
FocusManagerImpl fmi1 = FocusManagerImpl.getInstance();
final Project p1 = fmi1.getLastFocusedFrame().getProject();
showTestMessage(p1);
}, ModalityState.any());
}
@Override
public void onCancel() {
}
};
ProgressManager.getInstance().run(task);
}
});
cp.add(showDialogWrapperButton);
cp.add(showMessageButton);
cp.add(showProgressIndicatorButton);
controlDialog.pack();
controlDialog.setVisible(true);
}
use of com.intellij.openapi.wm.impl.FocusManagerImpl in project intellij-community by JetBrains.
the class IdeMouseEventDispatcher method dispatchMouseEvent.
/**
* @return {@code true} if and only if the passed event is already dispatched by the
* {@code IdeMouseEventDispatcher} and there is no need for any other processing of the event.
* If the method returns {@code false} then it means that the event should be delivered
* to normal event dispatching.
*/
public boolean dispatchMouseEvent(MouseEvent e) {
Component c = e.getComponent();
//frame activation by mouse click
if (e.getID() == MOUSE_PRESSED && c instanceof IdeFrame && !c.hasFocus()) {
IdeFocusManager focusManager = IdeFocusManager.getGlobalInstance();
if (focusManager instanceof FocusManagerImpl) {
Component at = SwingUtilities.getDeepestComponentAt(c, e.getX(), e.getY());
if (at != null && at.isFocusable()) {
((FocusManagerImpl) focusManager).setLastFocusedAtDeactivation((IdeFrame) c, at);
}
}
}
if (e.isPopupTrigger()) {
if (BUTTON3 == e.getButton()) {
if (Registry.is("ide.mouse.popup.trigger.modifiers.disabled") && (~BUTTON3_DOWN_MASK & e.getModifiersEx()) != 0) {
// it allows to use our mouse shortcuts for Ctrl+Button3, for example
resetPopupTrigger(e);
}
} else if (SystemInfo.isXWindow) {
// we can do better than silly triggering popup on everything but left click
resetPopupTrigger(e);
}
}
boolean ignore = false;
if (!(e.getID() == MOUSE_PRESSED || e.getID() == MOUSE_RELEASED || e.getID() == MOUSE_WHEEL && 0 < e.getModifiersEx() || e.getID() == MOUSE_CLICKED)) {
ignore = true;
}
patchClickCount(e);
int clickCount = e.getClickCount();
int button = MouseShortcut.getButton(e);
if (button == MouseShortcut.BUTTON_WHEEL_UP || button == MouseShortcut.BUTTON_WHEEL_DOWN) {
clickCount = 1;
}
if (e.isConsumed() || e.isPopupTrigger() || (button > 3 ? e.getID() != MOUSE_PRESSED && e.getID() != MOUSE_WHEEL : e.getID() != MOUSE_RELEASED) || clickCount < 1 || button == NOBUTTON) {
// See #16995. It did happen
ignore = true;
}
@JdkConstants.InputEventMask int modifiers = e.getModifiers();
@JdkConstants.InputEventMask int modifiersEx = e.getModifiersEx();
if (e.getID() == MOUSE_PRESSED) {
myPressedModifiersStored = true;
myModifiers = modifiers;
myModifiersEx = modifiersEx;
} else if (e.getID() == MOUSE_RELEASED) {
myForceTouchIsAllowed = true;
if (myPressedModifiersStored) {
myPressedModifiersStored = false;
modifiers = myModifiers;
modifiersEx = myModifiersEx;
}
}
final JRootPane root = findRoot(e);
if (root != null) {
BlockState blockState = myRootPane2BlockedId.get(root);
if (blockState != null) {
if (SWING_EVENTS_PRIORITY.indexOf(blockState.currentEventId) < SWING_EVENTS_PRIORITY.indexOf(e.getID())) {
blockState.currentEventId = e.getID();
if (blockState.blockMode == IdeEventQueue.BlockMode.COMPLETE) {
return true;
} else {
ignore = true;
}
} else {
myRootPane2BlockedId.remove(root);
}
}
}
if (c == null) {
throw new IllegalStateException("component cannot be null");
}
c = SwingUtilities.getDeepestComponentAt(c, e.getX(), e.getY());
if (c instanceof IdeGlassPaneImpl) {
c = ((IdeGlassPaneImpl) c).getTargetComponentFor(e);
}
if (c == null) {
// do nothing if component doesn't contains specified point
return false;
}
if (c instanceof MouseShortcutPanel || c.getParent() instanceof MouseShortcutPanel) {
// forward mouse processing to the special shortcut panel
return false;
}
if (isHorizontalScrolling(c, e)) {
boolean done = doHorizontalScrolling(c, (MouseWheelEvent) e);
if (done)
return true;
}
if (ignore)
return false;
// avoid "cyclic component initialization error" in case of dialogs shown because of component initialization failure
if (!KeymapManagerImpl.ourKeymapManagerInitialized) {
return false;
}
final MouseShortcut shortcut = new MouseShortcut(button, modifiersEx, clickCount);
fillActionsList(c, shortcut, IdeKeyEventDispatcher.isModalContext(c));
ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
if (actionManager != null) {
AnAction[] actions = myActions.toArray(new AnAction[myActions.size()]);
for (AnAction action : actions) {
DataContext dataContext = DataManager.getInstance().getDataContext(c);
Presentation presentation = myPresentationFactory.getPresentation(action);
AnActionEvent actionEvent = new AnActionEvent(e, dataContext, ActionPlaces.MAIN_MENU, presentation, ActionManager.getInstance(), modifiers);
if (ActionUtil.lastUpdateAndCheckDumb(action, actionEvent, false)) {
actionManager.fireBeforeActionPerformed(action, dataContext, actionEvent);
final Component context = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);
if (context != null && !context.isShowing())
continue;
ActionUtil.performActionDumbAware(action, actionEvent);
actionManager.fireAfterActionPerformed(action, dataContext, actionEvent);
e.consume();
}
}
}
return e.getButton() > 3;
}
use of com.intellij.openapi.wm.impl.FocusManagerImpl in project intellij-community by JetBrains.
the class IdeEventQueue method storeLastFocusedComponent.
private static void storeLastFocusedComponent(@NotNull WindowEvent we) {
final Window eventWindow = we.getWindow();
if (we.getID() == WindowEvent.WINDOW_DEACTIVATED || we.getID() == WindowEvent.WINDOW_LOST_FOCUS) {
Component frame = UIUtil.findUltimateParent(eventWindow);
Component focusOwnerInDeactivatedWindow = eventWindow.getMostRecentFocusOwner();
IdeFrame[] allProjectFrames = WindowManager.getInstance().getAllProjectFrames();
if (focusOwnerInDeactivatedWindow != null) {
for (IdeFrame ideFrame : allProjectFrames) {
JFrame aFrame = WindowManager.getInstance().getFrame(ideFrame.getProject());
if (aFrame.equals(frame)) {
IdeFocusManager focusManager = IdeFocusManager.getGlobalInstance();
if (focusManager instanceof FocusManagerImpl) {
((FocusManagerImpl) focusManager).setLastFocusedAtDeactivation(ideFrame, focusOwnerInDeactivatedWindow);
}
}
}
}
}
}
use of com.intellij.openapi.wm.impl.FocusManagerImpl in project intellij-community by JetBrains.
the class FocusTracesAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = e.getData(CommonDataKeys.PROJECT);
final IdeFocusManager manager = IdeFocusManager.getGlobalInstance();
if (!(manager instanceof FocusManagerImpl))
return;
final FocusManagerImpl focusManager = (FocusManagerImpl) manager;
myActive = !myActive;
if (myActive) {
myFocusTracker = new AWTEventListener() {
@Override
public void eventDispatched(AWTEvent event) {
if (event instanceof FocusEvent && event.getID() == FocusEvent.FOCUS_GAINED) {
focusManager.recordFocusRequest(((FocusEvent) event).getComponent(), false);
}
}
};
Toolkit.getDefaultToolkit().addAWTEventListener(myFocusTracker, AWTEvent.FOCUS_EVENT_MASK);
}
if (!myActive) {
final List<FocusRequestInfo> requests = focusManager.getRequests();
new FocusTracesDialog(project, new ArrayList<>(requests)).show();
Toolkit.getDefaultToolkit().removeAWTEventListener(myFocusTracker);
myFocusTracker = null;
requests.clear();
}
}
Aggregations